25#include "llvm/Config/llvm-config.h"
42#define LIBC_NAMESPACE __llvm_libc_apfloat
43#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
45#include "shared/math.h"
46#include "shared/math_check_exceptions.h"
48#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
50 if (usesLayout<IEEEFloat>(getSemantics())) \
51 return U.IEEE.METHOD_CALL; \
52 if (usesLayout<DoubleAPFloat>(getSemantics())) \
53 return U.Double.METHOD_CALL; \
54 llvm_unreachable("Unexpected semantics"); \
65#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
73constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
74constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
75constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
76constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
77constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
78constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
81constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
86constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
88constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
89constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
119constexpr fltSemantics APFloatBase::semX87DoubleExtended = {
131constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
132constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
133constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
134 1023, -1022 + 53, 53 + 53, 128};
234 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
235 A.precision <=
B.precision;
247 if (&From == &semPPCDoubleDouble || &To == &semPPCDoubleDouble)
263 if (FromHasSignedZero && !ToHasSignedZero)
270 bool LosesInfo =
false;
382 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
390 return Dst.precision >= Src.precision;
430static inline unsigned int
443 const unsigned int overlargeExponent = 24000;
447 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
450 bool isNegative = *p ==
'-';
451 if (*p ==
'-' || *p ==
'+') {
458 if (absExponent >= 10U)
459 return createError(
"Invalid character in exponent");
461 for (; p != end; ++p) {
464 return createError(
"Invalid character in exponent");
466 absExponent = absExponent * 10U + value;
467 if (absExponent >= overlargeExponent) {
468 absExponent = overlargeExponent;
474 return -(int) absExponent;
476 return (
int) absExponent;
483 int exponentAdjustment) {
489 bool negative = *p ==
'-';
490 if (*p ==
'-' || *p ==
'+') {
496 int unsignedExponent = 0;
497 bool overflow =
false;
498 for (; p != end; ++p) {
503 return createError(
"Invalid character in exponent");
505 unsignedExponent = unsignedExponent * 10 + value;
506 if (unsignedExponent > 32767) {
512 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
516 exponent = unsignedExponent;
518 exponent = -exponent;
519 exponent += exponentAdjustment;
520 if (exponent > 32767 || exponent < -32768)
525 exponent = negative ? -32768: 32767;
535 while (p != end && *p ==
'0')
538 if (p != end && *p ==
'.') {
541 if (end - begin == 1)
544 while (p != end && *p ==
'0')
577 return PtrOrErr.takeError();
580 D->firstSigDigit = p;
582 D->normalizedExponent = 0;
584 for (; p != end; ++p) {
587 return createError(
"String contains multiple dots");
597 if (*p !=
'e' && *p !=
'E')
598 return createError(
"Invalid character in significand");
601 if (dot != end && p - begin == 1)
607 return ExpOrErr.takeError();
608 D->exponent = *ExpOrErr;
616 if (p !=
D->firstSigDigit) {
622 while (p != begin && *p ==
'0');
623 while (p != begin && *p ==
'.');
628 D->normalizedExponent = (
D->exponent +
630 - (dot >
D->firstSigDigit && dot < p)));
642 unsigned int digitValue) {
647 else if (digitValue < 8 && digitValue > 0)
651 while (p != end && (*p ==
'0' || *p ==
'.'))
655 return createError(
"Invalid trailing hexadecimal fraction!");
661 if (hexDigit == UINT_MAX)
671 unsigned int partCount,
696 return lost_fraction;
711 return moreSignificant;
722HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
724 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
726 if (HUerr1 + HUerr2 == 0)
727 return inexactMultiply * 2;
729 return inexactMultiply + 2 * (HUerr1 + HUerr2);
755 if (part - boundary <= boundary - part)
756 return part - boundary;
758 return boundary - part;
761 if (part == boundary) {
767 }
else if (part == boundary - 1) {
779 19, 38, 75, 149, 298};
797 1, 5, 25, 125, 625, 3125, 15625, 78125};
808 *p1 = firstEightPowers[power & 7];
814 for (
unsigned int n = 0; power; power >>= 1, n++) {
821 result += partsCount;
822 if (p2[result - 1] == 0)
847static const char NaNL[] =
"nan";
848static const char NaNU[] =
"NAN";
855 const char *hexDigitChars)
857 unsigned int result =
count;
863 dst[
count] = hexDigitChars[part & 0xf];
903 switch (
X.getCategory()) {
913 if (
X.isDenormal() ||
X.isSmallestNormalized())
916 if (
X.getExactLog2() != INT_MIN)
924void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
925 semantics = ourSemantics;
926 unsigned count = partCount();
931void IEEEFloat::freeSignificand() {
933 delete [] significand.parts;
936void IEEEFloat::assign(
const IEEEFloat &rhs) {
937 assert(semantics == rhs.semantics);
940 category = rhs.category;
941 exponent = rhs.exponent;
943 copySignificand(rhs);
946void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
948 assert(rhs.partCount() >= partCount());
961 if (Negative && !semantics->hasSignedRepr)
963 "This floating point format does not support signed values");
967 exponent = exponentNaN();
970 unsigned numParts = partCount();
983 fill = &fill_storage;
987 if (!
fill ||
fill->getNumWords() < numParts)
991 std::min(
fill->getNumWords(), numParts));
994 unsigned bitsToPreserve = semantics->precision - 1;
995 unsigned part = bitsToPreserve / 64;
996 bitsToPreserve %= 64;
997 significand[part] &= ((1ULL << bitsToPreserve) - 1);
998 for (part++; part != numParts; ++part)
999 significand[part] = 0;
1003 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
1025 if (semantics == &APFloatBase::semX87DoubleExtended)
1031 if (semantics != rhs.semantics) {
1033 initialize(rhs.semantics);
1044 semantics = rhs.semantics;
1045 significand = rhs.significand;
1046 exponent = rhs.exponent;
1047 category = rhs.category;
1050 rhs.semantics = &APFloatBase::semBogus;
1056 (exponent == semantics->minExponent) &&
1066 significandMSB() == 0;
1071 isSignificandAllZerosExceptMSB();
1074unsigned int IEEEFloat::getNumHighBits()
const {
1081 const unsigned int NumHighBits = (semantics->
precision > 1)
1087bool IEEEFloat::isSignificandAllOnes()
const {
1092 for (
unsigned i = 0; i < PartCount - 1; i++)
1097 const unsigned NumHighBits = getNumHighBits();
1098 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1099 "Can not have more high bits to fill than integerPartWidth");
1102 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
1108bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1117 for (
unsigned i = 0; i < PartCount - 1; i++) {
1118 if (~Parts[i] & ~
unsigned{!i})
1123 const unsigned NumHighBits = getNumHighBits();
1124 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1125 "Can not have more high bits to fill than integerPartWidth");
1128 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1134bool IEEEFloat::isSignificandAllZeros()
const {
1140 for (
unsigned i = 0; i < PartCount - 1; i++)
1145 const unsigned NumHighBits = getNumHighBits();
1147 "clear than integerPartWidth");
1148 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1150 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1156bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1160 for (
unsigned i = 0; i < PartCount - 1; i++) {
1165 const unsigned NumHighBits = getNumHighBits();
1168 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1172 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1179 ? isSignificandAllOnesExceptLSB()
1184 return IsMaxExp && isSignificandAllOnes();
1199 if (semantics != rhs.semantics ||
1200 category != rhs.category ||
1209 return std::equal(significandParts(), significandParts() + partCount(),
1210 rhs.significandParts());
1214 initialize(&ourSemantics);
1219 significandParts()[0] =
value;
1224 initialize(&ourSemantics);
1240 initialize(rhs.semantics);
1245 *
this = std::move(rhs);
1250unsigned int IEEEFloat::partCount()
const {
1255 return const_cast<IEEEFloat *
>(
this)->significandParts();
1259 if (partCount() > 1)
1260 return significand.parts;
1262 return &significand.part;
1265void IEEEFloat::zeroSignificand() {
1270void IEEEFloat::incrementSignificand() {
1282 assert(semantics == rhs.semantics);
1283 assert(exponent == rhs.exponent);
1285 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1294 assert(semantics == rhs.semantics);
1295 assert(exponent == rhs.exponent);
1306 bool ignoreAddend) {
1310 assert(semantics == rhs.semantics);
1312 unsigned precision = semantics->precision;
1320 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1323 unsigned partsCount = partCount();
1326 rhs.significandParts(), partsCount, partsCount);
1330 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1331 exponent += rhs.exponent;
1345 if (!ignoreAddend && addend.isNonZero()) {
1349 Significand savedSignificand = significand;
1350 const fltSemantics *savedSemantics = semantics;
1353 unsigned extendedPrecision = 2 * precision + 1;
1354 if (omsb != extendedPrecision - 1) {
1355 assert(extendedPrecision > omsb);
1357 (extendedPrecision - 1) - omsb);
1358 exponent -= (extendedPrecision - 1) - omsb;
1362 fltSemantics extendedSemantics = *semantics;
1363 extendedSemantics.
precision = extendedPrecision;
1365 if (newPartsCount == 1)
1366 significand.part = fullSignificand[0];
1368 significand.parts = fullSignificand;
1369 semantics = &extendedSemantics;
1382 lost_fraction = extendedAddend.shiftSignificandRight(1);
1384 "Lost precision while shifting addend for fused-multiply-add.");
1386 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1389 if (newPartsCount == 1)
1390 fullSignificand[0] = significand.part;
1391 significand = savedSignificand;
1392 semantics = savedSemantics;
1394 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1401 exponent -= precision + 1;
1410 if (omsb > precision) {
1411 unsigned int bits, significantParts;
1414 bits = omsb - precision;
1416 lf =
shiftRight(fullSignificand, significantParts, bits);
1423 if (newPartsCount > 4)
1424 delete [] fullSignificand;
1426 return lost_fraction;
1435 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1442 assert(semantics == rhs.semantics);
1445 const integerPart *rhsSignificand = rhs.significandParts();
1446 unsigned partsCount = partCount();
1449 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1453 for (
unsigned i = 0; i < partsCount; i++) {
1454 dividend[i] = lhsSignificand[i];
1455 divisor[i] = rhsSignificand[i];
1456 lhsSignificand[i] = 0;
1459 exponent -= rhs.exponent;
1461 unsigned int precision = semantics->precision;
1464 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1471 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1487 for (bit = precision; bit; bit -= 1) {
1512 return lost_fraction;
1515unsigned int IEEEFloat::significandMSB()
const {
1519unsigned int IEEEFloat::significandLSB()
const {
1524lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1530 return shiftRight(significandParts(), partCount(), bits);
1534void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1535 assert(bits < semantics->precision ||
1536 (semantics->precision == 1 && bits <= 1));
1539 unsigned int partsCount = partCount();
1549 assert(semantics == rhs.semantics);
1553 int compare = exponent - rhs.exponent;
1605 exponent = semantics->maxExponent;
1607 semantics->precision);
1620bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1622 unsigned int bit)
const {
1629 switch (rounding_mode) {
1665 unsigned omsb = significandMSB() + 1;
1672 int exponentChange = omsb - semantics->precision;
1676 if (exponent + exponentChange > semantics->maxExponent)
1677 return handleOverflow(rounding_mode);
1681 if (exponent + exponentChange < semantics->minExponent)
1682 exponentChange = semantics->minExponent - exponent;
1685 if (exponentChange < 0) {
1688 shiftSignificandLeft(-exponentChange);
1693 if (exponentChange > 0) {
1697 lf = shiftSignificandRight(exponentChange);
1702 if (omsb > (
unsigned) exponentChange)
1703 omsb -= exponentChange;
1713 exponent == semantics->maxExponent && isSignificandAllOnes())
1714 return handleOverflow(rounding_mode);
1727 if (!semantics->hasZero)
1735 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1737 exponent = semantics->minExponent;
1739 incrementSignificand();
1740 omsb = significandMSB() + 1;
1743 if (omsb == (
unsigned) semantics->precision + 1) {
1747 if (exponent == semantics->maxExponent)
1754 shiftSignificandRight(1);
1763 exponent == semantics->maxExponent && isSignificandAllOnes())
1764 return handleOverflow(rounding_mode);
1769 if (omsb == semantics->precision)
1773 assert(omsb < semantics->precision);
1783 if (!semantics->hasZero)
1855 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1858 int bits = exponent - rhs.exponent;
1862 if ((bits < 0) && !semantics->hasSignedRepr)
1864 "This floating point format does not support signed values");
1867 bool lost_fraction_is_from_rhs =
false;
1871 else if (bits > 0) {
1872 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1873 lost_fraction_is_from_rhs =
true;
1874 shiftSignificandLeft(1);
1876 lost_fraction = shiftSignificandRight(-bits - 1);
1877 temp_rhs.shiftSignificandLeft(1);
1884 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1893 carry = temp_rhs.subtractSignificand(*
this, borrow);
1894 copySignificand(temp_rhs);
1897 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1906 carry = subtractSignificand(temp_rhs, borrow);
1909 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1922 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1923 carry = addSignificand(temp_rhs);
1925 lost_fraction = shiftSignificandRight(-bits);
1926 carry = addSignificand(rhs);
1933 return lost_fraction;
2126 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2127 fs = normalize(rounding_mode, lost_fraction);
2136 if (category ==
fcZero) {
2150 return addOrSubtract(rhs, rounding_mode,
false);
2156 return addOrSubtract(rhs, rounding_mode,
true);
2169 fs = normalize(rounding_mode, lost_fraction);
2187 fs = normalize(rounding_mode, lost_fraction);
2197 unsigned int origSign = sign;
2306 unsigned int origSign = sign;
2327 if (!semantics->hasZero && this->isSmallest())
2347 sign ^= multiplicand.sign;
2356 lost_fraction = multiplySignificand(multiplicand, addend);
2357 fs = normalize(rounding_mode, lost_fraction);
2370 fs = multiplySpecials(multiplicand);
2380 fs = addOrSubtract(addend, rounding_mode,
false);
2452 MagicConstant.sign = sign;
2458 fs =
add(MagicConstant, rounding_mode);
2462 subtract(MagicConstant, rounding_mode);
2473 assert(semantics == rhs.semantics);
2505 if (sign == rhs.sign)
2521 if (sign != rhs.sign) {
2557 unsigned oldPartCount = partCount();
2560 bool X86SpecialNan =
false;
2561 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2562 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2563 (!(*significandParts() & 0x8000000000000000ULL) ||
2564 !(*significandParts() & 0x4000000000000000ULL))) {
2567 X86SpecialNan =
true;
2578 int omsb = significandMSB() + 1;
2579 int exponentChange = omsb - fromSemantics.
precision;
2580 if (exponent + exponentChange < toSemantics.
minExponent)
2581 exponentChange = toSemantics.
minExponent - exponent;
2582 exponentChange = std::max(exponentChange, shift);
2583 if (exponentChange < 0) {
2584 shift -= exponentChange;
2585 exponent += exponentChange;
2586 }
else if (omsb <= -shift) {
2587 exponentChange = omsb + shift - 1;
2588 shift -= exponentChange;
2589 exponent += exponentChange;
2595 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2600 if (newPartCount > oldPartCount) {
2608 significand.parts = newParts;
2609 }
else if (newPartCount == 1 && oldPartCount != 1) {
2613 newPart = significandParts()[0];
2615 significand.part = newPart;
2619 semantics = &toSemantics;
2628 *losesInfo = (
fs !=
opOK);
2629 }
else if (category ==
fcNaN) {
2652 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2670 }
else if (category ==
fcZero &&
2687 if ((sign && !semantics->hasSignedRepr) ||
2688 (category ==
fcZero && !semantics->hasZero)) {
2694 if (category ==
fcZero && !semantics->hasZero)
2719 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2721 if (category ==
fcZero) {
2730 unsigned truncatedBits;
2738 truncatedBits = semantics->
precision -1U - exponent;
2742 unsigned int bits = exponent + 1U;
2748 if (bits < semantics->precision) {
2750 truncatedBits = semantics->
precision - bits;
2757 bits - semantics->precision);
2765 if (truncatedBits) {
2769 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2789 if (omsb == width &&
2825 rounding_mode, isExact);
2828 unsigned int bits, dstPartsCount;
2831 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2833 if (category ==
fcNaN)
2856 unsigned dstCount = partCount();
2857 unsigned precision = semantics->
precision;
2862 if (precision <= omsb) {
2863 exponent = omsb - 1;
2868 exponent = precision - 1;
2873 return normalize(rounding_mode, lost_fraction);
2887 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2891IEEEFloat::convertFromHexadecimalString(
StringRef s,
2900 unsigned partsCount = partCount();
2902 bool computedTrailingFraction =
false;
2910 return PtrOrErr.takeError();
2919 return createError(
"String contains multiple dots");
2925 if (hex_value == UINT_MAX)
2935 }
else if (!computedTrailingFraction) {
2938 return FractOrErr.takeError();
2939 lost_fraction = *FractOrErr;
2940 computedTrailingFraction =
true;
2946 return createError(
"Hex strings require an exponent");
2947 if (*p !=
'p' && *p !=
'P')
2948 return createError(
"Invalid character in significand");
2951 if (dot != end && p - begin == 1)
2955 if (p != firstSignificantDigit) {
2964 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2965 if (expAdjustment < 0)
2967 expAdjustment = expAdjustment * 4 - 1;
2971 expAdjustment += semantics->precision;
2977 return ExpOrErr.takeError();
2978 exponent = *ExpOrErr;
2981 return normalize(rounding_mode, lost_fraction);
2985IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2986 unsigned sigPartCount,
int exp,
2988 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2989 unsigned int power =
exp >= 0 ?
exp : -
exp;
3000 unsigned pow5PartCount =
powerOf5(pow5Parts.
data(), power);
3002 for (;; parts *= 2) {
3003 unsigned int excessPrecision, truncatedBits;
3006 excessPrecision = calcSemantics.
precision - semantics->precision;
3007 truncatedBits = excessPrecision;
3010 decSig.makeZero(sign);
3013 opStatus sigStatus = decSig.convertFromUnsignedParts(
3015 opStatus powStatus = pow5.convertFromUnsignedParts(
3018 decSig.exponent +=
exp;
3022 unsigned int powHUerr;
3026 calcLostFraction = decSig.multiplySignificand(pow5);
3027 powHUerr = powStatus !=
opOK;
3029 calcLostFraction = decSig.divideSignificand(pow5);
3031 if (decSig.exponent < semantics->minExponent) {
3032 excessPrecision += (semantics->minExponent - decSig.exponent);
3033 truncatedBits = excessPrecision;
3034 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
3043 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3048 excessPrecision, isNearest);
3051 if (HUdistance >= HUerr) {
3052 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3053 calcSemantics.
precision - excessPrecision,
3058 exponent = (decSig.exponent + semantics->precision
3059 - (calcSemantics.
precision - excessPrecision));
3063 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
3069Expected<APFloat::opStatus>
3070IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
3077 return std::move(Err);
3108 if (!semantics->hasZero)
3113 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3114 fs = handleOverflow(rounding_mode);
3120 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3121 (
D.normalizedExponent + 1) * 28738 <=
3122 8651 * (semantics->minExponent - (
int) semantics->precision)) {
3129 }
else if ((
D.normalizedExponent - 1) * 42039
3130 >= 12655 * semantics->maxExponent) {
3132 fs = handleOverflow(rounding_mode);
3135 unsigned int partCount;
3141 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3159 if (p == str.
end()) {
3164 if (decValue >= 10U) {
3165 delete[] decSignificand;
3166 return createError(
"Invalid character in significand");
3172 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3176 partCount, partCount + 1,
false);
3180 if (decSignificand[partCount])
3182 }
while (p <=
D.lastSigDigit);
3185 fs = roundSignificandWithExponent(decSignificand, partCount,
3186 D.exponent, rounding_mode);
3188 delete [] decSignificand;
3194bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3195 const size_t MIN_NAME_SIZE = 3;
3197 if (str.
size() < MIN_NAME_SIZE)
3200 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3207 if (str.
size() < MIN_NAME_SIZE)
3210 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3219 if (str.
size() < MIN_NAME_SIZE)
3226 makeNaN(IsSignaling, IsNegative);
3231 if (str.
front() ==
'(') {
3233 if (str.
size() <= 2 || str.
back() !=
')')
3240 unsigned Radix = 10;
3241 if (str[0] ==
'0') {
3242 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3253 makeNaN(IsSignaling, IsNegative, &Payload);
3261Expected<APFloat::opStatus>
3267 if (convertFromStringSpecials(str))
3272 size_t slen = str.
size();
3273 sign = *p ==
'-' ? 1 : 0;
3274 if (sign && !semantics->hasSignedRepr)
3276 "This floating point format does not support signed values");
3278 if (*p ==
'-' || *p ==
'+') {
3285 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3288 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3292 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3334 dst +=
sizeof NaNU - 1;
3339 *dst++ = upperCase ?
'X':
'x';
3341 if (hexDigits > 1) {
3343 memset (dst,
'0', hexDigits - 1);
3344 dst += hexDigits - 1;
3346 *dst++ = upperCase ?
'P':
'p';
3351 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3357 return static_cast<unsigned int>(dst - p);
3364char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3368 *dst++ = upperCase ?
'X':
'x';
3370 bool roundUp =
false;
3373 const integerPart *significand = significandParts();
3374 unsigned partsCount = partCount();
3378 unsigned valueBits = semantics->
precision + 3;
3383 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3389 if (hexDigits < outputDigits) {
3395 bits = valueBits - hexDigits * 4;
3397 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3399 outputDigits = hexDigits;
3409 while (outputDigits &&
count) {
3413 if (--
count == partsCount)
3416 part = significand[
count] << shift;
3424 curDigits = std::min(curDigits, outputDigits);
3425 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3426 outputDigits -= curDigits;
3436 }
while (*q ==
'0');
3440 memset (dst,
'0', outputDigits);
3441 dst += outputDigits;
3454 *dst++ = upperCase ?
'P':
'p';
3470 Arg.significandParts(),
3471 Arg.significandParts() + Arg.partCount()));
3483APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3484 assert(partCount() == 2);
3485 return convertIEEEFloatToAPInt<APFloatBase::semX87DoubleExtended>();
3488APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3503 extendedSemantics.
minExponent = APFloatBase::semIEEEdouble.minExponent;
3512 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
3518 if (u.isFiniteNonZero() && losesInfo) {
3526 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
3531 return APInt(128, words);
3534template <const fltSemantics &S>
3535APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3537 constexpr unsigned int trailing_significand_bits =
3538 S.precision - 1 + S.hasExplicitIntegerBit;
3542 constexpr uint64_t significand_mask = integer_bit - 1;
3543 constexpr unsigned int exponent_bits =
3544 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3545 static_assert(exponent_bits < 64);
3547 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3548 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3555 myexponent = exponent + bias;
3556 std::copy_n(significandParts(), mysignificand.size(),
3557 mysignificand.begin());
3558 if (myexponent == 1 &&
3559 !(significandParts()[integer_bit_part] & integer_bit))
3561 }
else if (category ==
fcZero) {
3564 myexponent = ::exponentZero(S) + bias;
3565 mysignificand.fill(0);
3570 myexponent = ::exponentInf(S) + bias;
3571 mysignificand.fill(0);
3572 if constexpr (S.hasExplicitIntegerBit) {
3573 mysignificand[0] =
integerPart{1} << (trailing_significand_bits - 1);
3579 myexponent = ::exponentNaN(S) + bias;
3580 std::copy_n(significandParts(), mysignificand.size(),
3581 mysignificand.begin());
3583 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3585 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3586 if constexpr (!S.hasExplicitIntegerBit) {
3587 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3589 words[mysignificand.size() - 1] &= significand_mask;
3592 std::fill(words_iter, words.end(),
uint64_t{0});
3593 constexpr size_t last_word = words.size() - 1;
3594 if constexpr (S.hasSignedRepr) {
3596 << ((S.sizeInBits - 1) % 64);
3597 words[last_word] |= shifted_sign;
3599 uint64_t shifted_exponent = (myexponent & exponent_mask)
3600 << (trailing_significand_bits % 64);
3601 words[last_word] |= shifted_exponent;
3602 if constexpr (last_word == 0) {
3603 return APInt(S.sizeInBits, words[0]);
3605 return APInt(S.sizeInBits, words);
3608APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3609 assert(partCount() == 2);
3610 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3613APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3615 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3618APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3620 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3623APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3624 assert(partCount() == 1);
3625 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3628APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3630 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3633APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3634 assert(partCount() == 1);
3635 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3638APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3639 assert(partCount() == 1);
3640 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3643APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3644 assert(partCount() == 1);
3645 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3648APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3649 assert(partCount() == 1);
3650 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3653APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3654 assert(partCount() == 1);
3655 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3658APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3659 assert(partCount() == 1);
3660 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3663APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3664 assert(partCount() == 1);
3665 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3668APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3669 assert(partCount() == 1);
3670 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3673APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3674 assert(partCount() == 1);
3675 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3678APInt IEEEFloat::convertFloat8E5M3FNUAPFloatToAPInt()
const {
3679 assert(partCount() == 1);
3680 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M3FNU>();
3683APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3684 assert(partCount() == 1);
3685 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3688APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3689 assert(partCount() == 1);
3690 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3693APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3694 assert(partCount() == 1);
3695 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3704 return convertHalfAPFloatToAPInt();
3707 return convertBFloatAPFloatToAPInt();
3710 return convertFloatAPFloatToAPInt();
3713 return convertDoubleAPFloatToAPInt();
3716 return convertQuadrupleAPFloatToAPInt();
3720 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3723 return convertFloat8E5M2APFloatToAPInt();
3726 return convertFloat8E5M2FNUZAPFloatToAPInt();
3729 return convertFloat8E4M3APFloatToAPInt();
3732 return convertFloat8E4M3FNAPFloatToAPInt();
3735 return convertFloat8E4M3FNUZAPFloatToAPInt();
3739 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3742 return convertFloat8E3M4APFloatToAPInt();
3745 return convertFloatTF32APFloatToAPInt();
3748 return convertFloat8E8M0FNUAPFloatToAPInt();
3751 return convertFloat8E5M3FNUAPFloatToAPInt();
3754 return convertFloat6E3M2FNAPFloatToAPInt();
3757 return convertFloat6E2M3FNAPFloatToAPInt();
3760 return convertFloat4E2M1FNAPFloatToAPInt();
3765 return convertF80LongDoubleAPFloatToAPInt();
3770 "Float semantics are not IEEEsingle");
3777 "Float semantics are not IEEEdouble");
3782#ifdef HAS_IEE754_FLOAT128
3783float128 IEEEFloat::convertToQuad()
const {
3785 "Float semantics are not IEEEquads");
3787 return api.bitsToQuad();
3791void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3792 return initFromIEEEAPInt<APFloatBase::semX87DoubleExtended>(api);
3795void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3801 initFromDoubleAPInt(
APInt(64, i1));
3823void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3824 initFromIEEEAPInt<APFloatBase::semFloat8E8M0FNU>(api);
3827void IEEEFloat::initFromFloat8E5M3FNUAPInt(
const APInt &api) {
3828 initFromIEEEAPInt<APFloatBase::semFloat8E5M3FNU>(api);
3831template <const fltSemantics &S>
3832void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3835 constexpr unsigned int trailing_significand_bits =
3836 S.precision - 1 + S.hasExplicitIntegerBit;
3839 constexpr uint64_t significand_mask = integer_bit - 1;
3840 constexpr unsigned int exponent_bits =
3841 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3842 static_assert(exponent_bits < 64);
3843 constexpr unsigned int stored_significand_parts =
3846 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3847 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3848 constexpr bool has_significand = trailing_significand_bits > 0;
3852 std::array<integerPart, stored_significand_parts> mysignificand;
3853 if constexpr (has_significand) {
3854 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3856 mysignificand[mysignificand.size() - 1] &= significand_mask;
3859 std::fill_n(mysignificand.begin(), mysignificand.size(), 0);
3862 mysignificand[0] = 1;
3869 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3872 assert(partCount() == mysignificand.size());
3874 sign = S.hasSignedRepr
3875 ?
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64))
3878 bool all_zero_significand =
3881 bool is_zero = myexponent == 0 && all_zero_significand && S.hasZero;
3884 bool is_inf =
false;
3886 if constexpr (S.hasExplicitIntegerBit) {
3888 static_assert(S.precision == 64);
3889 constexpr integerPart significand_mask_no_int_bit =
3890 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3892 mysignificand[0] >> (trailing_significand_bits - 1);
3894 is_inf = myexponent - bias == ::exponentInf(S) && myintegerbit == 1 &&
3895 (mysignificand[0] & significand_mask_no_int_bit) == 0;
3897 is_inf = myexponent - bias == ::exponentInf(S) && all_zero_significand;
3906 bool is_nan =
false;
3909 if constexpr (S.hasExplicitIntegerBit) {
3911 static_assert(S.precision == 64);
3913 mysignificand[0] >> (trailing_significand_bits - 1);
3914 constexpr integerPart significand_mask_no_int_bit =
3915 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3917 if (myexponent - bias == ::exponentNaN(S) &&
3918 (mysignificand[0] & significand_mask_no_int_bit) != 0) {
3921 }
else if (myexponent - bias == ::exponentNaN(S) &&
3922 (mysignificand[0] & significand_mask_no_int_bit) == 0) {
3925 }
else if (myexponent - bias != ::exponentNaN(S) && myexponent != 0 &&
3926 myintegerbit == 0) {
3931 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3934 bool all_ones_significand =
3935 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3936 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3937 (!significand_mask ||
3938 mysignificand[mysignificand.size() - 1] == significand_mask);
3939 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3941 is_nan = is_zero && sign;
3947 std::copy_n(mysignificand.begin(), mysignificand.size(),
3948 significandParts());
3958 exponent = myexponent - bias;
3959 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3960 if (myexponent == 0 && S.hasDenormals)
3961 exponent = S.minExponent;
3963 if constexpr (!S.hasExplicitIntegerBit) {
3964 significandParts()[mysignificand.size() - 1] |= integer_bit;
3969void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3970 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3973void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3974 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3977void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3978 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3981void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3982 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3985void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3986 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3989void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3990 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3993void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3994 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
3997void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3998 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
4001void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
4002 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
4005void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
4006 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
4009void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
4010 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
4013void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
4014 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
4017void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
4018 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
4021void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
4022 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
4025void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
4026 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
4029void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
4030 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
4036 if (Sem == &APFloatBase::semIEEEhalf)
4037 return initFromHalfAPInt(api);
4038 if (Sem == &APFloatBase::semBFloat)
4039 return initFromBFloatAPInt(api);
4040 if (Sem == &APFloatBase::semIEEEsingle)
4041 return initFromFloatAPInt(api);
4042 if (Sem == &APFloatBase::semIEEEdouble)
4043 return initFromDoubleAPInt(api);
4044 if (Sem == &APFloatBase::semX87DoubleExtended)
4045 return initFromF80LongDoubleAPInt(api);
4046 if (Sem == &APFloatBase::semIEEEquad)
4047 return initFromQuadrupleAPInt(api);
4048 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
4049 return initFromPPCDoubleDoubleLegacyAPInt(api);
4050 if (Sem == &APFloatBase::semFloat8E5M2)
4051 return initFromFloat8E5M2APInt(api);
4052 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
4053 return initFromFloat8E5M2FNUZAPInt(api);
4054 if (Sem == &APFloatBase::semFloat8E4M3)
4055 return initFromFloat8E4M3APInt(api);
4056 if (Sem == &APFloatBase::semFloat8E4M3FN)
4057 return initFromFloat8E4M3FNAPInt(api);
4058 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
4059 return initFromFloat8E4M3FNUZAPInt(api);
4060 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
4061 return initFromFloat8E4M3B11FNUZAPInt(api);
4062 if (Sem == &APFloatBase::semFloat8E3M4)
4063 return initFromFloat8E3M4APInt(api);
4064 if (Sem == &APFloatBase::semFloatTF32)
4065 return initFromFloatTF32APInt(api);
4066 if (Sem == &APFloatBase::semFloat8E8M0FNU)
4067 return initFromFloat8E8M0FNUAPInt(api);
4068 if (Sem == &APFloatBase::semFloat8E5M3FNU)
4069 return initFromFloat8E5M3FNUAPInt(api);
4070 if (Sem == &APFloatBase::semFloat6E3M2FN)
4071 return initFromFloat6E3M2FNAPInt(api);
4072 if (Sem == &APFloatBase::semFloat6E2M3FN)
4073 return initFromFloat6E2M3FNAPInt(api);
4074 if (Sem == &APFloatBase::semFloat4E2M1FN)
4075 return initFromFloat4E2M1FNAPInt(api);
4083 if (Negative && !semantics->hasSignedRepr)
4085 "This floating point format does not support signed values");
4092 exponent = semantics->maxExponent;
4096 unsigned PartCount = partCount();
4097 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4101 const unsigned NumUnusedHighBits =
4108 (semantics->precision > 1))
4115 if (Negative && !semantics->hasSignedRepr)
4117 "This floating point format does not support signed values");
4124 exponent = semantics->minExponent;
4129 if (Negative && !semantics->hasSignedRepr)
4131 "This floating point format does not support signed values");
4140 exponent = semantics->minExponent;
4145 initFromAPInt(&Sem, API);
4158 Buffer.
append(Str.begin(), Str.end());
4163 void AdjustToPrecision(
APInt &significand,
4164 int &
exp,
unsigned FormatPrecision) {
4168 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4170 if (bits <= bitsRequired)
return;
4172 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4173 if (!tensRemovable)
return;
4175 exp += tensRemovable;
4180 if (tensRemovable & 1)
4182 tensRemovable >>= 1;
4183 if (!tensRemovable)
break;
4187 significand = significand.
udiv(divisor);
4195 int &
exp,
unsigned FormatPrecision) {
4196 unsigned N = buffer.
size();
4197 if (
N <= FormatPrecision)
return;
4200 unsigned FirstSignificant =
N - FormatPrecision;
4207 if (buffer[FirstSignificant - 1] <
'5') {
4208 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4211 exp += FirstSignificant;
4212 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4218 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4219 if (buffer[
I] ==
'9') {
4228 if (FirstSignificant ==
N) {
4229 exp += FirstSignificant;
4235 exp += FirstSignificant;
4236 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4240 APInt significand,
unsigned FormatPrecision,
4241 unsigned FormatMaxPadding,
bool TruncateZero) {
4242 const int semanticsPrecision = significand.
getBitWidth();
4249 if (!FormatPrecision) {
4257 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4262 exp += trailingZeros;
4268 }
else if (
exp > 0) {
4270 significand = significand.
zext(semanticsPrecision +
exp);
4271 significand <<=
exp;
4285 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4289 significand = significand.
zext(precision);
4290 APInt five_to_the_i(precision, 5);
4293 significand *= five_to_the_i;
4298 five_to_the_i *= five_to_the_i;
4302 AdjustToPrecision(significand,
exp, FormatPrecision);
4307 unsigned precision = significand.getBitWidth();
4308 if (precision < 4) {
4311 significand = significand.zext(precision);
4313 APInt ten(precision, 10);
4314 APInt digit(precision, 0);
4316 bool inTrail =
true;
4317 while (significand != 0) {
4322 unsigned d = digit.getZExtValue();
4333 assert(!buffer.
empty() &&
"no characters in buffer!");
4337 AdjustToPrecision(buffer,
exp, FormatPrecision);
4339 unsigned NDigits = buffer.
size();
4342 bool FormatScientific;
4343 if (!FormatMaxPadding) {
4344 FormatScientific =
true;
4350 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4351 NDigits + (unsigned)
exp > FormatPrecision);
4354 int MSD =
exp + (int) (NDigits - 1);
4357 FormatScientific =
false;
4361 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4367 if (FormatScientific) {
4368 exp += (NDigits - 1);
4370 Str.push_back(buffer[NDigits-1]);
4372 if (NDigits == 1 && TruncateZero)
4375 for (
unsigned I = 1;
I != NDigits; ++
I)
4376 Str.push_back(buffer[NDigits-1-
I]);
4378 if (!TruncateZero && FormatPrecision > NDigits - 1)
4379 Str.append(FormatPrecision - NDigits + 1,
'0');
4381 Str.push_back(TruncateZero ?
'E' :
'e');
4383 Str.push_back(
exp >= 0 ?
'+' :
'-');
4392 if (!TruncateZero && expbuf.
size() < 2)
4394 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4395 Str.push_back(expbuf[
E-1-
I]);
4401 for (
unsigned I = 0;
I != NDigits; ++
I)
4402 Str.push_back(buffer[NDigits-1-
I]);
4403 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4411 int NWholeDigits =
exp + (int) NDigits;
4414 if (NWholeDigits > 0) {
4415 for (;
I != (unsigned) NWholeDigits; ++
I)
4416 Str.push_back(buffer[NDigits-
I-1]);
4419 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4423 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4427 for (;
I != NDigits; ++
I)
4428 Str.push_back(buffer[NDigits-
I-1]);
4434 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4438 return append(Str,
"-Inf");
4440 return append(Str,
"+Inf");
4442 case fcNaN:
return append(Str,
"NaN");
4448 if (!FormatMaxPadding) {
4450 append(Str,
"0.0E+0");
4453 if (FormatPrecision > 1)
4454 Str.append(FormatPrecision - 1,
'0');
4455 append(Str,
"e+00");
4467 int exp = exponent - ((int) semantics->precision - 1);
4469 semantics->precision,
4472 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4473 FormatMaxPadding, TruncateZero);
4485 for (
int i = 0; i < PartCount; ++i) {
4491 if (exponent != semantics->minExponent)
4494 int CountrParts = 0;
4495 for (
int i = 0; i < PartCount;
4497 if (Parts[i] != 0) {
4498 return exponent - semantics->precision + CountrParts +
4561 if (!semantics->hasZero)
4571 }
else if (semantics->nonFiniteBehavior ==
4579 exponent = semantics->maxExponent + 1;
4593 bool WillCrossBinadeBoundary =
4594 exponent != semantics->minExponent && isSignificandAllZeros();
4612 if (WillCrossBinadeBoundary) {
4633 if (WillCrossBinadeBoundary) {
4637 assert(exponent != semantics->maxExponent &&
4638 "We can not increment an exponent beyond the maxExponent allowed"
4639 " by the given floating point semantics.");
4642 incrementSignificand();
4656 assert(
isNaN() &&
"Can only be called on NaN values");
4658 unsigned Bits = semantics->precision - 1;
4663 return ::exponentNaN(*semantics);
4667 return ::exponentInf(*semantics);
4671 return ::exponentZero(*semantics);
4690 if (!semantics->hasZero)
4717 return Arg.exponent;
4722 Normalized.exponent += SignificandBits;
4724 return Normalized.exponent - SignificandBits;
4728 auto MaxExp =
X.getSemantics().maxExponent;
4729 auto MinExp =
X.getSemantics().minExponent;
4737 int SignificandBits =
X.getSemantics().precision - 1;
4738 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4741 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4764 return scalbn(Val, -Exp, RM);
4770 APFloat(APFloatBase::semIEEEdouble)}) {
4771 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4775 : Semantics(&S), Floats(new
APFloat[2]{
4778 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4784 APFloat(APFloatBase::semIEEEdouble)}) {
4785 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4791 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4792 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4793 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4799 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4800 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4801 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4802 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4806 : Semantics(RHS.Semantics),
4810 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4814 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4815 RHS.Semantics = &APFloatBase::semBogus;
4816 RHS.Floats =
nullptr;
4817 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4821 if (Semantics == RHS.Semantics && RHS.Floats) {
4822 Floats[0] = RHS.Floats[0];
4823 Floats[1] = RHS.Floats[1];
4824 }
else if (
this != &RHS) {
4857 Floats[0] = std::move(z);
4858 Floats[1].makeZero(
false);
4871 Status |= z.
add(a, RM);
4872 Status |= z.
add(c, RM);
4875 Floats[0] = std::move(z);
4876 Floats[1].makeZero(
false);
4881 Status |= zz.
add(cc, RM);
4885 Status |= Floats[1].subtract(z, RM);
4886 Status |= Floats[1].add(c, RM);
4887 Status |= Floats[1].add(zz, RM);
4891 Status |= Floats[1].subtract(z, RM);
4892 Status |= Floats[1].add(a, RM);
4893 Status |= Floats[1].add(zz, RM);
4898 Status |=
q.subtract(z, RM);
4903 Status |= zz.
add(c, RM);
4904 Status |=
q.add(z, RM);
4905 Status |=
q.subtract(a, RM);
4907 Status |= zz.
add(q, RM);
4908 Status |= zz.
add(
aa, RM);
4909 Status |= zz.
add(cc, RM);
4911 Floats[0] = std::move(z);
4912 Floats[1].makeZero(
false);
4916 Status |= Floats[0].add(zz, RM);
4918 Floats[1].makeZero(
false);
4921 Floats[1] = std::move(z);
4922 Status |= Floats[1].subtract(Floats[0], RM);
4923 Status |= Floats[1].add(zz, RM);
4949 LHS.isNegative() !=
RHS.isNegative()) {
4950 Out.makeNaN(
false,
Out.isNegative(),
nullptr);
4965 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4966 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4967 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4968 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4969 assert(&
Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4970 assert(&
Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4971 return Out.addImpl(
A, AA,
C, CC, RM);
4976 return addWithSpecial(*
this, RHS, *
this, RM);
4982 auto Ret =
add(RHS, RM);
4989 const auto &LHS = *
this;
5006 if (LHS.getCategory() ==
fcNaN) {
5010 if (RHS.getCategory() ==
fcNaN) {
5016 Out.makeNaN(
false,
false,
nullptr);
5028 "Special cases not handled exhaustively");
5031 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
5035 if (!
T.isFiniteNonZero()) {
5036 Floats[0] = std::move(
T);
5037 Floats[1].makeZero(
false);
5059 Status |= U.add(Tau, RM);
5062 if (!U.isFinite()) {
5063 Floats[1].makeZero(
false);
5068 Floats[1] = std::move(
T);
5075 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5076 "Unexpected Semantics");
5079 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
5085 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5086 "Unexpected Semantics");
5089 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5095 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5096 "Unexpected Semantics");
5099 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5108 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5109 "Unexpected Semantics");
5112 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
5121 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5122 "Unexpected Semantics");
5132 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5133 Floats[0] = std::move(RoundedHi);
5134 Floats[1].makeZero(
false);
5146 const APFloat RoundingError = Rounded - ToRound;
5147 if (TieBreaker.isNonZero() &&
5148 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5149 abs(RoundingError).isExactlyValue(0.5))
5158 if (RoundedHi !=
Hi) {
5163 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5165 Floats[0] = std::move(RoundedHi);
5166 Floats[1].makeZero(
false);
5179 LoRoundingMode = RM;
5187 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5190 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5192 Floats[0] = std::move(RoundedHi);
5193 Floats[1] = std::move(RoundedLo);
5198 Floats[0].changeSign();
5199 Floats[1].changeSign();
5205 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5210 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5216 const bool ThisIsSubtractive =
5217 Floats[0].isNegative() != Floats[1].isNegative();
5218 const bool RHSIsSubtractive =
5219 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5229 if (RHS.Floats[1].isZero())
5236 if (ThisIsSubtractive != RHSIsSubtractive)
5241 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5243 if (ThisIsSubtractive) {
5257 return Floats[0].getCategory();
5263 Floats[0].makeInf(Neg);
5264 Floats[1].makeZero(
false);
5268 Floats[0].makeZero(Neg);
5269 Floats[1].makeZero(
false);
5273 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5274 "Unexpected Semantics");
5276 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5278 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5284 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5285 "Unexpected Semantics");
5286 Floats[0].makeSmallest(Neg);
5287 Floats[1].makeZero(
false);
5291 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5292 "Unexpected Semantics");
5294 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5296 Floats[0].changeSign();
5297 Floats[1].makeZero(
false);
5301 Floats[0].makeNaN(SNaN, Neg,
fill);
5302 Floats[1].makeZero(
false);
5306 auto Result = Floats[0].compare(RHS.Floats[0]);
5309 return Floats[1].compare(RHS.Floats[1]);
5314 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5315 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5325 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5326 "Unexpected Semantics");
5328 Floats[0].bitcastToAPInt().getRawData()[0],
5329 Floats[1].bitcastToAPInt().getRawData()[0],
5336 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5337 "Unexpected Semantics");
5338 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5351 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5352 "Unexpected Semantics");
5402 if (InLattice(HiOld, NextLo)) {
5404 Floats[1] = std::move(NextLo);
5441 if (!InLattice(NextHi, NextLo))
5445 Floats[0] = std::move(NextHi);
5446 Floats[1] = std::move(NextLo);
5454 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5455 "Unexpected Semantics");
5497 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5498 if (HiExactLog2 >= 0 &&
5499 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5509 Input, Width,
true, RM, &LoIsExact);
5522 *IsExact = RoundStatus ==
opOK;
5534 APSInt LoResult{Width, !IsSigned};
5546 *IsExact = RoundStatus ==
opOK;
5552 unsigned int Width,
bool IsSigned,
5555 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5559 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5567 Bits = Width - IsSigned;
5612 if (SrcMSB == UINT_MAX) {
5619 const unsigned SrcBitWidth = SrcMSB + 1;
5635 return handleOverflow(RM);
5641 bool HiAsIntIsExact;
5658 if (
Error.isNegative()) {
5666 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5668 if (ErrorActiveBits > LoPrecision) {
5669 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5673 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5692 Floats[0] = std::move(
Hi);
5693 Floats[1] = std::move(
Lo);
5698 return handleOverflow(RM);
5704 Largest.makeLargest(
false);
5706 return handleOverflow(RM);
5718 const bool NegateInput = IsSigned &&
Input.isNegative();
5731 unsigned int HexDigits,
5734 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5735 "Unexpected Semantics");
5742 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5744 Floats[0] != Floats[0] + Floats[1]);
5773 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5774 "Unexpected Semantics");
5775 return Floats[0].isInteger() && Floats[1].isInteger();
5779 unsigned FormatPrecision,
5780 unsigned FormatMaxPadding,
5781 bool TruncateZero)
const {
5782 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5783 "Unexpected Semantics");
5785 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5805 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5807 if (
Hi.getExactLog2Abs() == INT_MIN)
5811 return IlogbResult - 1;
5817 "Unexpected Semantics");
5819 scalbn(Arg.Floats[0], Exp, RM),
5820 scalbn(Arg.Floats[1], Exp, RM));
5826 "Unexpected Semantics");
5836 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5858 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5875 LoRoundingMode = RM;
5876 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5884 if (RecomposedLo !=
Lo) {
5888 const APFloat RoundingError = RecomposedLo -
Lo;
5893 const APFloat ScaledUlpOfSecond =
5895 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5896 const bool RoundedLoAway =
5901 if (IsMidpoint && RoundedLoAway)
5917 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5929APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5934 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5949 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5951 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5959 assert(StatusOrErr &&
"Invalid floating point representation");
6011 APFloat Reciprocal =
6029 *Inv = std::move(Reciprocal);
6041 usesLayout<IEEEFloat>(ToSemantics))
6042 return U.IEEE.convert(ToSemantics, RM, losesInfo);
6044 usesLayout<DoubleAPFloat>(ToSemantics)) {
6045 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
6047 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
6048 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
6052 usesLayout<IEEEFloat>(ToSemantics)) {
6053 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
6054 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
6070#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
6083 bool *isExact)
const {
6087 rounding_mode, isExact);
6089 result =
APInt(bitWidth, parts);
6095 return getIEEE().convertToDouble();
6097 "Float semantics is not representable by IEEEdouble");
6098 APFloat Temp = *
this;
6106#ifdef HAS_IEE754_FLOAT128
6107float128 APFloat::convertToQuad()
const {
6109 return getIEEE().convertToQuad();
6111 "Float semantics is not representable by IEEEquad");
6117 return Temp.getIEEE().convertToQuad();
6123 return getIEEE().convertToFloat();
6125 "Float semantics is not representable by IEEEsingle");
6126 APFloat Temp = *
this;
6159 .
Case(
"Float8E5M2", &semFloat8E5M2)
6160 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6161 .
Case(
"Float8E5M3FNU", &semFloat8E5M3FNU)
6162 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6163 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6164 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6168APFloat::Storage::~Storage() {
6169 if (usesLayout<IEEEFloat>(*semantics)) {
6173 if (usesLayout<DoubleAPFloat>(*semantics)) {
6180APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6181 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6185 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6192APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6193 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6197 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6204APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6205 if (usesLayout<IEEEFloat>(*semantics) &&
6206 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6208 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6209 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6211 }
else if (
this != &
RHS) {
6213 new (
this) Storage(
RHS);
6218APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6219 if (usesLayout<IEEEFloat>(*semantics) &&
6220 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6222 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6223 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6225 }
else if (
this != &
RHS) {
6227 new (
this) Storage(std::move(
RHS));
6236 if (libc_exceptions & FE_INVALID)
6238 if (libc_exceptions & FE_DIVBYZERO)
6240 if (libc_exceptions & FE_OVERFLOW)
6242 if (libc_exceptions & FE_UNDERFLOW)
6244 if (libc_exceptions & FE_INEXACT)
6259 float x_val = x.convertToFloat();
6261 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6263 *status = getOpStatusFromLibc(exc);
6264 if (x.isSignaling()) {
6271 float result = LIBC_NAMESPACE::shared::expf(x_val);
6276 double x_val = x.convertToDouble();
6278 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6280 *status = getOpStatusFromLibc(exc);
6281 if (x.isSignaling()) {
6288 double result = LIBC_NAMESPACE::shared::exp(x_val);
6292 return std::nullopt;
6297#undef APFLOAT_DISPATCH_ON_SEMANTICS
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define PackCategoriesIntoKey(_lhs, _rhs)
A macro used to combine two fcCategory enums into one key which can be used in a switch statement to ...
This file declares a class to represent arbitrary precision floating point values and provide a varie...
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
Function Alias Analysis false
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static bool isNeg(Value *V)
Returns true if the operation is a negation of V, and it works for both integers and floats.
static bool isSigned(unsigned Opcode)
Utilities for dealing with flags related to floating point properties and mode controls.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static const fltSemantics & IEEEsingle()
static const fltSemantics & Float8E4M3FN()
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
static constexpr roundingMode rmTowardZero
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
static const fltSemantics & BFloat()
static const fltSemantics & IEEEquad()
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
static const fltSemantics & Float8E8M0FNU()
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
static const fltSemantics & IEEEdouble()
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static const fltSemantics & x87DoubleExtended()
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
static constexpr unsigned integerPartWidth
static const fltSemantics & PPCDoubleDoubleLegacy()
static LLVM_ABI bool isLosslesslyConvertibleTo(const fltSemantics &From, const fltSemantics &To, bool IgnoreNaNs=false)
Returns whether converting a value from From to To is known to preserve all information.
APInt::WordType integerPart
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static const fltSemantics & Float8E5M2FNUZ()
static const fltSemantics & Float8E4M3FNUZ()
static constexpr roundingMode rmTowardPositive
static const fltSemantics & IEEEhalf()
static const fltSemantics & Float4E2M1FN()
static const fltSemantics & Float6E2M3FN()
static const fltSemantics & Float8E4M3()
static const fltSemantics & Float8E4M3B11FNUZ()
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
static const fltSemantics & Float8E3M4()
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
static const fltSemantics & Float8E5M2()
fltCategory
Category of internally-represented number.
static constexpr roundingMode rmNearestTiesToAway
static const fltSemantics & PPCDoubleDouble()
@ S_PPCDoubleDoubleLegacy
static const fltSemantics & Float6E3M2FN()
opStatus
IEEE-754R 7: Default exception handling.
static const fltSemantics & Float8E5M3FNU()
static LLVM_ABI unsigned getArbitraryFPFormatSizeInBits(StringRef Format)
Returns the size in bits of a valid arbitrary floating-point format string, or 0 if the string is not...
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
static const fltSemantics & FloatTF32()
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
LLVM_ABI void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
opStatus divide(const APFloat &RHS, roundingMode RM)
bool isFiniteNonZero() const
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
cmpResult compareAbsoluteValue(const APFloat &RHS) const
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
opStatus add(const APFloat &RHS, roundingMode RM)
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
const fltSemantics & getSemantics() const
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
opStatus remainder(const APFloat &RHS)
APInt bitcastToAPInt() const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
opStatus next(bool nextDown)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
opStatus mod(const APFloat &RHS)
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
LLVM_DUMP_METHOD void dump() const
LLVM_ABI void print(raw_ostream &) const
opStatus roundToIntegral(roundingMode RM)
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
static LLVM_ABI void tcSetBit(WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static LLVM_ABI void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static LLVM_ABI void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static LLVM_ABI int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static LLVM_ABI WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI void tcExtract(WordType *, unsigned dstCount, const WordType *, unsigned srcBits, unsigned srcLSB)
Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to DST, of dstCOUNT parts,...
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static LLVM_ABI int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static LLVM_ABI void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static LLVM_ABI void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static LLVM_ABI void tcFullMultiply(WordType *, const WordType *, const WordType *, unsigned, unsigned)
DST = LHS * RHS, where DST has width the sum of the widths of the operands.
unsigned getNumWords() const
Get the number of words.
bool isNegative() const
Determine sign of this APInt.
static LLVM_ABI void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
void negate()
Negate this APInt in place.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
unsigned countr_zero() const
Count the number of trailing zero bits.
static LLVM_ABI unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
static LLVM_ABI void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static LLVM_ABI bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static LLVM_ABI unsigned tcMSB(const WordType *parts, unsigned n)
Returns the bit number of the most significant set bit of a number.
float bitsToFloat() const
Converts APInt bits to a float.
static LLVM_ABI int tcMultiplyPart(WordType *dst, const WordType *src, WordType multiplier, WordType carry, unsigned srcParts, unsigned dstParts, bool add)
DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false.
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
static LLVM_ABI WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI void tcNegate(WordType *, unsigned)
Negate a bignum in-place.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
double bitsToDouble() const
Converts APInt bits to a double.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
An arbitrary precision integer that knows its signedness.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This class is used to gather all the unique data bits of a node.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
char back() const
Get the last character in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
Get the string size.
char front() const
Get the first character in the string.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
bool consume_front_insensitive(StringRef Prefix)
Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI void makeSmallestNormalized(bool Neg)
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
LLVM_ABI void changeSign()
LLVM_ABI bool isLargest() const
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI fltCategory getCategory() const
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
LLVM_ABI APInt bitcastToAPInt() const
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_ABI bool isSmallest() const
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
LLVM_ABI bool isDenormal() const
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
LLVM_ABI void makeSmallest(bool Neg)
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
LLVM_ABI opStatus next(bool nextDown)
LLVM_ABI void makeInf(bool Neg)
LLVM_ABI bool isInteger() const
LLVM_ABI void makeZero(bool Neg)
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI bool isSmallestNormalized() const
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
LLVM_ABI void makeLargest(bool Neg)
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
LLVM_ABI APInt getNaNPayload() const
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI bool isNegative() const
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill)
LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits, bool upperCase, roundingMode) const
Write out a hexadecimal representation of the floating point value to DST, which must be of sufficien...
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
fltCategory getCategory() const
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
LLVM_ABI APInt getNaNPayload() const
bool isFiniteNonZero() const
bool needsCleanup() const
Returns whether this instance allocated memory.
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI APInt bitcastToAPInt() const
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
LLVM_ABI double convertToDouble() const
LLVM_ABI float convertToFloat() const
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Converts this value into a decimal string.
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
LLVM_ABI void makeInf(bool Neg=false)
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
LLVM_ABI void makeQuiet()
LLVM_ABI bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode)
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
LLVM_ABI IEEEFloat(const fltSemantics &)
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
const fltSemantics & getSemantics() const
bool isZero() const
Returns true if and only if the float is plus or minus zero.
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
LLVM_ABI void makeZero(bool Neg=false)
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
LLVM_ABI void changeSign()
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
LLVM_ABI bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr opStatus opInexact
LLVM_ABI SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
static constexpr fltCategory fcNaN
static constexpr opStatus opDivByZero
static constexpr opStatus opOverflow
static constexpr cmpResult cmpLessThan
const char unit< Period >::value[]
static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts, unsigned bits)
static constexpr roundingMode rmTowardPositive
static constexpr uninitializedTag uninitialized
static constexpr fltCategory fcZero
static constexpr opStatus opOK
static constexpr cmpResult cmpGreaterThan
static constexpr unsigned integerPartWidth
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
APFloatBase::ExponentType ExponentType
static constexpr fltCategory fcNormal
static constexpr opStatus opInvalidOp
APFloatBase::opStatus opStatus
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
APFloatBase::uninitializedTag uninitializedTag
static constexpr cmpResult cmpUnordered
static constexpr roundingMode rmTowardNegative
APFloatBase::roundingMode roundingMode
APFloatBase::cmpResult cmpResult
static constexpr fltCategory fcInfinity
static constexpr roundingMode rmNearestTiesToAway
static constexpr roundingMode rmTowardZero
static constexpr opStatus opUnderflow
static constexpr roundingMode rmNearestTiesToEven
LLVM_ABI int ilogb(const IEEEFloat &Arg)
static constexpr cmpResult cmpEqual
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
static std::pair< APFloat, APFloat > fastTwoSum(APFloat X, APFloat Y)
APFloatBase::integerPart integerPart
FormattedNumber decValue(uint64_t N, unsigned Width=DEC_WIDTH)
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
This is an optimization pass for GlobalISel generic memory operations.
static unsigned int partAsHex(char *dst, APFloatBase::integerPart part, unsigned int count, const char *hexDigitChars)
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
static const char infinityL[]
static constexpr APFloatBase::integerPart PowerOfFiveParts[]
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
static constexpr unsigned int partCountForBits(unsigned int bits)
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
static unsigned int powerOf5(APFloatBase::integerPart *dst, unsigned int power)
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
static APFloat harrisonUlp(const APFloat &X)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
static Expected< int > totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static char * writeUnsignedDecimal(char *dst, unsigned int n)
constexpr unsigned maxExponent
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
static constexpr unsigned NumPow5PartsOnStack
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
static const char infinityU[]
static constexpr unsigned PowerOfFivePartCounts[]
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
static Error interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
LLVM_READONLY LLVM_ABI std::optional< APFloat > exp(const APFloat &X, RoundingMode RM=APFloat::rmNearestTiesToEven, APFloat::opStatus *Status=nullptr)
Implement IEEE 754-2019 exp functions.
LLVM_ABI bool isFinite(const Loop *L)
Return true if this loop can be assumed to run for a finite number of iterations.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Returns: X * 2^Exp for integral exponents.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static unsigned int powerOfFivePartsForExponent(unsigned int power)
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
static Error createError(const Twine &Err)
static lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
static const char hexDigitsUpper[]
static unsigned int decDigitValue(unsigned int c)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant)
static Expected< StringRef::iterator > skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot)
RoundingMode
Rounding mode.
ArrayRef(const T &OneElt) -> ArrayRef< T >
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
static lostFraction lostFractionThroughTruncation(const APFloatBase::integerPart *parts, unsigned int partCount, unsigned int bits)
APFloat neg(APFloat X)
Returns the negated value of the argument.
static APFloatBase::integerPart ulpsFromBoundary(const APFloatBase::integerPart *parts, unsigned int bits, bool isNearest)
static char * writeSignedDecimal(char *dst, int value)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static Expected< lostFraction > trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue)
void consumeError(Error Err)
Consume a Error without doing anything.
static Expected< int > readExponent(StringRef::iterator begin, StringRef::iterator end)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
static const char hexDigitsLower[]
const char * lastSigDigit
const char * firstSigDigit
APFloatBase::ExponentType maxExponent
fltNonfiniteBehavior nonFiniteBehavior
APFloatBase::ExponentType minExponent
fltNanEncoding nanEncoding