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;
307 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
315 return Dst.precision >= Src.precision;
355static inline unsigned int
368 const unsigned int overlargeExponent = 24000;
372 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
375 bool isNegative = *p ==
'-';
376 if (*p ==
'-' || *p ==
'+') {
383 if (absExponent >= 10U)
384 return createError(
"Invalid character in exponent");
386 for (; p != end; ++p) {
389 return createError(
"Invalid character in exponent");
391 absExponent = absExponent * 10U + value;
392 if (absExponent >= overlargeExponent) {
393 absExponent = overlargeExponent;
399 return -(int) absExponent;
401 return (
int) absExponent;
408 int exponentAdjustment) {
414 bool negative = *p ==
'-';
415 if (*p ==
'-' || *p ==
'+') {
421 int unsignedExponent = 0;
422 bool overflow =
false;
423 for (; p != end; ++p) {
428 return createError(
"Invalid character in exponent");
430 unsignedExponent = unsignedExponent * 10 + value;
431 if (unsignedExponent > 32767) {
437 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
441 exponent = unsignedExponent;
443 exponent = -exponent;
444 exponent += exponentAdjustment;
445 if (exponent > 32767 || exponent < -32768)
450 exponent = negative ? -32768: 32767;
460 while (p != end && *p ==
'0')
463 if (p != end && *p ==
'.') {
466 if (end - begin == 1)
469 while (p != end && *p ==
'0')
502 return PtrOrErr.takeError();
505 D->firstSigDigit = p;
507 D->normalizedExponent = 0;
509 for (; p != end; ++p) {
512 return createError(
"String contains multiple dots");
522 if (*p !=
'e' && *p !=
'E')
523 return createError(
"Invalid character in significand");
526 if (dot != end && p - begin == 1)
532 return ExpOrErr.takeError();
533 D->exponent = *ExpOrErr;
541 if (p !=
D->firstSigDigit) {
547 while (p != begin && *p ==
'0');
548 while (p != begin && *p ==
'.');
553 D->normalizedExponent = (
D->exponent +
555 - (dot >
D->firstSigDigit && dot < p)));
567 unsigned int digitValue) {
572 else if (digitValue < 8 && digitValue > 0)
576 while (p != end && (*p ==
'0' || *p ==
'.'))
580 return createError(
"Invalid trailing hexadecimal fraction!");
586 if (hexDigit == UINT_MAX)
596 unsigned int partCount,
621 return lost_fraction;
636 return moreSignificant;
647HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
649 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
651 if (HUerr1 + HUerr2 == 0)
652 return inexactMultiply * 2;
654 return inexactMultiply + 2 * (HUerr1 + HUerr2);
680 if (part - boundary <= boundary - part)
681 return part - boundary;
683 return boundary - part;
686 if (part == boundary) {
692 }
else if (part == boundary - 1) {
709 pow5s[0] = 78125 * 5;
711 unsigned int partsCount = 1;
718 *p1 = firstEightPowers[power & 7];
724 for (
unsigned int n = 0; power; power >>= 1, n++) {
728 partsCount, partsCount);
730 if (pow5[partsCount - 1] == 0)
738 result += partsCount;
739 if (p2[result - 1] == 0)
764static const char NaNL[] =
"nan";
765static const char NaNU[] =
"NAN";
772 const char *hexDigitChars)
774 unsigned int result =
count;
780 dst[
count] = hexDigitChars[part & 0xf];
820 switch (
X.getCategory()) {
830 if (
X.isDenormal() ||
X.isSmallestNormalized())
833 if (
X.getExactLog2() != INT_MIN)
841void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
842 semantics = ourSemantics;
843 unsigned count = partCount();
848void IEEEFloat::freeSignificand() {
850 delete [] significand.parts;
853void IEEEFloat::assign(
const IEEEFloat &rhs) {
854 assert(semantics == rhs.semantics);
857 category = rhs.category;
858 exponent = rhs.exponent;
860 copySignificand(rhs);
863void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
865 assert(rhs.partCount() >= partCount());
878 if (Negative && !semantics->hasSignedRepr)
880 "This floating point format does not support signed values");
884 exponent = exponentNaN();
887 unsigned numParts = partCount();
900 fill = &fill_storage;
904 if (!
fill ||
fill->getNumWords() < numParts)
908 std::min(
fill->getNumWords(), numParts));
911 unsigned bitsToPreserve = semantics->precision - 1;
912 unsigned part = bitsToPreserve / 64;
913 bitsToPreserve %= 64;
914 significand[part] &= ((1ULL << bitsToPreserve) - 1);
915 for (part++; part != numParts; ++part)
916 significand[part] = 0;
920 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
942 if (semantics == &APFloatBase::semX87DoubleExtended)
948 if (semantics != rhs.semantics) {
950 initialize(rhs.semantics);
961 semantics = rhs.semantics;
962 significand = rhs.significand;
963 exponent = rhs.exponent;
964 category = rhs.category;
967 rhs.semantics = &APFloatBase::semBogus;
973 (exponent == semantics->minExponent) &&
983 significandMSB() == 0;
988 isSignificandAllZerosExceptMSB();
991unsigned int IEEEFloat::getNumHighBits()
const {
998 const unsigned int NumHighBits = (semantics->
precision > 1)
1004bool IEEEFloat::isSignificandAllOnes()
const {
1009 for (
unsigned i = 0; i < PartCount - 1; i++)
1014 const unsigned NumHighBits = getNumHighBits();
1015 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1016 "Can not have more high bits to fill than integerPartWidth");
1019 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
1025bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1034 for (
unsigned i = 0; i < PartCount - 1; i++) {
1035 if (~Parts[i] & ~
unsigned{!i})
1040 const unsigned NumHighBits = getNumHighBits();
1041 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1042 "Can not have more high bits to fill than integerPartWidth");
1045 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1051bool IEEEFloat::isSignificandAllZeros()
const {
1057 for (
unsigned i = 0; i < PartCount - 1; i++)
1062 const unsigned NumHighBits = getNumHighBits();
1064 "clear than integerPartWidth");
1065 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1067 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1073bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1077 for (
unsigned i = 0; i < PartCount - 1; i++) {
1082 const unsigned NumHighBits = getNumHighBits();
1085 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1089 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1096 ? isSignificandAllOnesExceptLSB()
1101 return IsMaxExp && isSignificandAllOnes();
1116 if (semantics != rhs.semantics ||
1117 category != rhs.category ||
1126 return std::equal(significandParts(), significandParts() + partCount(),
1127 rhs.significandParts());
1131 initialize(&ourSemantics);
1136 significandParts()[0] =
value;
1141 initialize(&ourSemantics);
1157 initialize(rhs.semantics);
1162 *
this = std::move(rhs);
1167unsigned int IEEEFloat::partCount()
const {
1172 return const_cast<IEEEFloat *
>(
this)->significandParts();
1176 if (partCount() > 1)
1177 return significand.parts;
1179 return &significand.part;
1182void IEEEFloat::zeroSignificand() {
1187void IEEEFloat::incrementSignificand() {
1199 assert(semantics == rhs.semantics);
1200 assert(exponent == rhs.exponent);
1202 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1211 assert(semantics == rhs.semantics);
1212 assert(exponent == rhs.exponent);
1223 bool ignoreAddend) {
1227 assert(semantics == rhs.semantics);
1229 unsigned precision = semantics->precision;
1237 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1240 unsigned partsCount = partCount();
1243 rhs.significandParts(), partsCount, partsCount);
1247 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1248 exponent += rhs.exponent;
1262 if (!ignoreAddend && addend.isNonZero()) {
1266 Significand savedSignificand = significand;
1267 const fltSemantics *savedSemantics = semantics;
1270 unsigned extendedPrecision = 2 * precision + 1;
1271 if (omsb != extendedPrecision - 1) {
1272 assert(extendedPrecision > omsb);
1274 (extendedPrecision - 1) - omsb);
1275 exponent -= (extendedPrecision - 1) - omsb;
1279 fltSemantics extendedSemantics = *semantics;
1280 extendedSemantics.
precision = extendedPrecision;
1282 if (newPartsCount == 1)
1283 significand.part = fullSignificand[0];
1285 significand.parts = fullSignificand;
1286 semantics = &extendedSemantics;
1299 lost_fraction = extendedAddend.shiftSignificandRight(1);
1301 "Lost precision while shifting addend for fused-multiply-add.");
1303 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1306 if (newPartsCount == 1)
1307 fullSignificand[0] = significand.part;
1308 significand = savedSignificand;
1309 semantics = savedSemantics;
1311 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1318 exponent -= precision + 1;
1327 if (omsb > precision) {
1328 unsigned int bits, significantParts;
1331 bits = omsb - precision;
1333 lf =
shiftRight(fullSignificand, significantParts, bits);
1340 if (newPartsCount > 4)
1341 delete [] fullSignificand;
1343 return lost_fraction;
1352 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1359 assert(semantics == rhs.semantics);
1362 const integerPart *rhsSignificand = rhs.significandParts();
1363 unsigned partsCount = partCount();
1366 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1370 for (
unsigned i = 0; i < partsCount; i++) {
1371 dividend[i] = lhsSignificand[i];
1372 divisor[i] = rhsSignificand[i];
1373 lhsSignificand[i] = 0;
1376 exponent -= rhs.exponent;
1378 unsigned int precision = semantics->precision;
1381 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1388 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1404 for (bit = precision; bit; bit -= 1) {
1429 return lost_fraction;
1432unsigned int IEEEFloat::significandMSB()
const {
1436unsigned int IEEEFloat::significandLSB()
const {
1441lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1447 return shiftRight(significandParts(), partCount(), bits);
1451void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1452 assert(bits < semantics->precision ||
1453 (semantics->precision == 1 && bits <= 1));
1456 unsigned int partsCount = partCount();
1466 assert(semantics == rhs.semantics);
1470 int compare = exponent - rhs.exponent;
1522 exponent = semantics->maxExponent;
1524 semantics->precision);
1537bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1539 unsigned int bit)
const {
1546 switch (rounding_mode) {
1582 unsigned omsb = significandMSB() + 1;
1589 int exponentChange = omsb - semantics->precision;
1593 if (exponent + exponentChange > semantics->maxExponent)
1594 return handleOverflow(rounding_mode);
1598 if (exponent + exponentChange < semantics->minExponent)
1599 exponentChange = semantics->minExponent - exponent;
1602 if (exponentChange < 0) {
1605 shiftSignificandLeft(-exponentChange);
1610 if (exponentChange > 0) {
1614 lf = shiftSignificandRight(exponentChange);
1619 if (omsb > (
unsigned) exponentChange)
1620 omsb -= exponentChange;
1630 exponent == semantics->maxExponent && isSignificandAllOnes())
1631 return handleOverflow(rounding_mode);
1644 if (!semantics->hasZero)
1652 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1654 exponent = semantics->minExponent;
1656 incrementSignificand();
1657 omsb = significandMSB() + 1;
1660 if (omsb == (
unsigned) semantics->precision + 1) {
1664 if (exponent == semantics->maxExponent)
1671 shiftSignificandRight(1);
1680 exponent == semantics->maxExponent && isSignificandAllOnes())
1681 return handleOverflow(rounding_mode);
1686 if (omsb == semantics->precision)
1690 assert(omsb < semantics->precision);
1700 if (!semantics->hasZero)
1772 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1775 int bits = exponent - rhs.exponent;
1779 if ((bits < 0) && !semantics->hasSignedRepr)
1781 "This floating point format does not support signed values");
1784 bool lost_fraction_is_from_rhs =
false;
1788 else if (bits > 0) {
1789 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1790 lost_fraction_is_from_rhs =
true;
1791 shiftSignificandLeft(1);
1793 lost_fraction = shiftSignificandRight(-bits - 1);
1794 temp_rhs.shiftSignificandLeft(1);
1801 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1810 carry = temp_rhs.subtractSignificand(*
this, borrow);
1811 copySignificand(temp_rhs);
1814 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1823 carry = subtractSignificand(temp_rhs, borrow);
1826 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1839 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1840 carry = addSignificand(temp_rhs);
1842 lost_fraction = shiftSignificandRight(-bits);
1843 carry = addSignificand(rhs);
1850 return lost_fraction;
2043 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2044 fs = normalize(rounding_mode, lost_fraction);
2053 if (category ==
fcZero) {
2067 return addOrSubtract(rhs, rounding_mode,
false);
2073 return addOrSubtract(rhs, rounding_mode,
true);
2086 fs = normalize(rounding_mode, lost_fraction);
2104 fs = normalize(rounding_mode, lost_fraction);
2114 unsigned int origSign = sign;
2223 unsigned int origSign = sign;
2244 if (!semantics->hasZero && this->isSmallest())
2264 sign ^= multiplicand.sign;
2273 lost_fraction = multiplySignificand(multiplicand, addend);
2274 fs = normalize(rounding_mode, lost_fraction);
2287 fs = multiplySpecials(multiplicand);
2297 fs = addOrSubtract(addend, rounding_mode,
false);
2369 MagicConstant.sign = sign;
2375 fs =
add(MagicConstant, rounding_mode);
2379 subtract(MagicConstant, rounding_mode);
2390 assert(semantics == rhs.semantics);
2422 if (sign == rhs.sign)
2438 if (sign != rhs.sign) {
2474 unsigned oldPartCount = partCount();
2477 bool X86SpecialNan =
false;
2478 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2479 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2480 (!(*significandParts() & 0x8000000000000000ULL) ||
2481 !(*significandParts() & 0x4000000000000000ULL))) {
2484 X86SpecialNan =
true;
2495 int omsb = significandMSB() + 1;
2496 int exponentChange = omsb - fromSemantics.
precision;
2497 if (exponent + exponentChange < toSemantics.
minExponent)
2498 exponentChange = toSemantics.
minExponent - exponent;
2499 exponentChange = std::max(exponentChange, shift);
2500 if (exponentChange < 0) {
2501 shift -= exponentChange;
2502 exponent += exponentChange;
2503 }
else if (omsb <= -shift) {
2504 exponentChange = omsb + shift - 1;
2505 shift -= exponentChange;
2506 exponent += exponentChange;
2512 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2517 if (newPartCount > oldPartCount) {
2525 significand.parts = newParts;
2526 }
else if (newPartCount == 1 && oldPartCount != 1) {
2530 newPart = significandParts()[0];
2532 significand.part = newPart;
2536 semantics = &toSemantics;
2545 *losesInfo = (
fs !=
opOK);
2546 }
else if (category ==
fcNaN) {
2564 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2581 }
else if (category ==
fcZero &&
2594 if (category ==
fcZero && !semantics->hasZero)
2619 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2621 if (category ==
fcZero) {
2630 unsigned truncatedBits;
2638 truncatedBits = semantics->
precision -1U - exponent;
2642 unsigned int bits = exponent + 1U;
2648 if (bits < semantics->precision) {
2650 truncatedBits = semantics->
precision - bits;
2657 bits - semantics->precision);
2665 if (truncatedBits) {
2669 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2689 if (omsb == width &&
2725 rounding_mode, isExact);
2728 unsigned int bits, dstPartsCount;
2731 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2733 if (category ==
fcNaN)
2756 unsigned dstCount = partCount();
2757 unsigned precision = semantics->
precision;
2762 if (precision <= omsb) {
2763 exponent = omsb - 1;
2768 exponent = precision - 1;
2773 return normalize(rounding_mode, lost_fraction);
2787 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2791IEEEFloat::convertFromHexadecimalString(
StringRef s,
2800 unsigned partsCount = partCount();
2802 bool computedTrailingFraction =
false;
2810 return PtrOrErr.takeError();
2819 return createError(
"String contains multiple dots");
2825 if (hex_value == UINT_MAX)
2835 }
else if (!computedTrailingFraction) {
2838 return FractOrErr.takeError();
2839 lost_fraction = *FractOrErr;
2840 computedTrailingFraction =
true;
2846 return createError(
"Hex strings require an exponent");
2847 if (*p !=
'p' && *p !=
'P')
2848 return createError(
"Invalid character in significand");
2851 if (dot != end && p - begin == 1)
2855 if (p != firstSignificantDigit) {
2864 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2865 if (expAdjustment < 0)
2867 expAdjustment = expAdjustment * 4 - 1;
2871 expAdjustment += semantics->precision;
2877 return ExpOrErr.takeError();
2878 exponent = *ExpOrErr;
2881 return normalize(rounding_mode, lost_fraction);
2885IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2886 unsigned sigPartCount,
int exp,
2888 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2899 for (;; parts *= 2) {
2900 unsigned int excessPrecision, truncatedBits;
2903 excessPrecision = calcSemantics.
precision - semantics->precision;
2904 truncatedBits = excessPrecision;
2907 decSig.makeZero(sign);
2910 opStatus sigStatus = decSig.convertFromUnsignedParts(
2912 opStatus powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2915 decSig.exponent +=
exp;
2919 unsigned int powHUerr;
2923 calcLostFraction = decSig.multiplySignificand(pow5);
2924 powHUerr = powStatus !=
opOK;
2926 calcLostFraction = decSig.divideSignificand(pow5);
2928 if (decSig.exponent < semantics->minExponent) {
2929 excessPrecision += (semantics->minExponent - decSig.exponent);
2930 truncatedBits = excessPrecision;
2931 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
2940 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
2945 excessPrecision, isNearest);
2948 if (HUdistance >= HUerr) {
2949 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
2950 calcSemantics.
precision - excessPrecision,
2955 exponent = (decSig.exponent + semantics->precision
2956 - (calcSemantics.
precision - excessPrecision));
2960 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
2966Expected<APFloat::opStatus>
2967IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
2974 return std::move(Err);
3005 if (!semantics->hasZero)
3010 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3011 fs = handleOverflow(rounding_mode);
3017 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3018 (
D.normalizedExponent + 1) * 28738 <=
3019 8651 * (semantics->minExponent - (
int) semantics->precision)) {
3026 }
else if ((
D.normalizedExponent - 1) * 42039
3027 >= 12655 * semantics->maxExponent) {
3029 fs = handleOverflow(rounding_mode);
3032 unsigned int partCount;
3038 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3056 if (p == str.
end()) {
3061 if (decValue >= 10U) {
3062 delete[] decSignificand;
3063 return createError(
"Invalid character in significand");
3069 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3073 partCount, partCount + 1,
false);
3077 if (decSignificand[partCount])
3079 }
while (p <=
D.lastSigDigit);
3082 fs = roundSignificandWithExponent(decSignificand, partCount,
3083 D.exponent, rounding_mode);
3085 delete [] decSignificand;
3091bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3092 const size_t MIN_NAME_SIZE = 3;
3094 if (str.
size() < MIN_NAME_SIZE)
3097 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3104 if (str.
size() < MIN_NAME_SIZE)
3107 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3116 if (str.
size() < MIN_NAME_SIZE)
3123 makeNaN(IsSignaling, IsNegative);
3128 if (str.
front() ==
'(') {
3130 if (str.
size() <= 2 || str.
back() !=
')')
3137 unsigned Radix = 10;
3138 if (str[0] ==
'0') {
3139 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3150 makeNaN(IsSignaling, IsNegative, &Payload);
3158Expected<APFloat::opStatus>
3164 if (convertFromStringSpecials(str))
3169 size_t slen = str.
size();
3170 sign = *p ==
'-' ? 1 : 0;
3171 if (sign && !semantics->hasSignedRepr)
3173 "This floating point format does not support signed values");
3175 if (*p ==
'-' || *p ==
'+') {
3182 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3185 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3189 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3231 dst +=
sizeof NaNU - 1;
3236 *dst++ = upperCase ?
'X':
'x';
3238 if (hexDigits > 1) {
3240 memset (dst,
'0', hexDigits - 1);
3241 dst += hexDigits - 1;
3243 *dst++ = upperCase ?
'P':
'p';
3248 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3254 return static_cast<unsigned int>(dst - p);
3261char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3265 *dst++ = upperCase ?
'X':
'x';
3267 bool roundUp =
false;
3270 const integerPart *significand = significandParts();
3271 unsigned partsCount = partCount();
3275 unsigned valueBits = semantics->
precision + 3;
3280 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3286 if (hexDigits < outputDigits) {
3292 bits = valueBits - hexDigits * 4;
3294 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3296 outputDigits = hexDigits;
3306 while (outputDigits &&
count) {
3310 if (--
count == partsCount)
3313 part = significand[
count] << shift;
3321 curDigits = std::min(curDigits, outputDigits);
3322 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3323 outputDigits -= curDigits;
3333 }
while (*q ==
'0');
3337 memset (dst,
'0', outputDigits);
3338 dst += outputDigits;
3351 *dst++ = upperCase ?
'P':
'p';
3367 Arg.significandParts(),
3368 Arg.significandParts() + Arg.partCount()));
3380APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3381 assert(partCount() == 2);
3382 return convertIEEEFloatToAPInt<APFloatBase::semX87DoubleExtended>();
3385APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3400 extendedSemantics.
minExponent = APFloatBase::semIEEEdouble.minExponent;
3409 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
3415 if (u.isFiniteNonZero() && losesInfo) {
3423 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
3428 return APInt(128, words);
3431template <const fltSemantics &S>
3432APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3434 constexpr unsigned int trailing_significand_bits =
3435 S.precision - 1 + S.hasExplicitIntegerBit;
3439 constexpr uint64_t significand_mask = integer_bit - 1;
3440 constexpr unsigned int exponent_bits =
3441 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3442 static_assert(exponent_bits < 64);
3443 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3444 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3445 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3447 uint64_t myexponent;
3452 myexponent = exponent + bias;
3453 std::copy_n(significandParts(), mysignificand.size(),
3454 mysignificand.begin());
3455 if (myexponent == 1 &&
3456 !(significandParts()[integer_bit_part] & integer_bit))
3458 }
else if (category ==
fcZero) {
3461 myexponent = ::exponentZero(S) + bias;
3462 mysignificand.fill(0);
3467 myexponent = ::exponentInf(S) + bias;
3468 mysignificand.fill(0);
3469 if constexpr (S.hasExplicitIntegerBit) {
3470 mysignificand[0] =
integerPart{1} << (trailing_significand_bits - 1);
3476 myexponent = ::exponentNaN(S) + bias;
3477 std::copy_n(significandParts(), mysignificand.size(),
3478 mysignificand.begin());
3480 std::array<uint64_t, (S.sizeInBits + 63) / 64> words;
3482 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3483 if constexpr (!S.hasExplicitIntegerBit) {
3484 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3486 words[mysignificand.size() - 1] &= significand_mask;
3489 std::fill(words_iter, words.end(), uint64_t{0});
3490 constexpr size_t last_word = words.size() - 1;
3491 uint64_t shifted_sign =
static_cast<uint64_t
>(sign & 1)
3492 << ((S.sizeInBits - 1) % 64);
3493 words[last_word] |= shifted_sign;
3494 uint64_t shifted_exponent = (myexponent & exponent_mask)
3495 << (trailing_significand_bits % 64);
3496 words[last_word] |= shifted_exponent;
3497 if constexpr (last_word == 0) {
3498 return APInt(S.sizeInBits, words[0]);
3500 return APInt(S.sizeInBits, words);
3503APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3504 assert(partCount() == 2);
3505 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3508APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3510 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3513APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3515 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3518APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3519 assert(partCount() == 1);
3520 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3523APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3525 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3528APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3529 assert(partCount() == 1);
3530 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3533APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3534 assert(partCount() == 1);
3535 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3538APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3539 assert(partCount() == 1);
3540 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3543APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3544 assert(partCount() == 1);
3545 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3548APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3549 assert(partCount() == 1);
3550 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3553APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3554 assert(partCount() == 1);
3555 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3558APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3559 assert(partCount() == 1);
3560 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3563APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3564 assert(partCount() == 1);
3565 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3568APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3569 assert(partCount() == 1);
3570 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3573APInt IEEEFloat::convertFloat8E5M3FNUAPFloatToAPInt()
const {
3574 assert(partCount() == 1);
3575 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M3FNU>();
3578APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3579 assert(partCount() == 1);
3580 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3583APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3584 assert(partCount() == 1);
3585 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3588APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3589 assert(partCount() == 1);
3590 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3599 return convertHalfAPFloatToAPInt();
3602 return convertBFloatAPFloatToAPInt();
3605 return convertFloatAPFloatToAPInt();
3608 return convertDoubleAPFloatToAPInt();
3611 return convertQuadrupleAPFloatToAPInt();
3615 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3618 return convertFloat8E5M2APFloatToAPInt();
3621 return convertFloat8E5M2FNUZAPFloatToAPInt();
3624 return convertFloat8E4M3APFloatToAPInt();
3627 return convertFloat8E4M3FNAPFloatToAPInt();
3630 return convertFloat8E4M3FNUZAPFloatToAPInt();
3634 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3637 return convertFloat8E3M4APFloatToAPInt();
3640 return convertFloatTF32APFloatToAPInt();
3643 return convertFloat8E8M0FNUAPFloatToAPInt();
3646 return convertFloat8E5M3FNUAPFloatToAPInt();
3649 return convertFloat6E3M2FNAPFloatToAPInt();
3652 return convertFloat6E2M3FNAPFloatToAPInt();
3655 return convertFloat4E2M1FNAPFloatToAPInt();
3660 return convertF80LongDoubleAPFloatToAPInt();
3665 "Float semantics are not IEEEsingle");
3672 "Float semantics are not IEEEdouble");
3677#ifdef HAS_IEE754_FLOAT128
3678float128 IEEEFloat::convertToQuad()
const {
3680 "Float semantics are not IEEEquads");
3682 return api.bitsToQuad();
3686void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3687 return initFromIEEEAPInt<APFloatBase::semX87DoubleExtended>(api);
3690void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3696 initFromDoubleAPInt(
APInt(64, i1));
3718void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3719 initFromIEEEAPInt<APFloatBase::semFloat8E8M0FNU>(api);
3722void IEEEFloat::initFromFloat8E5M3FNUAPInt(
const APInt &api) {
3723 initFromIEEEAPInt<APFloatBase::semFloat8E5M3FNU>(api);
3726template <const fltSemantics &S>
3727void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3730 constexpr unsigned int trailing_significand_bits =
3731 S.precision - 1 + S.hasExplicitIntegerBit;
3734 constexpr uint64_t significand_mask = integer_bit - 1;
3735 constexpr unsigned int exponent_bits =
3736 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3737 static_assert(exponent_bits < 64);
3738 constexpr unsigned int stored_significand_parts =
3740 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3741 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3742 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3743 constexpr bool has_significand = trailing_significand_bits > 0;
3747 std::array<integerPart, stored_significand_parts> mysignificand;
3748 if constexpr (has_significand) {
3749 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3751 mysignificand[mysignificand.size() - 1] &= significand_mask;
3754 std::fill_n(mysignificand.begin(), mysignificand.size(), 0);
3757 mysignificand[0] = 1;
3763 uint64_t myexponent =
3764 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3767 assert(partCount() == mysignificand.size());
3769 sign = S.hasSignedRepr
3770 ?
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64))
3773 bool all_zero_significand =
3776 bool is_zero = myexponent == 0 && all_zero_significand && S.hasZero;
3779 bool is_inf =
false;
3781 if constexpr (S.hasExplicitIntegerBit) {
3783 static_assert(S.precision == 64);
3784 constexpr integerPart significand_mask_no_int_bit =
3785 (uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3787 mysignificand[0] >> (trailing_significand_bits - 1);
3789 is_inf = myexponent - bias == ::exponentInf(S) && myintegerbit == 1 &&
3790 (mysignificand[0] & significand_mask_no_int_bit) == 0;
3792 is_inf = myexponent - bias == ::exponentInf(S) && all_zero_significand;
3801 bool is_nan =
false;
3804 if constexpr (S.hasExplicitIntegerBit) {
3806 static_assert(S.precision == 64);
3808 mysignificand[0] >> (trailing_significand_bits - 1);
3809 constexpr integerPart significand_mask_no_int_bit =
3810 (uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3812 if (myexponent - bias == ::exponentNaN(S) &&
3813 (mysignificand[0] & significand_mask_no_int_bit) != 0) {
3816 }
else if (myexponent - bias == ::exponentNaN(S) &&
3817 (mysignificand[0] & significand_mask_no_int_bit) == 0) {
3820 }
else if (myexponent - bias != ::exponentNaN(S) && myexponent != 0 &&
3821 myintegerbit == 0) {
3826 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3829 bool all_ones_significand =
3830 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3831 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3832 (!significand_mask ||
3833 mysignificand[mysignificand.size() - 1] == significand_mask);
3834 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3836 is_nan = is_zero && sign;
3842 std::copy_n(mysignificand.begin(), mysignificand.size(),
3843 significandParts());
3853 exponent = myexponent - bias;
3854 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3855 if (myexponent == 0 && S.hasDenormals)
3856 exponent = S.minExponent;
3858 if constexpr (!S.hasExplicitIntegerBit) {
3859 significandParts()[mysignificand.size() - 1] |= integer_bit;
3864void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3865 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3868void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3869 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3872void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3873 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3876void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3877 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3880void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3881 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3884void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3885 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3888void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3889 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
3892void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3893 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
3896void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3897 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
3900void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3901 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
3904void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3905 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
3908void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
3909 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
3912void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3913 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
3916void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3917 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
3920void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
3921 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
3924void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
3925 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
3931 if (Sem == &APFloatBase::semIEEEhalf)
3932 return initFromHalfAPInt(api);
3933 if (Sem == &APFloatBase::semBFloat)
3934 return initFromBFloatAPInt(api);
3935 if (Sem == &APFloatBase::semIEEEsingle)
3936 return initFromFloatAPInt(api);
3937 if (Sem == &APFloatBase::semIEEEdouble)
3938 return initFromDoubleAPInt(api);
3939 if (Sem == &APFloatBase::semX87DoubleExtended)
3940 return initFromF80LongDoubleAPInt(api);
3941 if (Sem == &APFloatBase::semIEEEquad)
3942 return initFromQuadrupleAPInt(api);
3943 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
3944 return initFromPPCDoubleDoubleLegacyAPInt(api);
3945 if (Sem == &APFloatBase::semFloat8E5M2)
3946 return initFromFloat8E5M2APInt(api);
3947 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
3948 return initFromFloat8E5M2FNUZAPInt(api);
3949 if (Sem == &APFloatBase::semFloat8E4M3)
3950 return initFromFloat8E4M3APInt(api);
3951 if (Sem == &APFloatBase::semFloat8E4M3FN)
3952 return initFromFloat8E4M3FNAPInt(api);
3953 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
3954 return initFromFloat8E4M3FNUZAPInt(api);
3955 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
3956 return initFromFloat8E4M3B11FNUZAPInt(api);
3957 if (Sem == &APFloatBase::semFloat8E3M4)
3958 return initFromFloat8E3M4APInt(api);
3959 if (Sem == &APFloatBase::semFloatTF32)
3960 return initFromFloatTF32APInt(api);
3961 if (Sem == &APFloatBase::semFloat8E8M0FNU)
3962 return initFromFloat8E8M0FNUAPInt(api);
3963 if (Sem == &APFloatBase::semFloat8E5M3FNU)
3964 return initFromFloat8E5M3FNUAPInt(api);
3965 if (Sem == &APFloatBase::semFloat6E3M2FN)
3966 return initFromFloat6E3M2FNAPInt(api);
3967 if (Sem == &APFloatBase::semFloat6E2M3FN)
3968 return initFromFloat6E2M3FNAPInt(api);
3969 if (Sem == &APFloatBase::semFloat4E2M1FN)
3970 return initFromFloat4E2M1FNAPInt(api);
3978 if (Negative && !semantics->hasSignedRepr)
3980 "This floating point format does not support signed values");
3987 exponent = semantics->maxExponent;
3991 unsigned PartCount = partCount();
3992 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
3996 const unsigned NumUnusedHighBits =
4003 (semantics->precision > 1))
4010 if (Negative && !semantics->hasSignedRepr)
4012 "This floating point format does not support signed values");
4019 exponent = semantics->minExponent;
4024 if (Negative && !semantics->hasSignedRepr)
4026 "This floating point format does not support signed values");
4035 exponent = semantics->minExponent;
4040 initFromAPInt(&Sem, API);
4053 Buffer.
append(Str.begin(), Str.end());
4058 void AdjustToPrecision(
APInt &significand,
4059 int &
exp,
unsigned FormatPrecision) {
4063 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4065 if (bits <= bitsRequired)
return;
4067 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4068 if (!tensRemovable)
return;
4070 exp += tensRemovable;
4075 if (tensRemovable & 1)
4077 tensRemovable >>= 1;
4078 if (!tensRemovable)
break;
4082 significand = significand.
udiv(divisor);
4090 int &
exp,
unsigned FormatPrecision) {
4091 unsigned N = buffer.
size();
4092 if (
N <= FormatPrecision)
return;
4095 unsigned FirstSignificant =
N - FormatPrecision;
4102 if (buffer[FirstSignificant - 1] <
'5') {
4103 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4106 exp += FirstSignificant;
4107 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4113 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4114 if (buffer[
I] ==
'9') {
4123 if (FirstSignificant ==
N) {
4124 exp += FirstSignificant;
4130 exp += FirstSignificant;
4131 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4135 APInt significand,
unsigned FormatPrecision,
4136 unsigned FormatMaxPadding,
bool TruncateZero) {
4137 const int semanticsPrecision = significand.
getBitWidth();
4144 if (!FormatPrecision) {
4152 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4157 exp += trailingZeros;
4163 }
else if (
exp > 0) {
4165 significand = significand.
zext(semanticsPrecision +
exp);
4166 significand <<=
exp;
4180 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4184 significand = significand.
zext(precision);
4185 APInt five_to_the_i(precision, 5);
4188 significand *= five_to_the_i;
4193 five_to_the_i *= five_to_the_i;
4197 AdjustToPrecision(significand,
exp, FormatPrecision);
4202 unsigned precision = significand.getBitWidth();
4203 if (precision < 4) {
4206 significand = significand.zext(precision);
4208 APInt ten(precision, 10);
4209 APInt digit(precision, 0);
4211 bool inTrail =
true;
4212 while (significand != 0) {
4217 unsigned d = digit.getZExtValue();
4228 assert(!buffer.
empty() &&
"no characters in buffer!");
4232 AdjustToPrecision(buffer,
exp, FormatPrecision);
4234 unsigned NDigits = buffer.
size();
4237 bool FormatScientific;
4238 if (!FormatMaxPadding) {
4239 FormatScientific =
true;
4245 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4246 NDigits + (unsigned)
exp > FormatPrecision);
4249 int MSD =
exp + (int) (NDigits - 1);
4252 FormatScientific =
false;
4256 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4262 if (FormatScientific) {
4263 exp += (NDigits - 1);
4265 Str.push_back(buffer[NDigits-1]);
4267 if (NDigits == 1 && TruncateZero)
4270 for (
unsigned I = 1;
I != NDigits; ++
I)
4271 Str.push_back(buffer[NDigits-1-
I]);
4273 if (!TruncateZero && FormatPrecision > NDigits - 1)
4274 Str.append(FormatPrecision - NDigits + 1,
'0');
4276 Str.push_back(TruncateZero ?
'E' :
'e');
4278 Str.push_back(
exp >= 0 ?
'+' :
'-');
4287 if (!TruncateZero && expbuf.
size() < 2)
4289 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4290 Str.push_back(expbuf[
E-1-
I]);
4296 for (
unsigned I = 0;
I != NDigits; ++
I)
4297 Str.push_back(buffer[NDigits-1-
I]);
4298 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4306 int NWholeDigits =
exp + (int) NDigits;
4309 if (NWholeDigits > 0) {
4310 for (;
I != (unsigned) NWholeDigits; ++
I)
4311 Str.push_back(buffer[NDigits-
I-1]);
4314 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4318 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4322 for (;
I != NDigits; ++
I)
4323 Str.push_back(buffer[NDigits-
I-1]);
4329 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4333 return append(Str,
"-Inf");
4335 return append(Str,
"+Inf");
4337 case fcNaN:
return append(Str,
"NaN");
4343 if (!FormatMaxPadding) {
4345 append(Str,
"0.0E+0");
4348 if (FormatPrecision > 1)
4349 Str.append(FormatPrecision - 1,
'0');
4350 append(Str,
"e+00");
4362 int exp = exponent - ((int) semantics->precision - 1);
4364 semantics->precision,
4367 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4368 FormatMaxPadding, TruncateZero);
4380 for (
int i = 0; i < PartCount; ++i) {
4386 if (exponent != semantics->minExponent)
4389 int CountrParts = 0;
4390 for (
int i = 0; i < PartCount;
4392 if (Parts[i] != 0) {
4393 return exponent - semantics->precision + CountrParts +
4456 if (!semantics->hasZero)
4466 }
else if (semantics->nonFiniteBehavior ==
4474 exponent = semantics->maxExponent + 1;
4488 bool WillCrossBinadeBoundary =
4489 exponent != semantics->minExponent && isSignificandAllZeros();
4507 if (WillCrossBinadeBoundary) {
4528 if (WillCrossBinadeBoundary) {
4532 assert(exponent != semantics->maxExponent &&
4533 "We can not increment an exponent beyond the maxExponent allowed"
4534 " by the given floating point semantics.");
4537 incrementSignificand();
4551 assert(
isNaN() &&
"Can only be called on NaN values");
4553 unsigned Bits = semantics->precision - 1;
4558 return ::exponentNaN(*semantics);
4562 return ::exponentInf(*semantics);
4566 return ::exponentZero(*semantics);
4585 if (!semantics->hasZero)
4612 return Arg.exponent;
4617 Normalized.exponent += SignificandBits;
4619 return Normalized.exponent - SignificandBits;
4623 auto MaxExp =
X.getSemantics().maxExponent;
4624 auto MinExp =
X.getSemantics().minExponent;
4632 int SignificandBits =
X.getSemantics().precision - 1;
4633 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4636 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4659 return scalbn(Val, -Exp, RM);
4665 APFloat(APFloatBase::semIEEEdouble)}) {
4666 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4670 : Semantics(&S), Floats(new
APFloat[2]{
4673 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4679 APFloat(APFloatBase::semIEEEdouble)}) {
4680 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4686 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4687 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4688 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4694 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4695 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4696 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4697 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4701 : Semantics(RHS.Semantics),
4705 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4709 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4710 RHS.Semantics = &APFloatBase::semBogus;
4711 RHS.Floats =
nullptr;
4712 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4716 if (Semantics == RHS.Semantics && RHS.Floats) {
4717 Floats[0] = RHS.Floats[0];
4718 Floats[1] = RHS.Floats[1];
4719 }
else if (
this != &RHS) {
4752 Floats[0] = std::move(z);
4753 Floats[1].makeZero(
false);
4766 Status |= z.
add(a, RM);
4767 Status |= z.
add(c, RM);
4770 Floats[0] = std::move(z);
4771 Floats[1].makeZero(
false);
4776 Status |= zz.
add(cc, RM);
4780 Status |= Floats[1].subtract(z, RM);
4781 Status |= Floats[1].add(c, RM);
4782 Status |= Floats[1].add(zz, RM);
4786 Status |= Floats[1].subtract(z, RM);
4787 Status |= Floats[1].add(a, RM);
4788 Status |= Floats[1].add(zz, RM);
4793 Status |=
q.subtract(z, RM);
4798 Status |= zz.
add(c, RM);
4799 Status |=
q.add(z, RM);
4800 Status |=
q.subtract(a, RM);
4802 Status |= zz.
add(q, RM);
4803 Status |= zz.
add(
aa, RM);
4804 Status |= zz.
add(cc, RM);
4806 Floats[0] = std::move(z);
4807 Floats[1].makeZero(
false);
4811 Status |= Floats[0].add(zz, RM);
4813 Floats[1].makeZero(
false);
4816 Floats[1] = std::move(z);
4817 Status |= Floats[1].subtract(Floats[0], RM);
4818 Status |= Floats[1].add(zz, RM);
4844 LHS.isNegative() !=
RHS.isNegative()) {
4845 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4860 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4861 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4862 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4863 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4864 assert(&Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4865 assert(&Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4866 return Out.addImpl(
A, AA,
C, CC, RM);
4871 return addWithSpecial(*
this, RHS, *
this, RM);
4877 auto Ret =
add(RHS, RM);
4884 const auto &LHS = *
this;
4901 if (LHS.getCategory() ==
fcNaN) {
4905 if (RHS.getCategory() ==
fcNaN) {
4911 Out.makeNaN(
false,
false,
nullptr);
4923 "Special cases not handled exhaustively");
4926 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
4930 if (!
T.isFiniteNonZero()) {
4931 Floats[0] = std::move(
T);
4932 Floats[1].makeZero(
false);
4954 Status |= U.add(Tau, RM);
4957 if (!U.isFinite()) {
4958 Floats[1].makeZero(
false);
4963 Floats[1] = std::move(
T);
4970 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4971 "Unexpected Semantics");
4974 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
4980 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4981 "Unexpected Semantics");
4984 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4990 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4991 "Unexpected Semantics");
4994 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5003 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5004 "Unexpected Semantics");
5007 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
5016 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5017 "Unexpected Semantics");
5027 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5028 Floats[0] = std::move(RoundedHi);
5029 Floats[1].makeZero(
false);
5041 const APFloat RoundingError = Rounded - ToRound;
5042 if (TieBreaker.isNonZero() &&
5043 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5044 abs(RoundingError).isExactlyValue(0.5))
5053 if (RoundedHi !=
Hi) {
5058 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5060 Floats[0] = std::move(RoundedHi);
5061 Floats[1].makeZero(
false);
5074 LoRoundingMode = RM;
5082 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5085 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5087 Floats[0] = std::move(RoundedHi);
5088 Floats[1] = std::move(RoundedLo);
5093 Floats[0].changeSign();
5094 Floats[1].changeSign();
5100 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5105 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5111 const bool ThisIsSubtractive =
5112 Floats[0].isNegative() != Floats[1].isNegative();
5113 const bool RHSIsSubtractive =
5114 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5124 if (RHS.Floats[1].isZero())
5131 if (ThisIsSubtractive != RHSIsSubtractive)
5136 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5138 if (ThisIsSubtractive) {
5152 return Floats[0].getCategory();
5158 Floats[0].makeInf(Neg);
5159 Floats[1].makeZero(
false);
5163 Floats[0].makeZero(Neg);
5164 Floats[1].makeZero(
false);
5168 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5169 "Unexpected Semantics");
5171 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5173 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5179 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5180 "Unexpected Semantics");
5181 Floats[0].makeSmallest(Neg);
5182 Floats[1].makeZero(
false);
5186 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5187 "Unexpected Semantics");
5189 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5191 Floats[0].changeSign();
5192 Floats[1].makeZero(
false);
5196 Floats[0].makeNaN(SNaN, Neg,
fill);
5197 Floats[1].makeZero(
false);
5201 auto Result = Floats[0].compare(RHS.Floats[0]);
5204 return Floats[1].compare(RHS.Floats[1]);
5209 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5210 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5220 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5221 "Unexpected Semantics");
5223 Floats[0].bitcastToAPInt().getRawData()[0],
5224 Floats[1].bitcastToAPInt().getRawData()[0],
5231 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5232 "Unexpected Semantics");
5233 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5246 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5247 "Unexpected Semantics");
5297 if (InLattice(HiOld, NextLo)) {
5299 Floats[1] = std::move(NextLo);
5336 if (!InLattice(NextHi, NextLo))
5340 Floats[0] = std::move(NextHi);
5341 Floats[1] = std::move(NextLo);
5349 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5350 "Unexpected Semantics");
5392 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5393 if (HiExactLog2 >= 0 &&
5394 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5404 Input, Width,
true, RM, &LoIsExact);
5417 *IsExact = RoundStatus ==
opOK;
5429 APSInt LoResult{Width, !IsSigned};
5441 *IsExact = RoundStatus ==
opOK;
5447 unsigned int Width,
bool IsSigned,
5450 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5454 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5462 Bits = Width - IsSigned;
5507 if (SrcMSB == UINT_MAX) {
5514 const unsigned SrcBitWidth = SrcMSB + 1;
5530 return handleOverflow(RM);
5536 bool HiAsIntIsExact;
5553 if (
Error.isNegative()) {
5561 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5563 if (ErrorActiveBits > LoPrecision) {
5564 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5568 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5587 Floats[0] = std::move(
Hi);
5588 Floats[1] = std::move(
Lo);
5593 return handleOverflow(RM);
5599 Largest.makeLargest(
false);
5601 return handleOverflow(RM);
5613 const bool NegateInput = IsSigned &&
Input.isNegative();
5626 unsigned int HexDigits,
5629 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5630 "Unexpected Semantics");
5637 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5639 Floats[0] != Floats[0] + Floats[1]);
5668 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5669 "Unexpected Semantics");
5670 return Floats[0].isInteger() && Floats[1].isInteger();
5674 unsigned FormatPrecision,
5675 unsigned FormatMaxPadding,
5676 bool TruncateZero)
const {
5677 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5678 "Unexpected Semantics");
5680 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5700 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5702 if (
Hi.getExactLog2Abs() == INT_MIN)
5706 return IlogbResult - 1;
5712 "Unexpected Semantics");
5714 scalbn(Arg.Floats[0], Exp, RM),
5715 scalbn(Arg.Floats[1], Exp, RM));
5721 "Unexpected Semantics");
5731 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5753 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5770 LoRoundingMode = RM;
5771 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5779 if (RecomposedLo !=
Lo) {
5783 const APFloat RoundingError = RecomposedLo -
Lo;
5788 const APFloat ScaledUlpOfSecond =
5790 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5791 const bool RoundedLoAway =
5796 if (IsMidpoint && RoundedLoAway)
5812 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5824APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5829 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5844 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5846 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5854 assert(StatusOrErr &&
"Invalid floating point representation");
5906 APFloat Reciprocal =
5924 *Inv = std::move(Reciprocal);
5936 usesLayout<IEEEFloat>(ToSemantics))
5937 return U.IEEE.convert(ToSemantics, RM, losesInfo);
5939 usesLayout<DoubleAPFloat>(ToSemantics)) {
5940 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
5942 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
5943 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
5947 usesLayout<IEEEFloat>(ToSemantics)) {
5948 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
5949 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
5965#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5978 bool *isExact)
const {
5982 rounding_mode, isExact);
5984 result =
APInt(bitWidth, parts);
5990 return getIEEE().convertToDouble();
5992 "Float semantics is not representable by IEEEdouble");
5993 APFloat Temp = *
this;
6001#ifdef HAS_IEE754_FLOAT128
6002float128 APFloat::convertToQuad()
const {
6004 return getIEEE().convertToQuad();
6006 "Float semantics is not representable by IEEEquad");
6012 return Temp.getIEEE().convertToQuad();
6018 return getIEEE().convertToFloat();
6020 "Float semantics is not representable by IEEEsingle");
6021 APFloat Temp = *
this;
6055 .
Case(
"Float8E5M2", &semFloat8E5M2)
6056 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6057 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6058 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6059 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6063APFloat::Storage::~Storage() {
6064 if (usesLayout<IEEEFloat>(*semantics)) {
6068 if (usesLayout<DoubleAPFloat>(*semantics)) {
6075APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6076 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6080 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6087APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6088 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6092 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6099APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6100 if (usesLayout<IEEEFloat>(*semantics) &&
6101 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6103 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6104 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6106 }
else if (
this != &
RHS) {
6108 new (
this) Storage(
RHS);
6113APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6114 if (usesLayout<IEEEFloat>(*semantics) &&
6115 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6117 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6118 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6120 }
else if (
this != &
RHS) {
6122 new (
this) Storage(std::move(
RHS));
6131 if (libc_exceptions & FE_INVALID)
6133 if (libc_exceptions & FE_DIVBYZERO)
6135 if (libc_exceptions & FE_OVERFLOW)
6137 if (libc_exceptions & FE_UNDERFLOW)
6139 if (libc_exceptions & FE_INEXACT)
6154 float x_val = x.convertToFloat();
6156 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6158 *status = getOpStatusFromLibc(exc);
6159 if (x.isSignaling()) {
6166 float result = LIBC_NAMESPACE::shared::expf(x_val);
6171 double x_val = x.convertToDouble();
6173 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6175 *status = getOpStatusFromLibc(exc);
6176 if (x.isSignaling()) {
6183 double result = LIBC_NAMESPACE::shared::exp(x_val);
6187 return std::nullopt;
6192#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()
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