24#include "llvm/Config/llvm-config.h"
40#define LIBC_NAMESPACE __llvm_libc_apfloat
41#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
43#include "shared/math.h"
44#include "shared/math_check_exceptions.h"
46#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
48 if (usesLayout<IEEEFloat>(getSemantics())) \
49 return U.IEEE.METHOD_CALL; \
50 if (usesLayout<DoubleAPFloat>(getSemantics())) \
51 return U.Double.METHOD_CALL; \
52 llvm_unreachable("Unexpected semantics"); \
63#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
71constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
72constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
73constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
74constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
75constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
76constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
79constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
84constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
86constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
87constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
117constexpr fltSemantics APFloatBase::semX87DoubleExtended = {
129constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
130constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
131constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
132 1023, -1022 + 53, 53 + 53, 128};
232 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
233 A.precision <=
B.precision;
245 if (&From == &semPPCDoubleDouble || &To == &semPPCDoubleDouble)
261 if (FromHasSignedZero && !ToHasSignedZero)
268 bool LosesInfo =
false;
371 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
379 return Dst.precision >= Src.precision;
419static inline unsigned int
432 const unsigned int overlargeExponent = 24000;
436 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
439 bool isNegative = *p ==
'-';
440 if (*p ==
'-' || *p ==
'+') {
447 if (absExponent >= 10U)
448 return createError(
"Invalid character in exponent");
450 for (; p != end; ++p) {
453 return createError(
"Invalid character in exponent");
455 absExponent = absExponent * 10U + value;
456 if (absExponent >= overlargeExponent) {
457 absExponent = overlargeExponent;
463 return -(int) absExponent;
465 return (
int) absExponent;
472 int exponentAdjustment) {
478 bool negative = *p ==
'-';
479 if (*p ==
'-' || *p ==
'+') {
485 int unsignedExponent = 0;
486 bool overflow =
false;
487 for (; p != end; ++p) {
492 return createError(
"Invalid character in exponent");
494 unsignedExponent = unsignedExponent * 10 + value;
495 if (unsignedExponent > 32767) {
501 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
505 exponent = unsignedExponent;
507 exponent = -exponent;
508 exponent += exponentAdjustment;
509 if (exponent > 32767 || exponent < -32768)
514 exponent = negative ? -32768: 32767;
524 while (p != end && *p ==
'0')
527 if (p != end && *p ==
'.') {
530 if (end - begin == 1)
533 while (p != end && *p ==
'0')
566 return PtrOrErr.takeError();
569 D->firstSigDigit = p;
571 D->normalizedExponent = 0;
573 for (; p != end; ++p) {
576 return createError(
"String contains multiple dots");
586 if (*p !=
'e' && *p !=
'E')
587 return createError(
"Invalid character in significand");
590 if (dot != end && p - begin == 1)
596 return ExpOrErr.takeError();
597 D->exponent = *ExpOrErr;
605 if (p !=
D->firstSigDigit) {
611 while (p != begin && *p ==
'0');
612 while (p != begin && *p ==
'.');
617 D->normalizedExponent = (
D->exponent +
619 - (dot >
D->firstSigDigit && dot < p)));
631 unsigned int digitValue) {
636 else if (digitValue < 8 && digitValue > 0)
640 while (p != end && (*p ==
'0' || *p ==
'.'))
644 return createError(
"Invalid trailing hexadecimal fraction!");
650 if (hexDigit == UINT_MAX)
660 unsigned int partCount,
685 return lost_fraction;
700 return moreSignificant;
711HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
713 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
715 if (HUerr1 + HUerr2 == 0)
716 return inexactMultiply * 2;
718 return inexactMultiply + 2 * (HUerr1 + HUerr2);
744 if (part - boundary <= boundary - part)
745 return part - boundary;
747 return boundary - part;
750 if (part == boundary) {
756 }
else if (part == boundary - 1) {
773 pow5s[0] = 78125 * 5;
775 unsigned int partsCount = 1;
782 *p1 = firstEightPowers[power & 7];
788 for (
unsigned int n = 0; power; power >>= 1, n++) {
792 partsCount, partsCount);
794 if (pow5[partsCount - 1] == 0)
802 result += partsCount;
803 if (p2[result - 1] == 0)
828static const char NaNL[] =
"nan";
829static const char NaNU[] =
"NAN";
836 const char *hexDigitChars)
838 unsigned int result =
count;
844 dst[
count] = hexDigitChars[part & 0xf];
884 switch (
X.getCategory()) {
894 if (
X.isDenormal() ||
X.isSmallestNormalized())
897 if (
X.getExactLog2() != INT_MIN)
905void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
906 semantics = ourSemantics;
907 unsigned count = partCount();
912void IEEEFloat::freeSignificand() {
914 delete [] significand.parts;
917void IEEEFloat::assign(
const IEEEFloat &rhs) {
918 assert(semantics == rhs.semantics);
921 category = rhs.category;
922 exponent = rhs.exponent;
924 copySignificand(rhs);
927void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
929 assert(rhs.partCount() >= partCount());
942 if (Negative && !semantics->hasSignedRepr)
944 "This floating point format does not support signed values");
948 exponent = exponentNaN();
951 unsigned numParts = partCount();
964 fill = &fill_storage;
968 if (!
fill ||
fill->getNumWords() < numParts)
972 std::min(
fill->getNumWords(), numParts));
975 unsigned bitsToPreserve = semantics->precision - 1;
976 unsigned part = bitsToPreserve / 64;
977 bitsToPreserve %= 64;
978 significand[part] &= ((1ULL << bitsToPreserve) - 1);
979 for (part++; part != numParts; ++part)
980 significand[part] = 0;
984 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
1006 if (semantics == &APFloatBase::semX87DoubleExtended)
1012 if (semantics != rhs.semantics) {
1014 initialize(rhs.semantics);
1025 semantics = rhs.semantics;
1026 significand = rhs.significand;
1027 exponent = rhs.exponent;
1028 category = rhs.category;
1031 rhs.semantics = &APFloatBase::semBogus;
1037 (exponent == semantics->minExponent) &&
1047 significandMSB() == 0;
1052 isSignificandAllZerosExceptMSB();
1055unsigned int IEEEFloat::getNumHighBits()
const {
1062 const unsigned int NumHighBits = (semantics->
precision > 1)
1068bool IEEEFloat::isSignificandAllOnes()
const {
1073 for (
unsigned i = 0; i < PartCount - 1; i++)
1078 const unsigned NumHighBits = getNumHighBits();
1079 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1080 "Can not have more high bits to fill than integerPartWidth");
1083 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
1089bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1098 for (
unsigned i = 0; i < PartCount - 1; i++) {
1099 if (~Parts[i] & ~
unsigned{!i})
1104 const unsigned NumHighBits = getNumHighBits();
1105 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1106 "Can not have more high bits to fill than integerPartWidth");
1109 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1115bool IEEEFloat::isSignificandAllZeros()
const {
1121 for (
unsigned i = 0; i < PartCount - 1; i++)
1126 const unsigned NumHighBits = getNumHighBits();
1128 "clear than integerPartWidth");
1129 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1131 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1137bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1141 for (
unsigned i = 0; i < PartCount - 1; i++) {
1146 const unsigned NumHighBits = getNumHighBits();
1149 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1153 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1160 ? isSignificandAllOnesExceptLSB()
1165 return IsMaxExp && isSignificandAllOnes();
1180 if (semantics != rhs.semantics ||
1181 category != rhs.category ||
1190 return std::equal(significandParts(), significandParts() + partCount(),
1191 rhs.significandParts());
1195 initialize(&ourSemantics);
1200 significandParts()[0] =
value;
1205 initialize(&ourSemantics);
1221 initialize(rhs.semantics);
1226 *
this = std::move(rhs);
1231unsigned int IEEEFloat::partCount()
const {
1236 return const_cast<IEEEFloat *
>(
this)->significandParts();
1240 if (partCount() > 1)
1241 return significand.parts;
1243 return &significand.part;
1246void IEEEFloat::zeroSignificand() {
1251void IEEEFloat::incrementSignificand() {
1263 assert(semantics == rhs.semantics);
1264 assert(exponent == rhs.exponent);
1266 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1275 assert(semantics == rhs.semantics);
1276 assert(exponent == rhs.exponent);
1287 bool ignoreAddend) {
1291 assert(semantics == rhs.semantics);
1293 unsigned precision = semantics->precision;
1301 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1304 unsigned partsCount = partCount();
1307 rhs.significandParts(), partsCount, partsCount);
1311 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1312 exponent += rhs.exponent;
1326 if (!ignoreAddend && addend.isNonZero()) {
1330 Significand savedSignificand = significand;
1331 const fltSemantics *savedSemantics = semantics;
1334 unsigned extendedPrecision = 2 * precision + 1;
1335 if (omsb != extendedPrecision - 1) {
1336 assert(extendedPrecision > omsb);
1338 (extendedPrecision - 1) - omsb);
1339 exponent -= (extendedPrecision - 1) - omsb;
1343 fltSemantics extendedSemantics = *semantics;
1344 extendedSemantics.
precision = extendedPrecision;
1346 if (newPartsCount == 1)
1347 significand.part = fullSignificand[0];
1349 significand.parts = fullSignificand;
1350 semantics = &extendedSemantics;
1363 lost_fraction = extendedAddend.shiftSignificandRight(1);
1365 "Lost precision while shifting addend for fused-multiply-add.");
1367 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1370 if (newPartsCount == 1)
1371 fullSignificand[0] = significand.part;
1372 significand = savedSignificand;
1373 semantics = savedSemantics;
1375 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1382 exponent -= precision + 1;
1391 if (omsb > precision) {
1392 unsigned int bits, significantParts;
1395 bits = omsb - precision;
1397 lf =
shiftRight(fullSignificand, significantParts, bits);
1404 if (newPartsCount > 4)
1405 delete [] fullSignificand;
1407 return lost_fraction;
1416 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1423 assert(semantics == rhs.semantics);
1426 const integerPart *rhsSignificand = rhs.significandParts();
1427 unsigned partsCount = partCount();
1430 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1434 for (
unsigned i = 0; i < partsCount; i++) {
1435 dividend[i] = lhsSignificand[i];
1436 divisor[i] = rhsSignificand[i];
1437 lhsSignificand[i] = 0;
1440 exponent -= rhs.exponent;
1442 unsigned int precision = semantics->precision;
1445 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1452 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1468 for (bit = precision; bit; bit -= 1) {
1493 return lost_fraction;
1496unsigned int IEEEFloat::significandMSB()
const {
1500unsigned int IEEEFloat::significandLSB()
const {
1505lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1511 return shiftRight(significandParts(), partCount(), bits);
1515void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1516 assert(bits < semantics->precision ||
1517 (semantics->precision == 1 && bits <= 1));
1520 unsigned int partsCount = partCount();
1530 assert(semantics == rhs.semantics);
1534 int compare = exponent - rhs.exponent;
1586 exponent = semantics->maxExponent;
1588 semantics->precision);
1601bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1603 unsigned int bit)
const {
1610 switch (rounding_mode) {
1646 unsigned omsb = significandMSB() + 1;
1653 int exponentChange = omsb - semantics->precision;
1657 if (exponent + exponentChange > semantics->maxExponent)
1658 return handleOverflow(rounding_mode);
1662 if (exponent + exponentChange < semantics->minExponent)
1663 exponentChange = semantics->minExponent - exponent;
1666 if (exponentChange < 0) {
1669 shiftSignificandLeft(-exponentChange);
1674 if (exponentChange > 0) {
1678 lf = shiftSignificandRight(exponentChange);
1683 if (omsb > (
unsigned) exponentChange)
1684 omsb -= exponentChange;
1694 exponent == semantics->maxExponent && isSignificandAllOnes())
1695 return handleOverflow(rounding_mode);
1708 if (!semantics->hasZero)
1716 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1718 exponent = semantics->minExponent;
1720 incrementSignificand();
1721 omsb = significandMSB() + 1;
1724 if (omsb == (
unsigned) semantics->precision + 1) {
1728 if (exponent == semantics->maxExponent)
1735 shiftSignificandRight(1);
1744 exponent == semantics->maxExponent && isSignificandAllOnes())
1745 return handleOverflow(rounding_mode);
1750 if (omsb == semantics->precision)
1754 assert(omsb < semantics->precision);
1764 if (!semantics->hasZero)
1836 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1839 int bits = exponent - rhs.exponent;
1843 if ((bits < 0) && !semantics->hasSignedRepr)
1845 "This floating point format does not support signed values");
1848 bool lost_fraction_is_from_rhs =
false;
1852 else if (bits > 0) {
1853 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1854 lost_fraction_is_from_rhs =
true;
1855 shiftSignificandLeft(1);
1857 lost_fraction = shiftSignificandRight(-bits - 1);
1858 temp_rhs.shiftSignificandLeft(1);
1865 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1874 carry = temp_rhs.subtractSignificand(*
this, borrow);
1875 copySignificand(temp_rhs);
1878 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1887 carry = subtractSignificand(temp_rhs, borrow);
1890 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1903 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1904 carry = addSignificand(temp_rhs);
1906 lost_fraction = shiftSignificandRight(-bits);
1907 carry = addSignificand(rhs);
1914 return lost_fraction;
2107 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2108 fs = normalize(rounding_mode, lost_fraction);
2117 if (category ==
fcZero) {
2131 return addOrSubtract(rhs, rounding_mode,
false);
2137 return addOrSubtract(rhs, rounding_mode,
true);
2150 fs = normalize(rounding_mode, lost_fraction);
2168 fs = normalize(rounding_mode, lost_fraction);
2178 unsigned int origSign = sign;
2287 unsigned int origSign = sign;
2308 if (!semantics->hasZero && this->isSmallest())
2328 sign ^= multiplicand.sign;
2337 lost_fraction = multiplySignificand(multiplicand, addend);
2338 fs = normalize(rounding_mode, lost_fraction);
2351 fs = multiplySpecials(multiplicand);
2361 fs = addOrSubtract(addend, rounding_mode,
false);
2433 MagicConstant.sign = sign;
2439 fs =
add(MagicConstant, rounding_mode);
2443 subtract(MagicConstant, rounding_mode);
2454 assert(semantics == rhs.semantics);
2486 if (sign == rhs.sign)
2502 if (sign != rhs.sign) {
2538 unsigned oldPartCount = partCount();
2541 bool X86SpecialNan =
false;
2542 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2543 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2544 (!(*significandParts() & 0x8000000000000000ULL) ||
2545 !(*significandParts() & 0x4000000000000000ULL))) {
2548 X86SpecialNan =
true;
2559 int omsb = significandMSB() + 1;
2560 int exponentChange = omsb - fromSemantics.
precision;
2561 if (exponent + exponentChange < toSemantics.
minExponent)
2562 exponentChange = toSemantics.
minExponent - exponent;
2563 exponentChange = std::max(exponentChange, shift);
2564 if (exponentChange < 0) {
2565 shift -= exponentChange;
2566 exponent += exponentChange;
2567 }
else if (omsb <= -shift) {
2568 exponentChange = omsb + shift - 1;
2569 shift -= exponentChange;
2570 exponent += exponentChange;
2576 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2581 if (newPartCount > oldPartCount) {
2589 significand.parts = newParts;
2590 }
else if (newPartCount == 1 && oldPartCount != 1) {
2594 newPart = significandParts()[0];
2596 significand.part = newPart;
2600 semantics = &toSemantics;
2609 *losesInfo = (
fs !=
opOK);
2610 }
else if (category ==
fcNaN) {
2633 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2651 }
else if (category ==
fcZero &&
2668 if ((sign && !semantics->hasSignedRepr) ||
2669 (category ==
fcZero && !semantics->hasZero)) {
2675 if (category ==
fcZero && !semantics->hasZero)
2700 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2702 if (category ==
fcZero) {
2711 unsigned truncatedBits;
2719 truncatedBits = semantics->
precision -1U - exponent;
2723 unsigned int bits = exponent + 1U;
2729 if (bits < semantics->precision) {
2731 truncatedBits = semantics->
precision - bits;
2738 bits - semantics->precision);
2746 if (truncatedBits) {
2750 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2770 if (omsb == width &&
2806 rounding_mode, isExact);
2809 unsigned int bits, dstPartsCount;
2812 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2814 if (category ==
fcNaN)
2837 unsigned dstCount = partCount();
2838 unsigned precision = semantics->
precision;
2843 if (precision <= omsb) {
2844 exponent = omsb - 1;
2849 exponent = precision - 1;
2854 return normalize(rounding_mode, lost_fraction);
2868 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2872IEEEFloat::convertFromHexadecimalString(
StringRef s,
2881 unsigned partsCount = partCount();
2883 bool computedTrailingFraction =
false;
2891 return PtrOrErr.takeError();
2900 return createError(
"String contains multiple dots");
2906 if (hex_value == UINT_MAX)
2916 }
else if (!computedTrailingFraction) {
2919 return FractOrErr.takeError();
2920 lost_fraction = *FractOrErr;
2921 computedTrailingFraction =
true;
2927 return createError(
"Hex strings require an exponent");
2928 if (*p !=
'p' && *p !=
'P')
2929 return createError(
"Invalid character in significand");
2932 if (dot != end && p - begin == 1)
2936 if (p != firstSignificantDigit) {
2945 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2946 if (expAdjustment < 0)
2948 expAdjustment = expAdjustment * 4 - 1;
2952 expAdjustment += semantics->precision;
2958 return ExpOrErr.takeError();
2959 exponent = *ExpOrErr;
2962 return normalize(rounding_mode, lost_fraction);
2966IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2967 unsigned sigPartCount,
int exp,
2969 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2980 for (;; parts *= 2) {
2981 unsigned int excessPrecision, truncatedBits;
2984 excessPrecision = calcSemantics.
precision - semantics->precision;
2985 truncatedBits = excessPrecision;
2988 decSig.makeZero(sign);
2991 opStatus sigStatus = decSig.convertFromUnsignedParts(
2993 opStatus powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2996 decSig.exponent +=
exp;
3000 unsigned int powHUerr;
3004 calcLostFraction = decSig.multiplySignificand(pow5);
3005 powHUerr = powStatus !=
opOK;
3007 calcLostFraction = decSig.divideSignificand(pow5);
3009 if (decSig.exponent < semantics->minExponent) {
3010 excessPrecision += (semantics->minExponent - decSig.exponent);
3011 truncatedBits = excessPrecision;
3012 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
3021 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3026 excessPrecision, isNearest);
3029 if (HUdistance >= HUerr) {
3030 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3031 calcSemantics.
precision - excessPrecision,
3036 exponent = (decSig.exponent + semantics->precision
3037 - (calcSemantics.
precision - excessPrecision));
3041 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
3047Expected<APFloat::opStatus>
3048IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
3055 return std::move(Err);
3086 if (!semantics->hasZero)
3091 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3092 fs = handleOverflow(rounding_mode);
3098 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3099 (
D.normalizedExponent + 1) * 28738 <=
3100 8651 * (semantics->minExponent - (
int) semantics->precision)) {
3107 }
else if ((
D.normalizedExponent - 1) * 42039
3108 >= 12655 * semantics->maxExponent) {
3110 fs = handleOverflow(rounding_mode);
3113 unsigned int partCount;
3119 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3137 if (p == str.
end()) {
3142 if (decValue >= 10U) {
3143 delete[] decSignificand;
3144 return createError(
"Invalid character in significand");
3150 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3154 partCount, partCount + 1,
false);
3158 if (decSignificand[partCount])
3160 }
while (p <=
D.lastSigDigit);
3163 fs = roundSignificandWithExponent(decSignificand, partCount,
3164 D.exponent, rounding_mode);
3166 delete [] decSignificand;
3172bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3173 const size_t MIN_NAME_SIZE = 3;
3175 if (str.
size() < MIN_NAME_SIZE)
3178 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3185 if (str.
size() < MIN_NAME_SIZE)
3188 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3197 if (str.
size() < MIN_NAME_SIZE)
3204 makeNaN(IsSignaling, IsNegative);
3209 if (str.
front() ==
'(') {
3211 if (str.
size() <= 2 || str.
back() !=
')')
3218 unsigned Radix = 10;
3219 if (str[0] ==
'0') {
3220 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3231 makeNaN(IsSignaling, IsNegative, &Payload);
3239Expected<APFloat::opStatus>
3245 if (convertFromStringSpecials(str))
3250 size_t slen = str.
size();
3251 sign = *p ==
'-' ? 1 : 0;
3252 if (sign && !semantics->hasSignedRepr)
3254 "This floating point format does not support signed values");
3256 if (*p ==
'-' || *p ==
'+') {
3263 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3266 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3270 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3312 dst +=
sizeof NaNU - 1;
3317 *dst++ = upperCase ?
'X':
'x';
3319 if (hexDigits > 1) {
3321 memset (dst,
'0', hexDigits - 1);
3322 dst += hexDigits - 1;
3324 *dst++ = upperCase ?
'P':
'p';
3329 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3335 return static_cast<unsigned int>(dst - p);
3342char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3346 *dst++ = upperCase ?
'X':
'x';
3348 bool roundUp =
false;
3351 const integerPart *significand = significandParts();
3352 unsigned partsCount = partCount();
3356 unsigned valueBits = semantics->
precision + 3;
3361 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3367 if (hexDigits < outputDigits) {
3373 bits = valueBits - hexDigits * 4;
3375 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3377 outputDigits = hexDigits;
3387 while (outputDigits &&
count) {
3391 if (--
count == partsCount)
3394 part = significand[
count] << shift;
3402 curDigits = std::min(curDigits, outputDigits);
3403 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3404 outputDigits -= curDigits;
3414 }
while (*q ==
'0');
3418 memset (dst,
'0', outputDigits);
3419 dst += outputDigits;
3432 *dst++ = upperCase ?
'P':
'p';
3448 Arg.significandParts(),
3449 Arg.significandParts() + Arg.partCount()));
3461APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3462 assert(partCount() == 2);
3463 return convertIEEEFloatToAPInt<APFloatBase::semX87DoubleExtended>();
3466APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3481 extendedSemantics.
minExponent = APFloatBase::semIEEEdouble.minExponent;
3490 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
3496 if (u.isFiniteNonZero() && losesInfo) {
3504 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
3509 return APInt(128, words);
3512template <const fltSemantics &S>
3513APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3515 constexpr unsigned int trailing_significand_bits =
3516 S.precision - 1 + S.hasExplicitIntegerBit;
3520 constexpr uint64_t significand_mask = integer_bit - 1;
3521 constexpr unsigned int exponent_bits =
3522 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3523 static_assert(exponent_bits < 64);
3525 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3526 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3533 myexponent = exponent + bias;
3534 std::copy_n(significandParts(), mysignificand.size(),
3535 mysignificand.begin());
3536 if (myexponent == 1 &&
3537 !(significandParts()[integer_bit_part] & integer_bit))
3539 }
else if (category ==
fcZero) {
3542 myexponent = ::exponentZero(S) + bias;
3543 mysignificand.fill(0);
3548 myexponent = ::exponentInf(S) + bias;
3549 mysignificand.fill(0);
3550 if constexpr (S.hasExplicitIntegerBit) {
3551 mysignificand[0] =
integerPart{1} << (trailing_significand_bits - 1);
3557 myexponent = ::exponentNaN(S) + bias;
3558 std::copy_n(significandParts(), mysignificand.size(),
3559 mysignificand.begin());
3561 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3563 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3564 if constexpr (!S.hasExplicitIntegerBit) {
3565 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3567 words[mysignificand.size() - 1] &= significand_mask;
3570 std::fill(words_iter, words.end(),
uint64_t{0});
3571 constexpr size_t last_word = words.size() - 1;
3573 << ((S.sizeInBits - 1) % 64);
3574 words[last_word] |= shifted_sign;
3575 uint64_t shifted_exponent = (myexponent & exponent_mask)
3576 << (trailing_significand_bits % 64);
3577 words[last_word] |= shifted_exponent;
3578 if constexpr (last_word == 0) {
3579 return APInt(S.sizeInBits, words[0]);
3581 return APInt(S.sizeInBits, words);
3584APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3585 assert(partCount() == 2);
3586 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3589APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3591 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3594APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3596 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3599APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3600 assert(partCount() == 1);
3601 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3604APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3606 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3609APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3610 assert(partCount() == 1);
3611 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3614APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3615 assert(partCount() == 1);
3616 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3619APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3620 assert(partCount() == 1);
3621 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3624APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3625 assert(partCount() == 1);
3626 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3629APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3630 assert(partCount() == 1);
3631 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3634APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3635 assert(partCount() == 1);
3636 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3639APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3640 assert(partCount() == 1);
3641 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3644APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3645 assert(partCount() == 1);
3646 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3649APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3650 assert(partCount() == 1);
3651 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3654APInt IEEEFloat::convertFloat8E5M3FNUAPFloatToAPInt()
const {
3655 assert(partCount() == 1);
3656 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M3FNU>();
3659APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3660 assert(partCount() == 1);
3661 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3664APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3665 assert(partCount() == 1);
3666 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3669APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3670 assert(partCount() == 1);
3671 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3680 return convertHalfAPFloatToAPInt();
3683 return convertBFloatAPFloatToAPInt();
3686 return convertFloatAPFloatToAPInt();
3689 return convertDoubleAPFloatToAPInt();
3692 return convertQuadrupleAPFloatToAPInt();
3696 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3699 return convertFloat8E5M2APFloatToAPInt();
3702 return convertFloat8E5M2FNUZAPFloatToAPInt();
3705 return convertFloat8E4M3APFloatToAPInt();
3708 return convertFloat8E4M3FNAPFloatToAPInt();
3711 return convertFloat8E4M3FNUZAPFloatToAPInt();
3715 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3718 return convertFloat8E3M4APFloatToAPInt();
3721 return convertFloatTF32APFloatToAPInt();
3724 return convertFloat8E8M0FNUAPFloatToAPInt();
3727 return convertFloat8E5M3FNUAPFloatToAPInt();
3730 return convertFloat6E3M2FNAPFloatToAPInt();
3733 return convertFloat6E2M3FNAPFloatToAPInt();
3736 return convertFloat4E2M1FNAPFloatToAPInt();
3741 return convertF80LongDoubleAPFloatToAPInt();
3746 "Float semantics are not IEEEsingle");
3753 "Float semantics are not IEEEdouble");
3758#ifdef HAS_IEE754_FLOAT128
3759float128 IEEEFloat::convertToQuad()
const {
3761 "Float semantics are not IEEEquads");
3763 return api.bitsToQuad();
3767void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3768 return initFromIEEEAPInt<APFloatBase::semX87DoubleExtended>(api);
3771void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3777 initFromDoubleAPInt(
APInt(64, i1));
3799void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3800 initFromIEEEAPInt<APFloatBase::semFloat8E8M0FNU>(api);
3803void IEEEFloat::initFromFloat8E5M3FNUAPInt(
const APInt &api) {
3804 initFromIEEEAPInt<APFloatBase::semFloat8E5M3FNU>(api);
3807template <const fltSemantics &S>
3808void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3811 constexpr unsigned int trailing_significand_bits =
3812 S.precision - 1 + S.hasExplicitIntegerBit;
3815 constexpr uint64_t significand_mask = integer_bit - 1;
3816 constexpr unsigned int exponent_bits =
3817 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3818 static_assert(exponent_bits < 64);
3819 constexpr unsigned int stored_significand_parts =
3822 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3823 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3824 constexpr bool has_significand = trailing_significand_bits > 0;
3828 std::array<integerPart, stored_significand_parts> mysignificand;
3829 if constexpr (has_significand) {
3830 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3832 mysignificand[mysignificand.size() - 1] &= significand_mask;
3835 std::fill_n(mysignificand.begin(), mysignificand.size(), 0);
3838 mysignificand[0] = 1;
3845 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3848 assert(partCount() == mysignificand.size());
3850 sign = S.hasSignedRepr
3851 ?
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64))
3854 bool all_zero_significand =
3857 bool is_zero = myexponent == 0 && all_zero_significand && S.hasZero;
3860 bool is_inf =
false;
3862 if constexpr (S.hasExplicitIntegerBit) {
3864 static_assert(S.precision == 64);
3865 constexpr integerPart significand_mask_no_int_bit =
3866 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3868 mysignificand[0] >> (trailing_significand_bits - 1);
3870 is_inf = myexponent - bias == ::exponentInf(S) && myintegerbit == 1 &&
3871 (mysignificand[0] & significand_mask_no_int_bit) == 0;
3873 is_inf = myexponent - bias == ::exponentInf(S) && all_zero_significand;
3882 bool is_nan =
false;
3885 if constexpr (S.hasExplicitIntegerBit) {
3887 static_assert(S.precision == 64);
3889 mysignificand[0] >> (trailing_significand_bits - 1);
3890 constexpr integerPart significand_mask_no_int_bit =
3891 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3893 if (myexponent - bias == ::exponentNaN(S) &&
3894 (mysignificand[0] & significand_mask_no_int_bit) != 0) {
3897 }
else if (myexponent - bias == ::exponentNaN(S) &&
3898 (mysignificand[0] & significand_mask_no_int_bit) == 0) {
3901 }
else if (myexponent - bias != ::exponentNaN(S) && myexponent != 0 &&
3902 myintegerbit == 0) {
3907 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3910 bool all_ones_significand =
3911 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3912 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3913 (!significand_mask ||
3914 mysignificand[mysignificand.size() - 1] == significand_mask);
3915 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3917 is_nan = is_zero && sign;
3923 std::copy_n(mysignificand.begin(), mysignificand.size(),
3924 significandParts());
3934 exponent = myexponent - bias;
3935 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3936 if (myexponent == 0 && S.hasDenormals)
3937 exponent = S.minExponent;
3939 if constexpr (!S.hasExplicitIntegerBit) {
3940 significandParts()[mysignificand.size() - 1] |= integer_bit;
3945void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3946 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3949void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3950 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3953void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3954 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3957void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3958 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3961void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3962 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3965void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3966 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3969void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3970 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
3973void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3974 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
3977void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3978 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
3981void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3982 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
3985void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3986 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
3989void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
3990 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
3993void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3994 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
3997void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3998 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
4001void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
4002 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
4005void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
4006 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
4012 if (Sem == &APFloatBase::semIEEEhalf)
4013 return initFromHalfAPInt(api);
4014 if (Sem == &APFloatBase::semBFloat)
4015 return initFromBFloatAPInt(api);
4016 if (Sem == &APFloatBase::semIEEEsingle)
4017 return initFromFloatAPInt(api);
4018 if (Sem == &APFloatBase::semIEEEdouble)
4019 return initFromDoubleAPInt(api);
4020 if (Sem == &APFloatBase::semX87DoubleExtended)
4021 return initFromF80LongDoubleAPInt(api);
4022 if (Sem == &APFloatBase::semIEEEquad)
4023 return initFromQuadrupleAPInt(api);
4024 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
4025 return initFromPPCDoubleDoubleLegacyAPInt(api);
4026 if (Sem == &APFloatBase::semFloat8E5M2)
4027 return initFromFloat8E5M2APInt(api);
4028 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
4029 return initFromFloat8E5M2FNUZAPInt(api);
4030 if (Sem == &APFloatBase::semFloat8E4M3)
4031 return initFromFloat8E4M3APInt(api);
4032 if (Sem == &APFloatBase::semFloat8E4M3FN)
4033 return initFromFloat8E4M3FNAPInt(api);
4034 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
4035 return initFromFloat8E4M3FNUZAPInt(api);
4036 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
4037 return initFromFloat8E4M3B11FNUZAPInt(api);
4038 if (Sem == &APFloatBase::semFloat8E3M4)
4039 return initFromFloat8E3M4APInt(api);
4040 if (Sem == &APFloatBase::semFloatTF32)
4041 return initFromFloatTF32APInt(api);
4042 if (Sem == &APFloatBase::semFloat8E8M0FNU)
4043 return initFromFloat8E8M0FNUAPInt(api);
4044 if (Sem == &APFloatBase::semFloat8E5M3FNU)
4045 return initFromFloat8E5M3FNUAPInt(api);
4046 if (Sem == &APFloatBase::semFloat6E3M2FN)
4047 return initFromFloat6E3M2FNAPInt(api);
4048 if (Sem == &APFloatBase::semFloat6E2M3FN)
4049 return initFromFloat6E2M3FNAPInt(api);
4050 if (Sem == &APFloatBase::semFloat4E2M1FN)
4051 return initFromFloat4E2M1FNAPInt(api);
4059 if (Negative && !semantics->hasSignedRepr)
4061 "This floating point format does not support signed values");
4068 exponent = semantics->maxExponent;
4072 unsigned PartCount = partCount();
4073 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4077 const unsigned NumUnusedHighBits =
4084 (semantics->precision > 1))
4091 if (Negative && !semantics->hasSignedRepr)
4093 "This floating point format does not support signed values");
4100 exponent = semantics->minExponent;
4105 if (Negative && !semantics->hasSignedRepr)
4107 "This floating point format does not support signed values");
4116 exponent = semantics->minExponent;
4121 initFromAPInt(&Sem, API);
4134 Buffer.
append(Str.begin(), Str.end());
4139 void AdjustToPrecision(
APInt &significand,
4140 int &
exp,
unsigned FormatPrecision) {
4144 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4146 if (bits <= bitsRequired)
return;
4148 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4149 if (!tensRemovable)
return;
4151 exp += tensRemovable;
4156 if (tensRemovable & 1)
4158 tensRemovable >>= 1;
4159 if (!tensRemovable)
break;
4163 significand = significand.
udiv(divisor);
4171 int &
exp,
unsigned FormatPrecision) {
4172 unsigned N = buffer.
size();
4173 if (
N <= FormatPrecision)
return;
4176 unsigned FirstSignificant =
N - FormatPrecision;
4183 if (buffer[FirstSignificant - 1] <
'5') {
4184 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4187 exp += FirstSignificant;
4188 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4194 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4195 if (buffer[
I] ==
'9') {
4204 if (FirstSignificant ==
N) {
4205 exp += FirstSignificant;
4211 exp += FirstSignificant;
4212 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4216 APInt significand,
unsigned FormatPrecision,
4217 unsigned FormatMaxPadding,
bool TruncateZero) {
4218 const int semanticsPrecision = significand.
getBitWidth();
4225 if (!FormatPrecision) {
4233 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4238 exp += trailingZeros;
4244 }
else if (
exp > 0) {
4246 significand = significand.
zext(semanticsPrecision +
exp);
4247 significand <<=
exp;
4261 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4265 significand = significand.
zext(precision);
4266 APInt five_to_the_i(precision, 5);
4269 significand *= five_to_the_i;
4274 five_to_the_i *= five_to_the_i;
4278 AdjustToPrecision(significand,
exp, FormatPrecision);
4283 unsigned precision = significand.getBitWidth();
4284 if (precision < 4) {
4287 significand = significand.zext(precision);
4289 APInt ten(precision, 10);
4290 APInt digit(precision, 0);
4292 bool inTrail =
true;
4293 while (significand != 0) {
4298 unsigned d = digit.getZExtValue();
4309 assert(!buffer.
empty() &&
"no characters in buffer!");
4313 AdjustToPrecision(buffer,
exp, FormatPrecision);
4315 unsigned NDigits = buffer.
size();
4318 bool FormatScientific;
4319 if (!FormatMaxPadding) {
4320 FormatScientific =
true;
4326 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4327 NDigits + (unsigned)
exp > FormatPrecision);
4330 int MSD =
exp + (int) (NDigits - 1);
4333 FormatScientific =
false;
4337 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4343 if (FormatScientific) {
4344 exp += (NDigits - 1);
4346 Str.push_back(buffer[NDigits-1]);
4348 if (NDigits == 1 && TruncateZero)
4351 for (
unsigned I = 1;
I != NDigits; ++
I)
4352 Str.push_back(buffer[NDigits-1-
I]);
4354 if (!TruncateZero && FormatPrecision > NDigits - 1)
4355 Str.append(FormatPrecision - NDigits + 1,
'0');
4357 Str.push_back(TruncateZero ?
'E' :
'e');
4359 Str.push_back(
exp >= 0 ?
'+' :
'-');
4368 if (!TruncateZero && expbuf.
size() < 2)
4370 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4371 Str.push_back(expbuf[
E-1-
I]);
4377 for (
unsigned I = 0;
I != NDigits; ++
I)
4378 Str.push_back(buffer[NDigits-1-
I]);
4379 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4387 int NWholeDigits =
exp + (int) NDigits;
4390 if (NWholeDigits > 0) {
4391 for (;
I != (unsigned) NWholeDigits; ++
I)
4392 Str.push_back(buffer[NDigits-
I-1]);
4395 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4399 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4403 for (;
I != NDigits; ++
I)
4404 Str.push_back(buffer[NDigits-
I-1]);
4410 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4414 return append(Str,
"-Inf");
4416 return append(Str,
"+Inf");
4418 case fcNaN:
return append(Str,
"NaN");
4424 if (!FormatMaxPadding) {
4426 append(Str,
"0.0E+0");
4429 if (FormatPrecision > 1)
4430 Str.append(FormatPrecision - 1,
'0');
4431 append(Str,
"e+00");
4443 int exp = exponent - ((int) semantics->precision - 1);
4445 semantics->precision,
4448 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4449 FormatMaxPadding, TruncateZero);
4461 for (
int i = 0; i < PartCount; ++i) {
4467 if (exponent != semantics->minExponent)
4470 int CountrParts = 0;
4471 for (
int i = 0; i < PartCount;
4473 if (Parts[i] != 0) {
4474 return exponent - semantics->precision + CountrParts +
4537 if (!semantics->hasZero)
4547 }
else if (semantics->nonFiniteBehavior ==
4555 exponent = semantics->maxExponent + 1;
4569 bool WillCrossBinadeBoundary =
4570 exponent != semantics->minExponent && isSignificandAllZeros();
4588 if (WillCrossBinadeBoundary) {
4609 if (WillCrossBinadeBoundary) {
4613 assert(exponent != semantics->maxExponent &&
4614 "We can not increment an exponent beyond the maxExponent allowed"
4615 " by the given floating point semantics.");
4618 incrementSignificand();
4632 assert(
isNaN() &&
"Can only be called on NaN values");
4634 unsigned Bits = semantics->precision - 1;
4639 return ::exponentNaN(*semantics);
4643 return ::exponentInf(*semantics);
4647 return ::exponentZero(*semantics);
4666 if (!semantics->hasZero)
4693 return Arg.exponent;
4698 Normalized.exponent += SignificandBits;
4700 return Normalized.exponent - SignificandBits;
4704 auto MaxExp =
X.getSemantics().maxExponent;
4705 auto MinExp =
X.getSemantics().minExponent;
4713 int SignificandBits =
X.getSemantics().precision - 1;
4714 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4717 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4740 return scalbn(Val, -Exp, RM);
4746 APFloat(APFloatBase::semIEEEdouble)}) {
4747 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4751 : Semantics(&S), Floats(new
APFloat[2]{
4754 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4760 APFloat(APFloatBase::semIEEEdouble)}) {
4761 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4767 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4768 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4769 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4775 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4776 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4777 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4778 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4782 : Semantics(RHS.Semantics),
4786 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4790 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4791 RHS.Semantics = &APFloatBase::semBogus;
4792 RHS.Floats =
nullptr;
4793 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4797 if (Semantics == RHS.Semantics && RHS.Floats) {
4798 Floats[0] = RHS.Floats[0];
4799 Floats[1] = RHS.Floats[1];
4800 }
else if (
this != &RHS) {
4833 Floats[0] = std::move(z);
4834 Floats[1].makeZero(
false);
4847 Status |= z.
add(a, RM);
4848 Status |= z.
add(c, RM);
4851 Floats[0] = std::move(z);
4852 Floats[1].makeZero(
false);
4857 Status |= zz.
add(cc, RM);
4861 Status |= Floats[1].subtract(z, RM);
4862 Status |= Floats[1].add(c, RM);
4863 Status |= Floats[1].add(zz, RM);
4867 Status |= Floats[1].subtract(z, RM);
4868 Status |= Floats[1].add(a, RM);
4869 Status |= Floats[1].add(zz, RM);
4874 Status |=
q.subtract(z, RM);
4879 Status |= zz.
add(c, RM);
4880 Status |=
q.add(z, RM);
4881 Status |=
q.subtract(a, RM);
4883 Status |= zz.
add(q, RM);
4884 Status |= zz.
add(
aa, RM);
4885 Status |= zz.
add(cc, RM);
4887 Floats[0] = std::move(z);
4888 Floats[1].makeZero(
false);
4892 Status |= Floats[0].add(zz, RM);
4894 Floats[1].makeZero(
false);
4897 Floats[1] = std::move(z);
4898 Status |= Floats[1].subtract(Floats[0], RM);
4899 Status |= Floats[1].add(zz, RM);
4925 LHS.isNegative() !=
RHS.isNegative()) {
4926 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4941 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4942 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4943 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4944 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4945 assert(&Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4946 assert(&Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4947 return Out.addImpl(
A, AA,
C, CC, RM);
4952 return addWithSpecial(*
this, RHS, *
this, RM);
4958 auto Ret =
add(RHS, RM);
4965 const auto &LHS = *
this;
4982 if (LHS.getCategory() ==
fcNaN) {
4986 if (RHS.getCategory() ==
fcNaN) {
4992 Out.makeNaN(
false,
false,
nullptr);
5004 "Special cases not handled exhaustively");
5007 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
5011 if (!
T.isFiniteNonZero()) {
5012 Floats[0] = std::move(
T);
5013 Floats[1].makeZero(
false);
5035 Status |= U.add(Tau, RM);
5038 if (!U.isFinite()) {
5039 Floats[1].makeZero(
false);
5044 Floats[1] = std::move(
T);
5051 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5052 "Unexpected Semantics");
5055 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
5061 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5062 "Unexpected Semantics");
5065 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5071 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5072 "Unexpected Semantics");
5075 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5084 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5085 "Unexpected Semantics");
5088 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
5097 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5098 "Unexpected Semantics");
5108 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5109 Floats[0] = std::move(RoundedHi);
5110 Floats[1].makeZero(
false);
5122 const APFloat RoundingError = Rounded - ToRound;
5123 if (TieBreaker.isNonZero() &&
5124 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5125 abs(RoundingError).isExactlyValue(0.5))
5134 if (RoundedHi !=
Hi) {
5139 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5141 Floats[0] = std::move(RoundedHi);
5142 Floats[1].makeZero(
false);
5155 LoRoundingMode = RM;
5163 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5166 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5168 Floats[0] = std::move(RoundedHi);
5169 Floats[1] = std::move(RoundedLo);
5174 Floats[0].changeSign();
5175 Floats[1].changeSign();
5181 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5186 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5192 const bool ThisIsSubtractive =
5193 Floats[0].isNegative() != Floats[1].isNegative();
5194 const bool RHSIsSubtractive =
5195 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5205 if (RHS.Floats[1].isZero())
5212 if (ThisIsSubtractive != RHSIsSubtractive)
5217 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5219 if (ThisIsSubtractive) {
5233 return Floats[0].getCategory();
5239 Floats[0].makeInf(Neg);
5240 Floats[1].makeZero(
false);
5244 Floats[0].makeZero(Neg);
5245 Floats[1].makeZero(
false);
5249 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5250 "Unexpected Semantics");
5252 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5254 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5260 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5261 "Unexpected Semantics");
5262 Floats[0].makeSmallest(Neg);
5263 Floats[1].makeZero(
false);
5267 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5268 "Unexpected Semantics");
5270 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5272 Floats[0].changeSign();
5273 Floats[1].makeZero(
false);
5277 Floats[0].makeNaN(SNaN, Neg,
fill);
5278 Floats[1].makeZero(
false);
5282 auto Result = Floats[0].compare(RHS.Floats[0]);
5285 return Floats[1].compare(RHS.Floats[1]);
5290 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5291 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5301 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5302 "Unexpected Semantics");
5304 Floats[0].bitcastToAPInt().getRawData()[0],
5305 Floats[1].bitcastToAPInt().getRawData()[0],
5312 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5313 "Unexpected Semantics");
5314 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5327 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5328 "Unexpected Semantics");
5378 if (InLattice(HiOld, NextLo)) {
5380 Floats[1] = std::move(NextLo);
5417 if (!InLattice(NextHi, NextLo))
5421 Floats[0] = std::move(NextHi);
5422 Floats[1] = std::move(NextLo);
5430 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5431 "Unexpected Semantics");
5473 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5474 if (HiExactLog2 >= 0 &&
5475 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5485 Input, Width,
true, RM, &LoIsExact);
5498 *IsExact = RoundStatus ==
opOK;
5510 APSInt LoResult{Width, !IsSigned};
5522 *IsExact = RoundStatus ==
opOK;
5528 unsigned int Width,
bool IsSigned,
5531 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5535 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5543 Bits = Width - IsSigned;
5588 if (SrcMSB == UINT_MAX) {
5595 const unsigned SrcBitWidth = SrcMSB + 1;
5611 return handleOverflow(RM);
5617 bool HiAsIntIsExact;
5634 if (
Error.isNegative()) {
5642 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5644 if (ErrorActiveBits > LoPrecision) {
5645 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5649 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5668 Floats[0] = std::move(
Hi);
5669 Floats[1] = std::move(
Lo);
5674 return handleOverflow(RM);
5680 Largest.makeLargest(
false);
5682 return handleOverflow(RM);
5694 const bool NegateInput = IsSigned &&
Input.isNegative();
5707 unsigned int HexDigits,
5710 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5711 "Unexpected Semantics");
5718 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5720 Floats[0] != Floats[0] + Floats[1]);
5749 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5750 "Unexpected Semantics");
5751 return Floats[0].isInteger() && Floats[1].isInteger();
5755 unsigned FormatPrecision,
5756 unsigned FormatMaxPadding,
5757 bool TruncateZero)
const {
5758 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5759 "Unexpected Semantics");
5761 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5781 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5783 if (
Hi.getExactLog2Abs() == INT_MIN)
5787 return IlogbResult - 1;
5793 "Unexpected Semantics");
5795 scalbn(Arg.Floats[0], Exp, RM),
5796 scalbn(Arg.Floats[1], Exp, RM));
5802 "Unexpected Semantics");
5812 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5834 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5851 LoRoundingMode = RM;
5852 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5860 if (RecomposedLo !=
Lo) {
5864 const APFloat RoundingError = RecomposedLo -
Lo;
5869 const APFloat ScaledUlpOfSecond =
5871 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5872 const bool RoundedLoAway =
5877 if (IsMidpoint && RoundedLoAway)
5893 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5905APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5910 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5925 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5927 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5935 assert(StatusOrErr &&
"Invalid floating point representation");
5987 APFloat Reciprocal =
6005 *Inv = std::move(Reciprocal);
6017 usesLayout<IEEEFloat>(ToSemantics))
6018 return U.IEEE.convert(ToSemantics, RM, losesInfo);
6020 usesLayout<DoubleAPFloat>(ToSemantics)) {
6021 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
6023 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
6024 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
6028 usesLayout<IEEEFloat>(ToSemantics)) {
6029 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
6030 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
6046#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
6059 bool *isExact)
const {
6063 rounding_mode, isExact);
6065 result =
APInt(bitWidth, parts);
6071 return getIEEE().convertToDouble();
6073 "Float semantics is not representable by IEEEdouble");
6074 APFloat Temp = *
this;
6082#ifdef HAS_IEE754_FLOAT128
6083float128 APFloat::convertToQuad()
const {
6085 return getIEEE().convertToQuad();
6087 "Float semantics is not representable by IEEEquad");
6093 return Temp.getIEEE().convertToQuad();
6099 return getIEEE().convertToFloat();
6101 "Float semantics is not representable by IEEEsingle");
6102 APFloat Temp = *
this;
6135 .
Case(
"Float8E5M2", &semFloat8E5M2)
6136 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6137 .
Case(
"Float8E5M3FNU", &semFloat8E5M3FNU)
6138 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6139 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6140 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6144APFloat::Storage::~Storage() {
6145 if (usesLayout<IEEEFloat>(*semantics)) {
6149 if (usesLayout<DoubleAPFloat>(*semantics)) {
6156APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6157 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6161 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6168APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6169 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6173 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6180APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6181 if (usesLayout<IEEEFloat>(*semantics) &&
6182 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6184 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6185 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6187 }
else if (
this != &
RHS) {
6189 new (
this) Storage(
RHS);
6194APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6195 if (usesLayout<IEEEFloat>(*semantics) &&
6196 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6198 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6199 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6201 }
else if (
this != &
RHS) {
6203 new (
this) Storage(std::move(
RHS));
6212 if (libc_exceptions & FE_INVALID)
6214 if (libc_exceptions & FE_DIVBYZERO)
6216 if (libc_exceptions & FE_OVERFLOW)
6218 if (libc_exceptions & FE_UNDERFLOW)
6220 if (libc_exceptions & FE_INEXACT)
6235 float x_val = x.convertToFloat();
6237 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6239 *status = getOpStatusFromLibc(exc);
6240 if (x.isSignaling()) {
6247 float result = LIBC_NAMESPACE::shared::expf(x_val);
6252 double x_val = x.convertToDouble();
6254 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6256 *status = getOpStatusFromLibc(exc);
6257 if (x.isSignaling()) {
6264 double result = LIBC_NAMESPACE::shared::exp(x_val);
6268 return std::nullopt;
6273#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 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...
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)
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[]
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...
const unsigned int maxPowerOfFiveExponent
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static char * writeUnsignedDecimal(char *dst, unsigned int n)
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.
const unsigned int maxPrecision
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[]
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.
const unsigned int maxPowerOfFiveParts
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 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)
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[]
const unsigned int maxExponent
static unsigned int decDigitValue(unsigned int c)
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