25#include "llvm/Config/llvm-config.h"
42#define LIBC_NAMESPACE __llvm_libc_apfloat
43#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
45#include "shared/math.h"
46#include "shared/math_check_exceptions.h"
48#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
50 if (usesLayout<IEEEFloat>(getSemantics())) \
51 return U.IEEE.METHOD_CALL; \
52 if (usesLayout<DoubleAPFloat>(getSemantics())) \
53 return U.Double.METHOD_CALL; \
54 llvm_unreachable("Unexpected semantics"); \
65#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
73constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
74constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
75constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
76constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
77constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
78constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
81constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
86constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
88constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
89constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
119constexpr fltSemantics APFloatBase::semX87DoubleExtended = {
131constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
132constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
133constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
134 1023, -1022 + 53, 53 + 53, 128};
234 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
235 A.precision <=
B.precision;
241 if (&From == &InitialTo)
247 if (&From == &semPPCDoubleDouble)
254 &InitialTo == &semPPCDoubleDouble ? semIEEEdouble : InitialTo;
269 if (FromHasSignedZero && !ToHasSignedZero)
276 bool LosesInfo =
false;
388 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
396 return Dst.precision >= Src.precision;
436static inline unsigned int
449 const unsigned int overlargeExponent = 24000;
453 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
456 bool isNegative = *p ==
'-';
457 if (*p ==
'-' || *p ==
'+') {
464 if (absExponent >= 10U)
465 return createError(
"Invalid character in exponent");
467 for (; p != end; ++p) {
470 return createError(
"Invalid character in exponent");
472 absExponent = absExponent * 10U + value;
473 if (absExponent >= overlargeExponent) {
474 absExponent = overlargeExponent;
480 return -(int) absExponent;
482 return (
int) absExponent;
489 int exponentAdjustment) {
495 bool negative = *p ==
'-';
496 if (*p ==
'-' || *p ==
'+') {
502 int unsignedExponent = 0;
503 bool overflow =
false;
504 for (; p != end; ++p) {
509 return createError(
"Invalid character in exponent");
511 unsignedExponent = unsignedExponent * 10 + value;
512 if (unsignedExponent > 32767) {
518 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
522 exponent = unsignedExponent;
524 exponent = -exponent;
525 exponent += exponentAdjustment;
526 if (exponent > 32767 || exponent < -32768)
531 exponent = negative ? -32768: 32767;
541 while (p != end && *p ==
'0')
544 if (p != end && *p ==
'.') {
547 if (end - begin == 1)
550 while (p != end && *p ==
'0')
583 return PtrOrErr.takeError();
586 D->firstSigDigit = p;
588 D->normalizedExponent = 0;
590 for (; p != end; ++p) {
593 return createError(
"String contains multiple dots");
603 if (*p !=
'e' && *p !=
'E')
604 return createError(
"Invalid character in significand");
607 if (dot != end && p - begin == 1)
613 return ExpOrErr.takeError();
614 D->exponent = *ExpOrErr;
622 if (p !=
D->firstSigDigit) {
628 while (p != begin && *p ==
'0');
629 while (p != begin && *p ==
'.');
634 D->normalizedExponent = (
D->exponent +
636 - (dot >
D->firstSigDigit && dot < p)));
648 unsigned int digitValue) {
653 else if (digitValue < 8 && digitValue > 0)
657 while (p != end && (*p ==
'0' || *p ==
'.'))
661 return createError(
"Invalid trailing hexadecimal fraction!");
667 if (hexDigit == UINT_MAX)
677 unsigned int partCount,
702 return lost_fraction;
717 return moreSignificant;
728HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
730 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
732 if (HUerr1 + HUerr2 == 0)
733 return inexactMultiply * 2;
735 return inexactMultiply + 2 * (HUerr1 + HUerr2);
761 if (part - boundary <= boundary - part)
762 return part - boundary;
764 return boundary - part;
767 if (part == boundary) {
773 }
else if (part == boundary - 1) {
785 19, 38, 75, 149, 298};
803 1, 5, 25, 125, 625, 3125, 15625, 78125};
814 *p1 = firstEightPowers[power & 7];
820 for (
unsigned int n = 0; power; power >>= 1, n++) {
827 result += partsCount;
828 if (p2[result - 1] == 0)
853static const char NaNL[] =
"nan";
854static const char NaNU[] =
"NAN";
861 const char *hexDigitChars)
863 unsigned int result =
count;
869 dst[
count] = hexDigitChars[part & 0xf];
909 switch (
X.getCategory()) {
919 if (
X.isDenormal() ||
X.isSmallestNormalized())
922 if (
X.getExactLog2() != INT_MIN)
930void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
931 semantics = ourSemantics;
932 unsigned count = partCount();
937void IEEEFloat::freeSignificand() {
939 delete [] significand.parts;
942void IEEEFloat::assign(
const IEEEFloat &rhs) {
943 assert(semantics == rhs.semantics);
946 category = rhs.category;
947 exponent = rhs.exponent;
949 copySignificand(rhs);
952void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
954 assert(rhs.partCount() >= partCount());
967 if (Negative && !semantics->hasSignedRepr)
969 "This floating point format does not support signed values");
973 exponent = exponentNaN();
976 unsigned numParts = partCount();
989 fill = &fill_storage;
993 if (!
fill ||
fill->getNumWords() < numParts)
997 std::min(
fill->getNumWords(), numParts));
1000 unsigned bitsToPreserve = semantics->precision - 1;
1001 unsigned part = bitsToPreserve / 64;
1002 bitsToPreserve %= 64;
1003 significand[part] &= ((1ULL << bitsToPreserve) - 1);
1004 for (part++; part != numParts; ++part)
1005 significand[part] = 0;
1009 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
1031 if (semantics == &APFloatBase::semX87DoubleExtended)
1037 if (semantics != rhs.semantics) {
1039 initialize(rhs.semantics);
1050 semantics = rhs.semantics;
1051 significand = rhs.significand;
1052 exponent = rhs.exponent;
1053 category = rhs.category;
1056 rhs.semantics = &APFloatBase::semBogus;
1062 (exponent == semantics->minExponent) &&
1072 significandMSB() == 0;
1077 isSignificandAllZerosExceptMSB();
1080unsigned int IEEEFloat::getNumHighBits()
const {
1087 const unsigned int NumHighBits = (semantics->
precision > 1)
1093bool IEEEFloat::isSignificandAllOnes()
const {
1098 for (
unsigned i = 0; i < PartCount - 1; i++)
1103 const unsigned NumHighBits = getNumHighBits();
1104 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1105 "Can not have more high bits to fill than integerPartWidth");
1108 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
1114bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1123 for (
unsigned i = 0; i < PartCount - 1; i++) {
1124 if (~Parts[i] & ~
unsigned{!i})
1129 const unsigned NumHighBits = getNumHighBits();
1130 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1131 "Can not have more high bits to fill than integerPartWidth");
1134 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1140bool IEEEFloat::isSignificandAllZeros()
const {
1146 for (
unsigned i = 0; i < PartCount - 1; i++)
1151 const unsigned NumHighBits = getNumHighBits();
1153 "clear than integerPartWidth");
1154 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1156 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1162bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1166 for (
unsigned i = 0; i < PartCount - 1; i++) {
1171 const unsigned NumHighBits = getNumHighBits();
1174 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1178 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1185 ? isSignificandAllOnesExceptLSB()
1190 return IsMaxExp && isSignificandAllOnes();
1205 if (semantics != rhs.semantics ||
1206 category != rhs.category ||
1215 return std::equal(significandParts(), significandParts() + partCount(),
1216 rhs.significandParts());
1220 initialize(&ourSemantics);
1225 significandParts()[0] =
value;
1230 initialize(&ourSemantics);
1246 initialize(rhs.semantics);
1251 *
this = std::move(rhs);
1256unsigned int IEEEFloat::partCount()
const {
1261 return const_cast<IEEEFloat *
>(
this)->significandParts();
1265 if (partCount() > 1)
1266 return significand.parts;
1268 return &significand.part;
1271void IEEEFloat::zeroSignificand() {
1276void IEEEFloat::incrementSignificand() {
1288 assert(semantics == rhs.semantics);
1289 assert(exponent == rhs.exponent);
1291 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1300 assert(semantics == rhs.semantics);
1301 assert(exponent == rhs.exponent);
1312 bool ignoreAddend) {
1316 assert(semantics == rhs.semantics);
1318 unsigned precision = semantics->precision;
1326 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1329 unsigned partsCount = partCount();
1332 rhs.significandParts(), partsCount, partsCount);
1336 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1337 exponent += rhs.exponent;
1351 if (!ignoreAddend && addend.isNonZero()) {
1355 Significand savedSignificand = significand;
1356 const fltSemantics *savedSemantics = semantics;
1359 unsigned extendedPrecision = 2 * precision + 1;
1360 if (omsb != extendedPrecision - 1) {
1361 assert(extendedPrecision > omsb);
1363 (extendedPrecision - 1) - omsb);
1364 exponent -= (extendedPrecision - 1) - omsb;
1368 fltSemantics extendedSemantics = *semantics;
1369 extendedSemantics.
precision = extendedPrecision;
1371 if (newPartsCount == 1)
1372 significand.part = fullSignificand[0];
1374 significand.parts = fullSignificand;
1375 semantics = &extendedSemantics;
1388 lost_fraction = extendedAddend.shiftSignificandRight(1);
1390 "Lost precision while shifting addend for fused-multiply-add.");
1392 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1395 if (newPartsCount == 1)
1396 fullSignificand[0] = significand.part;
1397 significand = savedSignificand;
1398 semantics = savedSemantics;
1400 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1407 exponent -= precision + 1;
1416 if (omsb > precision) {
1417 unsigned int bits, significantParts;
1420 bits = omsb - precision;
1422 lf =
shiftRight(fullSignificand, significantParts, bits);
1429 if (newPartsCount > 4)
1430 delete [] fullSignificand;
1432 return lost_fraction;
1441 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1448 assert(semantics == rhs.semantics);
1451 const integerPart *rhsSignificand = rhs.significandParts();
1452 unsigned partsCount = partCount();
1455 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1459 for (
unsigned i = 0; i < partsCount; i++) {
1460 dividend[i] = lhsSignificand[i];
1461 divisor[i] = rhsSignificand[i];
1462 lhsSignificand[i] = 0;
1465 exponent -= rhs.exponent;
1467 unsigned int precision = semantics->precision;
1470 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1477 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1493 for (bit = precision; bit; bit -= 1) {
1518 return lost_fraction;
1521unsigned int IEEEFloat::significandMSB()
const {
1525unsigned int IEEEFloat::significandLSB()
const {
1530lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1536 return shiftRight(significandParts(), partCount(), bits);
1540void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1541 assert(bits < semantics->precision ||
1542 (semantics->precision == 1 && bits <= 1));
1545 unsigned int partsCount = partCount();
1555 assert(semantics == rhs.semantics);
1559 int compare = exponent - rhs.exponent;
1611 exponent = semantics->maxExponent;
1613 semantics->precision);
1626bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1628 unsigned int bit)
const {
1635 switch (rounding_mode) {
1671 unsigned omsb = significandMSB() + 1;
1678 int exponentChange = omsb - semantics->precision;
1682 if (exponent + exponentChange > semantics->maxExponent)
1683 return handleOverflow(rounding_mode);
1687 if (exponent + exponentChange < semantics->minExponent)
1688 exponentChange = semantics->minExponent - exponent;
1691 if (exponentChange < 0) {
1694 shiftSignificandLeft(-exponentChange);
1699 if (exponentChange > 0) {
1703 lf = shiftSignificandRight(exponentChange);
1708 if (omsb > (
unsigned) exponentChange)
1709 omsb -= exponentChange;
1719 exponent == semantics->maxExponent && isSignificandAllOnes())
1720 return handleOverflow(rounding_mode);
1733 if (!semantics->hasZero)
1741 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1743 exponent = semantics->minExponent;
1745 incrementSignificand();
1746 omsb = significandMSB() + 1;
1749 if (omsb == (
unsigned) semantics->precision + 1) {
1753 if (exponent == semantics->maxExponent)
1760 shiftSignificandRight(1);
1769 exponent == semantics->maxExponent && isSignificandAllOnes())
1770 return handleOverflow(rounding_mode);
1775 if (omsb == semantics->precision)
1779 assert(omsb < semantics->precision);
1789 if (!semantics->hasZero)
1861 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1864 int bits = exponent - rhs.exponent;
1868 if ((bits < 0) && !semantics->hasSignedRepr)
1870 "This floating point format does not support signed values");
1873 bool lost_fraction_is_from_rhs =
false;
1877 else if (bits > 0) {
1878 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1879 lost_fraction_is_from_rhs =
true;
1880 shiftSignificandLeft(1);
1882 lost_fraction = shiftSignificandRight(-bits - 1);
1883 temp_rhs.shiftSignificandLeft(1);
1890 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1899 carry = temp_rhs.subtractSignificand(*
this, borrow);
1900 copySignificand(temp_rhs);
1903 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1912 carry = subtractSignificand(temp_rhs, borrow);
1915 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1928 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1929 carry = addSignificand(temp_rhs);
1931 lost_fraction = shiftSignificandRight(-bits);
1932 carry = addSignificand(rhs);
1939 return lost_fraction;
2132 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2133 fs = normalize(rounding_mode, lost_fraction);
2142 if (category ==
fcZero) {
2156 return addOrSubtract(rhs, rounding_mode,
false);
2162 return addOrSubtract(rhs, rounding_mode,
true);
2175 fs = normalize(rounding_mode, lost_fraction);
2193 fs = normalize(rounding_mode, lost_fraction);
2203 unsigned int origSign = sign;
2312 unsigned int origSign = sign;
2333 if (!semantics->hasZero && this->isSmallest())
2353 sign ^= multiplicand.sign;
2362 lost_fraction = multiplySignificand(multiplicand, addend);
2363 fs = normalize(rounding_mode, lost_fraction);
2376 fs = multiplySpecials(multiplicand);
2386 fs = addOrSubtract(addend, rounding_mode,
false);
2458 MagicConstant.sign = sign;
2464 fs =
add(MagicConstant, rounding_mode);
2468 subtract(MagicConstant, rounding_mode);
2479 assert(semantics == rhs.semantics);
2511 if (sign == rhs.sign)
2527 if (sign != rhs.sign) {
2563 unsigned oldPartCount = partCount();
2566 bool X86SpecialNan =
false;
2567 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2568 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2569 (!(*significandParts() & 0x8000000000000000ULL) ||
2570 !(*significandParts() & 0x4000000000000000ULL))) {
2573 X86SpecialNan =
true;
2584 int omsb = significandMSB() + 1;
2585 int exponentChange = omsb - fromSemantics.
precision;
2586 if (exponent + exponentChange < toSemantics.
minExponent)
2587 exponentChange = toSemantics.
minExponent - exponent;
2588 exponentChange = std::max(exponentChange, shift);
2589 if (exponentChange < 0) {
2590 shift -= exponentChange;
2591 exponent += exponentChange;
2592 }
else if (omsb <= -shift) {
2593 exponentChange = omsb + shift - 1;
2594 shift -= exponentChange;
2595 exponent += exponentChange;
2601 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2606 if (newPartCount > oldPartCount) {
2614 significand.parts = newParts;
2615 }
else if (newPartCount == 1 && oldPartCount != 1) {
2619 newPart = significandParts()[0];
2621 significand.part = newPart;
2625 semantics = &toSemantics;
2634 *losesInfo = (
fs !=
opOK);
2635 }
else if (category ==
fcNaN) {
2658 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2676 }
else if (category ==
fcZero &&
2693 if ((sign && !semantics->hasSignedRepr) ||
2694 (category ==
fcZero && !semantics->hasZero)) {
2700 if (category ==
fcZero && !semantics->hasZero)
2725 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2727 if (category ==
fcZero) {
2736 unsigned truncatedBits;
2744 truncatedBits = semantics->
precision -1U - exponent;
2748 unsigned int bits = exponent + 1U;
2754 if (bits < semantics->precision) {
2756 truncatedBits = semantics->
precision - bits;
2763 bits - semantics->precision);
2771 if (truncatedBits) {
2775 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2795 if (omsb == width &&
2831 rounding_mode, isExact);
2834 unsigned int bits, dstPartsCount;
2837 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2839 if (category ==
fcNaN)
2862 unsigned dstCount = partCount();
2863 unsigned precision = semantics->
precision;
2868 if (precision <= omsb) {
2869 exponent = omsb - 1;
2874 exponent = precision - 1;
2879 return normalize(rounding_mode, lost_fraction);
2893 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2897IEEEFloat::convertFromHexadecimalString(
StringRef s,
2906 unsigned partsCount = partCount();
2908 bool computedTrailingFraction =
false;
2916 return PtrOrErr.takeError();
2925 return createError(
"String contains multiple dots");
2931 if (hex_value == UINT_MAX)
2941 }
else if (!computedTrailingFraction) {
2944 return FractOrErr.takeError();
2945 lost_fraction = *FractOrErr;
2946 computedTrailingFraction =
true;
2952 return createError(
"Hex strings require an exponent");
2953 if (*p !=
'p' && *p !=
'P')
2954 return createError(
"Invalid character in significand");
2957 if (dot != end && p - begin == 1)
2961 if (p != firstSignificantDigit) {
2970 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2971 if (expAdjustment < 0)
2973 expAdjustment = expAdjustment * 4 - 1;
2977 expAdjustment += semantics->precision;
2983 return ExpOrErr.takeError();
2984 exponent = *ExpOrErr;
2987 return normalize(rounding_mode, lost_fraction);
2991IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2992 unsigned sigPartCount,
int exp,
2994 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2995 unsigned int power =
exp >= 0 ?
exp : -
exp;
3006 unsigned pow5PartCount =
powerOf5(pow5Parts.
data(), power);
3008 for (;; parts *= 2) {
3009 unsigned int excessPrecision, truncatedBits;
3012 excessPrecision = calcSemantics.
precision - semantics->precision;
3013 truncatedBits = excessPrecision;
3016 decSig.makeZero(sign);
3019 opStatus sigStatus = decSig.convertFromUnsignedParts(
3021 opStatus powStatus = pow5.convertFromUnsignedParts(
3024 decSig.exponent +=
exp;
3028 unsigned int powHUerr;
3032 calcLostFraction = decSig.multiplySignificand(pow5);
3033 powHUerr = powStatus !=
opOK;
3035 calcLostFraction = decSig.divideSignificand(pow5);
3037 if (decSig.exponent < semantics->minExponent) {
3038 excessPrecision += (semantics->minExponent - decSig.exponent);
3039 truncatedBits = excessPrecision;
3040 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
3049 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3054 excessPrecision, isNearest);
3057 if (HUdistance >= HUerr) {
3058 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3059 calcSemantics.
precision - excessPrecision,
3064 exponent = (decSig.exponent + semantics->precision
3065 - (calcSemantics.
precision - excessPrecision));
3069 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
3075Expected<APFloat::opStatus>
3076IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
3083 return std::move(Err);
3114 if (!semantics->hasZero)
3119 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3120 fs = handleOverflow(rounding_mode);
3126 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3127 (
D.normalizedExponent + 1) * 28738 <=
3128 8651 * (semantics->minExponent - (
int) semantics->precision)) {
3135 }
else if ((
D.normalizedExponent - 1) * 42039
3136 >= 12655 * semantics->maxExponent) {
3138 fs = handleOverflow(rounding_mode);
3141 unsigned int partCount;
3147 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3165 if (p == str.
end()) {
3170 if (decValue >= 10U) {
3171 delete[] decSignificand;
3172 return createError(
"Invalid character in significand");
3178 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3182 partCount, partCount + 1,
false);
3186 if (decSignificand[partCount])
3188 }
while (p <=
D.lastSigDigit);
3191 fs = roundSignificandWithExponent(decSignificand, partCount,
3192 D.exponent, rounding_mode);
3194 delete [] decSignificand;
3200bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3201 const size_t MIN_NAME_SIZE = 3;
3203 if (str.
size() < MIN_NAME_SIZE)
3206 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3213 if (str.
size() < MIN_NAME_SIZE)
3216 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3225 if (str.
size() < MIN_NAME_SIZE)
3232 makeNaN(IsSignaling, IsNegative);
3237 if (str.
front() ==
'(') {
3239 if (str.
size() <= 2 || str.
back() !=
')')
3246 unsigned Radix = 10;
3247 if (str[0] ==
'0') {
3248 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3259 makeNaN(IsSignaling, IsNegative, &Payload);
3267Expected<APFloat::opStatus>
3273 if (convertFromStringSpecials(str))
3278 size_t slen = str.
size();
3279 sign = *p ==
'-' ? 1 : 0;
3280 if (sign && !semantics->hasSignedRepr)
3282 "This floating point format does not support signed values");
3284 if (*p ==
'-' || *p ==
'+') {
3291 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3294 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3298 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3340 dst +=
sizeof NaNU - 1;
3345 *dst++ = upperCase ?
'X':
'x';
3347 if (hexDigits > 1) {
3349 memset (dst,
'0', hexDigits - 1);
3350 dst += hexDigits - 1;
3352 *dst++ = upperCase ?
'P':
'p';
3357 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3363 return static_cast<unsigned int>(dst - p);
3370char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3374 *dst++ = upperCase ?
'X':
'x';
3376 bool roundUp =
false;
3379 const integerPart *significand = significandParts();
3380 unsigned partsCount = partCount();
3384 unsigned valueBits = semantics->
precision + 3;
3389 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3395 if (hexDigits < outputDigits) {
3401 bits = valueBits - hexDigits * 4;
3403 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3405 outputDigits = hexDigits;
3415 while (outputDigits &&
count) {
3419 if (--
count == partsCount)
3422 part = significand[
count] << shift;
3430 curDigits = std::min(curDigits, outputDigits);
3431 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3432 outputDigits -= curDigits;
3442 }
while (*q ==
'0');
3446 memset (dst,
'0', outputDigits);
3447 dst += outputDigits;
3460 *dst++ = upperCase ?
'P':
'p';
3476 Arg.significandParts(),
3477 Arg.significandParts() + Arg.partCount()));
3489APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3490 assert(partCount() == 2);
3491 return convertIEEEFloatToAPInt<APFloatBase::semX87DoubleExtended>();
3494APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3509 extendedSemantics.
minExponent = APFloatBase::semIEEEdouble.minExponent;
3518 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
3524 if (u.isFiniteNonZero() && losesInfo) {
3532 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
3537 return APInt(128, words);
3540template <const fltSemantics &S>
3541APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3543 constexpr unsigned int trailing_significand_bits =
3544 S.precision - 1 + S.hasExplicitIntegerBit;
3548 constexpr uint64_t significand_mask = integer_bit - 1;
3549 constexpr unsigned int exponent_bits =
3550 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3551 static_assert(exponent_bits < 64);
3553 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3554 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3561 myexponent = exponent + bias;
3562 std::copy_n(significandParts(), mysignificand.size(),
3563 mysignificand.begin());
3564 if (myexponent == 1 &&
3565 !(significandParts()[integer_bit_part] & integer_bit))
3567 }
else if (category ==
fcZero) {
3570 myexponent = ::exponentZero(S) + bias;
3571 mysignificand.fill(0);
3576 myexponent = ::exponentInf(S) + bias;
3577 mysignificand.fill(0);
3578 if constexpr (S.hasExplicitIntegerBit) {
3579 mysignificand[0] =
integerPart{1} << (trailing_significand_bits - 1);
3585 myexponent = ::exponentNaN(S) + bias;
3586 std::copy_n(significandParts(), mysignificand.size(),
3587 mysignificand.begin());
3589 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3591 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3592 if constexpr (!S.hasExplicitIntegerBit) {
3593 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3595 words[mysignificand.size() - 1] &= significand_mask;
3598 std::fill(words_iter, words.end(),
uint64_t{0});
3599 constexpr size_t last_word = words.size() - 1;
3600 if constexpr (S.hasSignedRepr) {
3602 << ((S.sizeInBits - 1) % 64);
3603 words[last_word] |= shifted_sign;
3605 uint64_t shifted_exponent = (myexponent & exponent_mask)
3606 << (trailing_significand_bits % 64);
3607 words[last_word] |= shifted_exponent;
3608 if constexpr (last_word == 0) {
3609 return APInt(S.sizeInBits, words[0]);
3611 return APInt(S.sizeInBits, words);
3614APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3615 assert(partCount() == 2);
3616 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3619APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3621 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3624APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3626 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3629APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3630 assert(partCount() == 1);
3631 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3634APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3636 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3639APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3640 assert(partCount() == 1);
3641 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3644APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3645 assert(partCount() == 1);
3646 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3649APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3650 assert(partCount() == 1);
3651 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3654APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3655 assert(partCount() == 1);
3656 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3659APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3660 assert(partCount() == 1);
3661 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3664APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3665 assert(partCount() == 1);
3666 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3669APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3670 assert(partCount() == 1);
3671 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3674APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3675 assert(partCount() == 1);
3676 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3679APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3680 assert(partCount() == 1);
3681 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3684APInt IEEEFloat::convertFloat8E5M3FNUAPFloatToAPInt()
const {
3685 assert(partCount() == 1);
3686 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M3FNU>();
3689APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3690 assert(partCount() == 1);
3691 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3694APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3695 assert(partCount() == 1);
3696 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3699APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3700 assert(partCount() == 1);
3701 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3710 return convertHalfAPFloatToAPInt();
3713 return convertBFloatAPFloatToAPInt();
3716 return convertFloatAPFloatToAPInt();
3719 return convertDoubleAPFloatToAPInt();
3722 return convertQuadrupleAPFloatToAPInt();
3726 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3729 return convertFloat8E5M2APFloatToAPInt();
3732 return convertFloat8E5M2FNUZAPFloatToAPInt();
3735 return convertFloat8E4M3APFloatToAPInt();
3738 return convertFloat8E4M3FNAPFloatToAPInt();
3741 return convertFloat8E4M3FNUZAPFloatToAPInt();
3745 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3748 return convertFloat8E3M4APFloatToAPInt();
3751 return convertFloatTF32APFloatToAPInt();
3754 return convertFloat8E8M0FNUAPFloatToAPInt();
3757 return convertFloat8E5M3FNUAPFloatToAPInt();
3760 return convertFloat6E3M2FNAPFloatToAPInt();
3763 return convertFloat6E2M3FNAPFloatToAPInt();
3766 return convertFloat4E2M1FNAPFloatToAPInt();
3771 return convertF80LongDoubleAPFloatToAPInt();
3776 "Float semantics are not IEEEsingle");
3783 "Float semantics are not IEEEdouble");
3788#ifdef HAS_IEE754_FLOAT128
3789float128 IEEEFloat::convertToQuad()
const {
3791 "Float semantics are not IEEEquads");
3793 return api.bitsToQuad();
3797void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3798 return initFromIEEEAPInt<APFloatBase::semX87DoubleExtended>(api);
3801void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3807 initFromDoubleAPInt(
APInt(64, i1));
3829void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3830 initFromIEEEAPInt<APFloatBase::semFloat8E8M0FNU>(api);
3833void IEEEFloat::initFromFloat8E5M3FNUAPInt(
const APInt &api) {
3834 initFromIEEEAPInt<APFloatBase::semFloat8E5M3FNU>(api);
3837template <const fltSemantics &S>
3838void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3841 constexpr unsigned int trailing_significand_bits =
3842 S.precision - 1 + S.hasExplicitIntegerBit;
3845 constexpr uint64_t significand_mask = integer_bit - 1;
3846 constexpr unsigned int exponent_bits =
3847 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3848 static_assert(exponent_bits < 64);
3849 constexpr unsigned int stored_significand_parts =
3852 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3853 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3854 constexpr bool has_significand = trailing_significand_bits > 0;
3858 std::array<integerPart, stored_significand_parts> mysignificand;
3859 if constexpr (has_significand) {
3860 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3862 mysignificand[mysignificand.size() - 1] &= significand_mask;
3865 std::fill_n(mysignificand.begin(), mysignificand.size(), 0);
3868 mysignificand[0] = 1;
3875 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3878 assert(partCount() == mysignificand.size());
3880 sign = S.hasSignedRepr
3881 ?
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64))
3884 bool all_zero_significand =
3887 bool is_zero = myexponent == 0 && all_zero_significand && S.hasZero;
3890 bool is_inf =
false;
3892 if constexpr (S.hasExplicitIntegerBit) {
3894 static_assert(S.precision == 64);
3895 constexpr integerPart significand_mask_no_int_bit =
3896 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3898 mysignificand[0] >> (trailing_significand_bits - 1);
3900 is_inf = myexponent - bias == ::exponentInf(S) && myintegerbit == 1 &&
3901 (mysignificand[0] & significand_mask_no_int_bit) == 0;
3903 is_inf = myexponent - bias == ::exponentInf(S) && all_zero_significand;
3912 bool is_nan =
false;
3915 if constexpr (S.hasExplicitIntegerBit) {
3917 static_assert(S.precision == 64);
3919 mysignificand[0] >> (trailing_significand_bits - 1);
3920 constexpr integerPart significand_mask_no_int_bit =
3921 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3923 if (myexponent - bias == ::exponentNaN(S) &&
3924 (mysignificand[0] & significand_mask_no_int_bit) != 0) {
3927 }
else if (myexponent - bias == ::exponentNaN(S) &&
3928 (mysignificand[0] & significand_mask_no_int_bit) == 0) {
3931 }
else if (myexponent - bias != ::exponentNaN(S) && myexponent != 0 &&
3932 myintegerbit == 0) {
3937 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3940 bool all_ones_significand =
3941 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3942 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3943 (!significand_mask ||
3944 mysignificand[mysignificand.size() - 1] == significand_mask);
3945 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3947 is_nan = is_zero && sign;
3953 std::copy_n(mysignificand.begin(), mysignificand.size(),
3954 significandParts());
3964 exponent = myexponent - bias;
3965 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3966 if (myexponent == 0 && S.hasDenormals)
3967 exponent = S.minExponent;
3969 if constexpr (!S.hasExplicitIntegerBit) {
3970 significandParts()[mysignificand.size() - 1] |= integer_bit;
3975void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3976 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3979void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3980 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3983void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3984 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3987void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3988 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3991void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3992 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3995void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3996 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3999void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
4000 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
4003void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
4004 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
4007void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
4008 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
4011void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
4012 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
4015void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
4016 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
4019void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
4020 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
4023void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
4024 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
4027void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
4028 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
4031void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
4032 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
4035void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
4036 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
4042 if (Sem == &APFloatBase::semIEEEhalf)
4043 return initFromHalfAPInt(api);
4044 if (Sem == &APFloatBase::semBFloat)
4045 return initFromBFloatAPInt(api);
4046 if (Sem == &APFloatBase::semIEEEsingle)
4047 return initFromFloatAPInt(api);
4048 if (Sem == &APFloatBase::semIEEEdouble)
4049 return initFromDoubleAPInt(api);
4050 if (Sem == &APFloatBase::semX87DoubleExtended)
4051 return initFromF80LongDoubleAPInt(api);
4052 if (Sem == &APFloatBase::semIEEEquad)
4053 return initFromQuadrupleAPInt(api);
4054 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
4055 return initFromPPCDoubleDoubleLegacyAPInt(api);
4056 if (Sem == &APFloatBase::semFloat8E5M2)
4057 return initFromFloat8E5M2APInt(api);
4058 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
4059 return initFromFloat8E5M2FNUZAPInt(api);
4060 if (Sem == &APFloatBase::semFloat8E4M3)
4061 return initFromFloat8E4M3APInt(api);
4062 if (Sem == &APFloatBase::semFloat8E4M3FN)
4063 return initFromFloat8E4M3FNAPInt(api);
4064 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
4065 return initFromFloat8E4M3FNUZAPInt(api);
4066 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
4067 return initFromFloat8E4M3B11FNUZAPInt(api);
4068 if (Sem == &APFloatBase::semFloat8E3M4)
4069 return initFromFloat8E3M4APInt(api);
4070 if (Sem == &APFloatBase::semFloatTF32)
4071 return initFromFloatTF32APInt(api);
4072 if (Sem == &APFloatBase::semFloat8E8M0FNU)
4073 return initFromFloat8E8M0FNUAPInt(api);
4074 if (Sem == &APFloatBase::semFloat8E5M3FNU)
4075 return initFromFloat8E5M3FNUAPInt(api);
4076 if (Sem == &APFloatBase::semFloat6E3M2FN)
4077 return initFromFloat6E3M2FNAPInt(api);
4078 if (Sem == &APFloatBase::semFloat6E2M3FN)
4079 return initFromFloat6E2M3FNAPInt(api);
4080 if (Sem == &APFloatBase::semFloat4E2M1FN)
4081 return initFromFloat4E2M1FNAPInt(api);
4089 if (Negative && !semantics->hasSignedRepr)
4091 "This floating point format does not support signed values");
4098 exponent = semantics->maxExponent;
4102 unsigned PartCount = partCount();
4103 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4107 const unsigned NumUnusedHighBits =
4114 (semantics->precision > 1))
4121 if (Negative && !semantics->hasSignedRepr)
4123 "This floating point format does not support signed values");
4130 exponent = semantics->minExponent;
4135 if (Negative && !semantics->hasSignedRepr)
4137 "This floating point format does not support signed values");
4146 exponent = semantics->minExponent;
4151 initFromAPInt(&Sem, API);
4164 Buffer.
append(Str.begin(), Str.end());
4169 void AdjustToPrecision(
APInt &significand,
4170 int &
exp,
unsigned FormatPrecision) {
4174 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4176 if (bits <= bitsRequired)
return;
4178 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4179 if (!tensRemovable)
return;
4181 exp += tensRemovable;
4186 if (tensRemovable & 1)
4188 tensRemovable >>= 1;
4189 if (!tensRemovable)
break;
4193 significand = significand.
udiv(divisor);
4201 int &
exp,
unsigned FormatPrecision) {
4202 unsigned N = buffer.
size();
4203 if (
N <= FormatPrecision)
return;
4206 unsigned FirstSignificant =
N - FormatPrecision;
4213 if (buffer[FirstSignificant - 1] <
'5') {
4214 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4217 exp += FirstSignificant;
4218 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4224 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4225 if (buffer[
I] ==
'9') {
4234 if (FirstSignificant ==
N) {
4235 exp += FirstSignificant;
4241 exp += FirstSignificant;
4242 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4246 APInt significand,
unsigned FormatPrecision,
4247 unsigned FormatMaxPadding,
bool TruncateZero) {
4248 const int semanticsPrecision = significand.
getBitWidth();
4255 if (!FormatPrecision) {
4263 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4268 exp += trailingZeros;
4274 }
else if (
exp > 0) {
4276 significand = significand.
zext(semanticsPrecision +
exp);
4277 significand <<=
exp;
4291 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4295 significand = significand.
zext(precision);
4296 APInt five_to_the_i(precision, 5);
4299 significand *= five_to_the_i;
4304 five_to_the_i *= five_to_the_i;
4308 AdjustToPrecision(significand,
exp, FormatPrecision);
4313 unsigned precision = significand.getBitWidth();
4314 if (precision < 4) {
4317 significand = significand.zext(precision);
4319 APInt ten(precision, 10);
4320 APInt digit(precision, 0);
4322 bool inTrail =
true;
4323 while (significand != 0) {
4328 unsigned d = digit.getZExtValue();
4339 assert(!buffer.
empty() &&
"no characters in buffer!");
4343 AdjustToPrecision(buffer,
exp, FormatPrecision);
4345 unsigned NDigits = buffer.
size();
4348 bool FormatScientific;
4349 if (!FormatMaxPadding) {
4350 FormatScientific =
true;
4356 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4357 NDigits + (unsigned)
exp > FormatPrecision);
4360 int MSD =
exp + (int) (NDigits - 1);
4363 FormatScientific =
false;
4367 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4373 if (FormatScientific) {
4374 exp += (NDigits - 1);
4376 Str.push_back(buffer[NDigits-1]);
4378 if (NDigits == 1 && TruncateZero)
4381 for (
unsigned I = 1;
I != NDigits; ++
I)
4382 Str.push_back(buffer[NDigits-1-
I]);
4384 if (!TruncateZero && FormatPrecision > NDigits - 1)
4385 Str.append(FormatPrecision - NDigits + 1,
'0');
4387 Str.push_back(TruncateZero ?
'E' :
'e');
4389 Str.push_back(
exp >= 0 ?
'+' :
'-');
4398 if (!TruncateZero && expbuf.
size() < 2)
4400 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4401 Str.push_back(expbuf[
E-1-
I]);
4407 for (
unsigned I = 0;
I != NDigits; ++
I)
4408 Str.push_back(buffer[NDigits-1-
I]);
4409 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4417 int NWholeDigits =
exp + (int) NDigits;
4420 if (NWholeDigits > 0) {
4421 for (;
I != (unsigned) NWholeDigits; ++
I)
4422 Str.push_back(buffer[NDigits-
I-1]);
4425 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4429 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4433 for (;
I != NDigits; ++
I)
4434 Str.push_back(buffer[NDigits-
I-1]);
4440 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4444 return append(Str,
"-Inf");
4446 return append(Str,
"+Inf");
4448 case fcNaN:
return append(Str,
"NaN");
4454 if (!FormatMaxPadding) {
4456 append(Str,
"0.0E+0");
4459 if (FormatPrecision > 1)
4460 Str.append(FormatPrecision - 1,
'0');
4461 append(Str,
"e+00");
4473 int exp = exponent - ((int) semantics->precision - 1);
4475 semantics->precision,
4478 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4479 FormatMaxPadding, TruncateZero);
4491 for (
int i = 0; i < PartCount; ++i) {
4497 if (exponent != semantics->minExponent)
4500 int CountrParts = 0;
4501 for (
int i = 0; i < PartCount;
4503 if (Parts[i] != 0) {
4504 return exponent - semantics->precision + CountrParts +
4567 if (!semantics->hasZero)
4577 }
else if (semantics->nonFiniteBehavior ==
4585 exponent = semantics->maxExponent + 1;
4599 bool WillCrossBinadeBoundary =
4600 exponent != semantics->minExponent && isSignificandAllZeros();
4618 if (WillCrossBinadeBoundary) {
4639 if (WillCrossBinadeBoundary) {
4643 assert(exponent != semantics->maxExponent &&
4644 "We can not increment an exponent beyond the maxExponent allowed"
4645 " by the given floating point semantics.");
4648 incrementSignificand();
4662 assert(
isNaN() &&
"Can only be called on NaN values");
4664 unsigned Bits = semantics->precision - 1;
4669 return ::exponentNaN(*semantics);
4673 return ::exponentInf(*semantics);
4677 return ::exponentZero(*semantics);
4696 if (!semantics->hasZero)
4723 return Arg.exponent;
4728 Normalized.exponent += SignificandBits;
4730 return Normalized.exponent - SignificandBits;
4734 auto MaxExp =
X.getSemantics().maxExponent;
4735 auto MinExp =
X.getSemantics().minExponent;
4743 int SignificandBits =
X.getSemantics().precision - 1;
4744 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4747 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4770 return scalbn(Val, -Exp, RM);
4776 APFloat(APFloatBase::semIEEEdouble)}) {
4777 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4781 : Semantics(&S), Floats(new
APFloat[2]{
4784 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4790 APFloat(APFloatBase::semIEEEdouble)}) {
4791 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4797 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4798 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4799 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4805 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4806 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4807 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4808 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4812 : Semantics(RHS.Semantics),
4816 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4820 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4821 RHS.Semantics = &APFloatBase::semBogus;
4822 RHS.Floats =
nullptr;
4823 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4827 if (Semantics == RHS.Semantics && RHS.Floats) {
4828 Floats[0] = RHS.Floats[0];
4829 Floats[1] = RHS.Floats[1];
4830 }
else if (
this != &RHS) {
4863 Floats[0] = std::move(z);
4864 Floats[1].makeZero(
false);
4877 Status |= z.
add(a, RM);
4878 Status |= z.
add(c, RM);
4881 Floats[0] = std::move(z);
4882 Floats[1].makeZero(
false);
4887 Status |= zz.
add(cc, RM);
4891 Status |= Floats[1].subtract(z, RM);
4892 Status |= Floats[1].add(c, RM);
4893 Status |= Floats[1].add(zz, RM);
4897 Status |= Floats[1].subtract(z, RM);
4898 Status |= Floats[1].add(a, RM);
4899 Status |= Floats[1].add(zz, RM);
4904 Status |=
q.subtract(z, RM);
4909 Status |= zz.
add(c, RM);
4910 Status |=
q.add(z, RM);
4911 Status |=
q.subtract(a, RM);
4913 Status |= zz.
add(q, RM);
4914 Status |= zz.
add(
aa, RM);
4915 Status |= zz.
add(cc, RM);
4917 Floats[0] = std::move(z);
4918 Floats[1].makeZero(
false);
4922 Status |= Floats[0].add(zz, RM);
4924 Floats[1].makeZero(
false);
4927 Floats[1] = std::move(z);
4928 Status |= Floats[1].subtract(Floats[0], RM);
4929 Status |= Floats[1].add(zz, RM);
4955 LHS.isNegative() !=
RHS.isNegative()) {
4956 Out.makeNaN(
false,
Out.isNegative(),
nullptr);
4971 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4972 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4973 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4974 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4975 assert(&
Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4976 assert(&
Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4977 return Out.addImpl(
A, AA,
C, CC, RM);
4982 return addWithSpecial(*
this, RHS, *
this, RM);
4988 auto Ret =
add(RHS, RM);
4995 const auto &LHS = *
this;
5012 if (LHS.getCategory() ==
fcNaN) {
5016 if (RHS.getCategory() ==
fcNaN) {
5022 Out.makeNaN(
false,
false,
nullptr);
5034 "Special cases not handled exhaustively");
5037 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
5041 if (!
T.isFiniteNonZero()) {
5042 Floats[0] = std::move(
T);
5043 Floats[1].makeZero(
false);
5065 Status |= U.add(Tau, RM);
5068 if (!U.isFinite()) {
5069 Floats[1].makeZero(
false);
5074 Floats[1] = std::move(
T);
5081 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5082 "Unexpected Semantics");
5085 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
5091 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5092 "Unexpected Semantics");
5095 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5101 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5102 "Unexpected Semantics");
5105 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5114 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5115 "Unexpected Semantics");
5118 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
5127 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5128 "Unexpected Semantics");
5138 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5139 Floats[0] = std::move(RoundedHi);
5140 Floats[1].makeZero(
false);
5152 const APFloat RoundingError = Rounded - ToRound;
5153 if (TieBreaker.isNonZero() &&
5154 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5155 abs(RoundingError).isExactlyValue(0.5))
5164 if (RoundedHi !=
Hi) {
5169 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5171 Floats[0] = std::move(RoundedHi);
5172 Floats[1].makeZero(
false);
5185 LoRoundingMode = RM;
5193 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5196 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5198 Floats[0] = std::move(RoundedHi);
5199 Floats[1] = std::move(RoundedLo);
5204 Floats[0].changeSign();
5205 Floats[1].changeSign();
5211 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5216 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5222 const bool ThisIsSubtractive =
5223 Floats[0].isNegative() != Floats[1].isNegative();
5224 const bool RHSIsSubtractive =
5225 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5235 if (RHS.Floats[1].isZero())
5242 if (ThisIsSubtractive != RHSIsSubtractive)
5247 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5249 if (ThisIsSubtractive) {
5263 return Floats[0].getCategory();
5269 Floats[0].makeInf(Neg);
5270 Floats[1].makeZero(
false);
5274 Floats[0].makeZero(Neg);
5275 Floats[1].makeZero(
false);
5279 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5280 "Unexpected Semantics");
5282 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5284 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5290 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5291 "Unexpected Semantics");
5292 Floats[0].makeSmallest(Neg);
5293 Floats[1].makeZero(
false);
5297 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5298 "Unexpected Semantics");
5300 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5302 Floats[0].changeSign();
5303 Floats[1].makeZero(
false);
5307 Floats[0].makeNaN(SNaN, Neg,
fill);
5308 Floats[1].makeZero(
false);
5312 auto Result = Floats[0].compare(RHS.Floats[0]);
5315 return Floats[1].compare(RHS.Floats[1]);
5320 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5321 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5331 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5332 "Unexpected Semantics");
5334 Floats[0].bitcastToAPInt().getRawData()[0],
5335 Floats[1].bitcastToAPInt().getRawData()[0],
5342 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5343 "Unexpected Semantics");
5344 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5357 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5358 "Unexpected Semantics");
5408 if (InLattice(HiOld, NextLo)) {
5410 Floats[1] = std::move(NextLo);
5447 if (!InLattice(NextHi, NextLo))
5451 Floats[0] = std::move(NextHi);
5452 Floats[1] = std::move(NextLo);
5460 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5461 "Unexpected Semantics");
5503 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5504 if (HiExactLog2 >= 0 &&
5505 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5515 Input, Width,
true, RM, &LoIsExact);
5528 *IsExact = RoundStatus ==
opOK;
5540 APSInt LoResult{Width, !IsSigned};
5552 *IsExact = RoundStatus ==
opOK;
5558 unsigned int Width,
bool IsSigned,
5561 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5565 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5573 Bits = Width - IsSigned;
5618 if (SrcMSB == UINT_MAX) {
5625 const unsigned SrcBitWidth = SrcMSB + 1;
5641 return handleOverflow(RM);
5647 bool HiAsIntIsExact;
5664 if (
Error.isNegative()) {
5672 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5674 if (ErrorActiveBits > LoPrecision) {
5675 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5679 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5698 Floats[0] = std::move(
Hi);
5699 Floats[1] = std::move(
Lo);
5704 return handleOverflow(RM);
5710 Largest.makeLargest(
false);
5712 return handleOverflow(RM);
5724 const bool NegateInput = IsSigned &&
Input.isNegative();
5737 unsigned int HexDigits,
5740 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5741 "Unexpected Semantics");
5748 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5750 Floats[0] != Floats[0] + Floats[1]);
5779 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5780 "Unexpected Semantics");
5781 return Floats[0].isInteger() && Floats[1].isInteger();
5785 unsigned FormatPrecision,
5786 unsigned FormatMaxPadding,
5787 bool TruncateZero)
const {
5788 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5789 "Unexpected Semantics");
5791 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5811 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5813 if (
Hi.getExactLog2Abs() == INT_MIN)
5817 return IlogbResult - 1;
5823 "Unexpected Semantics");
5825 scalbn(Arg.Floats[0], Exp, RM),
5826 scalbn(Arg.Floats[1], Exp, RM));
5832 "Unexpected Semantics");
5842 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5864 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5881 LoRoundingMode = RM;
5882 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5890 if (RecomposedLo !=
Lo) {
5894 const APFloat RoundingError = RecomposedLo -
Lo;
5899 const APFloat ScaledUlpOfSecond =
5901 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5902 const bool RoundedLoAway =
5907 if (IsMidpoint && RoundedLoAway)
5923 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5935APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5940 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5955 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5957 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5965 assert(StatusOrErr &&
"Invalid floating point representation");
6017 APFloat Reciprocal =
6035 *Inv = std::move(Reciprocal);
6047 usesLayout<IEEEFloat>(ToSemantics))
6048 return U.IEEE.convert(ToSemantics, RM, losesInfo);
6050 usesLayout<DoubleAPFloat>(ToSemantics)) {
6051 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
6053 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
6054 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
6058 usesLayout<IEEEFloat>(ToSemantics)) {
6059 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
6060 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
6076#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
6089 bool *isExact)
const {
6093 rounding_mode, isExact);
6095 result =
APInt(bitWidth, parts);
6101 return getIEEE().convertToDouble();
6103 "Float semantics is not representable by IEEEdouble");
6104 APFloat Temp = *
this;
6112#ifdef HAS_IEE754_FLOAT128
6113float128 APFloat::convertToQuad()
const {
6115 return getIEEE().convertToQuad();
6117 "Float semantics is not representable by IEEEquad");
6123 return Temp.getIEEE().convertToQuad();
6129 return getIEEE().convertToFloat();
6131 "Float semantics is not representable by IEEEsingle");
6132 APFloat Temp = *
this;
6165 .
Case(
"Float8E5M2", &semFloat8E5M2)
6166 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6167 .
Case(
"Float8E5M3FNU", &semFloat8E5M3FNU)
6168 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6169 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6170 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6174APFloat::Storage::~Storage() {
6175 if (usesLayout<IEEEFloat>(*semantics)) {
6179 if (usesLayout<DoubleAPFloat>(*semantics)) {
6186APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6187 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6191 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6198APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6199 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6203 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6210APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6211 if (usesLayout<IEEEFloat>(*semantics) &&
6212 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6214 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6215 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6217 }
else if (
this != &
RHS) {
6219 new (
this) Storage(
RHS);
6224APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6225 if (usesLayout<IEEEFloat>(*semantics) &&
6226 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6228 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6229 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6231 }
else if (
this != &
RHS) {
6233 new (
this) Storage(std::move(
RHS));
6242 if (libc_exceptions & FE_INVALID)
6244 if (libc_exceptions & FE_DIVBYZERO)
6246 if (libc_exceptions & FE_OVERFLOW)
6248 if (libc_exceptions & FE_UNDERFLOW)
6250 if (libc_exceptions & FE_INEXACT)
6265 float x_val = x.convertToFloat();
6267 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6269 *status = getOpStatusFromLibc(exc);
6270 if (x.isSignaling()) {
6277 float result = LIBC_NAMESPACE::shared::expf(x_val);
6282 double x_val = x.convertToDouble();
6284 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6286 *status = getOpStatusFromLibc(exc);
6287 if (x.isSignaling()) {
6294 double result = LIBC_NAMESPACE::shared::exp(x_val);
6298 return std::nullopt;
6303#undef APFLOAT_DISPATCH_ON_SEMANTICS
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define PackCategoriesIntoKey(_lhs, _rhs)
A macro used to combine two fcCategory enums into one key which can be used in a switch statement to ...
This file declares a class to represent arbitrary precision floating point values and provide a varie...
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
Function Alias Analysis false
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static bool isNeg(Value *V)
Returns true if the operation is a negation of V, and it works for both integers and floats.
static bool isSigned(unsigned Opcode)
Utilities for dealing with flags related to floating point properties and mode controls.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static const fltSemantics & IEEEsingle()
static const fltSemantics & Float8E4M3FN()
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
static constexpr roundingMode rmTowardZero
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
static const fltSemantics & BFloat()
static const fltSemantics & IEEEquad()
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
static const fltSemantics & Float8E8M0FNU()
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
static const fltSemantics & IEEEdouble()
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static const fltSemantics & x87DoubleExtended()
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
static constexpr unsigned integerPartWidth
static const fltSemantics & PPCDoubleDoubleLegacy()
static LLVM_ABI bool isLosslesslyConvertibleTo(const fltSemantics &From, const fltSemantics &To, bool IgnoreNaNs=false)
Returns whether converting a value from From to To is known to preserve all information.
APInt::WordType integerPart
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static const fltSemantics & Float8E5M2FNUZ()
static const fltSemantics & Float8E4M3FNUZ()
static constexpr roundingMode rmTowardPositive
static const fltSemantics & IEEEhalf()
static const fltSemantics & Float4E2M1FN()
static const fltSemantics & Float6E2M3FN()
static const fltSemantics & Float8E4M3()
static const fltSemantics & Float8E4M3B11FNUZ()
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
static const fltSemantics & Float8E3M4()
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
static const fltSemantics & Float8E5M2()
fltCategory
Category of internally-represented number.
static constexpr roundingMode rmNearestTiesToAway
static const fltSemantics & PPCDoubleDouble()
@ S_PPCDoubleDoubleLegacy
static const fltSemantics & Float6E3M2FN()
opStatus
IEEE-754R 7: Default exception handling.
static const fltSemantics & Float8E5M3FNU()
static LLVM_ABI unsigned getArbitraryFPFormatSizeInBits(StringRef Format)
Returns the size in bits of a valid arbitrary floating-point format string, or 0 if the string is not...
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
static const fltSemantics & FloatTF32()
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
LLVM_ABI void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
opStatus divide(const APFloat &RHS, roundingMode RM)
bool isFiniteNonZero() const
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
cmpResult compareAbsoluteValue(const APFloat &RHS) const
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
opStatus add(const APFloat &RHS, roundingMode RM)
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
const fltSemantics & getSemantics() const
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
opStatus remainder(const APFloat &RHS)
APInt bitcastToAPInt() const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
opStatus next(bool nextDown)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
opStatus mod(const APFloat &RHS)
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
LLVM_DUMP_METHOD void dump() const
LLVM_ABI void print(raw_ostream &) const
opStatus roundToIntegral(roundingMode RM)
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
static LLVM_ABI void tcSetBit(WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static LLVM_ABI void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static LLVM_ABI void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static LLVM_ABI int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static LLVM_ABI WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI void tcExtract(WordType *, unsigned dstCount, const WordType *, unsigned srcBits, unsigned srcLSB)
Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to DST, of dstCOUNT parts,...
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static LLVM_ABI int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static LLVM_ABI void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static LLVM_ABI void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static LLVM_ABI void tcFullMultiply(WordType *, const WordType *, const WordType *, unsigned, unsigned)
DST = LHS * RHS, where DST has width the sum of the widths of the operands.
unsigned getNumWords() const
Get the number of words.
bool isNegative() const
Determine sign of this APInt.
static LLVM_ABI void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
void negate()
Negate this APInt in place.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
unsigned countr_zero() const
Count the number of trailing zero bits.
static LLVM_ABI unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
static LLVM_ABI void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static LLVM_ABI bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static LLVM_ABI unsigned tcMSB(const WordType *parts, unsigned n)
Returns the bit number of the most significant set bit of a number.
float bitsToFloat() const
Converts APInt bits to a float.
static LLVM_ABI int tcMultiplyPart(WordType *dst, const WordType *src, WordType multiplier, WordType carry, unsigned srcParts, unsigned dstParts, bool add)
DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false.
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
static LLVM_ABI WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI void tcNegate(WordType *, unsigned)
Negate a bignum in-place.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
double bitsToDouble() const
Converts APInt bits to a double.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
An arbitrary precision integer that knows its signedness.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This class is used to gather all the unique data bits of a node.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
char back() const
Get the last character in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
Get the string size.
char front() const
Get the first character in the string.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
bool consume_front_insensitive(StringRef Prefix)
Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI void makeSmallestNormalized(bool Neg)
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
LLVM_ABI void changeSign()
LLVM_ABI bool isLargest() const
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI fltCategory getCategory() const
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
LLVM_ABI APInt bitcastToAPInt() const
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_ABI bool isSmallest() const
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
LLVM_ABI bool isDenormal() const
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
LLVM_ABI void makeSmallest(bool Neg)
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
LLVM_ABI opStatus next(bool nextDown)
LLVM_ABI void makeInf(bool Neg)
LLVM_ABI bool isInteger() const
LLVM_ABI void makeZero(bool Neg)
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI bool isSmallestNormalized() const
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
LLVM_ABI void makeLargest(bool Neg)
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
LLVM_ABI APInt getNaNPayload() const
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI bool isNegative() const
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill)
LLVM_ABI unsigned int convertToHexString(char *dst, unsigned int hexDigits, bool upperCase, roundingMode) const
Write out a hexadecimal representation of the floating point value to DST, which must be of sufficien...
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
fltCategory getCategory() const
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
LLVM_ABI APInt getNaNPayload() const
bool isFiniteNonZero() const
bool needsCleanup() const
Returns whether this instance allocated memory.
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI APInt bitcastToAPInt() const
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
LLVM_ABI double convertToDouble() const
LLVM_ABI float convertToFloat() const
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Converts this value into a decimal string.
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
LLVM_ABI void makeInf(bool Neg=false)
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
LLVM_ABI void makeQuiet()
LLVM_ABI bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode)
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
LLVM_ABI IEEEFloat(const fltSemantics &)
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
const fltSemantics & getSemantics() const
bool isZero() const
Returns true if and only if the float is plus or minus zero.
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
LLVM_ABI void makeZero(bool Neg=false)
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
LLVM_ABI void changeSign()
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
LLVM_ABI bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr opStatus opInexact
LLVM_ABI SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
static constexpr fltCategory fcNaN
static constexpr opStatus opDivByZero
static constexpr opStatus opOverflow
static constexpr cmpResult cmpLessThan
const char unit< Period >::value[]
static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts, unsigned bits)
static constexpr roundingMode rmTowardPositive
static constexpr uninitializedTag uninitialized
static constexpr fltCategory fcZero
static constexpr opStatus opOK
static constexpr cmpResult cmpGreaterThan
static constexpr unsigned integerPartWidth
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
APFloatBase::ExponentType ExponentType
static constexpr fltCategory fcNormal
static constexpr opStatus opInvalidOp
APFloatBase::opStatus opStatus
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
APFloatBase::uninitializedTag uninitializedTag
static constexpr cmpResult cmpUnordered
static constexpr roundingMode rmTowardNegative
APFloatBase::roundingMode roundingMode
APFloatBase::cmpResult cmpResult
static constexpr fltCategory fcInfinity
static constexpr roundingMode rmNearestTiesToAway
static constexpr roundingMode rmTowardZero
static constexpr opStatus opUnderflow
static constexpr roundingMode rmNearestTiesToEven
LLVM_ABI int ilogb(const IEEEFloat &Arg)
static constexpr cmpResult cmpEqual
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
static std::pair< APFloat, APFloat > fastTwoSum(APFloat X, APFloat Y)
APFloatBase::integerPart integerPart
FormattedNumber decValue(uint64_t N, unsigned Width=DEC_WIDTH)
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
This is an optimization pass for GlobalISel generic memory operations.
static unsigned int partAsHex(char *dst, APFloatBase::integerPart part, unsigned int count, const char *hexDigitChars)
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
static const char infinityL[]
static constexpr APFloatBase::integerPart PowerOfFiveParts[]
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
static constexpr unsigned int partCountForBits(unsigned int bits)
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
static unsigned int powerOf5(APFloatBase::integerPart *dst, unsigned int power)
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
static APFloat harrisonUlp(const APFloat &X)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
static Expected< int > totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static char * writeUnsignedDecimal(char *dst, unsigned int n)
constexpr unsigned maxExponent
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
static constexpr unsigned NumPow5PartsOnStack
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
static const char infinityU[]
static constexpr unsigned PowerOfFivePartCounts[]
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
static Error interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
LLVM_READONLY LLVM_ABI std::optional< APFloat > exp(const APFloat &X, RoundingMode RM=APFloat::rmNearestTiesToEven, APFloat::opStatus *Status=nullptr)
Implement IEEE 754-2019 exp functions.
LLVM_ABI bool isFinite(const Loop *L)
Return true if this loop can be assumed to run for a finite number of iterations.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Returns: X * 2^Exp for integral exponents.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static unsigned int powerOfFivePartsForExponent(unsigned int power)
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
static Error createError(const Twine &Err)
static lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
static const char hexDigitsUpper[]
static unsigned int decDigitValue(unsigned int c)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant)
static Expected< StringRef::iterator > skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot)
RoundingMode
Rounding mode.
ArrayRef(const T &OneElt) -> ArrayRef< T >
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
static lostFraction lostFractionThroughTruncation(const APFloatBase::integerPart *parts, unsigned int partCount, unsigned int bits)
APFloat neg(APFloat X)
Returns the negated value of the argument.
static APFloatBase::integerPart ulpsFromBoundary(const APFloatBase::integerPart *parts, unsigned int bits, bool isNearest)
static char * writeSignedDecimal(char *dst, int value)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static Expected< lostFraction > trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue)
void consumeError(Error Err)
Consume a Error without doing anything.
static Expected< int > readExponent(StringRef::iterator begin, StringRef::iterator end)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
static const char hexDigitsLower[]
const char * lastSigDigit
const char * firstSigDigit
APFloatBase::ExponentType maxExponent
fltNonfiniteBehavior nonFiniteBehavior
APFloatBase::ExponentType minExponent
fltNanEncoding nanEncoding