23#include "llvm/Config/llvm-config.h"
31#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
33 if (usesLayout<IEEEFloat>(getSemantics())) \
34 return U.IEEE.METHOD_CALL; \
35 if (usesLayout<DoubleAPFloat>(getSemantics())) \
36 return U.Double.METHOD_CALL; \
37 llvm_unreachable("Unexpected semantics"); \
48#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
361 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
369 return Dst.precision >= Src.precision;
409static inline unsigned int
423 unsigned int absExponent;
424 const unsigned int overlargeExponent = 24000;
428 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end)) {
432 isNegative = (*p ==
'-');
433 if (*p ==
'-' || *p ==
'+') {
440 if (absExponent >= 10U)
441 return createError(
"Invalid character in exponent");
443 for (; p != end; ++p) {
448 return createError(
"Invalid character in exponent");
450 absExponent = absExponent * 10U +
value;
451 if (absExponent >= overlargeExponent) {
452 absExponent = overlargeExponent;
458 return -(int) absExponent;
460 return (
int) absExponent;
467 int exponentAdjustment) {
468 int unsignedExponent;
469 bool negative, overflow;
475 negative = *p ==
'-';
476 if (*p ==
'-' || *p ==
'+') {
482 unsignedExponent = 0;
484 for (; p != end; ++p) {
489 return createError(
"Invalid character in exponent");
491 unsignedExponent = unsignedExponent * 10 +
value;
492 if (unsignedExponent > 32767) {
498 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
502 exponent = unsignedExponent;
504 exponent = -exponent;
505 exponent += exponentAdjustment;
506 if (exponent > 32767 || exponent < -32768)
511 exponent = negative ? -32768: 32767;
521 while (p != end && *p ==
'0')
524 if (p != end && *p ==
'.') {
527 if (end - begin == 1)
530 while (p != end && *p ==
'0')
563 return PtrOrErr.takeError();
566 D->firstSigDigit = p;
568 D->normalizedExponent = 0;
570 for (; p != end; ++p) {
573 return createError(
"String contains multiple dots");
583 if (*p !=
'e' && *p !=
'E')
584 return createError(
"Invalid character in significand");
587 if (dot != end && p - begin == 1)
593 return ExpOrErr.takeError();
594 D->exponent = *ExpOrErr;
602 if (p !=
D->firstSigDigit) {
608 while (p != begin && *p ==
'0');
609 while (p != begin && *p ==
'.');
614 D->normalizedExponent = (
D->exponent +
616 - (dot >
D->firstSigDigit && dot < p)));
628 unsigned int digitValue) {
629 unsigned int hexDigit;
635 else if (digitValue < 8 && digitValue > 0)
639 while (p != end && (*p ==
'0' || *p ==
'.'))
643 return createError(
"Invalid trailing hexadecimal fraction!");
645 hexDigit = hexDigitValue(*p);
649 if (hexDigit == UINT_MAX)
659 unsigned int partCount,
688 return lost_fraction;
703 return moreSignificant;
714HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
716 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
718 if (HUerr1 + HUerr2 == 0)
719 return inexactMultiply * 2;
721 return inexactMultiply + 2 * (HUerr1 + HUerr2);
730 unsigned int count, partBits;
747 if (part - boundary <= boundary - part)
748 return part - boundary;
750 return boundary - part;
753 if (part == boundary) {
759 }
else if (part == boundary - 1) {
776 pow5s[0] = 78125 * 5;
778 unsigned int partsCount = 1;
786 *p1 = firstEightPowers[power & 7];
792 for (
unsigned int n = 0; power; power >>= 1, n++) {
796 partsCount, partsCount);
798 if (pow5[partsCount - 1] == 0)
806 result += partsCount;
807 if (p2[result - 1] == 0)
832static const char NaNL[] =
"nan";
833static const char NaNU[] =
"NAN";
840 const char *hexDigitChars)
842 unsigned int result =
count;
848 dst[
count] = hexDigitChars[part & 0xf];
888void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
891 semantics = ourSemantics;
897void IEEEFloat::freeSignificand() {
899 delete [] significand.parts;
902void IEEEFloat::assign(
const IEEEFloat &rhs) {
903 assert(semantics == rhs.semantics);
906 category = rhs.category;
907 exponent = rhs.exponent;
909 copySignificand(rhs);
912void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
914 assert(rhs.partCount() >= partCount());
929 "This floating point format does not support signed values");
933 exponent = exponentNaN();
936 unsigned numParts = partCount();
949 fill = &fill_storage;
960 unsigned bitsToPreserve = semantics->
precision - 1;
961 unsigned part = bitsToPreserve / 64;
962 bitsToPreserve %= 64;
963 significand[part] &= ((1ULL << bitsToPreserve) - 1);
964 for (part++; part != numParts; ++part)
965 significand[part] = 0;
997 if (semantics != rhs.semantics) {
999 initialize(rhs.semantics);
1010 semantics = rhs.semantics;
1011 significand = rhs.significand;
1012 exponent = rhs.exponent;
1013 category = rhs.category;
1031 significandMSB() == 0;
1036 isSignificandAllZerosExceptMSB();
1039unsigned int IEEEFloat::getNumHighBits()
const {
1046 const unsigned int NumHighBits = (semantics->
precision > 1)
1052bool IEEEFloat::isSignificandAllOnes()
const {
1057 for (
unsigned i = 0; i < PartCount - 1; i++)
1062 const unsigned NumHighBits = getNumHighBits();
1063 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1064 "Can not have more high bits to fill than integerPartWidth");
1067 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
1073bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1082 for (
unsigned i = 0; i < PartCount - 1; i++) {
1083 if (~Parts[i] & ~
unsigned{!i})
1088 const unsigned NumHighBits = getNumHighBits();
1089 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1090 "Can not have more high bits to fill than integerPartWidth");
1093 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1099bool IEEEFloat::isSignificandAllZeros()
const {
1105 for (
unsigned i = 0; i < PartCount - 1; i++)
1110 const unsigned NumHighBits = getNumHighBits();
1112 "clear than integerPartWidth");
1113 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1115 if ((semantics->
precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1121bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1125 for (
unsigned i = 0; i < PartCount - 1; i++) {
1130 const unsigned NumHighBits = getNumHighBits();
1133 return ((semantics->
precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1144 ? isSignificandAllOnesExceptLSB()
1149 return IsMaxExp && isSignificandAllOnes();
1164 if (semantics != rhs.semantics ||
1165 category != rhs.category ||
1174 return std::equal(significandParts(), significandParts() + partCount(),
1175 rhs.significandParts());
1179 initialize(&ourSemantics);
1184 significandParts()[0] =
value;
1189 initialize(&ourSemantics);
1205 initialize(rhs.semantics);
1210 *
this = std::move(rhs);
1215unsigned int IEEEFloat::partCount()
const {
1220 return const_cast<IEEEFloat *
>(
this)->significandParts();
1224 if (partCount() > 1)
1225 return significand.parts;
1227 return &significand.part;
1230void IEEEFloat::zeroSignificand() {
1235void IEEEFloat::incrementSignificand() {
1249 parts = significandParts();
1251 assert(semantics == rhs.semantics);
1252 assert(exponent == rhs.exponent);
1254 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1263 parts = significandParts();
1265 assert(semantics == rhs.semantics);
1266 assert(exponent == rhs.exponent);
1275lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs,
1277 bool ignoreAddend) {
1279 unsigned int partsCount, newPartsCount, precision;
1286 assert(semantics == rhs.semantics);
1294 if (newPartsCount > 4)
1297 fullSignificand = scratch;
1299 lhsSignificand = significandParts();
1300 partsCount = partCount();
1303 rhs.significandParts(), partsCount, partsCount);
1306 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1307 exponent += rhs.exponent;
1321 if (!ignoreAddend && addend.isNonZero()) {
1325 Significand savedSignificand = significand;
1329 unsigned int extendedPrecision;
1332 extendedPrecision = 2 * precision + 1;
1333 if (omsb != extendedPrecision - 1) {
1334 assert(extendedPrecision > omsb);
1336 (extendedPrecision - 1) - omsb);
1337 exponent -= (extendedPrecision - 1) - omsb;
1341 extendedSemantics = *semantics;
1342 extendedSemantics.
precision = extendedPrecision;
1344 if (newPartsCount == 1)
1345 significand.part = fullSignificand[0];
1347 significand.parts = fullSignificand;
1348 semantics = &extendedSemantics;
1362 lost_fraction = extendedAddend.shiftSignificandRight(1);
1364 "Lost precision while shifting addend for fused-multiply-add.");
1366 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1369 if (newPartsCount == 1)
1370 fullSignificand[0] = significand.part;
1371 significand = savedSignificand;
1372 semantics = savedSemantics;
1374 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1381 exponent -= precision + 1;
1390 if (omsb > precision) {
1391 unsigned int bits, significantParts;
1394 bits = omsb - precision;
1396 lf =
shiftRight(fullSignificand, significantParts, bits);
1403 if (newPartsCount > 4)
1404 delete [] fullSignificand;
1406 return lost_fraction;
1409lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs) {
1415 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->
hasZero);
1419lostFraction IEEEFloat::divideSignificand(
const IEEEFloat &rhs) {
1420 unsigned int bit, i, partsCount;
1426 assert(semantics == rhs.semantics);
1428 lhsSignificand = significandParts();
1429 rhsSignificand = rhs.significandParts();
1430 partsCount = partCount();
1437 divisor = dividend + partsCount;
1440 for (i = 0; i < partsCount; i++) {
1441 dividend[i] = lhsSignificand[i];
1442 divisor[i] = rhsSignificand[i];
1443 lhsSignificand[i] = 0;
1446 exponent -= rhs.exponent;
1448 unsigned int precision = semantics->
precision;
1451 bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1458 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1474 for (bit = precision; bit; bit -= 1) {
1498 return lost_fraction;
1501unsigned int IEEEFloat::significandMSB()
const {
1505unsigned int IEEEFloat::significandLSB()
const {
1510lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1516 return shiftRight(significandParts(), partCount(), bits);
1520void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1521 assert(bits < semantics->precision ||
1522 (semantics->
precision == 1 && bits <= 1));
1525 unsigned int partsCount = partCount();
1537 assert(semantics == rhs.semantics);
1541 compare = exponent - rhs.exponent;
1608bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1610 unsigned int bit)
const {
1617 switch (rounding_mode) {
1655 omsb = significandMSB() + 1;
1661 exponentChange = omsb - semantics->
precision;
1665 if (exponent + exponentChange > semantics->
maxExponent)
1666 return handleOverflow(rounding_mode);
1670 if (exponent + exponentChange < semantics->minExponent)
1671 exponentChange = semantics->
minExponent - exponent;
1674 if (exponentChange < 0) {
1677 shiftSignificandLeft(-exponentChange);
1682 if (exponentChange > 0) {
1686 lf = shiftSignificandRight(exponentChange);
1691 if (omsb > (
unsigned) exponentChange)
1692 omsb -= exponentChange;
1702 exponent == semantics->
maxExponent && isSignificandAllOnes())
1703 return handleOverflow(rounding_mode);
1724 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1728 incrementSignificand();
1729 omsb = significandMSB() + 1;
1732 if (omsb == (
unsigned) semantics->
precision + 1) {
1743 shiftSignificandRight(1);
1752 exponent == semantics->
maxExponent && isSignificandAllOnes())
1753 return handleOverflow(rounding_mode);
1762 assert(omsb < semantics->precision);
1837lostFraction IEEEFloat::addOrSubtractSignificand(
const IEEEFloat &rhs,
1845 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1848 bits = exponent - rhs.exponent;
1854 "This floating point format does not support signed values");
1860 else if (bits > 0) {
1861 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1862 shiftSignificandLeft(1);
1864 lost_fraction = shiftSignificandRight(-bits - 1);
1865 temp_rhs.shiftSignificandLeft(1);
1870 carry = temp_rhs.subtractSignificand
1872 copySignificand(temp_rhs);
1875 carry = subtractSignificand
1894 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1895 carry = addSignificand(temp_rhs);
1897 lost_fraction = shiftSignificandRight(-bits);
1898 carry = addSignificand(rhs);
1906 return lost_fraction;
2095 fs = addOrSubtractSpecials(rhs,
subtract);
2101 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2102 fs = normalize(rounding_mode, lost_fraction);
2111 if (category ==
fcZero) {
2125 return addOrSubtract(rhs, rounding_mode,
false);
2131 return addOrSubtract(rhs, rounding_mode,
true);
2140 fs = multiplySpecials(rhs);
2146 fs = normalize(rounding_mode, lost_fraction);
2160 fs = divideSpecials(rhs);
2166 fs = normalize(rounding_mode, lost_fraction);
2177 unsigned int origSign = sign;
2180 fs = remainderSpecials(rhs);
2287 fs = modSpecials(rhs);
2288 unsigned int origSign = sign;
2309 if (!semantics->
hasZero && this->isSmallest())
2329 sign ^= multiplicand.sign;
2338 lost_fraction = multiplySignificand(multiplicand, addend);
2339 fs = normalize(rounding_mode, lost_fraction);
2352 fs = multiplySpecials(multiplicand);
2362 fs = addOrSubtract(addend, rounding_mode,
false);
2436 MagicConstant.sign = sign;
2442 fs =
add(MagicConstant, rounding_mode);
2446 subtract(MagicConstant, rounding_mode);
2459 assert(semantics == rhs.semantics);
2491 if (sign == rhs.sign)
2506 if (sign != rhs.sign) {
2537 unsigned int newPartCount, oldPartCount;
2545 oldPartCount = partCount();
2548 bool X86SpecialNan =
false;
2551 (!(*significandParts() & 0x8000000000000000ULL) ||
2552 !(*significandParts() & 0x4000000000000000ULL))) {
2555 X86SpecialNan =
true;
2566 int omsb = significandMSB() + 1;
2567 int exponentChange = omsb - fromSemantics.
precision;
2568 if (exponent + exponentChange < toSemantics.
minExponent)
2569 exponentChange = toSemantics.
minExponent - exponent;
2570 if (exponentChange < shift)
2571 exponentChange = shift;
2572 if (exponentChange < 0) {
2573 shift -= exponentChange;
2574 exponent += exponentChange;
2575 }
else if (omsb <= -shift) {
2576 exponentChange = omsb + shift - 1;
2577 shift -= exponentChange;
2578 exponent += exponentChange;
2589 if (newPartCount > oldPartCount) {
2597 significand.parts = newParts;
2598 }
else if (newPartCount == 1 && oldPartCount != 1) {
2602 newPart = significandParts()[0];
2604 significand.part = newPart;
2608 semantics = &toSemantics;
2617 *losesInfo = (fs !=
opOK);
2618 }
else if (category ==
fcNaN) {
2653 }
else if (category ==
fcZero &&
2686 unsigned int dstPartsCount, truncatedBits;
2695 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2697 if (category ==
fcZero) {
2704 src = significandParts();
2713 truncatedBits = semantics->
precision -1U - exponent;
2717 unsigned int bits = exponent + 1U;
2723 if (bits < semantics->precision) {
2725 truncatedBits = semantics->
precision - bits;
2739 if (truncatedBits) {
2743 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2763 if (omsb == width &&
2800 fs = convertToSignExtendedInteger(parts, width,
isSigned, rounding_mode,
2804 unsigned int bits, dstPartsCount;
2807 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2809 if (category ==
fcNaN)
2829 unsigned int omsb, precision, dstCount;
2835 dst = significandParts();
2836 dstCount = partCount();
2841 if (precision <= omsb) {
2842 exponent = omsb - 1;
2847 exponent = precision - 1;
2852 return normalize(rounding_mode, lost_fraction);
2866 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2874 unsigned int srcCount,
bool isSigned,
2887 status = convertFromUnsignedParts(
copy, srcCount, rounding_mode);
2891 status = convertFromUnsignedParts(src, srcCount, rounding_mode);
2911 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2915IEEEFloat::convertFromHexadecimalString(
StringRef s,
2924 unsigned partsCount = partCount();
2926 bool computedTrailingFraction =
false;
2934 return PtrOrErr.takeError();
2943 return createError(
"String contains multiple dots");
2948 hex_value = hexDigitValue(*p);
2949 if (hex_value == UINT_MAX)
2959 }
else if (!computedTrailingFraction) {
2962 return FractOrErr.takeError();
2963 lost_fraction = *FractOrErr;
2964 computedTrailingFraction =
true;
2970 return createError(
"Hex strings require an exponent");
2971 if (*p !=
'p' && *p !=
'P')
2972 return createError(
"Invalid character in significand");
2975 if (dot != end && p - begin == 1)
2979 if (p != firstSignificantDigit) {
2988 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2989 if (expAdjustment < 0)
2991 expAdjustment = expAdjustment * 4 - 1;
3001 return ExpOrErr.takeError();
3002 exponent = *ExpOrErr;
3005 return normalize(rounding_mode, lost_fraction);
3009IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
3010 unsigned sigPartCount,
int exp,
3012 unsigned int parts, pow5PartCount;
3023 pow5PartCount =
powerOf5(pow5Parts, exp >= 0 ? exp: -exp);
3025 for (;; parts *= 2) {
3027 unsigned int excessPrecision, truncatedBits;
3031 truncatedBits = excessPrecision;
3034 decSig.makeZero(sign);
3037 sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
3039 powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
3042 decSig.exponent += exp;
3046 unsigned int powHUerr;
3050 calcLostFraction = decSig.multiplySignificand(pow5);
3051 powHUerr = powStatus !=
opOK;
3053 calcLostFraction = decSig.divideSignificand(pow5);
3056 excessPrecision += (semantics->
minExponent - decSig.exponent);
3057 truncatedBits = excessPrecision;
3058 if (excessPrecision > calcSemantics.
precision)
3059 excessPrecision = calcSemantics.
precision;
3068 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3073 excessPrecision, isNearest);
3076 if (HUdistance >= HUerr) {
3077 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3078 calcSemantics.
precision - excessPrecision,
3083 exponent = (decSig.exponent + semantics->
precision
3084 - (calcSemantics.
precision - excessPrecision));
3088 return normalize(rounding_mode, calcLostFraction);
3101 return std::move(Err);
3137 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3138 fs = handleOverflow(rounding_mode);
3144 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3145 (
D.normalizedExponent + 1) * 28738 <=
3153 }
else if ((
D.normalizedExponent - 1) * 42039
3156 fs = handleOverflow(rounding_mode);
3159 unsigned int partCount;
3165 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3183 if (p == str.
end()) {
3188 if (decValue >= 10U) {
3189 delete[] decSignificand;
3190 return createError(
"Invalid character in significand");
3193 val = val * 10 + decValue;
3196 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3200 partCount, partCount + 1,
false);
3204 if (decSignificand[partCount])
3206 }
while (p <=
D.lastSigDigit);
3209 fs = roundSignificandWithExponent(decSignificand, partCount,
3210 D.exponent, rounding_mode);
3212 delete [] decSignificand;
3218bool IEEEFloat::convertFromStringSpecials(
StringRef str) {
3219 const size_t MIN_NAME_SIZE = 3;
3221 if (str.
size() < MIN_NAME_SIZE)
3224 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf") {
3229 bool IsNegative = str.
front() ==
'-';
3232 if (str.
size() < MIN_NAME_SIZE)
3235 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3242 bool IsSignaling = str.
front() ==
's' || str.
front() ==
'S';
3245 if (str.
size() < MIN_NAME_SIZE)
3254 makeNaN(IsSignaling, IsNegative);
3259 if (str.
front() ==
'(') {
3261 if (str.
size() <= 2 || str.
back() !=
')')
3268 unsigned Radix = 10;
3269 if (str[0] ==
'0') {
3270 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3280 makeNaN(IsSignaling, IsNegative, &Payload);
3294 if (convertFromStringSpecials(str))
3299 size_t slen = str.
size();
3300 sign = *p ==
'-' ? 1 : 0;
3303 "This floating point format does not support signed values");
3305 if (*p ==
'-' || *p ==
'+') {
3312 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3315 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3319 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3363 dst +=
sizeof NaNU - 1;
3368 *dst++ = upperCase ?
'X':
'x';
3370 if (hexDigits > 1) {
3372 memset (dst,
'0', hexDigits - 1);
3373 dst += hexDigits - 1;
3375 *dst++ = upperCase ?
'P':
'p';
3380 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3386 return static_cast<unsigned int>(dst - p);
3393char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3396 unsigned int count, valueBits, shift, partsCount, outputDigits;
3397 const char *hexDigitChars;
3403 *dst++ = upperCase ?
'X':
'x';
3408 significand = significandParts();
3409 partsCount = partCount();
3418 outputDigits = (valueBits - significandLSB () + 3) / 4;
3424 if (hexDigits < outputDigits) {
3430 bits = valueBits - hexDigits * 4;
3432 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3434 outputDigits = hexDigits;
3444 while (outputDigits &&
count) {
3448 if (--
count == partsCount)
3451 part = significand[
count] << shift;
3459 if (curDigits > outputDigits)
3460 curDigits = outputDigits;
3461 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3462 outputDigits -= curDigits;
3471 *
q = hexDigitChars[hexDigitValue (*q) + 1];
3472 }
while (*q ==
'0');
3476 memset (dst,
'0', outputDigits);
3477 dst += outputDigits;
3490 *dst++ = upperCase ?
'P':
'p';
3506 Arg.significandParts(),
3507 Arg.significandParts() + Arg.partCount()));
3519APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3523 uint64_t myexponent, mysignificand;
3526 myexponent = exponent+16383;
3527 mysignificand = significandParts()[0];
3528 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
3530 }
else if (category==
fcZero) {
3534 myexponent = 0x7fff;
3535 mysignificand = 0x8000000000000000ULL;
3538 myexponent = 0x7fff;
3539 mysignificand = significandParts()[0];
3543 words[0] = mysignificand;
3544 words[1] = ((
uint64_t)(sign & 1) << 15) |
3545 (myexponent & 0x7fffLL);
3546 return APInt(80, words);
3549APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3574 words[0] = *
u.convertDoubleAPFloatToAPInt().getRawData();
3580 if (
u.isFiniteNonZero() && losesInfo) {
3590 words[1] = *
v.convertDoubleAPFloatToAPInt().getRawData();
3595 return APInt(128, words);
3598template <const fltSemantics &S>
3599APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3603 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3604 constexpr int integer_bit_part = trailing_significand_bits /
integerPartWidth;
3607 constexpr uint64_t significand_mask = integer_bit - 1;
3608 constexpr unsigned int exponent_bits =
3609 trailing_significand_bits ? (S.sizeInBits - 1 - trailing_significand_bits)
3611 static_assert(exponent_bits < 64);
3619 myexponent = exponent + bias;
3620 std::copy_n(significandParts(), mysignificand.size(),
3621 mysignificand.begin());
3622 if (myexponent == 1 &&
3623 !(significandParts()[integer_bit_part] & integer_bit))
3625 }
else if (category ==
fcZero) {
3628 myexponent = ::exponentZero(S) + bias;
3629 mysignificand.fill(0);
3634 myexponent = ::exponentInf(S) + bias;
3635 mysignificand.fill(0);
3640 myexponent = ::exponentNaN(S) + bias;
3641 std::copy_n(significandParts(), mysignificand.size(),
3642 mysignificand.begin());
3644 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3646 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3647 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3649 words[mysignificand.size() - 1] &= significand_mask;
3651 std::fill(words_iter, words.end(),
uint64_t{0});
3652 constexpr size_t last_word = words.size() - 1;
3654 << ((S.sizeInBits - 1) % 64);
3655 words[last_word] |= shifted_sign;
3656 uint64_t shifted_exponent = (myexponent & exponent_mask)
3657 << (trailing_significand_bits % 64);
3658 words[last_word] |= shifted_exponent;
3659 if constexpr (last_word == 0) {
3660 return APInt(S.sizeInBits, words[0]);
3662 return APInt(S.sizeInBits, words);
3665APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3666 assert(partCount() == 2);
3667 return convertIEEEFloatToAPInt<semIEEEquad>();
3670APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3672 return convertIEEEFloatToAPInt<semIEEEdouble>();
3675APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3677 return convertIEEEFloatToAPInt<semIEEEsingle>();
3680APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3681 assert(partCount() == 1);
3682 return convertIEEEFloatToAPInt<semBFloat>();
3685APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3687 return convertIEEEFloatToAPInt<semIEEEhalf>();
3690APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3691 assert(partCount() == 1);
3692 return convertIEEEFloatToAPInt<semFloat8E5M2>();
3695APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3696 assert(partCount() == 1);
3697 return convertIEEEFloatToAPInt<semFloat8E5M2FNUZ>();
3700APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3701 assert(partCount() == 1);
3702 return convertIEEEFloatToAPInt<semFloat8E4M3>();
3705APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3706 assert(partCount() == 1);
3707 return convertIEEEFloatToAPInt<semFloat8E4M3FN>();
3710APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3711 assert(partCount() == 1);
3712 return convertIEEEFloatToAPInt<semFloat8E4M3FNUZ>();
3715APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3716 assert(partCount() == 1);
3717 return convertIEEEFloatToAPInt<semFloat8E4M3B11FNUZ>();
3720APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3721 assert(partCount() == 1);
3722 return convertIEEEFloatToAPInt<semFloat8E3M4>();
3725APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3726 assert(partCount() == 1);
3727 return convertIEEEFloatToAPInt<semFloatTF32>();
3730APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3731 assert(partCount() == 1);
3732 return convertIEEEFloatToAPInt<semFloat8E8M0FNU>();
3735APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3736 assert(partCount() == 1);
3737 return convertIEEEFloatToAPInt<semFloat6E3M2FN>();
3740APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3741 assert(partCount() == 1);
3742 return convertIEEEFloatToAPInt<semFloat6E2M3FN>();
3745APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3746 assert(partCount() == 1);
3747 return convertIEEEFloatToAPInt<semFloat4E2M1FN>();
3756 return convertHalfAPFloatToAPInt();
3759 return convertBFloatAPFloatToAPInt();
3762 return convertFloatAPFloatToAPInt();
3765 return convertDoubleAPFloatToAPInt();
3768 return convertQuadrupleAPFloatToAPInt();
3771 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3774 return convertFloat8E5M2APFloatToAPInt();
3777 return convertFloat8E5M2FNUZAPFloatToAPInt();
3780 return convertFloat8E4M3APFloatToAPInt();
3783 return convertFloat8E4M3FNAPFloatToAPInt();
3786 return convertFloat8E4M3FNUZAPFloatToAPInt();
3789 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3792 return convertFloat8E3M4APFloatToAPInt();
3795 return convertFloatTF32APFloatToAPInt();
3798 return convertFloat8E8M0FNUAPFloatToAPInt();
3801 return convertFloat6E3M2FNAPFloatToAPInt();
3804 return convertFloat6E2M3FNAPFloatToAPInt();
3807 return convertFloat4E2M1FNAPFloatToAPInt();
3811 return convertF80LongDoubleAPFloatToAPInt();
3816 "Float semantics are not IEEEsingle");
3823 "Float semantics are not IEEEdouble");
3828#ifdef HAS_IEE754_FLOAT128
3829float128 IEEEFloat::convertToQuad()
const {
3831 "Float semantics are not IEEEquads");
3833 return api.bitsToQuad();
3844void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3847 uint64_t myexponent = (i2 & 0x7fff);
3849 uint8_t myintegerbit = mysignificand >> 63;
3854 sign =
static_cast<unsigned int>(i2>>15);
3855 if (myexponent == 0 && mysignificand == 0) {
3857 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3859 }
else if ((myexponent == 0x7fff && mysignificand != 0x8000000000000000ULL) ||
3860 (myexponent != 0x7fff && myexponent != 0 && myintegerbit == 0)) {
3862 exponent = exponentNaN();
3863 significandParts()[0] = mysignificand;
3864 significandParts()[1] = 0;
3867 exponent = myexponent - 16383;
3868 significandParts()[0] = mysignificand;
3869 significandParts()[1] = 0;
3875void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3882 initFromDoubleAPInt(
APInt(64, i1));
3903void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3904 const uint64_t exponent_mask = 0xff;
3906 uint64_t myexponent = (val & exponent_mask);
3909 assert(partCount() == 1);
3918 significandParts()[0] = mysignificand;
3922 if (val == exponent_mask) {
3924 exponent = exponentNaN();
3929 exponent = myexponent - 127;
3931template <const fltSemantics &S>
3932void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3936 constexpr uint64_t significand_mask = integer_bit - 1;
3937 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3938 constexpr unsigned int stored_significand_parts =
3940 constexpr unsigned int exponent_bits =
3941 S.sizeInBits - 1 - trailing_significand_bits;
3942 static_assert(exponent_bits < 64);
3944 constexpr int bias = -(S.minExponent - 1);
3948 std::array<integerPart, stored_significand_parts> mysignificand;
3949 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3950 if constexpr (significand_mask != 0) {
3951 mysignificand[mysignificand.size() - 1] &= significand_mask;
3958 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3961 assert(partCount() == mysignificand.size());
3963 sign =
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64));
3965 bool all_zero_significand =
3968 bool is_zero = myexponent == 0 && all_zero_significand;
3971 if (myexponent - bias == ::exponentInf(S) && all_zero_significand) {
3980 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3982 bool all_ones_significand =
3983 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3984 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3985 (!significand_mask ||
3986 mysignificand[mysignificand.size() - 1] == significand_mask);
3987 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3995 std::copy_n(mysignificand.begin(), mysignificand.size(),
3996 significandParts());
4006 exponent = myexponent - bias;
4007 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
4008 if (myexponent == 0)
4009 exponent = S.minExponent;
4011 significandParts()[mysignificand.size()-1] |= integer_bit;
4014void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
4015 initFromIEEEAPInt<semIEEEquad>(api);
4018void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
4019 initFromIEEEAPInt<semIEEEdouble>(api);
4022void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
4023 initFromIEEEAPInt<semIEEEsingle>(api);
4026void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
4027 initFromIEEEAPInt<semBFloat>(api);
4030void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
4031 initFromIEEEAPInt<semIEEEhalf>(api);
4034void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
4035 initFromIEEEAPInt<semFloat8E5M2>(api);
4038void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
4039 initFromIEEEAPInt<semFloat8E5M2FNUZ>(api);
4042void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
4043 initFromIEEEAPInt<semFloat8E4M3>(api);
4046void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
4047 initFromIEEEAPInt<semFloat8E4M3FN>(api);
4050void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
4051 initFromIEEEAPInt<semFloat8E4M3FNUZ>(api);
4054void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
4055 initFromIEEEAPInt<semFloat8E4M3B11FNUZ>(api);
4058void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
4059 initFromIEEEAPInt<semFloat8E3M4>(api);
4062void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
4063 initFromIEEEAPInt<semFloatTF32>(api);
4066void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
4067 initFromIEEEAPInt<semFloat6E3M2FN>(api);
4070void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
4071 initFromIEEEAPInt<semFloat6E2M3FN>(api);
4074void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
4075 initFromIEEEAPInt<semFloat4E2M1FN>(api);
4082 return initFromHalfAPInt(api);
4084 return initFromBFloatAPInt(api);
4086 return initFromFloatAPInt(api);
4088 return initFromDoubleAPInt(api);
4090 return initFromF80LongDoubleAPInt(api);
4092 return initFromQuadrupleAPInt(api);
4094 return initFromPPCDoubleDoubleLegacyAPInt(api);
4096 return initFromFloat8E5M2APInt(api);
4098 return initFromFloat8E5M2FNUZAPInt(api);
4100 return initFromFloat8E4M3APInt(api);
4102 return initFromFloat8E4M3FNAPInt(api);
4104 return initFromFloat8E4M3FNUZAPInt(api);
4106 return initFromFloat8E4M3B11FNUZAPInt(api);
4108 return initFromFloat8E3M4APInt(api);
4110 return initFromFloatTF32APInt(api);
4112 return initFromFloat8E8M0FNUAPInt(api);
4114 return initFromFloat6E3M2FNAPInt(api);
4116 return initFromFloat6E2M3FNAPInt(api);
4118 return initFromFloat4E2M1FNAPInt(api);
4125void IEEEFloat::makeLargest(
bool Negative) {
4126 if (Negative && !semantics->hasSignedRepr)
4128 "This floating point format does not support signed values");
4135 exponent = semantics->maxExponent;
4139 unsigned PartCount = partCount();
4140 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4144 const unsigned NumUnusedHighBits =
4145 PartCount*integerPartWidth - semantics->precision;
4146 significand[PartCount - 1] = (NumUnusedHighBits < integerPartWidth)
4151 (semantics->precision > 1))
4157void IEEEFloat::makeSmallest(
bool Negative) {
4158 if (Negative && !semantics->hasSignedRepr)
4160 "This floating point format does not support signed values");
4167 exponent = semantics->minExponent;
4171void IEEEFloat::makeSmallestNormalized(
bool Negative) {
4172 if (Negative && !semantics->hasSignedRepr)
4174 "This floating point format does not support signed values");
4183 exponent = semantics->minExponent;
4188 initFromAPInt(&Sem, API);
4191IEEEFloat::IEEEFloat(
float f) {
4195IEEEFloat::IEEEFloat(
double d) {
4201 Buffer.
append(Str.begin(), Str.end());
4206 void AdjustToPrecision(
APInt &significand,
4207 int &exp,
unsigned FormatPrecision) {
4211 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4213 if (bits <= bitsRequired)
return;
4215 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4216 if (!tensRemovable)
return;
4218 exp += tensRemovable;
4223 if (tensRemovable & 1)
4225 tensRemovable >>= 1;
4226 if (!tensRemovable)
break;
4230 significand = significand.
udiv(divisor);
4238 int &exp,
unsigned FormatPrecision) {
4239 unsigned N = buffer.
size();
4240 if (
N <= FormatPrecision)
return;
4243 unsigned FirstSignificant =
N - FormatPrecision;
4250 if (buffer[FirstSignificant - 1] <
'5') {
4251 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4254 exp += FirstSignificant;
4255 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4261 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4262 if (buffer[
I] ==
'9') {
4271 if (FirstSignificant ==
N) {
4272 exp += FirstSignificant;
4278 exp += FirstSignificant;
4279 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4283 APInt significand,
unsigned FormatPrecision,
4284 unsigned FormatMaxPadding,
bool TruncateZero) {
4285 const int semanticsPrecision = significand.
getBitWidth();
4292 if (!FormatPrecision) {
4300 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4305 exp += trailingZeros;
4311 }
else if (exp > 0) {
4313 significand = significand.
zext(semanticsPrecision + exp);
4314 significand <<= exp;
4328 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4332 significand = significand.
zext(precision);
4333 APInt five_to_the_i(precision, 5);
4336 significand *= five_to_the_i;
4341 five_to_the_i *= five_to_the_i;
4345 AdjustToPrecision(significand, exp, FormatPrecision);
4350 unsigned precision = significand.getBitWidth();
4351 if (precision < 4) {
4354 significand = significand.zext(precision);
4356 APInt ten(precision, 10);
4357 APInt digit(precision, 0);
4359 bool inTrail =
true;
4360 while (significand != 0) {
4365 unsigned d = digit.getZExtValue();
4376 assert(!buffer.
empty() &&
"no characters in buffer!");
4380 AdjustToPrecision(buffer, exp, FormatPrecision);
4382 unsigned NDigits = buffer.
size();
4385 bool FormatScientific;
4386 if (!FormatMaxPadding)
4387 FormatScientific =
true;
4393 FormatScientific = ((
unsigned) exp > FormatMaxPadding ||
4394 NDigits + (
unsigned) exp > FormatPrecision);
4397 int MSD = exp + (int) (NDigits - 1);
4400 FormatScientific =
false;
4404 FormatScientific = ((
unsigned) -MSD) > FormatMaxPadding;
4410 if (FormatScientific) {
4411 exp += (NDigits - 1);
4413 Str.push_back(buffer[NDigits-1]);
4415 if (NDigits == 1 && TruncateZero)
4418 for (
unsigned I = 1;
I != NDigits; ++
I)
4419 Str.push_back(buffer[NDigits-1-
I]);
4421 if (!TruncateZero && FormatPrecision > NDigits - 1)
4422 Str.append(FormatPrecision - NDigits + 1,
'0');
4424 Str.push_back(TruncateZero ?
'E' :
'e');
4426 Str.push_back(exp >= 0 ?
'+' :
'-');
4431 expbuf.
push_back((
char) (
'0' + (exp % 10)));
4435 if (!TruncateZero && expbuf.
size() < 2)
4437 for (
unsigned I = 0, E = expbuf.
size();
I != E; ++
I)
4438 Str.push_back(expbuf[E-1-
I]);
4444 for (
unsigned I = 0;
I != NDigits; ++
I)
4445 Str.push_back(buffer[NDigits-1-
I]);
4454 int NWholeDigits = exp + (int) NDigits;
4457 if (NWholeDigits > 0) {
4459 Str.push_back(buffer[NDigits-
I-1]);
4462 unsigned NZeros = 1 + (
unsigned) -NWholeDigits;
4466 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4470 for (;
I != NDigits; ++
I)
4471 Str.push_back(buffer[NDigits-
I-1]);
4477 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4481 return append(Str,
"-Inf");
4483 return append(Str,
"+Inf");
4485 case fcNaN:
return append(Str,
"NaN");
4491 if (!FormatMaxPadding) {
4493 append(Str,
"0.0E+0");
4496 if (FormatPrecision > 1)
4497 Str.append(FormatPrecision - 1,
'0');
4498 append(Str,
"e+00");
4509 int exp = exponent - ((int) semantics->precision - 1);
4511 semantics->precision,
4514 toStringImpl(Str, isNegative(), exp, significand, FormatPrecision,
4515 FormatMaxPadding, TruncateZero);
4519bool IEEEFloat::getExactInverse(
APFloat *inv)
const {
4521 if (!isFiniteNonZero())
4526 if (significandLSB() != semantics->precision - 1)
4531 if (reciprocal.
divide(*
this, rmNearestTiesToEven) != opOK)
4540 reciprocal.significandLSB() == reciprocal.semantics->
precision - 1);
4543 *inv =
APFloat(reciprocal, *semantics);
4548int IEEEFloat::getExactLog2Abs()
const {
4556 for (
int i = 0; i < PartCount; ++i) {
4562 if (exponent != semantics->minExponent)
4565 int CountrParts = 0;
4566 for (
int i = 0; i < PartCount;
4568 if (Parts[i] != 0) {
4569 return exponent - semantics->precision + CountrParts +
4577bool IEEEFloat::isSignaling()
const {
4614 if (isSignaling()) {
4615 result = opInvalidOp;
4617 makeNaN(
false, isNegative(),
nullptr);
4622 makeSmallest(
false);
4626 if (isSmallest() && isNegative()) {
4632 if (!semantics->hasZero)
4633 makeSmallestNormalized(
false);
4637 if (isLargest() && !isNegative()) {
4642 }
else if (semantics->nonFiniteBehavior ==
4649 category = fcInfinity;
4650 exponent = semantics->maxExponent + 1;
4664 bool WillCrossBinadeBoundary =
4665 exponent != semantics->minExponent && isSignificandAllZeros();
4683 if (WillCrossBinadeBoundary) {
4702 (!isDenormal() && isSignificandAllOnes());
4704 if (WillCrossBinadeBoundary) {
4708 assert(exponent != semantics->maxExponent &&
4709 "We can not increment an exponent beyond the maxExponent allowed"
4710 " by the given floating point semantics.");
4713 incrementSignificand();
4727 return ::exponentNaN(*semantics);
4731 return ::exponentInf(*semantics);
4735 return ::exponentZero(*semantics);
4738void IEEEFloat::makeInf(
bool Negative) {
4744 makeNaN(
false, Negative);
4747 category = fcInfinity;
4753void IEEEFloat::makeZero(
bool Negative) {
4754 if (!semantics->hasZero)
4767void IEEEFloat::makeQuiet() {
4781 return Arg.exponent;
4786 Normalized.exponent += SignificandBits;
4788 return Normalized.exponent - SignificandBits;
4792 auto MaxExp =
X.getSemantics().maxExponent;
4793 auto MinExp =
X.getSemantics().minExponent;
4801 int SignificandBits =
X.getSemantics().precision - 1;
4802 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4805 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4828 return scalbn(Val, -Exp, RM);
4861 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4868 : Semantics(
RHS.Semantics),
4882 if (Semantics ==
RHS.Semantics &&
RHS.Floats) {
4883 Floats[0] =
RHS.Floats[0];
4884 Floats[1] =
RHS.Floats[1];
4885 }
else if (
this != &
RHS) {
4903 Floats[0] = std::move(z);
4904 Floats[1].makeZero(
false);
4908 auto AComparedToC = a.compareAbsoluteValue(c);
4921 Floats[0] = std::move(z);
4922 Floats[1].makeZero(
false);
4931 Status |= Floats[1].subtract(z, RM);
4932 Status |= Floats[1].add(c, RM);
4933 Status |= Floats[1].add(zz, RM);
4937 Status |= Floats[1].subtract(z, RM);
4938 Status |= Floats[1].add(a, RM);
4939 Status |= Floats[1].add(zz, RM);
4957 Floats[0] = std::move(z);
4958 Floats[1].makeZero(
false);
4962 Status |= Floats[0].add(zz, RM);
4964 Floats[1].makeZero(
false);
4967 Floats[1] = std::move(z);
4968 Status |= Floats[1].subtract(Floats[0], RM);
4969 Status |= Floats[1].add(zz, RM);
4975 const DoubleAPFloat &RHS,
4995 LHS.isNegative() !=
RHS.isNegative()) {
4996 Out.makeNaN(
false, Out.isNegative(),
nullptr);
5017 return Out.addImpl(
A, AA,
C,
CC, RM);
5022 return addWithSpecial(*
this,
RHS, *
this, RM);
5035 const auto &
LHS = *
this;
5062 Out.makeNaN(
false,
false,
nullptr);
5074 "Special cases not handled exhaustively");
5081 if (!
T.isFiniteNonZero()) {
5083 Floats[1].makeZero(
false);
5105 Status |= U.add(Tau, RM);
5108 if (!U.isFinite()) {
5109 Floats[1].makeZero(
false);
5168 Floats[0].changeSign();
5169 Floats[1].changeSign();
5174 auto Result = Floats[0].compareAbsoluteValue(
RHS.Floats[0]);
5177 Result = Floats[1].compareAbsoluteValue(
RHS.Floats[1]);
5179 auto Against = Floats[0].isNegative() ^ Floats[1].isNegative();
5180 auto RHSAgainst =
RHS.Floats[0].isNegative() ^
RHS.Floats[1].isNegative();
5181 if (Against && !RHSAgainst)
5183 if (!Against && RHSAgainst)
5185 if (!Against && !RHSAgainst)
5187 if (Against && RHSAgainst)
5194 return Floats[0].getCategory();
5200 Floats[0].makeInf(Neg);
5201 Floats[1].makeZero(
false);
5205 Floats[0].makeZero(Neg);
5206 Floats[1].makeZero(
false);
5219 Floats[0].makeSmallest(Neg);
5220 Floats[1].makeZero(
false);
5227 Floats[0].changeSign();
5228 Floats[1].makeZero(
false);
5232 Floats[0].makeNaN(SNaN, Neg, fill);
5233 Floats[1].makeZero(
false);
5237 auto Result = Floats[0].compare(
RHS.Floats[0]);
5240 return Floats[1].compare(
RHS.Floats[1]);
5245 return Floats[0].bitwiseIsEqual(
RHS.Floats[0]) &&
5246 Floats[1].bitwiseIsEqual(
RHS.Floats[1]);
5258 Floats[0].bitcastToAPInt().getRawData()[0],
5259 Floats[1].bitcastToAPInt().getRawData()[0],
5276 auto Ret = Tmp.
next(nextDown);
5283 unsigned int Width,
bool IsSigned,
5302 unsigned int InputSize,
5313 unsigned int InputSize,
5323 unsigned int HexDigits,
5333 (Floats[0].isDenormal() || Floats[1].isDenormal() ||
5335 Floats[0] != Floats[0] + Floats[1]);
5365 return Floats[0].isInteger() && Floats[1].isInteger();
5369 unsigned FormatPrecision,
5370 unsigned FormatMaxPadding,
5371 bool TruncateZero)
const {
5374 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5402 scalbn(Arg.Floats[1], Exp, RM));
5409 APFloat Second = Arg.Floats[1];
5411 Second =
scalbn(Second, -Exp, RM);
5417APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5418 if (usesLayout<IEEEFloat>(Semantics)) {
5419 new (&
IEEE) IEEEFloat(std::move(
F));
5422 if (usesLayout<DoubleAPFloat>(Semantics)) {
5425 DoubleAPFloat(Semantics,
APFloat(std::move(
F), S),
5438 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5440 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5448 assert(StatusOrErr &&
"Invalid floating point representation");
5472 usesLayout<IEEEFloat>(ToSemantics))
5473 return U.IEEE.convert(ToSemantics, RM, losesInfo);
5475 usesLayout<DoubleAPFloat>(ToSemantics)) {
5478 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
5482 usesLayout<IEEEFloat>(ToSemantics)) {
5483 auto Ret = getIEEE().
convert(ToSemantics, RM, losesInfo);
5484 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
5500#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5517 bool *isExact)
const {
5521 rounding_mode, isExact);
5523 result =
APInt(bitWidth, parts);
5531 "Float semantics is not representable by IEEEdouble");
5540#ifdef HAS_IEE754_FLOAT128
5541float128 APFloat::convertToQuad()
const {
5543 return getIEEE().convertToQuad();
5545 "Float semantics is not representable by IEEEquad");
5551 return Temp.getIEEE().convertToQuad();
5559 "Float semantics is not representable by IEEEsingle");
5570#undef APFLOAT_DISPATCH_ON_SEMANTICS
#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...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#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.
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
Given that RA is a live value
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isSigned(unsigned int 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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 getExactInverse(APFloat *inv) const
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
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 APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
const fltSemantics & getSemantics() const
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
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)
FPClassTest classify() const
Return the FPClassTest which will return true for the value.
opStatus mod(const APFloat &RHS)
Expected< opStatus > convertFromString(StringRef, roundingMode)
void print(raw_ostream &) const
opStatus roundToIntegral(roundingMode RM)
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
Class for arbitrary precision integers.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static 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 void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
APInt zext(unsigned width) const
Zero extend to a new width.
static WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static 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.
APInt trunc(unsigned width) const
Truncate to new width.
static int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static 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 void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
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 unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
static void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static 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 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 WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static 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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - 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.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
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.
StringRef - 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.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - 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
back - 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
size - Get the string size.
char front() const
front - Get the first character in the string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void makeSmallestNormalized(bool Neg)
DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
LLVM_READONLY int getExactLog2() const
opStatus remainder(const DoubleAPFloat &RHS)
opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
fltCategory getCategory() const
bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
LLVM_READONLY int getExactLog2Abs() const
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
APInt bitcastToAPInt() const
bool getExactInverse(APFloat *inv) const
Expected< opStatus > convertFromString(StringRef, roundingMode)
opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
void makeSmallest(bool Neg)
opStatus next(bool nextDown)
opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
bool isSmallestNormalized() const
opStatus mod(const DoubleAPFloat &RHS)
DoubleAPFloat(const fltSemantics &S)
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
void makeLargest(bool Neg)
cmpResult compare(const DoubleAPFloat &RHS) const
opStatus roundToIntegral(roundingMode RM)
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
void makeNaN(bool SNaN, bool Neg, const APInt *fill)
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...
cmpResult compareAbsoluteValue(const IEEEFloat &) const
opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
fltCategory getCategory() const
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
bool isFiniteNonZero() const
bool needsCleanup() const
Returns whether this instance allocated memory.
APInt bitcastToAPInt() const
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.
opStatus divide(const IEEEFloat &, roundingMode)
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
opStatus remainder(const IEEEFloat &)
IEEE remainder.
double convertToDouble() const
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
float convertToFloat() const
opStatus subtract(const IEEEFloat &, roundingMode)
void makeInf(bool Neg=false)
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
opStatus add(const IEEEFloat &, roundingMode)
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
Expected< opStatus > convertFromString(StringRef, roundingMode)
void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
friend int ilogb(const IEEEFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
opStatus multiply(const IEEEFloat &, roundingMode)
opStatus roundToIntegral(roundingMode)
IEEEFloat & operator=(const IEEEFloat &)
friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Returns: X * 2^Exp for integral exponents.
bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
bool isInteger() const
Returns true if and only if the number is an exact integer.
IEEEFloat(const fltSemantics &)
opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
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.
bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
void makeZero(bool Neg=false)
opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
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
APFloatBase::roundingMode roundingMode
static constexpr fltCategory fcNaN
static constexpr opStatus opDivByZero
static constexpr opStatus opOverflow
static constexpr cmpResult cmpLessThan
static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts, unsigned bits)
APFloatBase::opStatus opStatus
static constexpr roundingMode rmTowardPositive
static constexpr uninitializedTag uninitialized
static constexpr fltCategory fcZero
static constexpr opStatus opOK
static constexpr cmpResult cmpGreaterThan
static constexpr unsigned integerPartWidth
APFloatBase::ExponentType ExponentType
hash_code hash_value(const IEEEFloat &Arg)
static constexpr fltCategory fcNormal
static constexpr opStatus opInvalidOp
IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
APFloatBase::integerPart integerPart
static constexpr cmpResult cmpUnordered
static constexpr roundingMode rmTowardNegative
static constexpr fltCategory fcInfinity
static constexpr roundingMode rmNearestTiesToAway
static constexpr roundingMode rmTowardZero
static constexpr opStatus opUnderflow
static constexpr roundingMode rmNearestTiesToEven
int ilogb(const IEEEFloat &Arg)
static constexpr cmpResult cmpEqual
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)
static constexpr fltSemantics semBogus
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.
hash_code hash_value(const FixedPointSemantics &Val)
int popcount(T Value) noexcept
Count the number of set bits in a value.
static constexpr unsigned int partCountForBits(unsigned int bits)
static constexpr fltSemantics semFloat8E8M0FNU
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
static unsigned int powerOf5(APFloatBase::integerPart *dst, unsigned int power)
static constexpr fltSemantics semFloat6E2M3FN
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
static Expected< int > totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
static constexpr fltSemantics semIEEEquad
const unsigned int maxPowerOfFiveExponent
static constexpr fltSemantics semFloat6E3M2FN
static char * writeUnsignedDecimal(char *dst, unsigned int n)
static constexpr fltSemantics semFloat8E4M3FNUZ
const unsigned int maxPrecision
static constexpr fltSemantics semIEEEdouble
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 constexpr fltSemantics semFloat8E4M3FN
static const char infinityU[]
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
static constexpr fltSemantics semPPCDoubleDouble
static Error interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
static constexpr fltSemantics semFloat8E5M2FNUZ
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
static constexpr fltSemantics semIEEEsingle
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
static constexpr fltSemantics semFloat4E2M1FN
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 constexpr fltSemantics semIEEEhalf
static constexpr fltSemantics semPPCDoubleDoubleLegacy
static lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
static constexpr fltSemantics semFloat8E5M2
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
static const char hexDigitsUpper[]
const unsigned int maxExponent
static unsigned int decDigitValue(unsigned int c)
static constexpr fltSemantics semFloat8E4M3B11FNUZ
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.
OutputIt copy(R &&Range, OutputIt Out)
static constexpr fltSemantics semX87DoubleExtended
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
static constexpr fltSemantics semFloatTF32
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
static lostFraction lostFractionThroughTruncation(const APFloatBase::integerPart *parts, unsigned int partCount, unsigned int bits)
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 constexpr fltSemantics semBFloat
static Expected< lostFraction > trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue)
void consumeError(Error Err)
Consume a Error without doing anything.
static constexpr fltSemantics semFloat8E3M4
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.
static constexpr fltSemantics semFloat8E4M3
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[]
Implement std::hash so that hash_code can be used in STL containers.
static const llvm::fltSemantics & EnumToSemantics(Semantics S)
static const fltSemantics & IEEEsingle() LLVM_READNONE
static bool semanticsHasInf(const fltSemantics &)
static const fltSemantics & Float6E3M2FN() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToAway
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
static const fltSemantics & PPCDoubleDoubleLegacy() LLVM_READNONE
static constexpr roundingMode rmTowardNegative
static ExponentType semanticsMinExponent(const fltSemantics &)
static constexpr roundingMode rmNearestTiesToEven
static unsigned int semanticsSizeInBits(const fltSemantics &)
static bool semanticsHasSignedRepr(const fltSemantics &)
static const fltSemantics & Float8E4M3() LLVM_READNONE
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static const fltSemantics & Float8E4M3FN() LLVM_READNONE
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static constexpr roundingMode rmTowardZero
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & Float4E2M1FN() LLVM_READNONE
static const fltSemantics & Float8E8M0FNU() LLVM_READNONE
static const fltSemantics & Float8E4M3B11FNUZ() LLVM_READNONE
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
static ExponentType semanticsMaxExponent(const fltSemantics &)
static unsigned int semanticsPrecision(const fltSemantics &)
static const fltSemantics & IEEEdouble() LLVM_READNONE
static bool semanticsHasNaN(const fltSemantics &)
static const fltSemantics & Float8E5M2() LLVM_READNONE
static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
static constexpr unsigned integerPartWidth
static const fltSemantics & IEEEhalf() LLVM_READNONE
APInt::WordType integerPart
static constexpr roundingMode rmTowardPositive
static bool semanticsHasZero(const fltSemantics &)
static bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static const fltSemantics & Float8E4M3FNUZ() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
static const fltSemantics & FloatTF32() LLVM_READNONE
static const fltSemantics & Float8E5M2FNUZ() LLVM_READNONE
static const fltSemantics & Float6E2M3FN() LLVM_READNONE
fltCategory
Category of internally-represented number.
@ S_PPCDoubleDoubleLegacy
static const fltSemantics & Float8E3M4() LLVM_READNONE
opStatus
IEEE-754R 7: Default exception handling.
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
static unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
const char * lastSigDigit
const char * firstSigDigit
bool isRepresentableBy(const fltSemantics &S) const
APFloatBase::ExponentType maxExponent
fltNonfiniteBehavior nonFiniteBehavior
APFloatBase::ExponentType minExponent
fltNanEncoding nanEncoding