24#include "llvm/Config/llvm-config.h"
40#define LIBC_NAMESPACE __llvm_libc_apfloat
41#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
43#include "shared/math.h"
44#include "shared/math_check_exceptions.h"
46#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
48 if (usesLayout<IEEEFloat>(getSemantics())) \
49 return U.IEEE.METHOD_CALL; \
50 if (usesLayout<DoubleAPFloat>(getSemantics())) \
51 return U.Double.METHOD_CALL; \
52 llvm_unreachable("Unexpected semantics"); \
63#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
71constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
72constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
73constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
74constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
75constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
76constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
79constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
84constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
86constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
87constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
105constexpr fltSemantics APFloatBase::semX87DoubleExtended = {16383, -16382, 64,
107constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
108constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
109constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
110 1023, -1022 + 53, 53 + 53, 128};
206 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
207 A.precision <=
B.precision;
281 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
289 return Dst.precision >= Src.precision;
329static inline unsigned int
342 const unsigned int overlargeExponent = 24000;
346 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
349 bool isNegative = *p ==
'-';
350 if (*p ==
'-' || *p ==
'+') {
357 if (absExponent >= 10U)
358 return createError(
"Invalid character in exponent");
360 for (; p != end; ++p) {
363 return createError(
"Invalid character in exponent");
365 absExponent = absExponent * 10U + value;
366 if (absExponent >= overlargeExponent) {
367 absExponent = overlargeExponent;
373 return -(int) absExponent;
375 return (
int) absExponent;
382 int exponentAdjustment) {
388 bool negative = *p ==
'-';
389 if (*p ==
'-' || *p ==
'+') {
395 int unsignedExponent = 0;
396 bool overflow =
false;
397 for (; p != end; ++p) {
402 return createError(
"Invalid character in exponent");
404 unsignedExponent = unsignedExponent * 10 + value;
405 if (unsignedExponent > 32767) {
411 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
415 exponent = unsignedExponent;
417 exponent = -exponent;
418 exponent += exponentAdjustment;
419 if (exponent > 32767 || exponent < -32768)
424 exponent = negative ? -32768: 32767;
434 while (p != end && *p ==
'0')
437 if (p != end && *p ==
'.') {
440 if (end - begin == 1)
443 while (p != end && *p ==
'0')
476 return PtrOrErr.takeError();
479 D->firstSigDigit = p;
481 D->normalizedExponent = 0;
483 for (; p != end; ++p) {
486 return createError(
"String contains multiple dots");
496 if (*p !=
'e' && *p !=
'E')
497 return createError(
"Invalid character in significand");
500 if (dot != end && p - begin == 1)
506 return ExpOrErr.takeError();
507 D->exponent = *ExpOrErr;
515 if (p !=
D->firstSigDigit) {
521 while (p != begin && *p ==
'0');
522 while (p != begin && *p ==
'.');
527 D->normalizedExponent = (
D->exponent +
529 - (dot >
D->firstSigDigit && dot < p)));
541 unsigned int digitValue) {
546 else if (digitValue < 8 && digitValue > 0)
550 while (p != end && (*p ==
'0' || *p ==
'.'))
554 return createError(
"Invalid trailing hexadecimal fraction!");
560 if (hexDigit == UINT_MAX)
570 unsigned int partCount,
595 return lost_fraction;
610 return moreSignificant;
621HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
623 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
625 if (HUerr1 + HUerr2 == 0)
626 return inexactMultiply * 2;
628 return inexactMultiply + 2 * (HUerr1 + HUerr2);
654 if (part - boundary <= boundary - part)
655 return part - boundary;
657 return boundary - part;
660 if (part == boundary) {
666 }
else if (part == boundary - 1) {
683 pow5s[0] = 78125 * 5;
685 unsigned int partsCount = 1;
692 *p1 = firstEightPowers[power & 7];
698 for (
unsigned int n = 0; power; power >>= 1, n++) {
702 partsCount, partsCount);
704 if (pow5[partsCount - 1] == 0)
712 result += partsCount;
713 if (p2[result - 1] == 0)
738static const char NaNL[] =
"nan";
739static const char NaNU[] =
"NAN";
746 const char *hexDigitChars)
748 unsigned int result =
count;
754 dst[
count] = hexDigitChars[part & 0xf];
794 switch (
X.getCategory()) {
804 if (
X.isDenormal() ||
X.isSmallestNormalized())
807 if (
X.getExactLog2() != INT_MIN)
815void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
816 semantics = ourSemantics;
817 unsigned count = partCount();
822void IEEEFloat::freeSignificand() {
824 delete [] significand.parts;
827void IEEEFloat::assign(
const IEEEFloat &rhs) {
828 assert(semantics == rhs.semantics);
831 category = rhs.category;
832 exponent = rhs.exponent;
834 copySignificand(rhs);
837void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
839 assert(rhs.partCount() >= partCount());
852 if (Negative && !semantics->hasSignedRepr)
854 "This floating point format does not support signed values");
858 exponent = exponentNaN();
861 unsigned numParts = partCount();
874 fill = &fill_storage;
878 if (!
fill ||
fill->getNumWords() < numParts)
882 std::min(
fill->getNumWords(), numParts));
885 unsigned bitsToPreserve = semantics->precision - 1;
886 unsigned part = bitsToPreserve / 64;
887 bitsToPreserve %= 64;
888 significand[part] &= ((1ULL << bitsToPreserve) - 1);
889 for (part++; part != numParts; ++part)
890 significand[part] = 0;
894 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
916 if (semantics == &APFloatBase::semX87DoubleExtended)
922 if (semantics != rhs.semantics) {
924 initialize(rhs.semantics);
935 semantics = rhs.semantics;
936 significand = rhs.significand;
937 exponent = rhs.exponent;
938 category = rhs.category;
941 rhs.semantics = &APFloatBase::semBogus;
948 semantics->precision - 1) == 0);
956 significandMSB() == 0;
961 isSignificandAllZerosExceptMSB();
964unsigned int IEEEFloat::getNumHighBits()
const {
971 const unsigned int NumHighBits = (semantics->
precision > 1)
977bool IEEEFloat::isSignificandAllOnes()
const {
982 for (
unsigned i = 0; i < PartCount - 1; i++)
987 const unsigned NumHighBits = getNumHighBits();
988 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
989 "Can not have more high bits to fill than integerPartWidth");
992 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
998bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1007 for (
unsigned i = 0; i < PartCount - 1; i++) {
1008 if (~Parts[i] & ~
unsigned{!i})
1013 const unsigned NumHighBits = getNumHighBits();
1014 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1015 "Can not have more high bits to fill than integerPartWidth");
1018 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1024bool IEEEFloat::isSignificandAllZeros()
const {
1030 for (
unsigned i = 0; i < PartCount - 1; i++)
1035 const unsigned NumHighBits = getNumHighBits();
1037 "clear than integerPartWidth");
1038 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1040 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1046bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1050 for (
unsigned i = 0; i < PartCount - 1; i++) {
1055 const unsigned NumHighBits = getNumHighBits();
1058 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1062 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1069 ? isSignificandAllOnesExceptLSB()
1074 return IsMaxExp && isSignificandAllOnes();
1089 if (semantics != rhs.semantics ||
1090 category != rhs.category ||
1099 return std::equal(significandParts(), significandParts() + partCount(),
1100 rhs.significandParts());
1104 initialize(&ourSemantics);
1109 significandParts()[0] =
value;
1114 initialize(&ourSemantics);
1130 initialize(rhs.semantics);
1135 *
this = std::move(rhs);
1140unsigned int IEEEFloat::partCount()
const {
1145 return const_cast<IEEEFloat *
>(
this)->significandParts();
1149 if (partCount() > 1)
1150 return significand.parts;
1152 return &significand.part;
1155void IEEEFloat::zeroSignificand() {
1160void IEEEFloat::incrementSignificand() {
1172 assert(semantics == rhs.semantics);
1173 assert(exponent == rhs.exponent);
1175 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1184 assert(semantics == rhs.semantics);
1185 assert(exponent == rhs.exponent);
1196 bool ignoreAddend) {
1200 assert(semantics == rhs.semantics);
1202 unsigned precision = semantics->precision;
1210 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1213 unsigned partsCount = partCount();
1216 rhs.significandParts(), partsCount, partsCount);
1220 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1221 exponent += rhs.exponent;
1235 if (!ignoreAddend && addend.isNonZero()) {
1239 Significand savedSignificand = significand;
1240 const fltSemantics *savedSemantics = semantics;
1243 unsigned extendedPrecision = 2 * precision + 1;
1244 if (omsb != extendedPrecision - 1) {
1245 assert(extendedPrecision > omsb);
1247 (extendedPrecision - 1) - omsb);
1248 exponent -= (extendedPrecision - 1) - omsb;
1252 fltSemantics extendedSemantics = *semantics;
1253 extendedSemantics.
precision = extendedPrecision;
1255 if (newPartsCount == 1)
1256 significand.part = fullSignificand[0];
1258 significand.parts = fullSignificand;
1259 semantics = &extendedSemantics;
1272 lost_fraction = extendedAddend.shiftSignificandRight(1);
1274 "Lost precision while shifting addend for fused-multiply-add.");
1276 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1279 if (newPartsCount == 1)
1280 fullSignificand[0] = significand.part;
1281 significand = savedSignificand;
1282 semantics = savedSemantics;
1284 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1291 exponent -= precision + 1;
1300 if (omsb > precision) {
1301 unsigned int bits, significantParts;
1304 bits = omsb - precision;
1306 lf =
shiftRight(fullSignificand, significantParts, bits);
1313 if (newPartsCount > 4)
1314 delete [] fullSignificand;
1316 return lost_fraction;
1325 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1332 assert(semantics == rhs.semantics);
1335 const integerPart *rhsSignificand = rhs.significandParts();
1336 unsigned partsCount = partCount();
1339 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1343 for (
unsigned i = 0; i < partsCount; i++) {
1344 dividend[i] = lhsSignificand[i];
1345 divisor[i] = rhsSignificand[i];
1346 lhsSignificand[i] = 0;
1349 exponent -= rhs.exponent;
1351 unsigned int precision = semantics->precision;
1354 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1361 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1377 for (bit = precision; bit; bit -= 1) {
1402 return lost_fraction;
1405unsigned int IEEEFloat::significandMSB()
const {
1409unsigned int IEEEFloat::significandLSB()
const {
1414lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1420 return shiftRight(significandParts(), partCount(), bits);
1424void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1425 assert(bits < semantics->precision ||
1426 (semantics->precision == 1 && bits <= 1));
1429 unsigned int partsCount = partCount();
1439 assert(semantics == rhs.semantics);
1443 int compare = exponent - rhs.exponent;
1495 exponent = semantics->maxExponent;
1497 semantics->precision);
1510bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1512 unsigned int bit)
const {
1519 switch (rounding_mode) {
1555 unsigned omsb = significandMSB() + 1;
1562 int exponentChange = omsb - semantics->precision;
1566 if (exponent + exponentChange > semantics->maxExponent)
1567 return handleOverflow(rounding_mode);
1571 if (exponent + exponentChange < semantics->minExponent)
1572 exponentChange = semantics->minExponent - exponent;
1575 if (exponentChange < 0) {
1578 shiftSignificandLeft(-exponentChange);
1583 if (exponentChange > 0) {
1587 lf = shiftSignificandRight(exponentChange);
1592 if (omsb > (
unsigned) exponentChange)
1593 omsb -= exponentChange;
1603 exponent == semantics->maxExponent && isSignificandAllOnes())
1604 return handleOverflow(rounding_mode);
1617 if (!semantics->hasZero)
1625 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1627 exponent = semantics->minExponent;
1629 incrementSignificand();
1630 omsb = significandMSB() + 1;
1633 if (omsb == (
unsigned) semantics->precision + 1) {
1637 if (exponent == semantics->maxExponent)
1644 shiftSignificandRight(1);
1653 exponent == semantics->maxExponent && isSignificandAllOnes())
1654 return handleOverflow(rounding_mode);
1659 if (omsb == semantics->precision)
1663 assert(omsb < semantics->precision);
1673 if (!semantics->hasZero)
1745 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1748 int bits = exponent - rhs.exponent;
1752 if ((bits < 0) && !semantics->hasSignedRepr)
1754 "This floating point format does not support signed values");
1757 bool lost_fraction_is_from_rhs =
false;
1761 else if (bits > 0) {
1762 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1763 lost_fraction_is_from_rhs =
true;
1764 shiftSignificandLeft(1);
1766 lost_fraction = shiftSignificandRight(-bits - 1);
1767 temp_rhs.shiftSignificandLeft(1);
1774 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1783 carry = temp_rhs.subtractSignificand(*
this, borrow);
1784 copySignificand(temp_rhs);
1787 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1796 carry = subtractSignificand(temp_rhs, borrow);
1799 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1812 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1813 carry = addSignificand(temp_rhs);
1815 lost_fraction = shiftSignificandRight(-bits);
1816 carry = addSignificand(rhs);
1823 return lost_fraction;
2016 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2017 fs = normalize(rounding_mode, lost_fraction);
2026 if (category ==
fcZero) {
2040 return addOrSubtract(rhs, rounding_mode,
false);
2046 return addOrSubtract(rhs, rounding_mode,
true);
2059 fs = normalize(rounding_mode, lost_fraction);
2077 fs = normalize(rounding_mode, lost_fraction);
2087 unsigned int origSign = sign;
2196 unsigned int origSign = sign;
2217 if (!semantics->hasZero && this->isSmallest())
2237 sign ^= multiplicand.sign;
2246 lost_fraction = multiplySignificand(multiplicand, addend);
2247 fs = normalize(rounding_mode, lost_fraction);
2260 fs = multiplySpecials(multiplicand);
2270 fs = addOrSubtract(addend, rounding_mode,
false);
2342 MagicConstant.sign = sign;
2348 fs =
add(MagicConstant, rounding_mode);
2352 subtract(MagicConstant, rounding_mode);
2363 assert(semantics == rhs.semantics);
2395 if (sign == rhs.sign)
2411 if (sign != rhs.sign) {
2447 unsigned oldPartCount = partCount();
2450 bool X86SpecialNan =
false;
2451 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2452 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2453 (!(*significandParts() & 0x8000000000000000ULL) ||
2454 !(*significandParts() & 0x4000000000000000ULL))) {
2457 X86SpecialNan =
true;
2468 int omsb = significandMSB() + 1;
2469 int exponentChange = omsb - fromSemantics.
precision;
2470 if (exponent + exponentChange < toSemantics.
minExponent)
2471 exponentChange = toSemantics.
minExponent - exponent;
2472 exponentChange = std::max(exponentChange, shift);
2473 if (exponentChange < 0) {
2474 shift -= exponentChange;
2475 exponent += exponentChange;
2476 }
else if (omsb <= -shift) {
2477 exponentChange = omsb + shift - 1;
2478 shift -= exponentChange;
2479 exponent += exponentChange;
2485 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2490 if (newPartCount > oldPartCount) {
2498 significand.parts = newParts;
2499 }
else if (newPartCount == 1 && oldPartCount != 1) {
2503 newPart = significandParts()[0];
2505 significand.part = newPart;
2509 semantics = &toSemantics;
2518 *losesInfo = (
fs !=
opOK);
2519 }
else if (category ==
fcNaN) {
2537 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2554 }
else if (category ==
fcZero &&
2567 if (category ==
fcZero && !semantics->hasZero)
2592 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2594 if (category ==
fcZero) {
2603 unsigned truncatedBits;
2611 truncatedBits = semantics->
precision -1U - exponent;
2615 unsigned int bits = exponent + 1U;
2621 if (bits < semantics->precision) {
2623 truncatedBits = semantics->
precision - bits;
2630 bits - semantics->precision);
2638 if (truncatedBits) {
2642 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2662 if (omsb == width &&
2698 rounding_mode, isExact);
2701 unsigned int bits, dstPartsCount;
2704 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2706 if (category ==
fcNaN)
2729 unsigned dstCount = partCount();
2730 unsigned precision = semantics->
precision;
2735 if (precision <= omsb) {
2736 exponent = omsb - 1;
2741 exponent = precision - 1;
2746 return normalize(rounding_mode, lost_fraction);
2760 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2764IEEEFloat::convertFromHexadecimalString(
StringRef s,
2773 unsigned partsCount = partCount();
2775 bool computedTrailingFraction =
false;
2783 return PtrOrErr.takeError();
2792 return createError(
"String contains multiple dots");
2798 if (hex_value == UINT_MAX)
2808 }
else if (!computedTrailingFraction) {
2811 return FractOrErr.takeError();
2812 lost_fraction = *FractOrErr;
2813 computedTrailingFraction =
true;
2819 return createError(
"Hex strings require an exponent");
2820 if (*p !=
'p' && *p !=
'P')
2821 return createError(
"Invalid character in significand");
2824 if (dot != end && p - begin == 1)
2828 if (p != firstSignificantDigit) {
2837 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2838 if (expAdjustment < 0)
2840 expAdjustment = expAdjustment * 4 - 1;
2844 expAdjustment += semantics->precision;
2850 return ExpOrErr.takeError();
2851 exponent = *ExpOrErr;
2854 return normalize(rounding_mode, lost_fraction);
2858IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2859 unsigned sigPartCount,
int exp,
2861 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2872 for (;; parts *= 2) {
2873 unsigned int excessPrecision, truncatedBits;
2876 excessPrecision = calcSemantics.
precision - semantics->precision;
2877 truncatedBits = excessPrecision;
2880 decSig.makeZero(sign);
2883 opStatus sigStatus = decSig.convertFromUnsignedParts(
2885 opStatus powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2888 decSig.exponent +=
exp;
2892 unsigned int powHUerr;
2896 calcLostFraction = decSig.multiplySignificand(pow5);
2897 powHUerr = powStatus !=
opOK;
2899 calcLostFraction = decSig.divideSignificand(pow5);
2901 if (decSig.exponent < semantics->minExponent) {
2902 excessPrecision += (semantics->minExponent - decSig.exponent);
2903 truncatedBits = excessPrecision;
2904 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
2913 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
2918 excessPrecision, isNearest);
2921 if (HUdistance >= HUerr) {
2922 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
2923 calcSemantics.
precision - excessPrecision,
2928 exponent = (decSig.exponent + semantics->precision
2929 - (calcSemantics.
precision - excessPrecision));
2933 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
2939Expected<APFloat::opStatus>
2940IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
2947 return std::move(Err);
2978 if (!semantics->hasZero)
2983 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
2984 fs = handleOverflow(rounding_mode);
2990 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
2991 (
D.normalizedExponent + 1) * 28738 <=
2992 8651 * (semantics->minExponent - (
int) semantics->precision)) {
2999 }
else if ((
D.normalizedExponent - 1) * 42039
3000 >= 12655 * semantics->maxExponent) {
3002 fs = handleOverflow(rounding_mode);
3005 unsigned int partCount;
3011 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3029 if (p == str.
end()) {
3034 if (decValue >= 10U) {
3035 delete[] decSignificand;
3036 return createError(
"Invalid character in significand");
3039 val = val * 10 + decValue;
3042 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3046 partCount, partCount + 1,
false);
3050 if (decSignificand[partCount])
3052 }
while (p <=
D.lastSigDigit);
3055 fs = roundSignificandWithExponent(decSignificand, partCount,
3056 D.exponent, rounding_mode);
3058 delete [] decSignificand;
3064bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3065 const size_t MIN_NAME_SIZE = 3;
3067 if (str.
size() < MIN_NAME_SIZE)
3070 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3077 if (str.
size() < MIN_NAME_SIZE)
3080 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3089 if (str.
size() < MIN_NAME_SIZE)
3096 makeNaN(IsSignaling, IsNegative);
3101 if (str.
front() ==
'(') {
3103 if (str.
size() <= 2 || str.
back() !=
')')
3110 unsigned Radix = 10;
3111 if (str[0] ==
'0') {
3112 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3123 makeNaN(IsSignaling, IsNegative, &Payload);
3131Expected<APFloat::opStatus>
3137 if (convertFromStringSpecials(str))
3142 size_t slen = str.
size();
3143 sign = *p ==
'-' ? 1 : 0;
3144 if (sign && !semantics->hasSignedRepr)
3146 "This floating point format does not support signed values");
3148 if (*p ==
'-' || *p ==
'+') {
3155 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3158 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3162 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3204 dst +=
sizeof NaNU - 1;
3209 *dst++ = upperCase ?
'X':
'x';
3211 if (hexDigits > 1) {
3213 memset (dst,
'0', hexDigits - 1);
3214 dst += hexDigits - 1;
3216 *dst++ = upperCase ?
'P':
'p';
3221 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3227 return static_cast<unsigned int>(dst - p);
3234char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3238 *dst++ = upperCase ?
'X':
'x';
3240 bool roundUp =
false;
3243 const integerPart *significand = significandParts();
3244 unsigned partsCount = partCount();
3248 unsigned valueBits = semantics->
precision + 3;
3253 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3259 if (hexDigits < outputDigits) {
3265 bits = valueBits - hexDigits * 4;
3267 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3269 outputDigits = hexDigits;
3279 while (outputDigits &&
count) {
3283 if (--
count == partsCount)
3286 part = significand[
count] << shift;
3294 curDigits = std::min(curDigits, outputDigits);
3295 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3296 outputDigits -= curDigits;
3306 }
while (*q ==
'0');
3310 memset (dst,
'0', outputDigits);
3311 dst += outputDigits;
3324 *dst++ = upperCase ?
'P':
'p';
3340 Arg.significandParts(),
3341 Arg.significandParts() + Arg.partCount()));
3353APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3358 uint64_t myexponent, mysignificand;
3361 myexponent = exponent+16383;
3362 mysignificand = significandParts()[0];
3363 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
3365 }
else if (category==
fcZero) {
3369 myexponent = 0x7fff;
3370 mysignificand = 0x8000000000000000ULL;
3373 myexponent = 0x7fff;
3374 mysignificand = significandParts()[0];
3378 words[0] = mysignificand;
3379 words[1] = ((uint64_t)(sign & 1) << 15) |
3380 (myexponent & 0x7fffLL);
3381 return APInt(80, words);
3384APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3386 (
const llvm::fltSemantics *)&APFloatBase::semPPCDoubleDoubleLegacy);
3398 fltSemantics extendedSemantics = *semantics;
3408 words[0] = *
u.convertDoubleAPFloatToAPInt().getRawData();
3414 if (
u.isFiniteNonZero() && losesInfo) {
3422 words[1] = *
v.convertDoubleAPFloatToAPInt().getRawData();
3427 return APInt(128, words);
3430template <const fltSemantics &S>
3431APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3433 const int bias = (semantics == &APFloatBase::semFloat8E8M0FNU)
3435 : -(S.minExponent - 1);
3436 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3437 constexpr int integer_bit_part = trailing_significand_bits /
integerPartWidth;
3440 constexpr uint64_t significand_mask = integer_bit - 1;
3441 constexpr unsigned int exponent_bits =
3442 trailing_significand_bits ? (S.sizeInBits - 1 - trailing_significand_bits)
3444 static_assert(exponent_bits < 64);
3445 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3447 uint64_t myexponent;
3452 myexponent = exponent + bias;
3453 std::copy_n(significandParts(), mysignificand.size(),
3454 mysignificand.begin());
3455 if (myexponent == 1 &&
3456 !(significandParts()[integer_bit_part] & integer_bit))
3458 }
else if (category ==
fcZero) {
3461 myexponent = ::exponentZero(S) + bias;
3462 mysignificand.fill(0);
3467 myexponent = ::exponentInf(S) + bias;
3468 mysignificand.fill(0);
3473 myexponent = ::exponentNaN(S) + bias;
3474 std::copy_n(significandParts(), mysignificand.size(),
3475 mysignificand.begin());
3477 std::array<uint64_t, (S.sizeInBits + 63) / 64> words;
3479 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3480 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3482 words[mysignificand.size() - 1] &= significand_mask;
3484 std::fill(words_iter, words.end(), uint64_t{0});
3485 constexpr size_t last_word = words.size() - 1;
3486 uint64_t shifted_sign =
static_cast<uint64_t
>(sign & 1)
3487 << ((S.sizeInBits - 1) % 64);
3488 words[last_word] |= shifted_sign;
3489 uint64_t shifted_exponent = (myexponent & exponent_mask)
3490 << (trailing_significand_bits % 64);
3491 words[last_word] |= shifted_exponent;
3492 if constexpr (last_word == 0) {
3493 return APInt(S.sizeInBits, words[0]);
3495 return APInt(S.sizeInBits, words);
3498APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3499 assert(partCount() == 2);
3500 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3503APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3505 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3508APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3510 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3513APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3514 assert(partCount() == 1);
3515 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3518APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3520 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3523APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3524 assert(partCount() == 1);
3525 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3528APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3529 assert(partCount() == 1);
3530 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3533APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3534 assert(partCount() == 1);
3535 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3538APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3539 assert(partCount() == 1);
3540 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3543APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3544 assert(partCount() == 1);
3545 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3548APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3549 assert(partCount() == 1);
3550 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3553APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3554 assert(partCount() == 1);
3555 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3558APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3559 assert(partCount() == 1);
3560 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3563APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3564 assert(partCount() == 1);
3565 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3568APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3569 assert(partCount() == 1);
3570 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3573APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3574 assert(partCount() == 1);
3575 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3578APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3579 assert(partCount() == 1);
3580 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3589 return convertHalfAPFloatToAPInt();
3592 return convertBFloatAPFloatToAPInt();
3595 return convertFloatAPFloatToAPInt();
3598 return convertDoubleAPFloatToAPInt();
3601 return convertQuadrupleAPFloatToAPInt();
3605 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3608 return convertFloat8E5M2APFloatToAPInt();
3611 return convertFloat8E5M2FNUZAPFloatToAPInt();
3614 return convertFloat8E4M3APFloatToAPInt();
3617 return convertFloat8E4M3FNAPFloatToAPInt();
3620 return convertFloat8E4M3FNUZAPFloatToAPInt();
3624 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3627 return convertFloat8E3M4APFloatToAPInt();
3630 return convertFloatTF32APFloatToAPInt();
3633 return convertFloat8E8M0FNUAPFloatToAPInt();
3636 return convertFloat6E3M2FNAPFloatToAPInt();
3639 return convertFloat6E2M3FNAPFloatToAPInt();
3642 return convertFloat4E2M1FNAPFloatToAPInt();
3647 return convertF80LongDoubleAPFloatToAPInt();
3652 "Float semantics are not IEEEsingle");
3659 "Float semantics are not IEEEdouble");
3664#ifdef HAS_IEE754_FLOAT128
3665float128 IEEEFloat::convertToQuad()
const {
3667 "Float semantics are not IEEEquads");
3669 return api.bitsToQuad();
3680void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3683 uint64_t myexponent = (i2 & 0x7fff);
3685 uint8_t myintegerbit = mysignificand >> 63;
3687 initialize(&APFloatBase::semX87DoubleExtended);
3690 sign =
static_cast<unsigned int>(i2>>15);
3691 if (myexponent == 0 && mysignificand == 0) {
3693 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3695 }
else if ((myexponent == 0x7fff && mysignificand != 0x8000000000000000ULL) ||
3696 (myexponent != 0x7fff && myexponent != 0 && myintegerbit == 0)) {
3698 exponent = exponentNaN();
3699 significandParts()[0] = mysignificand;
3700 significandParts()[1] = 0;
3703 exponent = myexponent - 16383;
3704 significandParts()[0] = mysignificand;
3705 significandParts()[1] = 0;
3711void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3717 initFromDoubleAPInt(APInt(64, i1));
3718 [[maybe_unused]]
opStatus fs =
convert(APFloatBase::semPPCDoubleDoubleLegacy,
3725 IEEEFloat v(APFloatBase::semIEEEdouble, APInt(64, i2));
3739void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3740 const uint64_t exponent_mask = 0xff;
3742 uint64_t myexponent = val & exponent_mask;
3744 initialize(&APFloatBase::semFloat8E8M0FNU);
3745 assert(partCount() == 1);
3753 uint64_t mysignificand = 1;
3754 significandParts()[0] = mysignificand;
3758 if (val == exponent_mask) {
3760 exponent = exponentNaN();
3765 exponent = myexponent - 127;
3768template <const fltSemantics &S>
3769void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3773 constexpr uint64_t significand_mask = integer_bit - 1;
3774 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3775 constexpr unsigned int stored_significand_parts =
3777 constexpr unsigned int exponent_bits =
3778 S.sizeInBits - 1 - trailing_significand_bits;
3779 static_assert(exponent_bits < 64);
3780 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3781 constexpr int bias = -(S.minExponent - 1);
3785 std::array<integerPart, stored_significand_parts> mysignificand;
3786 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3787 if constexpr (significand_mask != 0) {
3788 mysignificand[mysignificand.size() - 1] &= significand_mask;
3794 uint64_t myexponent =
3795 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3798 assert(partCount() == mysignificand.size());
3800 sign =
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64));
3804 bool is_zero = myexponent == 0 && all_zero_significand;
3807 if (myexponent - bias == ::exponentInf(S) && all_zero_significand) {
3813 bool is_nan =
false;
3816 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3818 bool all_ones_significand =
3819 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3820 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3821 (!significand_mask ||
3822 mysignificand[mysignificand.size() - 1] == significand_mask);
3823 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3825 is_nan = is_zero && sign;
3831 std::copy_n(mysignificand.begin(), mysignificand.size(),
3832 significandParts());
3842 exponent = myexponent - bias;
3843 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3844 if (myexponent == 0)
3845 exponent = S.minExponent;
3847 significandParts()[mysignificand.size()-1] |= integer_bit;
3850void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3851 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3854void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3855 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3858void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3859 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3862void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3863 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3866void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3867 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3870void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3871 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3874void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3875 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
3878void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3879 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
3882void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3883 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
3886void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3887 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
3890void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3891 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
3894void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
3895 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
3898void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3899 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
3902void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3903 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
3906void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
3907 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
3910void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
3911 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
3917 if (Sem == &APFloatBase::semIEEEhalf)
3918 return initFromHalfAPInt(api);
3919 if (Sem == &APFloatBase::semBFloat)
3920 return initFromBFloatAPInt(api);
3921 if (Sem == &APFloatBase::semIEEEsingle)
3922 return initFromFloatAPInt(api);
3923 if (Sem == &APFloatBase::semIEEEdouble)
3924 return initFromDoubleAPInt(api);
3925 if (Sem == &APFloatBase::semX87DoubleExtended)
3926 return initFromF80LongDoubleAPInt(api);
3927 if (Sem == &APFloatBase::semIEEEquad)
3928 return initFromQuadrupleAPInt(api);
3929 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
3930 return initFromPPCDoubleDoubleLegacyAPInt(api);
3931 if (Sem == &APFloatBase::semFloat8E5M2)
3932 return initFromFloat8E5M2APInt(api);
3933 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
3934 return initFromFloat8E5M2FNUZAPInt(api);
3935 if (Sem == &APFloatBase::semFloat8E4M3)
3936 return initFromFloat8E4M3APInt(api);
3937 if (Sem == &APFloatBase::semFloat8E4M3FN)
3938 return initFromFloat8E4M3FNAPInt(api);
3939 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
3940 return initFromFloat8E4M3FNUZAPInt(api);
3941 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
3942 return initFromFloat8E4M3B11FNUZAPInt(api);
3943 if (Sem == &APFloatBase::semFloat8E3M4)
3944 return initFromFloat8E3M4APInt(api);
3945 if (Sem == &APFloatBase::semFloatTF32)
3946 return initFromFloatTF32APInt(api);
3947 if (Sem == &APFloatBase::semFloat8E8M0FNU)
3948 return initFromFloat8E8M0FNUAPInt(api);
3949 if (Sem == &APFloatBase::semFloat6E3M2FN)
3950 return initFromFloat6E3M2FNAPInt(api);
3951 if (Sem == &APFloatBase::semFloat6E2M3FN)
3952 return initFromFloat6E2M3FNAPInt(api);
3953 if (Sem == &APFloatBase::semFloat4E2M1FN)
3954 return initFromFloat4E2M1FNAPInt(api);
3962 if (Negative && !semantics->hasSignedRepr)
3964 "This floating point format does not support signed values");
3971 exponent = semantics->maxExponent;
3975 unsigned PartCount = partCount();
3976 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
3980 const unsigned NumUnusedHighBits =
3987 (semantics->precision > 1))
3994 if (Negative && !semantics->hasSignedRepr)
3996 "This floating point format does not support signed values");
4003 exponent = semantics->minExponent;
4008 if (Negative && !semantics->hasSignedRepr)
4010 "This floating point format does not support signed values");
4019 exponent = semantics->minExponent;
4024 initFromAPInt(&Sem, API);
4037 Buffer.
append(Str.begin(), Str.end());
4042 void AdjustToPrecision(
APInt &significand,
4043 int &
exp,
unsigned FormatPrecision) {
4047 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4049 if (bits <= bitsRequired)
return;
4051 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4052 if (!tensRemovable)
return;
4054 exp += tensRemovable;
4059 if (tensRemovable & 1)
4061 tensRemovable >>= 1;
4062 if (!tensRemovable)
break;
4066 significand = significand.
udiv(divisor);
4074 int &
exp,
unsigned FormatPrecision) {
4075 unsigned N = buffer.
size();
4076 if (
N <= FormatPrecision)
return;
4079 unsigned FirstSignificant =
N - FormatPrecision;
4086 if (buffer[FirstSignificant - 1] <
'5') {
4087 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4090 exp += FirstSignificant;
4091 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4097 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4098 if (buffer[
I] ==
'9') {
4107 if (FirstSignificant ==
N) {
4108 exp += FirstSignificant;
4114 exp += FirstSignificant;
4115 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4119 APInt significand,
unsigned FormatPrecision,
4120 unsigned FormatMaxPadding,
bool TruncateZero) {
4121 const int semanticsPrecision = significand.
getBitWidth();
4128 if (!FormatPrecision) {
4136 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4141 exp += trailingZeros;
4147 }
else if (
exp > 0) {
4149 significand = significand.
zext(semanticsPrecision +
exp);
4150 significand <<=
exp;
4164 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4168 significand = significand.
zext(precision);
4169 APInt five_to_the_i(precision, 5);
4172 significand *= five_to_the_i;
4177 five_to_the_i *= five_to_the_i;
4181 AdjustToPrecision(significand,
exp, FormatPrecision);
4186 unsigned precision = significand.getBitWidth();
4187 if (precision < 4) {
4190 significand = significand.zext(precision);
4192 APInt ten(precision, 10);
4193 APInt digit(precision, 0);
4195 bool inTrail =
true;
4196 while (significand != 0) {
4201 unsigned d = digit.getZExtValue();
4212 assert(!buffer.
empty() &&
"no characters in buffer!");
4216 AdjustToPrecision(buffer,
exp, FormatPrecision);
4218 unsigned NDigits = buffer.
size();
4221 bool FormatScientific;
4222 if (!FormatMaxPadding) {
4223 FormatScientific =
true;
4229 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4230 NDigits + (unsigned)
exp > FormatPrecision);
4233 int MSD =
exp + (int) (NDigits - 1);
4236 FormatScientific =
false;
4240 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4246 if (FormatScientific) {
4247 exp += (NDigits - 1);
4249 Str.push_back(buffer[NDigits-1]);
4251 if (NDigits == 1 && TruncateZero)
4254 for (
unsigned I = 1;
I != NDigits; ++
I)
4255 Str.push_back(buffer[NDigits-1-
I]);
4257 if (!TruncateZero && FormatPrecision > NDigits - 1)
4258 Str.append(FormatPrecision - NDigits + 1,
'0');
4260 Str.push_back(TruncateZero ?
'E' :
'e');
4262 Str.push_back(
exp >= 0 ?
'+' :
'-');
4271 if (!TruncateZero && expbuf.
size() < 2)
4273 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4274 Str.push_back(expbuf[
E-1-
I]);
4280 for (
unsigned I = 0;
I != NDigits; ++
I)
4281 Str.push_back(buffer[NDigits-1-
I]);
4282 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4290 int NWholeDigits =
exp + (int) NDigits;
4293 if (NWholeDigits > 0) {
4294 for (;
I != (unsigned) NWholeDigits; ++
I)
4295 Str.push_back(buffer[NDigits-
I-1]);
4298 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4302 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4306 for (;
I != NDigits; ++
I)
4307 Str.push_back(buffer[NDigits-
I-1]);
4313 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4317 return append(Str,
"-Inf");
4319 return append(Str,
"+Inf");
4321 case fcNaN:
return append(Str,
"NaN");
4327 if (!FormatMaxPadding) {
4329 append(Str,
"0.0E+0");
4332 if (FormatPrecision > 1)
4333 Str.append(FormatPrecision - 1,
'0');
4334 append(Str,
"e+00");
4346 int exp = exponent - ((int) semantics->precision - 1);
4348 semantics->precision,
4351 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4352 FormatMaxPadding, TruncateZero);
4364 for (
int i = 0; i < PartCount; ++i) {
4370 if (exponent != semantics->minExponent)
4373 int CountrParts = 0;
4374 for (
int i = 0; i < PartCount;
4376 if (Parts[i] != 0) {
4377 return exponent - semantics->precision + CountrParts +
4440 if (!semantics->hasZero)
4450 }
else if (semantics->nonFiniteBehavior ==
4458 exponent = semantics->maxExponent + 1;
4472 bool WillCrossBinadeBoundary =
4473 exponent != semantics->minExponent && isSignificandAllZeros();
4491 if (WillCrossBinadeBoundary) {
4512 if (WillCrossBinadeBoundary) {
4516 assert(exponent != semantics->maxExponent &&
4517 "We can not increment an exponent beyond the maxExponent allowed"
4518 " by the given floating point semantics.");
4521 incrementSignificand();
4535 assert(
isNaN() &&
"Can only be called on NaN values");
4537 unsigned Bits = semantics->precision - 1;
4542 return ::exponentNaN(*semantics);
4546 return ::exponentInf(*semantics);
4550 return ::exponentZero(*semantics);
4569 if (!semantics->hasZero)
4596 return Arg.exponent;
4601 Normalized.exponent += SignificandBits;
4603 return Normalized.exponent - SignificandBits;
4607 auto MaxExp =
X.getSemantics().maxExponent;
4608 auto MinExp =
X.getSemantics().minExponent;
4616 int SignificandBits =
X.getSemantics().precision - 1;
4617 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4620 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4643 return scalbn(Val, -Exp, RM);
4649 APFloat(APFloatBase::semIEEEdouble)}) {
4650 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4654 : Semantics(&S), Floats(new
APFloat[2]{
4657 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4663 APFloat(APFloatBase::semIEEEdouble)}) {
4664 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4670 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4671 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4672 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4678 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4679 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4680 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4681 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4685 : Semantics(RHS.Semantics),
4689 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4693 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4694 RHS.Semantics = &APFloatBase::semBogus;
4695 RHS.Floats =
nullptr;
4696 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4700 if (Semantics == RHS.Semantics && RHS.Floats) {
4701 Floats[0] = RHS.Floats[0];
4702 Floats[1] = RHS.Floats[1];
4703 }
else if (
this != &RHS) {
4736 Floats[0] = std::move(z);
4737 Floats[1].makeZero(
false);
4750 Status |= z.
add(a, RM);
4751 Status |= z.
add(c, RM);
4754 Floats[0] = std::move(z);
4755 Floats[1].makeZero(
false);
4760 Status |= zz.
add(cc, RM);
4764 Status |= Floats[1].subtract(z, RM);
4765 Status |= Floats[1].add(c, RM);
4766 Status |= Floats[1].add(zz, RM);
4770 Status |= Floats[1].subtract(z, RM);
4771 Status |= Floats[1].add(a, RM);
4772 Status |= Floats[1].add(zz, RM);
4777 Status |=
q.subtract(z, RM);
4782 Status |= zz.
add(c, RM);
4783 Status |=
q.add(z, RM);
4784 Status |=
q.subtract(a, RM);
4786 Status |= zz.
add(q, RM);
4787 Status |= zz.
add(
aa, RM);
4788 Status |= zz.
add(cc, RM);
4790 Floats[0] = std::move(z);
4791 Floats[1].makeZero(
false);
4795 Status |= Floats[0].add(zz, RM);
4797 Floats[1].makeZero(
false);
4800 Floats[1] = std::move(z);
4801 Status |= Floats[1].subtract(Floats[0], RM);
4802 Status |= Floats[1].add(zz, RM);
4828 LHS.isNegative() !=
RHS.isNegative()) {
4829 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4844 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4845 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4846 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4847 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4848 assert(&Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4849 assert(&Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4850 return Out.addImpl(
A, AA,
C, CC, RM);
4855 return addWithSpecial(*
this, RHS, *
this, RM);
4861 auto Ret =
add(RHS, RM);
4868 const auto &LHS = *
this;
4885 if (LHS.getCategory() ==
fcNaN) {
4889 if (RHS.getCategory() ==
fcNaN) {
4895 Out.makeNaN(
false,
false,
nullptr);
4907 "Special cases not handled exhaustively");
4910 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
4914 if (!
T.isFiniteNonZero()) {
4915 Floats[0] = std::move(
T);
4916 Floats[1].makeZero(
false);
4938 Status |= U.add(Tau, RM);
4941 if (!U.isFinite()) {
4942 Floats[1].makeZero(
false);
4947 Floats[1] = std::move(
T);
4954 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4955 "Unexpected Semantics");
4958 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
4964 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4965 "Unexpected Semantics");
4968 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4974 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4975 "Unexpected Semantics");
4978 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4987 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4988 "Unexpected Semantics");
4991 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
5000 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5001 "Unexpected Semantics");
5011 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5012 Floats[0] = std::move(RoundedHi);
5013 Floats[1].makeZero(
false);
5025 const APFloat RoundingError = Rounded - ToRound;
5026 if (TieBreaker.isNonZero() &&
5027 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5028 abs(RoundingError).isExactlyValue(0.5))
5037 if (RoundedHi !=
Hi) {
5042 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5044 Floats[0] = std::move(RoundedHi);
5045 Floats[1].makeZero(
false);
5058 LoRoundingMode = RM;
5066 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5069 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5071 Floats[0] = std::move(RoundedHi);
5072 Floats[1] = std::move(RoundedLo);
5077 Floats[0].changeSign();
5078 Floats[1].changeSign();
5084 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5089 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5095 const bool ThisIsSubtractive =
5096 Floats[0].isNegative() != Floats[1].isNegative();
5097 const bool RHSIsSubtractive =
5098 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5108 if (RHS.Floats[1].isZero())
5115 if (ThisIsSubtractive != RHSIsSubtractive)
5120 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5122 if (ThisIsSubtractive) {
5136 return Floats[0].getCategory();
5142 Floats[0].makeInf(Neg);
5143 Floats[1].makeZero(
false);
5147 Floats[0].makeZero(Neg);
5148 Floats[1].makeZero(
false);
5152 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5153 "Unexpected Semantics");
5155 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5157 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5163 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5164 "Unexpected Semantics");
5165 Floats[0].makeSmallest(Neg);
5166 Floats[1].makeZero(
false);
5170 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5171 "Unexpected Semantics");
5173 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5175 Floats[0].changeSign();
5176 Floats[1].makeZero(
false);
5180 Floats[0].makeNaN(SNaN, Neg,
fill);
5181 Floats[1].makeZero(
false);
5185 auto Result = Floats[0].compare(RHS.Floats[0]);
5188 return Floats[1].compare(RHS.Floats[1]);
5193 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5194 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5204 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5205 "Unexpected Semantics");
5207 Floats[0].bitcastToAPInt().getRawData()[0],
5208 Floats[1].bitcastToAPInt().getRawData()[0],
5215 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5216 "Unexpected Semantics");
5217 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5230 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5231 "Unexpected Semantics");
5281 if (InLattice(HiOld, NextLo)) {
5283 Floats[1] = std::move(NextLo);
5320 if (!InLattice(NextHi, NextLo))
5324 Floats[0] = std::move(NextHi);
5325 Floats[1] = std::move(NextLo);
5333 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5334 "Unexpected Semantics");
5376 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5377 if (HiExactLog2 >= 0 &&
5378 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5388 Input, Width,
true, RM, &LoIsExact);
5401 *IsExact = RoundStatus ==
opOK;
5413 APSInt LoResult{Width, !IsSigned};
5425 *IsExact = RoundStatus ==
opOK;
5431 unsigned int Width,
bool IsSigned,
5434 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5438 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5446 Bits = Width - IsSigned;
5491 if (SrcMSB == UINT_MAX) {
5498 const unsigned SrcBitWidth = SrcMSB + 1;
5514 return handleOverflow(RM);
5520 bool HiAsIntIsExact;
5537 if (
Error.isNegative()) {
5545 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5547 if (ErrorActiveBits > LoPrecision) {
5548 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5552 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5571 Floats[0] = std::move(
Hi);
5572 Floats[1] = std::move(
Lo);
5577 return handleOverflow(RM);
5583 Largest.makeLargest(
false);
5585 return handleOverflow(RM);
5597 const bool NegateInput = IsSigned &&
Input.isNegative();
5610 unsigned int HexDigits,
5613 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5614 "Unexpected Semantics");
5621 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5623 Floats[0] != Floats[0] + Floats[1]);
5652 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5653 "Unexpected Semantics");
5654 return Floats[0].isInteger() && Floats[1].isInteger();
5658 unsigned FormatPrecision,
5659 unsigned FormatMaxPadding,
5660 bool TruncateZero)
const {
5661 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5662 "Unexpected Semantics");
5664 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5684 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5686 if (
Hi.getExactLog2Abs() == INT_MIN)
5690 return IlogbResult - 1;
5696 "Unexpected Semantics");
5698 scalbn(Arg.Floats[0], Exp, RM),
5699 scalbn(Arg.Floats[1], Exp, RM));
5705 "Unexpected Semantics");
5715 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5737 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5754 LoRoundingMode = RM;
5755 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5763 if (RecomposedLo !=
Lo) {
5767 const APFloat RoundingError = RecomposedLo -
Lo;
5772 const APFloat ScaledUlpOfSecond =
5774 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5775 const bool RoundedLoAway =
5780 if (IsMidpoint && RoundedLoAway)
5796 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5808APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5813 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5828 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5830 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5838 assert(StatusOrErr &&
"Invalid floating point representation");
5890 APFloat Reciprocal =
5908 *Inv = std::move(Reciprocal);
5920 usesLayout<IEEEFloat>(ToSemantics))
5921 return U.IEEE.convert(ToSemantics, RM, losesInfo);
5923 usesLayout<DoubleAPFloat>(ToSemantics)) {
5924 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
5926 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
5927 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
5931 usesLayout<IEEEFloat>(ToSemantics)) {
5932 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
5933 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
5949#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5962 bool *isExact)
const {
5966 rounding_mode, isExact);
5968 result =
APInt(bitWidth, parts);
5974 return getIEEE().convertToDouble();
5976 "Float semantics is not representable by IEEEdouble");
5977 APFloat Temp = *
this;
5985#ifdef HAS_IEE754_FLOAT128
5986float128 APFloat::convertToQuad()
const {
5988 return getIEEE().convertToQuad();
5990 "Float semantics is not representable by IEEEquad");
5996 return Temp.getIEEE().convertToQuad();
6002 return getIEEE().convertToFloat();
6004 "Float semantics is not representable by IEEEsingle");
6005 APFloat Temp = *
this;
6015 "Float8E5M2",
"Float8E5M2FNUZ",
"Float8E4M3",
"Float8E4M3FN",
6016 "Float8E4M3FNUZ",
"Float8E4M3B11FNUZ",
"Float8E3M4",
"Float8E8M0FNU",
6017 "Float6E3M2FN",
"Float6E2M3FN",
"Float4E2M1FN"};
6025 .
Case(
"Float8E5M2", &semFloat8E5M2)
6026 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6027 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6028 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6029 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6033APFloat::Storage::~Storage() {
6034 if (usesLayout<IEEEFloat>(*semantics)) {
6038 if (usesLayout<DoubleAPFloat>(*semantics)) {
6045APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6046 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6050 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6057APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6058 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6062 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6069APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6070 if (usesLayout<IEEEFloat>(*semantics) &&
6071 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6073 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6074 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6076 }
else if (
this != &
RHS) {
6078 new (
this) Storage(
RHS);
6083APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6084 if (usesLayout<IEEEFloat>(*semantics) &&
6085 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6087 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6088 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6090 }
else if (
this != &
RHS) {
6092 new (
this) Storage(std::move(
RHS));
6101 if (libc_exceptions & FE_INVALID)
6103 if (libc_exceptions & FE_DIVBYZERO)
6105 if (libc_exceptions & FE_OVERFLOW)
6107 if (libc_exceptions & FE_UNDERFLOW)
6109 if (libc_exceptions & FE_INEXACT)
6124 float x_val = x.convertToFloat();
6126 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6128 *status = getOpStatusFromLibc(exc);
6129 float result = LIBC_NAMESPACE::shared::expf(x_val);
6134 double x_val = x.convertToDouble();
6136 LIBC_NAMESPACE::shared::check::exp_exceptions(x_val, FE_TONEAREST);
6138 *status = getOpStatusFromLibc(exc);
6139 double result = LIBC_NAMESPACE::shared::exp(x_val);
6143 return std::nullopt;
6148#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< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static bool isNeg(Value *V)
Returns true if the operation is a negation of V, and it works for both integers and floats.
static bool isSigned(unsigned Opcode)
Utilities for dealing with flags related to floating point properties and mode controls.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
static const fltSemantics & IEEEsingle()
static const fltSemantics & Float8E4M3FN()
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
static constexpr roundingMode rmTowardZero
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
static const fltSemantics & BFloat()
static const fltSemantics & IEEEquad()
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
static const fltSemantics & Float8E8M0FNU()
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
static const fltSemantics & IEEEdouble()
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static const fltSemantics & x87DoubleExtended()
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
static constexpr unsigned integerPartWidth
static const fltSemantics & PPCDoubleDoubleLegacy()
APInt::WordType integerPart
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static const fltSemantics & Float8E5M2FNUZ()
static const fltSemantics & Float8E4M3FNUZ()
static constexpr roundingMode rmTowardPositive
static const fltSemantics & IEEEhalf()
static const fltSemantics & Float4E2M1FN()
static const fltSemantics & Float6E2M3FN()
static const fltSemantics & Float8E4M3()
static const fltSemantics & Float8E4M3B11FNUZ()
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
static const fltSemantics & Float8E3M4()
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
static const fltSemantics & Float8E5M2()
fltCategory
Category of internally-represented number.
static constexpr roundingMode rmNearestTiesToAway
static const fltSemantics & PPCDoubleDouble()
@ S_PPCDoubleDoubleLegacy
static const fltSemantics & Float6E3M2FN()
opStatus
IEEE-754R 7: Default exception handling.
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
static const fltSemantics & FloatTF32()
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
LLVM_ABI void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
opStatus divide(const APFloat &RHS, roundingMode RM)
bool isFiniteNonZero() const
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
cmpResult compareAbsoluteValue(const APFloat &RHS) const
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
opStatus add(const APFloat &RHS, roundingMode RM)
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
const fltSemantics & getSemantics() const
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
opStatus remainder(const APFloat &RHS)
APInt bitcastToAPInt() const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
opStatus next(bool nextDown)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
opStatus mod(const APFloat &RHS)
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
LLVM_DUMP_METHOD void dump() const
LLVM_ABI void print(raw_ostream &) const
opStatus roundToIntegral(roundingMode RM)
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
static LLVM_ABI void tcSetBit(WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static LLVM_ABI void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static LLVM_ABI void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static LLVM_ABI int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static LLVM_ABI WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI void tcExtract(WordType *, unsigned dstCount, const WordType *, unsigned srcBits, unsigned srcLSB)
Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to DST, of dstCOUNT parts,...
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static LLVM_ABI int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static LLVM_ABI void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static LLVM_ABI void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static LLVM_ABI void tcFullMultiply(WordType *, const WordType *, const WordType *, unsigned, unsigned)
DST = LHS * RHS, where DST has width the sum of the widths of the operands.
unsigned getNumWords() const
Get the number of words.
bool isNegative() const
Determine sign of this APInt.
static LLVM_ABI void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
void negate()
Negate this APInt in place.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
unsigned countr_zero() const
Count the number of trailing zero bits.
static LLVM_ABI unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
static LLVM_ABI void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static LLVM_ABI bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static LLVM_ABI unsigned tcMSB(const WordType *parts, unsigned n)
Returns the bit number of the most significant set bit of a number.
float bitsToFloat() const
Converts APInt bits to a float.
static LLVM_ABI int tcMultiplyPart(WordType *dst, const WordType *src, WordType multiplier, WordType carry, unsigned srcParts, unsigned dstParts, bool add)
DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false.
static constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
static LLVM_ABI WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI void tcNegate(WordType *, unsigned)
Negate a bignum in-place.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
double bitsToDouble() const
Converts APInt bits to a double.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
An arbitrary precision integer that knows its signedness.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
This class is used to gather all the unique data bits of a node.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
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.
@ C
The default llvm calling convention, compatible with C.
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
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
This is an optimization pass for GlobalISel generic memory operations.
static unsigned int partAsHex(char *dst, APFloatBase::integerPart part, unsigned int count, const char *hexDigitChars)
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
static const char infinityL[]
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
static constexpr unsigned int partCountForBits(unsigned int bits)
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
static unsigned int powerOf5(APFloatBase::integerPart *dst, unsigned int power)
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
static APFloat harrisonUlp(const APFloat &X)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
static Expected< int > totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
const unsigned int maxPowerOfFiveExponent
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static char * writeUnsignedDecimal(char *dst, unsigned int n)
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
const unsigned int maxPrecision
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
static const char infinityU[]
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
static Error interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
LLVM_READONLY LLVM_ABI std::optional< APFloat > exp(const APFloat &X, RoundingMode RM=APFloat::rmNearestTiesToEven, APFloat::opStatus *Status=nullptr)
Implement IEEE 754-2019 exp functions.
LLVM_ABI bool isFinite(const Loop *L)
Return true if this loop can be assumed to run for a finite number of iterations.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
const unsigned int maxPowerOfFiveParts
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Returns: X * 2^Exp for integral exponents.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
static Error createError(const Twine &Err)
static lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
static const char hexDigitsUpper[]
FunctionAddr VTableAddr uintptr_t uintptr_t Data
const unsigned int maxExponent
static unsigned int decDigitValue(unsigned int c)
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant)
static Expected< StringRef::iterator > skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot)
RoundingMode
Rounding mode.
ArrayRef(const T &OneElt) -> ArrayRef< T >
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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