37 #define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
41 static_assert(
integerPartWidth % 4 == 0,
"Part width must be divisible by 4!");
157 static inline unsigned int
164 static inline unsigned int
179 unsigned int absExponent;
180 const unsigned int overlargeExponent = 24000;
183 assert(p != end &&
"Exponent has no digits");
185 isNegative = (*p ==
'-');
186 if (*p ==
'-' || *p ==
'+') {
188 assert(p != end &&
"Exponent has no digits");
192 assert(absExponent < 10U &&
"Invalid character in exponent");
194 for (; p !=
end; ++p) {
198 assert(value < 10U &&
"Invalid character in exponent");
200 value += absExponent * 10;
201 if (absExponent >= overlargeExponent) {
202 absExponent = overlargeExponent;
209 assert(p == end &&
"Invalid exponent in exponent");
212 return -(int) absExponent;
214 return (
int) absExponent;
221 int exponentAdjustment)
223 int unsignedExponent;
224 bool negative, overflow;
227 assert(p != end &&
"Exponent has no digits");
229 negative = *p ==
'-';
230 if (*p ==
'-' || *p ==
'+') {
232 assert(p != end &&
"Exponent has no digits");
235 unsignedExponent = 0;
237 for (; p !=
end; ++p) {
241 assert(value < 10U &&
"Invalid character in exponent");
243 unsignedExponent = unsignedExponent * 10 + value;
244 if (unsignedExponent > 32767) {
250 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
254 exponent = unsignedExponent;
256 exponent = -exponent;
257 exponent += exponentAdjustment;
258 if (exponent > 32767 || exponent < -32768)
263 exponent = negative ? -32768: 32767;
274 while (p != end && *p ==
'0')
277 if (p != end && *p ==
'.') {
280 assert(end - begin != 1 &&
"Significand has no digits");
282 while (p != end && *p ==
'0')
320 for (; p !=
end; ++p) {
322 assert(dot == end &&
"String contains multiple dots");
332 assert((*p ==
'e' || *p ==
'E') &&
"Invalid character in significand");
333 assert(p != begin &&
"Significand has no digits");
334 assert((dot == end || p - begin != 1) &&
"Significand has no digits");
351 while (p != begin && *p ==
'0');
352 while (p != begin && *p ==
'.');
370 unsigned int digitValue)
372 unsigned int hexDigit;
378 else if (digitValue < 8 && digitValue > 0)
382 while (p != end && (*p ==
'0' || *p ==
'.'))
385 assert(p != end &&
"Invalid trailing hexadecimal fraction!");
401 unsigned int partCount,
430 return lost_fraction;
445 return moreSignificant;
456 HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
458 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
460 if (HUerr1 + HUerr2 == 0)
461 return inexactMultiply * 2;
463 return inexactMultiply + 2 * (HUerr1 + HUerr2);
472 unsigned int count, partBits;
489 if (part - boundary <= boundary - part)
490 return part - boundary;
492 return boundary - part;
495 if (part == boundary) {
501 }
else if (part == boundary - 1) {
517 static const integerPart firstEightPowers[] = { 1, 5, 25, 125, 625, 3125,
520 pow5s[0] = 78125 * 5;
522 unsigned int partsCount[16] = { 1 };
530 *p1 = firstEightPowers[power & 7];
536 for (
unsigned int n = 0; power; power >>= 1, n++) {
543 pc = partsCount[n - 1];
546 if (pow5[pc - 1] == 0)
556 if (p2[result - 1] == 0)
581 static const char NaNL[] =
"nan";
582 static const char NaNU[] =
"NAN";
589 const char *hexDigitChars)
591 unsigned int result =
count;
597 dst[
count] = hexDigitChars[part & 0xf];
637 void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
640 semantics = ourSemantics;
646 void IEEEFloat::freeSignificand() {
648 delete [] significand.parts;
651 void IEEEFloat::assign(
const IEEEFloat &rhs) {
652 assert(semantics == rhs.semantics);
655 category = rhs.category;
656 exponent = rhs.exponent;
658 copySignificand(rhs);
661 void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
663 assert(rhs.partCount() >= partCount());
677 unsigned numParts = partCount();
687 unsigned bitsToPreserve = semantics->
precision - 1;
688 unsigned part = bitsToPreserve / 64;
689 bitsToPreserve %= 64;
690 significand[part] &= ((1ULL << bitsToPreserve) - 1);
691 for (part++; part != numParts; ++part)
692 significand[part] = 0;
695 unsigned QNaNBit = semantics->
precision - 2;
720 if (semantics != rhs.semantics) {
722 initialize(rhs.semantics);
733 semantics = rhs.semantics;
734 significand = rhs.significand;
735 exponent = rhs.exponent;
736 category = rhs.category;
754 significandMSB() == 0;
757 bool IEEEFloat::isSignificandAllOnes()
const {
761 const unsigned PartCount = partCount();
762 for (
unsigned i = 0;
i < PartCount - 1;
i++)
767 const unsigned NumHighBits =
770 "fill than integerPartWidth");
773 if (~(Parts[PartCount - 1] | HighBitFill))
779 bool IEEEFloat::isSignificandAllZeros()
const {
783 const unsigned PartCount = partCount();
785 for (
unsigned i = 0; i < PartCount - 1; i++)
789 const unsigned NumHighBits =
792 "clear than integerPartWidth");
795 if (Parts[PartCount - 1] & HighBitMask)
805 && isSignificandAllOnes();
819 if (semantics != rhs.semantics ||
820 category != rhs.category ||
829 return std::equal(significandParts(), significandParts() + partCount(),
830 rhs.significandParts());
834 initialize(&ourSemantics);
839 significandParts()[0] = value;
844 initialize(&ourSemantics);
855 initialize(rhs.semantics);
860 *
this = std::move(rhs);
870 unsigned int IEEEFloat::partCount()
const {
874 const integerPart *IEEEFloat::significandParts()
const {
875 return const_cast<IEEEFloat *
>(
this)->significandParts();
880 return significand.parts;
882 return &significand.part;
885 void IEEEFloat::zeroSignificand() {
890 void IEEEFloat::incrementSignificand() {
901 integerPart IEEEFloat::addSignificand(
const IEEEFloat &rhs) {
904 parts = significandParts();
906 assert(semantics == rhs.semantics);
907 assert(exponent == rhs.exponent);
909 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
914 integerPart IEEEFloat::subtractSignificand(
const IEEEFloat &rhs,
918 parts = significandParts();
920 assert(semantics == rhs.semantics);
921 assert(exponent == rhs.exponent);
930 lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs,
931 const IEEEFloat *addend) {
933 unsigned int partsCount, newPartsCount, precision;
940 assert(semantics == rhs.semantics);
948 if (newPartsCount > 4)
951 fullSignificand = scratch;
953 lhsSignificand = significandParts();
954 partsCount = partCount();
957 rhs.significandParts(), partsCount, partsCount);
960 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
961 exponent += rhs.exponent;
975 if (addend && addend->isNonZero()) {
979 Significand savedSignificand = significand;
983 unsigned int extendedPrecision;
986 extendedPrecision = 2 * precision + 1;
987 if (omsb != extendedPrecision - 1) {
988 assert(extendedPrecision > omsb);
990 (extendedPrecision - 1) - omsb);
991 exponent -= (extendedPrecision - 1) - omsb;
995 extendedSemantics = *semantics;
996 extendedSemantics.
precision = extendedPrecision;
998 if (newPartsCount == 1)
999 significand.part = fullSignificand[0];
1001 significand.parts = fullSignificand;
1002 semantics = &extendedSemantics;
1005 status = extendedAddend.convert(extendedSemantics,
rmTowardZero, &ignored);
1012 lost_fraction = extendedAddend.shiftSignificandRight(1);
1014 "Lost precision while shifting addend for fused-multiply-add.");
1016 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1019 if (newPartsCount == 1)
1020 fullSignificand[0] = significand.part;
1021 significand = savedSignificand;
1022 semantics = savedSemantics;
1024 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1031 exponent -= precision + 1;
1040 if (omsb > precision) {
1041 unsigned int bits, significantParts;
1044 bits = omsb - precision;
1046 lf =
shiftRight(fullSignificand, significantParts, bits);
1053 if (newPartsCount > 4)
1054 delete [] fullSignificand;
1056 return lost_fraction;
1060 lostFraction IEEEFloat::divideSignificand(
const IEEEFloat &rhs) {
1061 unsigned int bit,
i, partsCount;
1067 assert(semantics == rhs.semantics);
1069 lhsSignificand = significandParts();
1070 rhsSignificand = rhs.significandParts();
1071 partsCount = partCount();
1078 divisor = dividend + partsCount;
1081 for (i = 0; i < partsCount; i++) {
1082 dividend[
i] = lhsSignificand[
i];
1083 divisor[
i] = rhsSignificand[
i];
1084 lhsSignificand[
i] = 0;
1087 exponent -= rhs.exponent;
1089 unsigned int precision = semantics->
precision;
1092 bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1099 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1115 for (bit = precision; bit; bit -= 1) {
1139 return lost_fraction;
1142 unsigned int IEEEFloat::significandMSB()
const {
1146 unsigned int IEEEFloat::significandLSB()
const {
1157 return shiftRight(significandParts(), partCount(), bits);
1161 void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1162 assert(bits < semantics->precision);
1165 unsigned int partsCount = partCount();
1178 assert(semantics == rhs.semantics);
1182 compare = exponent - rhs.exponent;
1192 else if (compare < 0)
1224 bool IEEEFloat::roundAwayFromZero(roundingMode rounding_mode,
1226 unsigned int bit)
const {
1233 switch (rounding_mode) {
1268 omsb = significandMSB() + 1;
1274 exponentChange = omsb - semantics->
precision;
1278 if (exponent + exponentChange > semantics->
maxExponent)
1279 return handleOverflow(rounding_mode);
1283 if (exponent + exponentChange < semantics->minExponent)
1284 exponentChange = semantics->
minExponent - exponent;
1287 if (exponentChange < 0) {
1290 shiftSignificandLeft(-exponentChange);
1295 if (exponentChange > 0) {
1299 lf = shiftSignificandRight(exponentChange);
1304 if (omsb > (
unsigned) exponentChange)
1305 omsb -= exponentChange;
1325 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1329 incrementSignificand();
1330 omsb = significandMSB() + 1;
1333 if (omsb == (
unsigned) semantics->
precision + 1) {
1343 shiftSignificandRight(1);
1355 assert(omsb < semantics->precision);
1385 sign = rhs.sign ^ subtract;
1387 copySignificand(rhs);
1408 if (((sign ^ rhs.sign)!=0) != subtract) {
1421 lostFraction IEEEFloat::addOrSubtractSignificand(
const IEEEFloat &rhs,
1429 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1432 bits = exponent - rhs.exponent;
1442 }
else if (bits > 0) {
1443 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1444 shiftSignificandLeft(1);
1447 lost_fraction = shiftSignificandRight(-bits - 1);
1448 temp_rhs.shiftSignificandLeft(1);
1453 carry = temp_rhs.subtractSignificand
1455 copySignificand(temp_rhs);
1458 carry = subtractSignificand
1477 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1478 carry = addSignificand(temp_rhs);
1480 lost_fraction = shiftSignificandRight(-bits);
1481 carry = addSignificand(rhs);
1489 return lost_fraction;
1509 copySignificand(rhs);
1543 copySignificand(rhs);
1592 copySignificand(rhs);
1626 roundingMode rounding_mode,
1630 fs = addOrSubtractSpecials(rhs, subtract);
1636 lost_fraction = addOrSubtractSignificand(rhs, subtract);
1637 fs = normalize(rounding_mode, lost_fraction);
1646 if (category ==
fcZero) {
1647 if (rhs.category !=
fcZero || (sign == rhs.sign) == subtract)
1657 return addOrSubtract(rhs, rounding_mode,
false);
1663 return addOrSubtract(rhs, rounding_mode,
true);
1672 fs = multiplySpecials(rhs);
1675 lostFraction lost_fraction = multiplySignificand(rhs,
nullptr);
1676 fs = normalize(rounding_mode, lost_fraction);
1690 fs = divideSpecials(rhs);
1694 fs = normalize(rounding_mode, lost_fraction);
1706 unsigned int origSign = sign;
1712 int parts = partCount();
1742 fs = modSpecials(rhs);
1746 unsigned int origSign = sign;
1752 int parts = partCount();
1786 sign ^= multiplicand.sign;
1795 lost_fraction = multiplySignificand(multiplicand, &addend);
1796 fs = normalize(rounding_mode, lost_fraction);
1806 fs = multiplySpecials(multiplicand);
1816 fs = addOrSubtract(addend, rounding_mode,
false);
1851 fs =
add(MagicConstant, rounding_mode);
1855 fs =
subtract(MagicConstant, rounding_mode);
1869 assert(semantics == rhs.semantics);
1901 if (sign == rhs.sign)
1916 if (sign != rhs.sign) {
1947 unsigned int newPartCount, oldPartCount;
1954 oldPartCount = partCount();
1957 bool X86SpecialNan =
false;
1960 (!(*significandParts() & 0x8000000000000000ULL) ||
1961 !(*significandParts() & 0x4000000000000000ULL))) {
1964 X86SpecialNan =
true;
1973 int exponentChange = significandMSB() + 1 - fromSemantics.
precision;
1974 if (exponent + exponentChange < toSemantics.
minExponent)
1975 exponentChange = toSemantics.
minExponent - exponent;
1976 if (exponentChange < shift)
1977 exponentChange = shift;
1978 if (exponentChange < 0) {
1979 shift -= exponentChange;
1980 exponent += exponentChange;
1986 lostFraction =
shiftRight(significandParts(), oldPartCount, -shift);
1989 if (newPartCount > oldPartCount) {
1997 significand.parts = newParts;
1998 }
else if (newPartCount == 1 && oldPartCount != 1) {
2002 newPart = significandParts()[0];
2004 significand.part = newPart;
2008 semantics = &toSemantics;
2016 fs = normalize(rounding_mode, lostFraction);
2017 *losesInfo = (fs !=
opOK);
2018 }
else if (category ==
fcNaN) {
2019 *losesInfo = lostFraction !=
lfExactlyZero || X86SpecialNan;
2050 integerPart *parts,
unsigned int width,
bool isSigned,
2051 roundingMode rounding_mode,
bool *isExact)
const {
2054 unsigned int dstPartsCount, truncatedBits;
2064 if (category ==
fcZero) {
2071 src = significandParts();
2080 truncatedBits = semantics->
precision -1U - exponent;
2084 unsigned int bits = exponent + 1U;
2090 if (bits < semantics->precision) {
2104 if (truncatedBits) {
2108 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2117 unsigned int omsb =
APInt::tcMSB(parts, dstPartsCount) + 1;
2128 if (omsb == width &&
APInt::tcLSB(parts, dstPartsCount) + 1 != omsb)
2138 if (omsb >= width + !isSigned)
2161 roundingMode rounding_mode,
2162 bool *isExact)
const {
2165 fs = convertToSignExtendedInteger(parts, width, isSigned, rounding_mode,
2169 unsigned int bits, dstPartsCount;
2173 if (category ==
fcNaN)
2178 bits = width - isSigned;
2181 if (sign && isSigned)
2193 roundingMode rounding_mode,
2194 bool *isExact)
const {
2198 parts.data(), bitWidth, result.
isSigned(), rounding_mode, isExact);
2200 result =
APInt(bitWidth, parts);
2208 const integerPart *src,
unsigned int srcCount, roundingMode rounding_mode) {
2209 unsigned int omsb, precision, dstCount;
2215 dst = significandParts();
2216 dstCount = partCount();
2221 if (precision <= omsb) {
2222 exponent = omsb - 1;
2227 exponent = precision - 1;
2232 return normalize(rounding_mode, lost_fraction);
2246 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2254 unsigned int srcCount,
bool isSigned,
2267 status = convertFromUnsignedParts(copy, srcCount, rounding_mode);
2271 status = convertFromUnsignedParts(src, srcCount, rounding_mode);
2280 unsigned int width,
bool isSigned,
2291 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2295 IEEEFloat::convertFromHexadecimalString(
StringRef s,
2296 roundingMode rounding_mode) {
2304 unsigned partsCount = partCount();
2306 bool computedTrailingFraction =
false;
2319 assert(dot == end &&
"String contains multiple dots");
2325 if (hex_value == -1U)
2335 }
else if (!computedTrailingFraction) {
2337 computedTrailingFraction =
true;
2342 assert(p != end &&
"Hex strings require an exponent");
2343 assert((*p ==
'p' || *p ==
'P') &&
"Invalid character in significand");
2344 assert(p != begin &&
"Significand has no digits");
2345 assert((dot == end || p - begin != 1) &&
"Significand has no digits");
2348 if (p != firstSignificantDigit) {
2357 expAdjustment =
static_cast<int>(dot - firstSignificantDigit);
2358 if (expAdjustment < 0)
2360 expAdjustment = expAdjustment * 4 - 1;
2371 return normalize(rounding_mode, lost_fraction);
2375 IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2376 unsigned sigPartCount,
int exp,
2377 roundingMode rounding_mode) {
2378 unsigned int parts, pow5PartCount;
2389 pow5PartCount =
powerOf5(pow5Parts, exp >= 0 ? exp: -exp);
2391 for (;; parts *= 2) {
2393 unsigned int excessPrecision, truncatedBits;
2395 calcSemantics.
precision = parts * integerPartWidth - 1;
2397 truncatedBits = excessPrecision;
2400 decSig.makeZero(sign);
2403 sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
2405 powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2408 decSig.exponent += exp;
2412 unsigned int powHUerr;
2416 calcLostFraction = decSig.multiplySignificand(pow5,
nullptr);
2417 powHUerr = powStatus !=
opOK;
2419 calcLostFraction = decSig.divideSignificand(pow5);
2422 excessPrecision += (semantics->
minExponent - decSig.exponent);
2423 truncatedBits = excessPrecision;
2424 if (excessPrecision > calcSemantics.
precision)
2425 excessPrecision = calcSemantics.
precision;
2434 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
2439 excessPrecision, isNearest);
2442 if (HUdistance >= HUerr) {
2443 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
2444 calcSemantics.
precision - excessPrecision,
2449 exponent = (decSig.exponent + semantics->
precision
2450 - (calcSemantics.
precision - excessPrecision));
2454 return normalize(rounding_mode, calcLostFraction);
2460 IEEEFloat::convertFromDecimalString(
StringRef str, roundingMode rounding_mode) {
2499 fs = handleOverflow(rounding_mode);
2517 fs = handleOverflow(rounding_mode);
2520 unsigned int partCount;
2544 if (p == str.
end()) {
2549 assert(decValue < 10U &&
"Invalid character in significand");
2551 val = val * 10 + decValue;
2558 partCount, partCount + 1,
false);
2562 if (decSignificand[partCount])
2567 fs = roundSignificandWithExponent(decSignificand, partCount,
2570 delete [] decSignificand;
2576 bool IEEEFloat::convertFromStringSpecials(
StringRef str) {
2605 if (convertFromStringSpecials(str))
2610 size_t slen = str.
size();
2611 sign = *p ==
'-' ? 1 : 0;
2612 if (*p ==
'-' || *p ==
'+') {
2615 assert(slen &&
"String has no digits");
2618 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
2619 assert(slen - 2 &&
"Invalid string");
2620 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
2624 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
2663 dst +=
sizeof infinityL - 1;
2668 dst +=
sizeof NaNU - 1;
2673 *dst++ = upperCase ?
'X':
'x';
2675 if (hexDigits > 1) {
2677 memset (dst,
'0', hexDigits - 1);
2678 dst += hexDigits - 1;
2680 *dst++ = upperCase ?
'P':
'p';
2685 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
2691 return static_cast<unsigned int>(dst - p);
2698 char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
2700 roundingMode rounding_mode)
const {
2701 unsigned int count, valueBits, shift, partsCount, outputDigits;
2702 const char *hexDigitChars;
2708 *dst++ = upperCase ?
'X':
'x';
2713 significand = significandParts();
2714 partsCount = partCount();
2723 outputDigits = (valueBits - significandLSB () + 3) / 4;
2729 if (hexDigits < outputDigits) {
2735 bits = valueBits - hexDigits * 4;
2737 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
2739 outputDigits = hexDigits;
2747 count = (valueBits + integerPartWidth - 1) / integerPartWidth;
2749 while (outputDigits && count) {
2753 if (--count == partsCount)
2756 part = significand[
count] << shift;
2759 part |= significand[count - 1] >> (integerPartWidth - shift);
2762 unsigned int curDigits = integerPartWidth / 4;
2764 if (curDigits > outputDigits)
2765 curDigits = outputDigits;
2766 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
2767 outputDigits -= curDigits;
2777 }
while (*q ==
'0');
2781 memset (dst,
'0', outputDigits);
2782 dst += outputDigits;
2795 *dst++ = upperCase ?
'P':
'p';
2804 Arg.
isNaN() ? (uint8_t)0 : (uint8_t)Arg.sign,
2808 return hash_combine((uint8_t)Arg.category, (uint8_t)Arg.sign,
2811 Arg.significandParts(),
2812 Arg.significandParts() + Arg.partCount()));
2824 APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
2828 uint64_t myexponent, mysignificand;
2831 myexponent = exponent+16383;
2832 mysignificand = significandParts()[0];
2833 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
2835 }
else if (category==
fcZero) {
2839 myexponent = 0x7fff;
2840 mysignificand = 0x8000000000000000ULL;
2843 myexponent = 0x7fff;
2844 mysignificand = significandParts()[0];
2848 words[0] = mysignificand;
2849 words[1] = ((uint64_t)(sign & 1) << 15) |
2850 (myexponent & 0x7fffLL);
2851 return APInt(80, words);
2854 APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt()
const {
2879 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
2885 if (u.isFiniteNonZero() && losesInfo) {
2895 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
2900 return APInt(128, words);
2903 APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
2907 uint64_t myexponent, mysignificand, mysignificand2;
2910 myexponent = exponent+16383;
2911 mysignificand = significandParts()[0];
2912 mysignificand2 = significandParts()[1];
2913 if (myexponent==1 && !(mysignificand2 & 0x1000000000000LL))
2915 }
else if (category==
fcZero) {
2917 mysignificand = mysignificand2 = 0;
2919 myexponent = 0x7fff;
2920 mysignificand = mysignificand2 = 0;
2923 myexponent = 0x7fff;
2924 mysignificand = significandParts()[0];
2925 mysignificand2 = significandParts()[1];
2929 words[0] = mysignificand;
2930 words[1] = ((uint64_t)(sign & 1) << 63) |
2931 ((myexponent & 0x7fff) << 48) |
2932 (mysignificand2 & 0xffffffffffffLL);
2934 return APInt(128, words);
2937 APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
2941 uint64_t myexponent, mysignificand;
2944 myexponent = exponent+1023;
2945 mysignificand = *significandParts();
2946 if (myexponent==1 && !(mysignificand & 0x10000000000000LL))
2948 }
else if (category==
fcZero) {
2957 mysignificand = *significandParts();
2960 return APInt(64, ((((uint64_t)(sign & 1) << 63) |
2961 ((myexponent & 0x7ff) << 52) |
2962 (mysignificand & 0xfffffffffffffLL))));
2965 APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
2969 uint32_t myexponent, mysignificand;
2972 myexponent = exponent+127;
2973 mysignificand = (
uint32_t)*significandParts();
2974 if (myexponent == 1 && !(mysignificand & 0x800000))
2976 }
else if (category==
fcZero) {
2985 mysignificand = (
uint32_t)*significandParts();
2988 return APInt(32, (((sign&1) << 31) | ((myexponent&0xff) << 23) |
2989 (mysignificand & 0x7fffff)));
2992 APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
2996 uint32_t myexponent, mysignificand;
2999 myexponent = exponent+15;
3000 mysignificand = (
uint32_t)*significandParts();
3001 if (myexponent == 1 && !(mysignificand & 0x400))
3003 }
else if (category==
fcZero) {
3012 mysignificand = (
uint32_t)*significandParts();
3015 return APInt(16, (((sign&1) << 15) | ((myexponent&0x1f) << 10) |
3016 (mysignificand & 0x3ff)));
3025 return convertHalfAPFloatToAPInt();
3028 return convertFloatAPFloatToAPInt();
3031 return convertDoubleAPFloatToAPInt();
3034 return convertQuadrupleAPFloatToAPInt();
3037 return convertPPCDoubleDoubleAPFloatToAPInt();
3041 return convertF80LongDoubleAPFloatToAPInt();
3046 "Float semantics are not IEEEsingle");
3053 "Float semantics are not IEEEdouble");
3065 void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3069 uint64_t myexponent = (i2 & 0x7fff);
3070 uint64_t mysignificand = i1;
3075 sign =
static_cast<unsigned int>(i2>>15);
3076 if (myexponent==0 && mysignificand==0) {
3079 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3082 }
else if (myexponent==0x7fff && mysignificand!=0x8000000000000000ULL) {
3085 significandParts()[0] = mysignificand;
3086 significandParts()[1] = 0;
3089 exponent = myexponent - 16383;
3090 significandParts()[0] = mysignificand;
3091 significandParts()[1] = 0;
3097 void IEEEFloat::initFromPPCDoubleDoubleAPInt(
const APInt &api) {
3105 initFromDoubleAPInt(
APInt(64, i1));
3121 void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3125 uint64_t myexponent = (i2 >> 48) & 0x7fff;
3126 uint64_t mysignificand = i1;
3127 uint64_t mysignificand2 = i2 & 0xffffffffffffLL;
3132 sign =
static_cast<unsigned int>(i2>>63);
3133 if (myexponent==0 &&
3134 (mysignificand==0 && mysignificand2==0)) {
3137 }
else if (myexponent==0x7fff &&
3138 (mysignificand==0 && mysignificand2==0)) {
3141 }
else if (myexponent==0x7fff &&
3142 (mysignificand!=0 || mysignificand2 !=0)) {
3145 significandParts()[0] = mysignificand;
3146 significandParts()[1] = mysignificand2;
3149 exponent = myexponent - 16383;
3150 significandParts()[0] = mysignificand;
3151 significandParts()[1] = mysignificand2;
3155 significandParts()[1] |= 0x1000000000000LL;
3159 void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3162 uint64_t myexponent = (i >> 52) & 0x7ff;
3163 uint64_t mysignificand = i & 0xfffffffffffffLL;
3168 sign =
static_cast<unsigned int>(i>>63);
3169 if (myexponent==0 && mysignificand==0) {
3172 }
else if (myexponent==0x7ff && mysignificand==0) {
3175 }
else if (myexponent==0x7ff && mysignificand!=0) {
3178 *significandParts() = mysignificand;
3181 exponent = myexponent - 1023;
3182 *significandParts() = mysignificand;
3186 *significandParts() |= 0x10000000000000LL;
3190 void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3193 uint32_t myexponent = (i >> 23) & 0xff;
3194 uint32_t mysignificand = i & 0x7fffff;
3200 if (myexponent==0 && mysignificand==0) {
3203 }
else if (myexponent==0xff && mysignificand==0) {
3206 }
else if (myexponent==0xff && mysignificand!=0) {
3209 *significandParts() = mysignificand;
3212 exponent = myexponent - 127;
3213 *significandParts() = mysignificand;
3217 *significandParts() |= 0x800000;
3221 void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3224 uint32_t myexponent = (i >> 10) & 0x1f;
3225 uint32_t mysignificand = i & 0x3ff;
3231 if (myexponent==0 && mysignificand==0) {
3234 }
else if (myexponent==0x1f && mysignificand==0) {
3237 }
else if (myexponent==0x1f && mysignificand!=0) {
3240 *significandParts() = mysignificand;
3243 exponent = myexponent - 15;
3244 *significandParts() = mysignificand;
3248 *significandParts() |= 0x400;
3258 return initFromHalfAPInt(api);
3260 return initFromFloatAPInt(api);
3262 return initFromDoubleAPInt(api);
3264 return initFromF80LongDoubleAPInt(api);
3266 return initFromQuadrupleAPInt(api);
3268 return initFromPPCDoubleDoubleAPInt(api);
3286 unsigned PartCount = partCount();
3287 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
3291 const unsigned NumUnusedHighBits =
3292 PartCount*integerPartWidth - semantics->
precision;
3326 initFromAPInt(&Sem, API);
3344 void AdjustToPrecision(
APInt &significand,
3345 int &exp,
unsigned FormatPrecision) {
3349 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
3351 if (bits <= bitsRequired)
return;
3353 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
3354 if (!tensRemovable)
return;
3356 exp += tensRemovable;
3361 if (tensRemovable & 1)
3363 tensRemovable >>= 1;
3364 if (!tensRemovable)
break;
3368 significand = significand.
udiv(divisor);
3376 int &exp,
unsigned FormatPrecision) {
3377 unsigned N = buffer.
size();
3378 if (N <= FormatPrecision)
return;
3381 unsigned FirstSignificant = N - FormatPrecision;
3388 if (buffer[FirstSignificant - 1] <
'5') {
3389 while (FirstSignificant < N && buffer[FirstSignificant] ==
'0')
3392 exp += FirstSignificant;
3393 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
3399 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
3400 if (buffer[
I] ==
'9') {
3409 if (FirstSignificant == N) {
3410 exp += FirstSignificant;
3416 exp += FirstSignificant;
3417 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
3422 unsigned FormatMaxPadding)
const {
3426 return append(Str,
"-Inf");
3428 return append(Str,
"+Inf");
3436 if (!FormatMaxPadding)
3450 int exp = exponent - ((int) semantics->
precision - 1);
3457 if (!FormatPrecision) {
3465 FormatPrecision = 2 + semantics->
precision * 59 / 196;
3470 exp += trailingZeros;
3471 significand = significand.
lshr(trailingZeros);
3476 }
else if (exp > 0) {
3479 significand <<= exp;
3493 unsigned precision = semantics->
precision + (137 * texp + 136) / 59;
3497 significand = significand.
zext(precision);
3498 APInt five_to_the_i(precision, 5);
3500 if (texp & 1) significand *= five_to_the_i;
3504 five_to_the_i *= five_to_the_i;
3508 AdjustToPrecision(significand, exp, FormatPrecision);
3514 APInt ten(precision, 10);
3515 APInt digit(precision, 0);
3517 bool inTrail =
true;
3518 while (significand != 0) {
3526 if (inTrail && !d) exp++;
3533 assert(!buffer.
empty() &&
"no characters in buffer!");
3537 AdjustToPrecision(buffer, exp, FormatPrecision);
3539 unsigned NDigits = buffer.
size();
3542 bool FormatScientific;
3543 if (!FormatMaxPadding)
3544 FormatScientific =
true;
3550 FormatScientific = ((
unsigned) exp > FormatMaxPadding ||
3551 NDigits + (
unsigned) exp > FormatPrecision);
3554 int MSD = exp + (int) (NDigits - 1);
3557 FormatScientific =
false;
3561 FormatScientific = ((
unsigned) -MSD) > FormatMaxPadding;
3567 if (FormatScientific) {
3568 exp += (NDigits - 1);
3575 for (
unsigned I = 1;
I != NDigits; ++
I)
3580 if (exp < 0) exp = -exp;
3583 expbuf.
push_back((
char) (
'0' + (exp % 10)));
3586 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
3593 for (
unsigned I = 0;
I != NDigits; ++
I)
3603 int NWholeDigits = exp + (int) NDigits;
3606 if (NWholeDigits > 0) {
3607 for (; I != (
unsigned) NWholeDigits; ++
I)
3611 unsigned NZeros = 1 + (
unsigned) -NWholeDigits;
3615 for (
unsigned Z = 1; Z != NZeros; ++Z)
3619 for (; I != NDigits; ++
I)
3630 if (significandLSB() != semantics->
precision - 1)
3644 reciprocal.significandLSB() == reciprocal.semantics->
precision - 1);
3722 bool WillCrossBinadeBoundary =
3723 exponent != semantics->
minExponent && isSignificandAllZeros();
3741 if (WillCrossBinadeBoundary) {
3757 bool WillCrossBinadeBoundary = !
isDenormal() && isSignificandAllOnes();
3759 if (WillCrossBinadeBoundary) {
3764 "We can not increment an exponent beyond the maxExponent allowed"
3765 " by the given floating point semantics.");
3768 incrementSignificand();
3808 return Arg.exponent;
3813 Normalized.exponent += SignificandBits;
3815 return Normalized.exponent - SignificandBits;
3829 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
3832 X.exponent +=
std::min(std::max(Exp, -MaxIncrement - 1), MaxIncrement);
3855 return scalbn(Val, -Exp, RM);
3887 Floats(new
APFloat[2]{std::move(First), std::move(Second)}) {
3896 : Semantics(RHS.Semantics),
3904 : Semantics(RHS.Semantics),
Floats(std::move(RHS.
Floats)) {
3910 if (Semantics == RHS.Semantics && RHS.Floats) {
3911 Floats[0] = RHS.Floats[0];
3912 Floats[1] = RHS.Floats[1];
3913 }
else if (
this != &RHS) {
3927 Status |= z.
add(c, RM);
3930 Floats[0] = std::move(z);
3931 Floats[1].makeZero(
false);
3935 auto AComparedToC = a.compareAbsoluteValue(c);
3937 Status |= z.
add(aa, RM);
3940 Status |= z.
add(c, RM);
3941 Status |= z.
add(a, RM);
3944 Status |= z.
add(a, RM);
3945 Status |= z.
add(c, RM);
3948 Floats[0] = std::move(z);
3949 Floats[1].makeZero(
false);
3954 Status |= zz.
add(cc, RM);
3958 Status |= Floats[1].subtract(z, RM);
3959 Status |= Floats[1].add(c, RM);
3960 Status |= Floats[1].add(zz, RM);
3964 Status |= Floats[1].subtract(z, RM);
3965 Status |= Floats[1].add(a, RM);
3966 Status |= Floats[1].add(zz, RM);
3976 Status |= zz.
add(c, RM);
3977 Status |= q.
add(z, RM);
3980 Status |= zz.
add(q, RM);
3981 Status |= zz.
add(aa, RM);
3982 Status |= zz.
add(cc, RM);
3984 Floats[0] = std::move(z);
3985 Floats[1].makeZero(
false);
3989 Status |= Floats[0].add(zz, RM);
3990 if (!Floats[0].isFinite()) {
3991 Floats[1].makeZero(
false);
3994 Floats[1] = std::move(z);
3995 Status |= Floats[1].subtract(Floats[0], RM);
3996 Status |= Floats[1].add(zz, RM);
4002 const DoubleAPFloat &RHS,
4005 if (LHS.getCategory() ==
fcNaN) {
4009 if (RHS.getCategory() ==
fcNaN) {
4013 if (LHS.getCategory() ==
fcZero) {
4017 if (RHS.getCategory() ==
fcZero) {
4022 LHS.isNegative() != RHS.isNegative()) {
4023 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4039 APInt(64, LHS.Floats[0].bitcastToAPInt().getRawData()[0])),
4048 auto Ret = Out.addImpl(
A, AA,
C, CC, RM);
4051 uint64_t Buffer[] = {Out.Floats[0].bitcastToAPInt().getRawData()[0],
4052 Out.Floats[1].bitcastToAPInt().getRawData()[0]};
4059 return addWithSpecial(*
this, RHS, *
this, RM);
4065 auto Ret =
add(RHS, RM);
4071 Floats[0].changeSign();
4072 Floats[1].changeSign();
4077 auto Result = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
4080 Result = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
4082 auto Against = Floats[0].isNegative() ^ Floats[1].isNegative();
4083 auto RHSAgainst = RHS.Floats[0].isNegative() ^ RHS.Floats[1].isNegative();
4084 if (Against && !RHSAgainst)
4086 if (!Against && RHSAgainst)
4088 if (!Against && !RHSAgainst)
4090 if (Against && RHSAgainst)
4097 return Floats[0].getCategory();
4103 Floats[0].makeInf(Neg);
4104 Floats[1].makeZero(
false);
4108 Floats[0].makeNaN(SNaN, Neg, fill);
4109 Floats[1].makeZero(
false);
4114 APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
4115 if (usesLayout<IEEEFloat>(Semantics)) {
4116 new (&
IEEE) IEEEFloat(std::move(F));
4119 if (usesLayout<DoubleAPFloat>(Semantics)) {
4121 DoubleAPFloat(Semantics,
APFloat(std::move(F), F.getSemantics()),
4144 usesLayout<IEEEFloat>(ToSemantics))
4145 return U.IEEE.convert(ToSemantics, RM, losesInfo);
4147 usesLayout<DoubleAPFloat>(ToSemantics)) {
4156 usesLayout<IEEEFloat>(ToSemantics)) {
4157 auto Ret = getIEEE().
convert(ToSemantics, RM, losesInfo);
4158 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
4189 OS << Buffer <<
"\n";
static StringRef::iterator skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot)
DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
fltCategory
Category of internally-represented number.
void push_back(const T &Elt)
static void tcExtract(integerPart *, unsigned int dstCount, const integerPart *, unsigned int srcBits, unsigned int srcLSB)
Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to DST, of dstCOUNT parts...
const_iterator end(StringRef path)
Get end iterator over path.
void makeNaN(bool SNaN, bool Neg, const APInt *fill)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
uint64_t getZExtValue() const
Get zero extended value.
static void tcSetLeastSignificantBits(integerPart *, unsigned int, unsigned int bits)
Set the least significant BITS and clear the rest.
const unsigned int maxPowerOfFiveParts
void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
opStatus roundToIntegral(roundingMode)
bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
void makeInf(bool Neg=false)
static unsigned int powerOf5(integerPart *dst, unsigned int power)
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
const_iterator begin(StringRef path)
Get begin iterator over path.
hash_code hash_value(const IEEEFloat &Arg)
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
static integerPart tcIncrement(integerPart *, unsigned int)
Increment a bignum in-place. Return the carry flag.
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
static unsigned int tcLSB(const integerPart *, unsigned int)
Returns the bit number of the least or most significant set bit of a number.
const char * firstSigDigit
bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
bool isNegative() const
Determine sign of this APInt.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
opStatus convertFromString(StringRef, roundingMode)
static const fltSemantics & x87DoubleExtended()
static const fltSemantics semX87DoubleExtended
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
static int readExponent(StringRef::iterator begin, StringRef::iterator end)
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
IEEEFloat(const fltSemantics &)
static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE=false)
Returns a float which is bitcasted from an all one value int.
void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
static int tcMultiplyPart(integerPart *dst, const integerPart *src, integerPart multiplier, integerPart carry, unsigned int srcParts, unsigned int dstParts, bool add)
DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false...
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool isFiniteNonZero() const
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
static bool tcIsZero(const integerPart *, unsigned int)
Returns true if a bignum is zero, false otherwise.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
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...
opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
static const char infinityU[]
static ExponentType semanticsMaxExponent(const fltSemantics &)
bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
static void tcNegate(integerPart *, unsigned int)
Negate a bignum in-place.
LLVM_NODISCARD bool empty() const
void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
static void tcAssign(integerPart *, const integerPart *, unsigned int)
Assign one bignum to another.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
IEEEFloat & operator=(const IEEEFloat &)
void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
static void tcShiftLeft(integerPart *, unsigned int parts, unsigned int count)
Shift a bignum left COUNT bits.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
static unsigned int semanticsSizeInBits(const fltSemantics &)
cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
fltCategory getCategory() const
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
static int tcExtractBit(const integerPart *, unsigned int bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
Function Alias Analysis false
static void tcClearBit(integerPart *, unsigned int bit)
Clear the given bit of a bignum. Zero-based.
bool isZero() const
Returns true if and only if the float is plus or minus zero.
unsigned getActiveBits() const
Compute the number of active bits in the value.
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM)
opStatus subtract(const APFloat &RHS, roundingMode RM)
opStatus convertFromString(StringRef, roundingMode)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
DoubleAPFloat(const fltSemantics &S)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
bool isInteger() const
Returns true if and only if the number is an exact integer.
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
static ExponentType semanticsMinExponent(const fltSemantics &)
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
const fltSemantics & getSemantics() const
opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, bool *) const
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
cmpResult compareAbsoluteValue(const IEEEFloat &) const
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static const fltSemantics & IEEEsingle()
static integerPart tcDecrement(integerPart *, unsigned int)
Decrement a bignum in-place. Return the borrow flag.
static const char infinityL[]
static int totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
static void tcSet(integerPart *, integerPart, unsigned int)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts...
static char * writeUnsignedDecimal(char *dst, unsigned int n)
assert &[0] Floats()==&semPPCDoubleDoubleImpl||&Floats[0].getSemantics()==&semIEEEdouble
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
APInt trunc(unsigned width) const
Truncate to new width.
IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode)
opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
const unsigned int integerPartWidth
const unsigned int maxPowerOfFiveExponent
static const fltSemantics & IEEEhalf()
static lostFraction lostFractionThroughTruncation(const integerPart *parts, unsigned int partCount, unsigned int bits)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static unsigned int tcFullMultiply(integerPart *, const integerPart *, const integerPart *, unsigned, unsigned)
DST = LHS * RHS, where DST has width the sum of the widths of the operands.
opStatus remainder(const IEEEFloat &)
IEEE remainder.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
unsigned getBitWidth() const
Return the number of bits in the APInt.
const unsigned int maxPrecision
static integerPart tcAdd(integerPart *, const integerPart *, integerPart carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static const fltSemantics semPPCDoubleDoubleImpl
static const fltSemantics semIEEEdouble
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
uint64_t NextPowerOf2(uint64_t A)
NextPowerOf2 - Returns the next power of two (in 64-bits) that is strictly greater than A...
static lostFraction shiftRight(integerPart *dst, unsigned int parts, unsigned int bits)
static const fltSemantics & IEEEquad()
iterator erase(const_iterator CI)
static int tcCompare(const integerPart *, const integerPart *, unsigned int)
Comparison (unsigned) of two bignums.
static unsigned int partCountForBits(unsigned int bits)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static void tcSetBit(integerPart *, unsigned int bit)
Set the given bit of a bignum. Zero-based.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
Converts this value into a decimal string.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static const fltSemantics semBogus
APFloatBase::ExponentType minExponent
signed short ExponentType
A signed type to represent a floating point numbers unbiased exponent.
void makeZero(bool Neg=false)
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
opStatus add(const IEEEFloat &, roundingMode)
void copySign(const IEEEFloat &)
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
opStatus subtract(const IEEEFloat &, roundingMode)
static const char hexDigitsLower[]
static lostFraction trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue)
static unsigned int semanticsPrecision(const fltSemantics &)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
void print(raw_ostream &) const
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static const char hexDigitsUpper[]
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static unsigned int tcMSB(const integerPart *parts, unsigned int n)
const char * lastSigDigit
static const fltSemantics semIEEEsingle
APFloatBase::ExponentType maxExponent
static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant)
static const fltSemantics semIEEEquad
double bitsToDouble() const
Converts APInt bits to a double.
static const fltSemantics & IEEEdouble()
static char * writeSignedDecimal(char *dst, int value)
static integerPart ulpsFromBoundary(const integerPart *parts, unsigned int bits, bool isNearest)
opStatus add(const APFloat &RHS, roundingMode RM)
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative. ...
opStatus
IEEE-754R 7: Default exception handling.
double convertToDouble() const
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
bool needsCleanup() const
Returns whether this instance allocated memory.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
static const fltSemantics semPPCDoubleDouble
static const fltSemantics & PPCDoubleDouble()
static unsigned int decDigitValue(unsigned int c)
float convertToFloat() const
const unsigned int maxExponent
static integerPart tcSubtract(integerPart *, const integerPart *, integerPart carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
opStatus divide(const IEEEFloat &, roundingMode)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
APInt bitcastToAPInt() const
opStatus multiply(const IEEEFloat &, roundingMode)
bool getExactInverse(IEEEFloat *inv) const
If this value has an exact multiplicative inverse, store it in inv and return true.
This class implements an extremely fast bulk output stream that can only output to a stream...
static void interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
StringRef - Represent a constant reference to a string, i.e.
#define PackCategoriesIntoKey(_lhs, _rhs)
A macro used to combine two fcCategory enums into one key which can be used in a switch statement to ...
APInt zext(unsigned width) const
Zero extend to a new width.
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
std::error_code status(const Twine &path, file_status &result)
Get file status as if by POSIX stat().
static void tcShiftRight(integerPart *, unsigned int parts, unsigned int count)
Shift a bignum right COUNT bits.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
const fltSemantics & getSemantics() const
static unsigned int partAsHex(char *dst, integerPart part, unsigned int count, const char *hexDigitChars)
static const fltSemantics semIEEEhalf
int ilogb(const IEEEFloat &Arg)
float bitsToFloat() const
Converts APInt bits to a double.
unsigned getNumWords() const
Get the number of words.