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"); \
72constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
73constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
74constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
75constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
76constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
77constexpr fltSemantics APFloatBase::semX87DoubleExtended = {
89constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
90constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
91 1023, -1022 + 53, 53 + 53, 128};
92constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
95constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
100constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
102constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
103constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
133constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
233 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
234 A.precision <=
B.precision;
240 if (&From == &InitialTo)
246 if (&From == &semPPCDoubleDouble)
253 &InitialTo == &semPPCDoubleDouble ? semIEEEdouble : InitialTo;
268 if (FromHasSignedZero && !ToHasSignedZero)
275 bool LosesInfo =
false;
387 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
395 return Dst.precision >= Src.precision;
435static inline unsigned int
448 const unsigned int overlargeExponent = 24000;
452 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
455 bool isNegative = *p ==
'-';
456 if (*p ==
'-' || *p ==
'+') {
463 if (absExponent >= 10U)
464 return createError(
"Invalid character in exponent");
466 for (; p != end; ++p) {
469 return createError(
"Invalid character in exponent");
471 absExponent = absExponent * 10U + value;
472 if (absExponent >= overlargeExponent) {
473 absExponent = overlargeExponent;
479 return -(int) absExponent;
481 return (
int) absExponent;
488 int exponentAdjustment) {
494 bool negative = *p ==
'-';
495 if (*p ==
'-' || *p ==
'+') {
501 int unsignedExponent = 0;
502 bool overflow =
false;
503 for (; p != end; ++p) {
508 return createError(
"Invalid character in exponent");
510 unsignedExponent = unsignedExponent * 10 + value;
511 if (unsignedExponent > 32767) {
517 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
521 exponent = unsignedExponent;
523 exponent = -exponent;
524 exponent += exponentAdjustment;
525 if (exponent > 32767 || exponent < -32768)
530 exponent = negative ? -32768: 32767;
540 while (p != end && *p ==
'0')
543 if (p != end && *p ==
'.') {
546 if (end - begin == 1)
549 while (p != end && *p ==
'0')
582 return PtrOrErr.takeError();
585 D->firstSigDigit = p;
587 D->normalizedExponent = 0;
589 for (; p != end; ++p) {
592 return createError(
"String contains multiple dots");
602 if (*p !=
'e' && *p !=
'E')
603 return createError(
"Invalid character in significand");
606 if (dot != end && p - begin == 1)
612 return ExpOrErr.takeError();
613 D->exponent = *ExpOrErr;
621 if (p !=
D->firstSigDigit) {
627 while (p != begin && *p ==
'0');
628 while (p != begin && *p ==
'.');
633 D->normalizedExponent = (
D->exponent +
635 - (dot >
D->firstSigDigit && dot < p)));
647 unsigned int digitValue) {
652 else if (digitValue < 8 && digitValue > 0)
656 while (p != end && (*p ==
'0' || *p ==
'.'))
660 return createError(
"Invalid trailing hexadecimal fraction!");
666 if (hexDigit == UINT_MAX)
676 unsigned int partCount,
701 return lost_fraction;
716 return moreSignificant;
727HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
729 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
731 if (HUerr1 + HUerr2 == 0)
732 return inexactMultiply * 2;
734 return inexactMultiply + 2 * (HUerr1 + HUerr2);
760 if (part - boundary <= boundary - part)
761 return part - boundary;
763 return boundary - part;
766 if (part == boundary) {
772 }
else if (part == boundary - 1) {
784 19, 38, 75, 149, 298};
802 1, 5, 25, 125, 625, 3125, 15625, 78125};
813 *p1 = firstEightPowers[power & 7];
819 for (
unsigned int n = 0; power; power >>= 1, n++) {
826 result += partsCount;
827 if (p2[result - 1] == 0)
852static const char NaNL[] =
"nan";
853static const char NaNU[] =
"NAN";
860 const char *hexDigitChars)
862 unsigned int result =
count;
868 dst[
count] = hexDigitChars[part & 0xf];
908 switch (
X.getCategory()) {
918 if (
X.isDenormal() ||
X.isSmallestNormalized())
921 if (
X.getExactLog2() != INT_MIN)
929void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
930 semantics = ourSemantics;
931 unsigned count = partCount();
936void IEEEFloat::freeSignificand() {
938 delete [] significand.parts;
941void IEEEFloat::assign(
const IEEEFloat &rhs) {
942 assert(semantics == rhs.semantics);
945 category = rhs.category;
946 exponent = rhs.exponent;
948 copySignificand(rhs);
951void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
953 assert(rhs.partCount() >= partCount());
966 if (Negative && !semantics->hasSignedRepr)
968 "This floating point format does not support signed values");
972 exponent = exponentNaN();
975 unsigned numParts = partCount();
988 fill = &fill_storage;
992 if (!
fill ||
fill->getNumWords() < numParts)
996 std::min(
fill->getNumWords(), numParts));
999 unsigned bitsToPreserve = semantics->precision - 1;
1000 unsigned part = bitsToPreserve / 64;
1001 bitsToPreserve %= 64;
1002 significand[part] &= ((1ULL << bitsToPreserve) - 1);
1003 for (part++; part != numParts; ++part)
1004 significand[part] = 0;
1008 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
1030 if (semantics == &APFloatBase::semX87DoubleExtended)
1036 if (semantics != rhs.semantics) {
1038 initialize(rhs.semantics);
1049 semantics = rhs.semantics;
1050 significand = rhs.significand;
1051 exponent = rhs.exponent;
1052 category = rhs.category;
1055 rhs.semantics = &APFloatBase::semBogus;
1061 (exponent == semantics->minExponent) &&
1071 significandMSB() == 0;
1076 isSignificandAllZerosExceptMSB();
1079unsigned int IEEEFloat::getNumHighBits()
const {
1086 const unsigned int NumHighBits = (semantics->
precision > 1)
1092bool IEEEFloat::isSignificandAllOnes()
const {
1097 for (
unsigned i = 0; i < PartCount - 1; i++)
1102 const unsigned NumHighBits = getNumHighBits();
1103 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1104 "Can not have more high bits to fill than integerPartWidth");
1107 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
1113bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1122 for (
unsigned i = 0; i < PartCount - 1; i++) {
1123 if (~Parts[i] & ~
unsigned{!i})
1128 const unsigned NumHighBits = getNumHighBits();
1129 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1130 "Can not have more high bits to fill than integerPartWidth");
1133 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1139bool IEEEFloat::isSignificandAllZeros()
const {
1145 for (
unsigned i = 0; i < PartCount - 1; i++)
1150 const unsigned NumHighBits = getNumHighBits();
1152 "clear than integerPartWidth");
1153 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1155 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1161bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1165 for (
unsigned i = 0; i < PartCount - 1; i++) {
1170 const unsigned NumHighBits = getNumHighBits();
1173 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1177 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1184 ? isSignificandAllOnesExceptLSB()
1189 return IsMaxExp && isSignificandAllOnes();
1204 if (semantics != rhs.semantics ||
1205 category != rhs.category ||
1214 return std::equal(significandParts(), significandParts() + partCount(),
1215 rhs.significandParts());
1219 initialize(&ourSemantics);
1224 significandParts()[0] =
value;
1229 initialize(&ourSemantics);
1245 initialize(rhs.semantics);
1250 *
this = std::move(rhs);
1255unsigned int IEEEFloat::partCount()
const {
1260 return const_cast<IEEEFloat *
>(
this)->significandParts();
1264 if (partCount() > 1)
1265 return significand.parts;
1267 return &significand.part;
1270void IEEEFloat::zeroSignificand() {
1275void IEEEFloat::incrementSignificand() {
1287 assert(semantics == rhs.semantics);
1288 assert(exponent == rhs.exponent);
1290 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1299 assert(semantics == rhs.semantics);
1300 assert(exponent == rhs.exponent);
1311 bool ignoreAddend) {
1315 assert(semantics == rhs.semantics);
1317 unsigned precision = semantics->precision;
1325 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1328 unsigned partsCount = partCount();
1331 rhs.significandParts(), partsCount, partsCount);
1335 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1336 exponent += rhs.exponent;
1350 if (!ignoreAddend && addend.isNonZero()) {
1354 Significand savedSignificand = significand;
1355 const fltSemantics *savedSemantics = semantics;
1358 unsigned extendedPrecision = 2 * precision + 1;
1359 if (omsb != extendedPrecision - 1) {
1360 assert(extendedPrecision > omsb);
1362 (extendedPrecision - 1) - omsb);
1363 exponent -= (extendedPrecision - 1) - omsb;
1367 fltSemantics extendedSemantics = *semantics;
1368 extendedSemantics.
precision = extendedPrecision;
1370 if (newPartsCount == 1)
1371 significand.part = fullSignificand[0];
1373 significand.parts = fullSignificand;
1374 semantics = &extendedSemantics;
1387 lost_fraction = extendedAddend.shiftSignificandRight(1);
1389 "Lost precision while shifting addend for fused-multiply-add.");
1391 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1394 if (newPartsCount == 1)
1395 fullSignificand[0] = significand.part;
1396 significand = savedSignificand;
1397 semantics = savedSemantics;
1399 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1406 exponent -= precision + 1;
1415 if (omsb > precision) {
1416 unsigned int bits, significantParts;
1419 bits = omsb - precision;
1421 lf =
shiftRight(fullSignificand, significantParts, bits);
1428 if (newPartsCount > 4)
1429 delete [] fullSignificand;
1431 return lost_fraction;
1440 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1447 assert(semantics == rhs.semantics);
1450 const integerPart *rhsSignificand = rhs.significandParts();
1451 unsigned partsCount = partCount();
1454 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1458 for (
unsigned i = 0; i < partsCount; i++) {
1459 dividend[i] = lhsSignificand[i];
1460 divisor[i] = rhsSignificand[i];
1461 lhsSignificand[i] = 0;
1464 exponent -= rhs.exponent;
1466 unsigned int precision = semantics->precision;
1469 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1476 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1492 for (bit = precision; bit; bit -= 1) {
1517 return lost_fraction;
1520unsigned int IEEEFloat::significandMSB()
const {
1524unsigned int IEEEFloat::significandLSB()
const {
1529lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1535 return shiftRight(significandParts(), partCount(), bits);
1539void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1540 assert(bits < semantics->precision ||
1541 (semantics->precision == 1 && bits <= 1));
1544 unsigned int partsCount = partCount();
1554 assert(semantics == rhs.semantics);
1558 int compare = exponent - rhs.exponent;
1610 exponent = semantics->maxExponent;
1612 semantics->precision);
1625bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1627 unsigned int bit)
const {
1634 switch (rounding_mode) {
1670 unsigned omsb = significandMSB() + 1;
1677 int exponentChange = omsb - semantics->precision;
1681 if (exponent + exponentChange > semantics->maxExponent)
1682 return handleOverflow(rounding_mode);
1686 if (exponent + exponentChange < semantics->minExponent)
1687 exponentChange = semantics->minExponent - exponent;
1690 if (exponentChange < 0) {
1693 shiftSignificandLeft(-exponentChange);
1698 if (exponentChange > 0) {
1702 lf = shiftSignificandRight(exponentChange);
1707 if (omsb > (
unsigned) exponentChange)
1708 omsb -= exponentChange;
1718 exponent == semantics->maxExponent && isSignificandAllOnes())
1719 return handleOverflow(rounding_mode);
1732 if (!semantics->hasZero)
1740 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1742 exponent = semantics->minExponent;
1744 incrementSignificand();
1745 omsb = significandMSB() + 1;
1748 if (omsb == (
unsigned) semantics->precision + 1) {
1752 if (exponent == semantics->maxExponent)
1759 shiftSignificandRight(1);
1768 exponent == semantics->maxExponent && isSignificandAllOnes())
1769 return handleOverflow(rounding_mode);
1774 if (omsb == semantics->precision)
1778 assert(omsb < semantics->precision);
1788 if (!semantics->hasZero)
1860 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1863 int bits = exponent - rhs.exponent;
1867 if ((bits < 0) && !semantics->hasSignedRepr)
1869 "This floating point format does not support signed values");
1872 bool lost_fraction_is_from_rhs =
false;
1876 else if (bits > 0) {
1877 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1878 lost_fraction_is_from_rhs =
true;
1879 shiftSignificandLeft(1);
1881 lost_fraction = shiftSignificandRight(-bits - 1);
1882 temp_rhs.shiftSignificandLeft(1);
1889 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1898 carry = temp_rhs.subtractSignificand(*
this, borrow);
1899 copySignificand(temp_rhs);
1902 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1911 carry = subtractSignificand(temp_rhs, borrow);
1914 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1927 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1928 carry = addSignificand(temp_rhs);
1930 lost_fraction = shiftSignificandRight(-bits);
1931 carry = addSignificand(rhs);
1938 return lost_fraction;
2131 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2132 fs = normalize(rounding_mode, lost_fraction);
2141 if (category ==
fcZero) {
2155 return addOrSubtract(rhs, rounding_mode,
false);
2161 return addOrSubtract(rhs, rounding_mode,
true);
2174 fs = normalize(rounding_mode, lost_fraction);
2192 fs = normalize(rounding_mode, lost_fraction);
2202 unsigned int origSign = sign;
2311 unsigned int origSign = sign;
2332 if (!semantics->hasZero && this->isSmallest())
2352 sign ^= multiplicand.sign;
2361 lost_fraction = multiplySignificand(multiplicand, addend);
2362 fs = normalize(rounding_mode, lost_fraction);
2375 fs = multiplySpecials(multiplicand);
2385 fs = addOrSubtract(addend, rounding_mode,
false);
2457 MagicConstant.sign = sign;
2463 fs =
add(MagicConstant, rounding_mode);
2467 subtract(MagicConstant, rounding_mode);
2478 assert(semantics == rhs.semantics);
2510 if (sign == rhs.sign)
2526 if (sign != rhs.sign) {
2562 unsigned oldPartCount = partCount();
2565 bool X86SpecialNan =
false;
2566 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2567 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2568 (!(*significandParts() & 0x8000000000000000ULL) ||
2569 !(*significandParts() & 0x4000000000000000ULL))) {
2572 X86SpecialNan =
true;
2583 int omsb = significandMSB() + 1;
2584 int exponentChange = omsb - fromSemantics.
precision;
2585 if (exponent + exponentChange < toSemantics.
minExponent)
2586 exponentChange = toSemantics.
minExponent - exponent;
2587 exponentChange = std::max(exponentChange, shift);
2588 if (exponentChange < 0) {
2589 shift -= exponentChange;
2590 exponent += exponentChange;
2591 }
else if (omsb <= -shift) {
2592 exponentChange = omsb + shift - 1;
2593 shift -= exponentChange;
2594 exponent += exponentChange;
2600 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2605 if (newPartCount > oldPartCount) {
2613 significand.parts = newParts;
2614 }
else if (newPartCount == 1 && oldPartCount != 1) {
2618 newPart = significandParts()[0];
2620 significand.part = newPart;
2624 semantics = &toSemantics;
2633 *losesInfo = (
fs !=
opOK);
2634 }
else if (category ==
fcNaN) {
2657 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2675 }
else if (category ==
fcZero &&
2692 if ((sign && !semantics->hasSignedRepr) ||
2693 (category ==
fcZero && !semantics->hasZero)) {
2699 if (category ==
fcZero && !semantics->hasZero)
2724 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2726 if (category ==
fcZero) {
2735 unsigned truncatedBits;
2743 truncatedBits = semantics->
precision -1U - exponent;
2747 unsigned int bits = exponent + 1U;
2753 if (bits < semantics->precision) {
2755 truncatedBits = semantics->
precision - bits;
2762 bits - semantics->precision);
2770 if (truncatedBits) {
2774 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2794 if (omsb == width &&
2830 rounding_mode, isExact);
2833 unsigned int bits, dstPartsCount;
2836 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2838 if (category ==
fcNaN)
2861 unsigned dstCount = partCount();
2862 unsigned precision = semantics->
precision;
2867 if (precision <= omsb) {
2868 exponent = omsb - 1;
2873 exponent = precision - 1;
2878 return normalize(rounding_mode, lost_fraction);
2892 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2896IEEEFloat::convertFromHexadecimalString(
StringRef s,
2905 unsigned partsCount = partCount();
2907 bool computedTrailingFraction =
false;
2915 return PtrOrErr.takeError();
2924 return createError(
"String contains multiple dots");
2930 if (hex_value == UINT_MAX)
2940 }
else if (!computedTrailingFraction) {
2943 return FractOrErr.takeError();
2944 lost_fraction = *FractOrErr;
2945 computedTrailingFraction =
true;
2951 return createError(
"Hex strings require an exponent");
2952 if (*p !=
'p' && *p !=
'P')
2953 return createError(
"Invalid character in significand");
2956 if (dot != end && p - begin == 1)
2960 if (p != firstSignificantDigit) {
2969 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2970 if (expAdjustment < 0)
2972 expAdjustment = expAdjustment * 4 - 1;
2976 expAdjustment += semantics->precision;
2982 return ExpOrErr.takeError();
2983 exponent = *ExpOrErr;
2986 return normalize(rounding_mode, lost_fraction);
2990IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2991 unsigned sigPartCount,
int exp,
2993 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2994 unsigned int power =
exp >= 0 ?
exp : -
exp;
3005 unsigned pow5PartCount =
powerOf5(pow5Parts.
data(), power);
3007 for (;; parts *= 2) {
3008 unsigned int excessPrecision, truncatedBits;
3011 excessPrecision = calcSemantics.
precision - semantics->precision;
3012 truncatedBits = excessPrecision;
3015 decSig.makeZero(sign);
3018 opStatus sigStatus = decSig.convertFromUnsignedParts(
3020 opStatus powStatus = pow5.convertFromUnsignedParts(
3023 decSig.exponent +=
exp;
3027 unsigned int powHUerr;
3031 calcLostFraction = decSig.multiplySignificand(pow5);
3032 powHUerr = powStatus !=
opOK;
3034 calcLostFraction = decSig.divideSignificand(pow5);
3036 if (decSig.exponent < semantics->minExponent) {
3037 excessPrecision += (semantics->minExponent - decSig.exponent);
3038 truncatedBits = excessPrecision;
3039 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
3048 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3053 excessPrecision, isNearest);
3056 if (HUdistance >= HUerr) {
3057 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3058 calcSemantics.
precision - excessPrecision,
3063 exponent = (decSig.exponent + semantics->precision
3064 - (calcSemantics.
precision - excessPrecision));
3068 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
3074Expected<APFloat::opStatus>
3075IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
3082 return std::move(Err);
3113 if (!semantics->hasZero)
3118 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3119 fs = handleOverflow(rounding_mode);
3125 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3126 (
D.normalizedExponent + 1) * 28738 <=
3127 8651 * (semantics->minExponent - (
int) semantics->precision)) {
3134 }
else if ((
D.normalizedExponent - 1) * 42039
3135 >= 12655 * semantics->maxExponent) {
3137 fs = handleOverflow(rounding_mode);
3140 unsigned int partCount;
3146 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3164 if (p == str.
end()) {
3169 if (decValue >= 10U) {
3170 delete[] decSignificand;
3171 return createError(
"Invalid character in significand");
3177 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3181 partCount, partCount + 1,
false);
3185 if (decSignificand[partCount])
3187 }
while (p <=
D.lastSigDigit);
3190 fs = roundSignificandWithExponent(decSignificand, partCount,
3191 D.exponent, rounding_mode);
3193 delete [] decSignificand;
3199bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3200 const size_t MIN_NAME_SIZE = 3;
3202 if (str.
size() < MIN_NAME_SIZE)
3205 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3212 if (str.
size() < MIN_NAME_SIZE)
3215 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3224 if (str.
size() < MIN_NAME_SIZE)
3231 makeNaN(IsSignaling, IsNegative);
3236 if (str.
front() ==
'(') {
3238 if (str.
size() <= 2 || str.
back() !=
')')
3245 unsigned Radix = 10;
3246 if (str[0] ==
'0') {
3247 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3258 makeNaN(IsSignaling, IsNegative, &Payload);
3266Expected<APFloat::opStatus>
3272 if (convertFromStringSpecials(str))
3277 size_t slen = str.
size();
3278 sign = *p ==
'-' ? 1 : 0;
3279 if (sign && !semantics->hasSignedRepr)
3281 "This floating point format does not support signed values");
3283 if (*p ==
'-' || *p ==
'+') {
3290 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3293 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3297 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3339 dst +=
sizeof NaNU - 1;
3344 *dst++ = upperCase ?
'X':
'x';
3346 if (hexDigits > 1) {
3348 memset (dst,
'0', hexDigits - 1);
3349 dst += hexDigits - 1;
3351 *dst++ = upperCase ?
'P':
'p';
3356 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3362 return static_cast<unsigned int>(dst - p);
3369char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3373 *dst++ = upperCase ?
'X':
'x';
3375 bool roundUp =
false;
3378 const integerPart *significand = significandParts();
3379 unsigned partsCount = partCount();
3383 unsigned valueBits = semantics->
precision + 3;
3388 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3394 if (hexDigits < outputDigits) {
3400 bits = valueBits - hexDigits * 4;
3402 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3404 outputDigits = hexDigits;
3414 while (outputDigits &&
count) {
3418 if (--
count == partsCount)
3421 part = significand[
count] << shift;
3429 curDigits = std::min(curDigits, outputDigits);
3430 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3431 outputDigits -= curDigits;
3441 }
while (*q ==
'0');
3445 memset (dst,
'0', outputDigits);
3446 dst += outputDigits;
3459 *dst++ = upperCase ?
'P':
'p';
3475 Arg.significandParts(),
3476 Arg.significandParts() + Arg.partCount()));
3488APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3489 assert(partCount() == 2);
3490 return convertIEEEFloatToAPInt<APFloatBase::semX87DoubleExtended>();
3493APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3508 extendedSemantics.
minExponent = APFloatBase::semIEEEdouble.minExponent;
3517 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
3523 if (u.isFiniteNonZero() && losesInfo) {
3531 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
3536 return APInt(128, words);
3539template <const fltSemantics &S>
3540APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3542 constexpr unsigned int trailing_significand_bits =
3543 S.precision - 1 + S.hasExplicitIntegerBit;
3547 constexpr uint64_t significand_mask = integer_bit - 1;
3548 constexpr unsigned int exponent_bits =
3549 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3550 static_assert(exponent_bits < 64);
3552 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3553 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3560 myexponent = exponent + bias;
3561 std::copy_n(significandParts(), mysignificand.size(),
3562 mysignificand.begin());
3563 if (myexponent == 1 &&
3564 !(significandParts()[integer_bit_part] & integer_bit))
3566 }
else if (category ==
fcZero) {
3569 myexponent = ::exponentZero(S) + bias;
3570 mysignificand.fill(0);
3575 myexponent = ::exponentInf(S) + bias;
3576 mysignificand.fill(0);
3577 if constexpr (S.hasExplicitIntegerBit) {
3578 mysignificand[0] =
integerPart{1} << (trailing_significand_bits - 1);
3584 myexponent = ::exponentNaN(S) + bias;
3585 std::copy_n(significandParts(), mysignificand.size(),
3586 mysignificand.begin());
3588 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3590 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3591 if constexpr (!S.hasExplicitIntegerBit) {
3592 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3594 words[mysignificand.size() - 1] &= significand_mask;
3597 std::fill(words_iter, words.end(),
uint64_t{0});
3598 constexpr size_t last_word = words.size() - 1;
3599 if constexpr (S.hasSignedRepr) {
3601 << ((S.sizeInBits - 1) % 64);
3602 words[last_word] |= shifted_sign;
3604 uint64_t shifted_exponent = (myexponent & exponent_mask)
3605 << (trailing_significand_bits % 64);
3606 words[last_word] |= shifted_exponent;
3607 if constexpr (last_word == 0) {
3608 return APInt(S.sizeInBits, words[0]);
3610 return APInt(S.sizeInBits, words);
3613APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3614 assert(partCount() == 2);
3615 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3618APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3620 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3623APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3625 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3628APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3629 assert(partCount() == 1);
3630 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3633APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3635 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3638APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3639 assert(partCount() == 1);
3640 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3643APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3644 assert(partCount() == 1);
3645 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3648APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3649 assert(partCount() == 1);
3650 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3653APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3654 assert(partCount() == 1);
3655 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3658APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3659 assert(partCount() == 1);
3660 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3663APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3664 assert(partCount() == 1);
3665 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3668APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3669 assert(partCount() == 1);
3670 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3673APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3674 assert(partCount() == 1);
3675 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3678APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3679 assert(partCount() == 1);
3680 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3683APInt IEEEFloat::convertFloat8E5M3FNUAPFloatToAPInt()
const {
3684 assert(partCount() == 1);
3685 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M3FNU>();
3688APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3689 assert(partCount() == 1);
3690 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3693APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3694 assert(partCount() == 1);
3695 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3698APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3699 assert(partCount() == 1);
3700 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3709 return convertHalfAPFloatToAPInt();
3712 return convertBFloatAPFloatToAPInt();
3715 return convertFloatAPFloatToAPInt();
3718 return convertDoubleAPFloatToAPInt();
3721 return convertQuadrupleAPFloatToAPInt();
3725 return convertF80LongDoubleAPFloatToAPInt();
3729 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3732 return convertFloat8E5M2APFloatToAPInt();
3735 return convertFloat8E5M2FNUZAPFloatToAPInt();
3738 return convertFloat8E4M3APFloatToAPInt();
3741 return convertFloat8E4M3FNAPFloatToAPInt();
3744 return convertFloat8E4M3FNUZAPFloatToAPInt();
3748 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3751 return convertFloat8E3M4APFloatToAPInt();
3754 return convertFloatTF32APFloatToAPInt();
3757 return convertFloat8E8M0FNUAPFloatToAPInt();
3760 return convertFloat8E5M3FNUAPFloatToAPInt();
3763 return convertFloat6E3M2FNAPFloatToAPInt();
3766 return convertFloat6E2M3FNAPFloatToAPInt();
3769 return convertFloat4E2M1FNAPFloatToAPInt();
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));
3833void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3834 initFromIEEEAPInt<APFloatBase::semFloat8E8M0FNU>(api);
3837void IEEEFloat::initFromFloat8E5M3FNUAPInt(
const APInt &api) {
3838 initFromIEEEAPInt<APFloatBase::semFloat8E5M3FNU>(api);
3841template <const fltSemantics &S>
3842void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3845 constexpr unsigned int trailing_significand_bits =
3846 S.precision - 1 + S.hasExplicitIntegerBit;
3849 constexpr uint64_t significand_mask = integer_bit - 1;
3850 constexpr unsigned int exponent_bits =
3851 S.sizeInBits - (S.hasSignedRepr ? 1 : 0) - trailing_significand_bits;
3852 static_assert(exponent_bits < 64);
3853 constexpr unsigned int stored_significand_parts =
3856 constexpr bool is_zero_exp_reserved = S.hasDenormals || S.hasZero;
3857 constexpr int bias = -(S.minExponent - (is_zero_exp_reserved ? 1 : 0));
3858 constexpr bool has_significand = trailing_significand_bits > 0;
3862 std::array<integerPart, stored_significand_parts> mysignificand;
3863 if constexpr (has_significand) {
3864 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3866 mysignificand[mysignificand.size() - 1] &= significand_mask;
3869 std::fill_n(mysignificand.begin(), mysignificand.size(), 0);
3872 mysignificand[0] = 1;
3879 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3882 assert(partCount() == mysignificand.size());
3884 sign = S.hasSignedRepr
3885 ?
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64))
3888 bool all_zero_significand =
3891 bool is_zero = myexponent == 0 && all_zero_significand && S.hasZero;
3894 bool is_inf =
false;
3896 if constexpr (S.hasExplicitIntegerBit) {
3898 static_assert(S.precision == 64);
3899 constexpr integerPart significand_mask_no_int_bit =
3900 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3902 mysignificand[0] >> (trailing_significand_bits - 1);
3904 is_inf = myexponent - bias == ::exponentInf(S) && myintegerbit == 1 &&
3905 (mysignificand[0] & significand_mask_no_int_bit) == 0;
3907 is_inf = myexponent - bias == ::exponentInf(S) && all_zero_significand;
3916 bool is_nan =
false;
3919 if constexpr (S.hasExplicitIntegerBit) {
3921 static_assert(S.precision == 64);
3923 mysignificand[0] >> (trailing_significand_bits - 1);
3924 constexpr integerPart significand_mask_no_int_bit =
3925 (
uint64_t{1} << (trailing_significand_bits - 1)) - 1;
3927 if (myexponent - bias == ::exponentNaN(S) &&
3928 (mysignificand[0] & significand_mask_no_int_bit) != 0) {
3931 }
else if (myexponent - bias == ::exponentNaN(S) &&
3932 (mysignificand[0] & significand_mask_no_int_bit) == 0) {
3935 }
else if (myexponent - bias != ::exponentNaN(S) && myexponent != 0 &&
3936 myintegerbit == 0) {
3941 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3944 bool all_ones_significand =
3945 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3946 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3947 (!significand_mask ||
3948 mysignificand[mysignificand.size() - 1] == significand_mask);
3949 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3951 is_nan = is_zero && sign;
3957 std::copy_n(mysignificand.begin(), mysignificand.size(),
3958 significandParts());
3968 exponent = myexponent - bias;
3969 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3970 if (myexponent == 0 && S.hasDenormals)
3971 exponent = S.minExponent;
3973 if constexpr (!S.hasExplicitIntegerBit) {
3974 significandParts()[mysignificand.size() - 1] |= integer_bit;
3979void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3980 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3983void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3984 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3987void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3988 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3991void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3992 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3995void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3996 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3999void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
4000 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
4003void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
4004 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
4007void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
4008 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
4011void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
4012 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
4015void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
4016 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
4019void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
4020 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
4023void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
4024 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
4027void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
4028 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
4031void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
4032 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
4035void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
4036 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
4039void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
4040 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
4046 if (Sem == &APFloatBase::semIEEEhalf)
4047 return initFromHalfAPInt(api);
4048 if (Sem == &APFloatBase::semBFloat)
4049 return initFromBFloatAPInt(api);
4050 if (Sem == &APFloatBase::semIEEEsingle)
4051 return initFromFloatAPInt(api);
4052 if (Sem == &APFloatBase::semIEEEdouble)
4053 return initFromDoubleAPInt(api);
4054 if (Sem == &APFloatBase::semIEEEquad)
4055 return initFromQuadrupleAPInt(api);
4056 if (Sem == &APFloatBase::semX87DoubleExtended)
4057 return initFromF80LongDoubleAPInt(api);
4058 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
4059 return initFromPPCDoubleDoubleLegacyAPInt(api);
4060 if (Sem == &APFloatBase::semFloat8E5M2)
4061 return initFromFloat8E5M2APInt(api);
4062 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
4063 return initFromFloat8E5M2FNUZAPInt(api);
4064 if (Sem == &APFloatBase::semFloat8E4M3)
4065 return initFromFloat8E4M3APInt(api);
4066 if (Sem == &APFloatBase::semFloat8E4M3FN)
4067 return initFromFloat8E4M3FNAPInt(api);
4068 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
4069 return initFromFloat8E4M3FNUZAPInt(api);
4070 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
4071 return initFromFloat8E4M3B11FNUZAPInt(api);
4072 if (Sem == &APFloatBase::semFloat8E3M4)
4073 return initFromFloat8E3M4APInt(api);
4074 if (Sem == &APFloatBase::semFloatTF32)
4075 return initFromFloatTF32APInt(api);
4076 if (Sem == &APFloatBase::semFloat8E8M0FNU)
4077 return initFromFloat8E8M0FNUAPInt(api);
4078 if (Sem == &APFloatBase::semFloat8E5M3FNU)
4079 return initFromFloat8E5M3FNUAPInt(api);
4080 if (Sem == &APFloatBase::semFloat6E3M2FN)
4081 return initFromFloat6E3M2FNAPInt(api);
4082 if (Sem == &APFloatBase::semFloat6E2M3FN)
4083 return initFromFloat6E2M3FNAPInt(api);
4084 if (Sem == &APFloatBase::semFloat4E2M1FN)
4085 return initFromFloat4E2M1FNAPInt(api);
4093 if (Negative && !semantics->hasSignedRepr)
4095 "This floating point format does not support signed values");
4102 exponent = semantics->maxExponent;
4106 unsigned PartCount = partCount();
4107 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4111 const unsigned NumUnusedHighBits =
4118 (semantics->precision > 1))
4125 if (Negative && !semantics->hasSignedRepr)
4127 "This floating point format does not support signed values");
4134 exponent = semantics->minExponent;
4139 if (Negative && !semantics->hasSignedRepr)
4141 "This floating point format does not support signed values");
4150 exponent = semantics->minExponent;
4155 initFromAPInt(&Sem, API);
4168 Buffer.
append(Str.begin(), Str.end());
4173 void AdjustToPrecision(
APInt &significand,
4174 int &
exp,
unsigned FormatPrecision) {
4178 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4180 if (bits <= bitsRequired)
return;
4182 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4183 if (!tensRemovable)
return;
4185 exp += tensRemovable;
4190 if (tensRemovable & 1)
4192 tensRemovable >>= 1;
4193 if (!tensRemovable)
break;
4197 significand = significand.
udiv(divisor);
4205 int &
exp,
unsigned FormatPrecision) {
4206 unsigned N = buffer.
size();
4207 if (
N <= FormatPrecision)
return;
4210 unsigned FirstSignificant =
N - FormatPrecision;
4217 if (buffer[FirstSignificant - 1] <
'5') {
4218 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4221 exp += FirstSignificant;
4222 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4228 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4229 if (buffer[
I] ==
'9') {
4238 if (FirstSignificant ==
N) {
4239 exp += FirstSignificant;
4245 exp += FirstSignificant;
4246 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4250 APInt significand,
unsigned FormatPrecision,
4251 unsigned FormatMaxPadding,
bool TruncateZero) {
4252 const int semanticsPrecision = significand.
getBitWidth();
4259 if (!FormatPrecision) {
4267 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4272 exp += trailingZeros;
4278 }
else if (
exp > 0) {
4280 significand = significand.
zext(semanticsPrecision +
exp);
4281 significand <<=
exp;
4295 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4299 significand = significand.
zext(precision);
4300 APInt five_to_the_i(precision, 5);
4303 significand *= five_to_the_i;
4308 five_to_the_i *= five_to_the_i;
4312 AdjustToPrecision(significand,
exp, FormatPrecision);
4317 unsigned precision = significand.getBitWidth();
4318 if (precision < 4) {
4321 significand = significand.zext(precision);
4323 APInt ten(precision, 10);
4324 APInt digit(precision, 0);
4326 bool inTrail =
true;
4327 while (significand != 0) {
4332 unsigned d = digit.getZExtValue();
4343 assert(!buffer.
empty() &&
"no characters in buffer!");
4347 AdjustToPrecision(buffer,
exp, FormatPrecision);
4349 unsigned NDigits = buffer.
size();
4352 bool FormatScientific;
4353 if (!FormatMaxPadding) {
4354 FormatScientific =
true;
4360 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4361 NDigits + (unsigned)
exp > FormatPrecision);
4364 int MSD =
exp + (int) (NDigits - 1);
4367 FormatScientific =
false;
4371 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4377 if (FormatScientific) {
4378 exp += (NDigits - 1);
4380 Str.push_back(buffer[NDigits-1]);
4382 if (NDigits == 1 && TruncateZero)
4385 for (
unsigned I = 1;
I != NDigits; ++
I)
4386 Str.push_back(buffer[NDigits-1-
I]);
4388 if (!TruncateZero && FormatPrecision > NDigits - 1)
4389 Str.append(FormatPrecision - NDigits + 1,
'0');
4391 Str.push_back(TruncateZero ?
'E' :
'e');
4393 Str.push_back(
exp >= 0 ?
'+' :
'-');
4402 if (!TruncateZero && expbuf.
size() < 2)
4404 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4405 Str.push_back(expbuf[
E-1-
I]);
4411 for (
unsigned I = 0;
I != NDigits; ++
I)
4412 Str.push_back(buffer[NDigits-1-
I]);
4413 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4421 int NWholeDigits =
exp + (int) NDigits;
4424 if (NWholeDigits > 0) {
4425 for (;
I != (unsigned) NWholeDigits; ++
I)
4426 Str.push_back(buffer[NDigits-
I-1]);
4429 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4433 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4437 for (;
I != NDigits; ++
I)
4438 Str.push_back(buffer[NDigits-
I-1]);
4444 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4448 return append(Str,
"-Inf");
4450 return append(Str,
"+Inf");
4452 case fcNaN:
return append(Str,
"NaN");
4458 if (!FormatMaxPadding) {
4460 append(Str,
"0.0E+0");
4463 if (FormatPrecision > 1)
4464 Str.append(FormatPrecision - 1,
'0');
4465 append(Str,
"e+00");
4477 int exp = exponent - ((int) semantics->precision - 1);
4479 semantics->precision,
4482 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4483 FormatMaxPadding, TruncateZero);
4495 for (
int i = 0; i < PartCount; ++i) {
4501 if (exponent != semantics->minExponent)
4504 int CountrParts = 0;
4505 for (
int i = 0; i < PartCount;
4507 if (Parts[i] != 0) {
4508 return exponent - semantics->precision + CountrParts +
4571 if (!semantics->hasZero)
4581 }
else if (semantics->nonFiniteBehavior ==
4589 exponent = semantics->maxExponent + 1;
4603 bool WillCrossBinadeBoundary =
4604 exponent != semantics->minExponent && isSignificandAllZeros();
4622 if (WillCrossBinadeBoundary) {
4643 if (WillCrossBinadeBoundary) {
4647 assert(exponent != semantics->maxExponent &&
4648 "We can not increment an exponent beyond the maxExponent allowed"
4649 " by the given floating point semantics.");
4652 incrementSignificand();
4666 assert(
isNaN() &&
"Can only be called on NaN values");
4668 unsigned Bits = semantics->precision - 1;
4673 return ::exponentNaN(*semantics);
4677 return ::exponentInf(*semantics);
4681 return ::exponentZero(*semantics);
4700 if (!semantics->hasZero)
4727 return Arg.exponent;
4732 Normalized.exponent += SignificandBits;
4734 return Normalized.exponent - SignificandBits;
4738 auto MaxExp =
X.getSemantics().maxExponent;
4739 auto MinExp =
X.getSemantics().minExponent;
4747 int SignificandBits =
X.getSemantics().precision - 1;
4748 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4751 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4774 return scalbn(Val, -Exp, RM);
4780 APFloat(APFloatBase::semIEEEdouble)}) {
4781 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4785 : Semantics(&S), Floats(new
APFloat[2]{
4788 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4794 APFloat(APFloatBase::semIEEEdouble)}) {
4795 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4801 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4802 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4803 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4809 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4810 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4811 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4812 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4816 : Semantics(RHS.Semantics),
4820 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4824 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4825 RHS.Semantics = &APFloatBase::semBogus;
4826 RHS.Floats =
nullptr;
4827 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4831 if (Semantics == RHS.Semantics && RHS.Floats) {
4832 Floats[0] = RHS.Floats[0];
4833 Floats[1] = RHS.Floats[1];
4834 }
else if (
this != &RHS) {
4867 Floats[0] = std::move(z);
4868 Floats[1].makeZero(
false);
4881 Status |= z.
add(a, RM);
4882 Status |= z.
add(c, RM);
4885 Floats[0] = std::move(z);
4886 Floats[1].makeZero(
false);
4891 Status |= zz.
add(cc, RM);
4895 Status |= Floats[1].subtract(z, RM);
4896 Status |= Floats[1].add(c, RM);
4897 Status |= Floats[1].add(zz, RM);
4901 Status |= Floats[1].subtract(z, RM);
4902 Status |= Floats[1].add(a, RM);
4903 Status |= Floats[1].add(zz, RM);
4908 Status |=
q.subtract(z, RM);
4913 Status |= zz.
add(c, RM);
4914 Status |=
q.add(z, RM);
4915 Status |=
q.subtract(a, RM);
4917 Status |= zz.
add(q, RM);
4918 Status |= zz.
add(
aa, RM);
4919 Status |= zz.
add(cc, RM);
4921 Floats[0] = std::move(z);
4922 Floats[1].makeZero(
false);
4926 Status |= Floats[0].add(zz, RM);
4928 Floats[1].makeZero(
false);
4931 Floats[1] = std::move(z);
4932 Status |= Floats[1].subtract(Floats[0], RM);
4933 Status |= Floats[1].add(zz, RM);
4959 LHS.isNegative() !=
RHS.isNegative()) {
4960 Out.makeNaN(
false,
Out.isNegative(),
nullptr);
4975 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4976 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4977 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4978 assert(&
CC.getSemantics() == &APFloatBase::semIEEEdouble);
4979 assert(&
Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4980 assert(&
Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4981 return Out.addImpl(
A, AA,
C,
CC, RM);
4986 return addWithSpecial(*
this, RHS, *
this, RM);
4992 auto Ret =
add(RHS, RM);
4999 const auto &LHS = *
this;
5016 if (LHS.getCategory() ==
fcNaN) {
5020 if (RHS.getCategory() ==
fcNaN) {
5026 Out.makeNaN(
false,
false,
nullptr);
5038 "Special cases not handled exhaustively");
5041 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
5045 if (!
T.isFiniteNonZero()) {
5046 Floats[0] = std::move(
T);
5047 Floats[1].makeZero(
false);
5069 Status |= U.add(Tau, RM);
5072 if (!U.isFinite()) {
5073 Floats[1].makeZero(
false);
5078 Floats[1] = std::move(
T);
5085 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5086 "Unexpected Semantics");
5089 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
5095 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5096 "Unexpected Semantics");
5099 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5105 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5106 "Unexpected Semantics");
5109 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
5118 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5119 "Unexpected Semantics");
5122 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
5131 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5132 "Unexpected Semantics");
5142 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5143 Floats[0] = std::move(RoundedHi);
5144 Floats[1].makeZero(
false);
5156 const APFloat RoundingError = Rounded - ToRound;
5157 if (TieBreaker.isNonZero() &&
5158 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5159 abs(RoundingError).isExactlyValue(0.5))
5168 if (RoundedHi !=
Hi) {
5173 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5175 Floats[0] = std::move(RoundedHi);
5176 Floats[1].makeZero(
false);
5189 LoRoundingMode = RM;
5197 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5200 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5202 Floats[0] = std::move(RoundedHi);
5203 Floats[1] = std::move(RoundedLo);
5208 Floats[0].changeSign();
5209 Floats[1].changeSign();
5215 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5220 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5226 const bool ThisIsSubtractive =
5227 Floats[0].isNegative() != Floats[1].isNegative();
5228 const bool RHSIsSubtractive =
5229 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5239 if (RHS.Floats[1].isZero())
5246 if (ThisIsSubtractive != RHSIsSubtractive)
5251 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5253 if (ThisIsSubtractive) {
5267 return Floats[0].getCategory();
5273 Floats[0].makeInf(Neg);
5274 Floats[1].makeZero(
false);
5278 Floats[0].makeZero(Neg);
5279 Floats[1].makeZero(
false);
5283 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5284 "Unexpected Semantics");
5286 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5288 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5294 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5295 "Unexpected Semantics");
5296 Floats[0].makeSmallest(Neg);
5297 Floats[1].makeZero(
false);
5301 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5302 "Unexpected Semantics");
5304 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5306 Floats[0].changeSign();
5307 Floats[1].makeZero(
false);
5311 Floats[0].makeNaN(SNaN, Neg,
fill);
5312 Floats[1].makeZero(
false);
5316 auto Result = Floats[0].compare(RHS.Floats[0]);
5319 return Floats[1].compare(RHS.Floats[1]);
5324 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5325 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5335 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5336 "Unexpected Semantics");
5338 Floats[0].bitcastToAPInt().getRawData()[0],
5339 Floats[1].bitcastToAPInt().getRawData()[0],
5346 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5347 "Unexpected Semantics");
5348 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5361 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5362 "Unexpected Semantics");
5412 if (InLattice(HiOld, NextLo)) {
5414 Floats[1] = std::move(NextLo);
5451 if (!InLattice(NextHi, NextLo))
5455 Floats[0] = std::move(NextHi);
5456 Floats[1] = std::move(NextLo);
5464 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5465 "Unexpected Semantics");
5507 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5508 if (HiExactLog2 >= 0 &&
5509 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5519 Input, Width,
true, RM, &LoIsExact);
5532 *IsExact = RoundStatus ==
opOK;
5544 APSInt LoResult{Width, !IsSigned};
5556 *IsExact = RoundStatus ==
opOK;
5562 unsigned int Width,
bool IsSigned,
5565 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5569 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5577 Bits = Width - IsSigned;
5622 if (SrcMSB == UINT_MAX) {
5629 const unsigned SrcBitWidth = SrcMSB + 1;
5645 return handleOverflow(RM);
5651 bool HiAsIntIsExact;
5668 if (
Error.isNegative()) {
5676 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5678 if (ErrorActiveBits > LoPrecision) {
5679 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5683 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5702 Floats[0] = std::move(
Hi);
5703 Floats[1] = std::move(
Lo);
5708 return handleOverflow(RM);
5714 Largest.makeLargest(
false);
5716 return handleOverflow(RM);
5728 const bool NegateInput = IsSigned &&
Input.isNegative();
5741 unsigned int HexDigits,
5744 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5745 "Unexpected Semantics");
5752 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5754 Floats[0] != Floats[0] + Floats[1]);
5783 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5784 "Unexpected Semantics");
5785 return Floats[0].isInteger() && Floats[1].isInteger();
5789 unsigned FormatPrecision,
5790 unsigned FormatMaxPadding,
5791 bool TruncateZero)
const {
5792 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5793 "Unexpected Semantics");
5795 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5815 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5817 if (
Hi.getExactLog2Abs() == INT_MIN)
5821 return IlogbResult - 1;
5827 "Unexpected Semantics");
5829 scalbn(Arg.Floats[0], Exp, RM),
5830 scalbn(Arg.Floats[1], Exp, RM));
5836 "Unexpected Semantics");
5846 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5868 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5885 LoRoundingMode = RM;
5886 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5894 if (RecomposedLo !=
Lo) {
5898 const APFloat RoundingError = RecomposedLo -
Lo;
5903 const APFloat ScaledUlpOfSecond =
5905 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5906 const bool RoundedLoAway =
5911 if (IsMidpoint && RoundedLoAway)
5927 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5939APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5944 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5959 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5961 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5969 assert(StatusOrErr &&
"Invalid floating point representation");
6021 APFloat Reciprocal =
6039 *Inv = std::move(Reciprocal);
6051 usesLayout<IEEEFloat>(ToSemantics))
6052 return U.IEEE.convert(ToSemantics, RM, losesInfo);
6054 usesLayout<DoubleAPFloat>(ToSemantics)) {
6055 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
6057 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
6058 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
6062 usesLayout<IEEEFloat>(ToSemantics)) {
6063 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
6064 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
6080#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
6093 bool *isExact)
const {
6097 rounding_mode, isExact);
6099 result =
APInt(bitWidth, parts);
6105 return getIEEE().convertToDouble();
6107 "Float semantics is not representable by IEEEdouble");
6108 APFloat Temp = *
this;
6116#ifdef HAS_IEE754_FLOAT128
6117float128 APFloat::convertToQuad()
const {
6119 return getIEEE().convertToQuad();
6121 "Float semantics is not representable by IEEEquad");
6127 return Temp.getIEEE().convertToQuad();
6133 return getIEEE().convertToFloat();
6135 "Float semantics is not representable by IEEEsingle");
6136 APFloat Temp = *
this;
6169 .
Case(
"Float8E5M2", &semFloat8E5M2)
6170 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6171 .
Case(
"Float8E5M3FNU", &semFloat8E5M3FNU)
6172 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6173 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6174 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6178APFloat::Storage::~Storage() {
6179 if (usesLayout<IEEEFloat>(*semantics)) {
6183 if (usesLayout<DoubleAPFloat>(*semantics)) {
6190APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6191 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6195 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6202APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6203 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6207 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6214APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6215 if (usesLayout<IEEEFloat>(*semantics) &&
6216 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6218 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6219 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6221 }
else if (
this != &
RHS) {
6223 new (
this) Storage(
RHS);
6228APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6229 if (usesLayout<IEEEFloat>(*semantics) &&
6230 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6232 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6233 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6235 }
else if (
this != &
RHS) {
6237 new (
this) Storage(std::move(
RHS));
6246 if (libc_exceptions & FE_INVALID)
6248 if (libc_exceptions & FE_DIVBYZERO)
6250 if (libc_exceptions & FE_OVERFLOW)
6252 if (libc_exceptions & FE_UNDERFLOW)
6254 if (libc_exceptions & FE_INEXACT)
6269 float x_val = x.convertToFloat();
6271 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6273 *status = getOpStatusFromLibc(exc);
6274 if (x.isSignaling()) {
6281 float result = LIBC_NAMESPACE::shared::expf(x_val);
6286 double x_val = x.convertToDouble();
6288 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6290 *status = getOpStatusFromLibc(exc);
6291 if (x.isSignaling()) {
6298 double result = LIBC_NAMESPACE::shared::exp(x_val);
6302 return std::nullopt;
6307#undef APFLOAT_DISPATCH_ON_SEMANTICS
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr int packCategoriesIntoKey(int LHS, int RHS)
A function used to combine two fcCategory enums into one key which can be used in a switch statement ...
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