29 #define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
31 if (usesLayout<IEEEFloat>(getSemantics())) \
32 return U.IEEE.METHOD_CALL; \
33 if (usesLayout<DoubleAPFloat>(getSemantics())) \
34 return U.Double.METHOD_CALL; \
35 llvm_unreachable("Unexpected semantics"); \
46 #define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
175 static inline unsigned int
182 static inline unsigned int
197 unsigned int absExponent;
198 const unsigned int overlargeExponent = 24000;
201 assert(p != end &&
"Exponent has no digits");
203 isNegative = (*p ==
'-');
204 if (*p ==
'-' || *p ==
'+') {
206 assert(p != end &&
"Exponent has no digits");
210 assert(absExponent < 10U &&
"Invalid character in exponent");
212 for (; p !=
end; ++p) {
216 assert(value < 10U &&
"Invalid character in exponent");
218 value += absExponent * 10;
219 if (absExponent >= overlargeExponent) {
220 absExponent = overlargeExponent;
227 assert(p == end &&
"Invalid exponent in exponent");
230 return -(int) absExponent;
232 return (
int) absExponent;
239 int exponentAdjustment)
241 int unsignedExponent;
242 bool negative, overflow;
245 assert(p != end &&
"Exponent has no digits");
247 negative = *p ==
'-';
248 if (*p ==
'-' || *p ==
'+') {
250 assert(p != end &&
"Exponent has no digits");
253 unsignedExponent = 0;
255 for (; p !=
end; ++p) {
259 assert(value < 10U &&
"Invalid character in exponent");
261 unsignedExponent = unsignedExponent * 10 + value;
262 if (unsignedExponent > 32767) {
268 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
272 exponent = unsignedExponent;
274 exponent = -exponent;
275 exponent += exponentAdjustment;
276 if (exponent > 32767 || exponent < -32768)
281 exponent = negative ? -32768: 32767;
292 while (p != end && *p ==
'0')
295 if (p != end && *p ==
'.') {
298 assert(end - begin != 1 &&
"Significand has no digits");
300 while (p != end && *p ==
'0')
338 for (; p !=
end; ++p) {
340 assert(dot == end &&
"String contains multiple dots");
350 assert((*p ==
'e' || *p ==
'E') &&
"Invalid character in significand");
351 assert(p != begin &&
"Significand has no digits");
352 assert((dot == end || p - begin != 1) &&
"Significand has no digits");
369 while (p != begin && *p ==
'0');
370 while (p != begin && *p ==
'.');
388 unsigned int digitValue)
390 unsigned int hexDigit;
396 else if (digitValue < 8 && digitValue > 0)
400 while (p != end && (*p ==
'0' || *p ==
'.'))
403 assert(p != end &&
"Invalid trailing hexadecimal fraction!");
419 unsigned int partCount,
448 return lost_fraction;
463 return moreSignificant;
474 HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
476 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
478 if (HUerr1 + HUerr2 == 0)
479 return inexactMultiply * 2;
481 return inexactMultiply + 2 * (HUerr1 + HUerr2);
490 unsigned int count, partBits;
507 if (part - boundary <= boundary - part)
508 return part - boundary;
510 return boundary - part;
513 if (part == boundary) {
519 }
else if (part == boundary - 1) {
536 pow5s[0] = 78125 * 5;
538 unsigned int partsCount[16] = { 1 };
546 *p1 = firstEightPowers[power & 7];
552 for (
unsigned int n = 0; power; power >>= 1, n++) {
559 pc = partsCount[n - 1];
562 if (pow5[pc - 1] == 0)
572 if (p2[result - 1] == 0)
597 static const char NaNL[] =
"nan";
598 static const char NaNU[] =
"NAN";
605 const char *hexDigitChars)
607 unsigned int result =
count;
613 dst[
count] = hexDigitChars[part & 0xf];
653 void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
656 semantics = ourSemantics;
662 void IEEEFloat::freeSignificand() {
664 delete [] significand.parts;
667 void IEEEFloat::assign(
const IEEEFloat &rhs) {
668 assert(semantics == rhs.semantics);
671 category = rhs.category;
672 exponent = rhs.exponent;
674 copySignificand(rhs);
677 void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
679 assert(rhs.partCount() >= partCount());
693 unsigned numParts = partCount();
703 unsigned bitsToPreserve = semantics->
precision - 1;
704 unsigned part = bitsToPreserve / 64;
705 bitsToPreserve %= 64;
706 significand[part] &= ((1ULL << bitsToPreserve) - 1);
707 for (part++; part != numParts; ++part)
708 significand[part] = 0;
711 unsigned QNaNBit = semantics->
precision - 2;
736 if (semantics != rhs.semantics) {
738 initialize(rhs.semantics);
749 semantics = rhs.semantics;
750 significand = rhs.significand;
751 exponent = rhs.exponent;
752 category = rhs.category;
770 significandMSB() == 0;
773 bool IEEEFloat::isSignificandAllOnes()
const {
777 const unsigned PartCount = partCount();
778 for (
unsigned i = 0; i < PartCount - 1; i++)
783 const unsigned NumHighBits =
786 "fill than integerPartWidth");
789 if (~(Parts[PartCount - 1] | HighBitFill))
795 bool IEEEFloat::isSignificandAllZeros()
const {
799 const unsigned PartCount = partCount();
801 for (
unsigned i = 0; i < PartCount - 1; i++)
805 const unsigned NumHighBits =
808 "clear than integerPartWidth");
811 if (Parts[PartCount - 1] & HighBitMask)
821 && isSignificandAllOnes();
835 if (semantics != rhs.semantics ||
836 category != rhs.category ||
845 return std::equal(significandParts(), significandParts() + partCount(),
846 rhs.significandParts());
850 initialize(&ourSemantics);
855 significandParts()[0] = value;
860 initialize(&ourSemantics);
871 initialize(rhs.semantics);
876 *
this = std::move(rhs);
881 unsigned int IEEEFloat::partCount()
const {
886 return const_cast<IEEEFloat *
>(
this)->significandParts();
891 return significand.parts;
893 return &significand.part;
896 void IEEEFloat::zeroSignificand() {
901 void IEEEFloat::incrementSignificand() {
915 parts = significandParts();
917 assert(semantics == rhs.semantics);
918 assert(exponent == rhs.exponent);
920 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
926 integerPart borrow) {
929 parts = significandParts();
931 assert(semantics == rhs.semantics);
932 assert(exponent == rhs.exponent);
941 lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs,
942 const IEEEFloat *addend) {
944 unsigned int partsCount, newPartsCount, precision;
951 assert(semantics == rhs.semantics);
959 if (newPartsCount > 4)
962 fullSignificand = scratch;
964 lhsSignificand = significandParts();
965 partsCount = partCount();
968 rhs.significandParts(), partsCount, partsCount);
971 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
972 exponent += rhs.exponent;
986 if (addend && addend->isNonZero()) {
990 Significand savedSignificand = significand;
994 unsigned int extendedPrecision;
997 extendedPrecision = 2 * precision + 1;
998 if (omsb != extendedPrecision - 1) {
999 assert(extendedPrecision > omsb);
1001 (extendedPrecision - 1) - omsb);
1002 exponent -= (extendedPrecision - 1) - omsb;
1006 extendedSemantics = *semantics;
1007 extendedSemantics.
precision = extendedPrecision;
1009 if (newPartsCount == 1)
1010 significand.part = fullSignificand[0];
1012 significand.parts = fullSignificand;
1013 semantics = &extendedSemantics;
1016 status = extendedAddend.convert(extendedSemantics,
rmTowardZero, &ignored);
1023 lost_fraction = extendedAddend.shiftSignificandRight(1);
1025 "Lost precision while shifting addend for fused-multiply-add.");
1027 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1030 if (newPartsCount == 1)
1031 fullSignificand[0] = significand.part;
1032 significand = savedSignificand;
1033 semantics = savedSemantics;
1035 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1042 exponent -= precision + 1;
1051 if (omsb > precision) {
1052 unsigned int bits, significantParts;
1055 bits = omsb - precision;
1057 lf =
shiftRight(fullSignificand, significantParts, bits);
1064 if (newPartsCount > 4)
1065 delete [] fullSignificand;
1067 return lost_fraction;
1071 lostFraction IEEEFloat::divideSignificand(
const IEEEFloat &rhs) {
1072 unsigned int bit, i, partsCount;
1078 assert(semantics == rhs.semantics);
1080 lhsSignificand = significandParts();
1081 rhsSignificand = rhs.significandParts();
1082 partsCount = partCount();
1089 divisor = dividend + partsCount;
1092 for (i = 0; i < partsCount; i++) {
1093 dividend[i] = lhsSignificand[i];
1094 divisor[i] = rhsSignificand[i];
1095 lhsSignificand[i] = 0;
1098 exponent -= rhs.exponent;
1100 unsigned int precision = semantics->
precision;
1103 bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1110 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1126 for (bit = precision; bit; bit -= 1) {
1150 return lost_fraction;
1153 unsigned int IEEEFloat::significandMSB()
const {
1157 unsigned int IEEEFloat::significandLSB()
const {
1168 return shiftRight(significandParts(), partCount(), bits);
1172 void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1173 assert(bits < semantics->precision);
1176 unsigned int partsCount = partCount();
1189 assert(semantics == rhs.semantics);
1193 compare = exponent - rhs.exponent;
1203 else if (compare < 0)
1235 bool IEEEFloat::roundAwayFromZero(roundingMode rounding_mode,
1237 unsigned int bit)
const {
1244 switch (rounding_mode) {
1279 omsb = significandMSB() + 1;
1285 exponentChange = omsb - semantics->
precision;
1289 if (exponent + exponentChange > semantics->
maxExponent)
1290 return handleOverflow(rounding_mode);
1294 if (exponent + exponentChange < semantics->minExponent)
1295 exponentChange = semantics->
minExponent - exponent;
1298 if (exponentChange < 0) {
1301 shiftSignificandLeft(-exponentChange);
1306 if (exponentChange > 0) {
1310 lf = shiftSignificandRight(exponentChange);
1315 if (omsb > (
unsigned) exponentChange)
1316 omsb -= exponentChange;
1336 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1340 incrementSignificand();
1341 omsb = significandMSB() + 1;
1344 if (omsb == (
unsigned) semantics->
precision + 1) {
1354 shiftSignificandRight(1);
1366 assert(omsb < semantics->precision);
1396 sign = rhs.sign ^ subtract;
1398 copySignificand(rhs);
1419 if (((sign ^ rhs.sign)!=0) != subtract) {
1432 lostFraction IEEEFloat::addOrSubtractSignificand(
const IEEEFloat &rhs,
1440 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1443 bits = exponent - rhs.exponent;
1453 }
else if (bits > 0) {
1454 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1455 shiftSignificandLeft(1);
1458 lost_fraction = shiftSignificandRight(-bits - 1);
1459 temp_rhs.shiftSignificandLeft(1);
1464 carry = temp_rhs.subtractSignificand
1466 copySignificand(temp_rhs);
1469 carry = subtractSignificand
1488 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1489 carry = addSignificand(temp_rhs);
1491 lost_fraction = shiftSignificandRight(-bits);
1492 carry = addSignificand(rhs);
1500 return lost_fraction;
1520 copySignificand(rhs);
1554 copySignificand(rhs);
1605 copySignificand(rhs);
1629 roundingMode rounding_mode,
1633 fs = addOrSubtractSpecials(rhs, subtract);
1639 lost_fraction = addOrSubtractSignificand(rhs, subtract);
1640 fs = normalize(rounding_mode, lost_fraction);
1649 if (category ==
fcZero) {
1650 if (rhs.category !=
fcZero || (sign == rhs.sign) == subtract)
1660 return addOrSubtract(rhs, rounding_mode,
false);
1666 return addOrSubtract(rhs, rounding_mode,
true);
1675 fs = multiplySpecials(rhs);
1678 lostFraction lost_fraction = multiplySignificand(rhs,
nullptr);
1679 fs = normalize(rounding_mode, lost_fraction);
1693 fs = divideSpecials(rhs);
1697 fs = normalize(rounding_mode, lost_fraction);
1709 unsigned int origSign = sign;
1715 int parts = partCount();
1745 fs = modSpecials(rhs);
1767 sign ^= multiplicand.sign;
1776 lost_fraction = multiplySignificand(multiplicand, &addend);
1777 fs = normalize(rounding_mode, lost_fraction);
1787 fs = multiplySpecials(multiplicand);
1797 fs = addOrSubtract(addend, rounding_mode,
false);
1824 MagicConstant.sign = sign;
1832 fs =
add(MagicConstant, rounding_mode);
1836 fs =
subtract(MagicConstant, rounding_mode);
1850 assert(semantics == rhs.semantics);
1882 if (sign == rhs.sign)
1897 if (sign != rhs.sign) {
1928 unsigned int newPartCount, oldPartCount;
1935 oldPartCount = partCount();
1938 bool X86SpecialNan =
false;
1941 (!(*significandParts() & 0x8000000000000000ULL) ||
1942 !(*significandParts() & 0x4000000000000000ULL))) {
1945 X86SpecialNan =
true;
1954 int exponentChange = significandMSB() + 1 - fromSemantics.
precision;
1955 if (exponent + exponentChange < toSemantics.
minExponent)
1956 exponentChange = toSemantics.
minExponent - exponent;
1957 if (exponentChange < shift)
1958 exponentChange = shift;
1959 if (exponentChange < 0) {
1960 shift -= exponentChange;
1961 exponent += exponentChange;
1967 lostFraction =
shiftRight(significandParts(), oldPartCount, -shift);
1970 if (newPartCount > oldPartCount) {
1978 significand.parts = newParts;
1979 }
else if (newPartCount == 1 && oldPartCount != 1) {
1983 newPart = significandParts()[0];
1985 significand.part = newPart;
1989 semantics = &toSemantics;
1997 fs = normalize(rounding_mode, lostFraction);
1998 *losesInfo = (fs !=
opOK);
1999 }
else if (category ==
fcNaN) {
2000 *losesInfo = lostFraction !=
lfExactlyZero || X86SpecialNan;
2032 roundingMode rounding_mode,
bool *isExact)
const {
2035 unsigned int dstPartsCount, truncatedBits;
2044 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2046 if (category ==
fcZero) {
2053 src = significandParts();
2062 truncatedBits = semantics->
precision -1U - exponent;
2066 unsigned int bits = exponent + 1U;
2072 if (bits < semantics->precision) {
2088 if (truncatedBits) {
2092 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2112 if (omsb == width &&
2123 if (omsb >= width + !isSigned)
2145 unsigned int width,
bool isSigned,
2149 fs = convertToSignExtendedInteger(parts, width, isSigned, rounding_mode,
2153 unsigned int bits, dstPartsCount;
2156 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2158 if (category ==
fcNaN)
2163 bits = width - isSigned;
2166 if (sign && isSigned)
2177 const integerPart *src,
unsigned int srcCount, roundingMode rounding_mode) {
2178 unsigned int omsb, precision, dstCount;
2184 dst = significandParts();
2185 dstCount = partCount();
2190 if (precision <= omsb) {
2191 exponent = omsb - 1;
2196 exponent = precision - 1;
2201 return normalize(rounding_mode, lost_fraction);
2215 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2223 unsigned int srcCount,
bool isSigned,
2236 status = convertFromUnsignedParts(copy, srcCount, rounding_mode);
2240 status = convertFromUnsignedParts(src, srcCount, rounding_mode);
2249 unsigned int width,
bool isSigned,
2260 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2264 IEEEFloat::convertFromHexadecimalString(
StringRef s,
2265 roundingMode rounding_mode) {
2273 unsigned partsCount = partCount();
2275 bool computedTrailingFraction =
false;
2288 assert(dot == end &&
"String contains multiple dots");
2294 if (hex_value == -1U)
2304 }
else if (!computedTrailingFraction) {
2306 computedTrailingFraction =
true;
2311 assert(p != end &&
"Hex strings require an exponent");
2312 assert((*p ==
'p' || *p ==
'P') &&
"Invalid character in significand");
2313 assert(p != begin &&
"Significand has no digits");
2314 assert((dot == end || p - begin != 1) &&
"Significand has no digits");
2317 if (p != firstSignificantDigit) {
2326 expAdjustment =
static_cast<int>(dot - firstSignificantDigit);
2327 if (expAdjustment < 0)
2329 expAdjustment = expAdjustment * 4 - 1;
2340 return normalize(rounding_mode, lost_fraction);
2344 IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2345 unsigned sigPartCount,
int exp,
2346 roundingMode rounding_mode) {
2347 unsigned int parts, pow5PartCount;
2358 pow5PartCount =
powerOf5(pow5Parts, exp >= 0 ? exp: -exp);
2360 for (;; parts *= 2) {
2362 unsigned int excessPrecision, truncatedBits;
2364 calcSemantics.
precision = parts * integerPartWidth - 1;
2366 truncatedBits = excessPrecision;
2369 decSig.makeZero(sign);
2372 sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
2374 powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2377 decSig.exponent += exp;
2381 unsigned int powHUerr;
2385 calcLostFraction = decSig.multiplySignificand(pow5,
nullptr);
2386 powHUerr = powStatus !=
opOK;
2388 calcLostFraction = decSig.divideSignificand(pow5);
2391 excessPrecision += (semantics->
minExponent - decSig.exponent);
2392 truncatedBits = excessPrecision;
2393 if (excessPrecision > calcSemantics.
precision)
2394 excessPrecision = calcSemantics.
precision;
2403 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
2408 excessPrecision, isNearest);
2411 if (HUdistance >= HUerr) {
2412 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
2413 calcSemantics.
precision - excessPrecision,
2418 exponent = (decSig.exponent + semantics->
precision
2419 - (calcSemantics.
precision - excessPrecision));
2423 return normalize(rounding_mode, calcLostFraction);
2429 IEEEFloat::convertFromDecimalString(
StringRef str, roundingMode rounding_mode) {
2468 fs = handleOverflow(rounding_mode);
2486 fs = handleOverflow(rounding_mode);
2489 unsigned int partCount;
2513 if (p == str.
end()) {
2518 assert(decValue < 10U &&
"Invalid character in significand");
2520 val = val * 10 + decValue;
2527 partCount, partCount + 1,
false);
2531 if (decSignificand[partCount])
2536 fs = roundSignificandWithExponent(decSignificand, partCount,
2539 delete [] decSignificand;
2545 bool IEEEFloat::convertFromStringSpecials(
StringRef str) {
2574 if (convertFromStringSpecials(str))
2579 size_t slen = str.
size();
2580 sign = *p ==
'-' ? 1 : 0;
2581 if (*p ==
'-' || *p ==
'+') {
2584 assert(slen &&
"String has no digits");
2587 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
2588 assert(slen - 2 &&
"Invalid string");
2589 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
2593 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
2632 dst +=
sizeof infinityL - 1;
2637 dst +=
sizeof NaNU - 1;
2642 *dst++ = upperCase ?
'X':
'x';
2644 if (hexDigits > 1) {
2646 memset (dst,
'0', hexDigits - 1);
2647 dst += hexDigits - 1;
2649 *dst++ = upperCase ?
'P':
'p';
2654 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
2660 return static_cast<unsigned int>(dst - p);
2667 char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
2669 roundingMode rounding_mode)
const {
2670 unsigned int count, valueBits, shift, partsCount, outputDigits;
2671 const char *hexDigitChars;
2677 *dst++ = upperCase ?
'X':
'x';
2682 significand = significandParts();
2683 partsCount = partCount();
2692 outputDigits = (valueBits - significandLSB () + 3) / 4;
2698 if (hexDigits < outputDigits) {
2704 bits = valueBits - hexDigits * 4;
2706 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
2708 outputDigits = hexDigits;
2716 count = (valueBits + integerPartWidth - 1) / integerPartWidth;
2718 while (outputDigits && count) {
2722 if (--count == partsCount)
2725 part = significand[
count] << shift;
2728 part |= significand[count - 1] >> (integerPartWidth - shift);
2731 unsigned int curDigits = integerPartWidth / 4;
2733 if (curDigits > outputDigits)
2734 curDigits = outputDigits;
2735 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
2736 outputDigits -= curDigits;
2746 }
while (*q ==
'0');
2750 memset (dst,
'0', outputDigits);
2751 dst += outputDigits;
2764 *dst++ = upperCase ?
'P':
'p';
2773 Arg.
isNaN() ? (uint8_t)0 : (uint8_t)Arg.sign,
2777 return hash_combine((uint8_t)Arg.category, (uint8_t)Arg.sign,
2780 Arg.significandParts(),
2781 Arg.significandParts() + Arg.partCount()));
2793 APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
2797 uint64_t myexponent, mysignificand;
2800 myexponent = exponent+16383;
2801 mysignificand = significandParts()[0];
2802 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
2804 }
else if (category==
fcZero) {
2808 myexponent = 0x7fff;
2809 mysignificand = 0x8000000000000000ULL;
2812 myexponent = 0x7fff;
2813 mysignificand = significandParts()[0];
2817 words[0] = mysignificand;
2818 words[1] = ((uint64_t)(sign & 1) << 15) |
2819 (myexponent & 0x7fffLL);
2820 return APInt(80, words);
2823 APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt()
const {
2848 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
2854 if (u.isFiniteNonZero() && losesInfo) {
2864 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
2869 return APInt(128, words);
2872 APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
2876 uint64_t myexponent, mysignificand, mysignificand2;
2879 myexponent = exponent+16383;
2880 mysignificand = significandParts()[0];
2881 mysignificand2 = significandParts()[1];
2882 if (myexponent==1 && !(mysignificand2 & 0x1000000000000LL))
2884 }
else if (category==
fcZero) {
2886 mysignificand = mysignificand2 = 0;
2888 myexponent = 0x7fff;
2889 mysignificand = mysignificand2 = 0;
2892 myexponent = 0x7fff;
2893 mysignificand = significandParts()[0];
2894 mysignificand2 = significandParts()[1];
2898 words[0] = mysignificand;
2899 words[1] = ((uint64_t)(sign & 1) << 63) |
2900 ((myexponent & 0x7fff) << 48) |
2901 (mysignificand2 & 0xffffffffffffLL);
2903 return APInt(128, words);
2906 APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
2910 uint64_t myexponent, mysignificand;
2913 myexponent = exponent+1023;
2914 mysignificand = *significandParts();
2915 if (myexponent==1 && !(mysignificand & 0x10000000000000LL))
2917 }
else if (category==
fcZero) {
2926 mysignificand = *significandParts();
2929 return APInt(64, ((((uint64_t)(sign & 1) << 63) |
2930 ((myexponent & 0x7ff) << 52) |
2931 (mysignificand & 0xfffffffffffffLL))));
2934 APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
2938 uint32_t myexponent, mysignificand;
2941 myexponent = exponent+127;
2942 mysignificand = (
uint32_t)*significandParts();
2943 if (myexponent == 1 && !(mysignificand & 0x800000))
2945 }
else if (category==
fcZero) {
2954 mysignificand = (
uint32_t)*significandParts();
2957 return APInt(32, (((sign&1) << 31) | ((myexponent&0xff) << 23) |
2958 (mysignificand & 0x7fffff)));
2961 APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
2965 uint32_t myexponent, mysignificand;
2968 myexponent = exponent+15;
2969 mysignificand = (
uint32_t)*significandParts();
2970 if (myexponent == 1 && !(mysignificand & 0x400))
2972 }
else if (category==
fcZero) {
2981 mysignificand = (
uint32_t)*significandParts();
2984 return APInt(16, (((sign&1) << 15) | ((myexponent&0x1f) << 10) |
2985 (mysignificand & 0x3ff)));
2994 return convertHalfAPFloatToAPInt();
2997 return convertFloatAPFloatToAPInt();
3000 return convertDoubleAPFloatToAPInt();
3003 return convertQuadrupleAPFloatToAPInt();
3006 return convertPPCDoubleDoubleAPFloatToAPInt();
3010 return convertF80LongDoubleAPFloatToAPInt();
3015 "Float semantics are not IEEEsingle");
3022 "Float semantics are not IEEEdouble");
3034 void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3038 uint64_t myexponent = (i2 & 0x7fff);
3039 uint64_t mysignificand = i1;
3044 sign =
static_cast<unsigned int>(i2>>15);
3045 if (myexponent==0 && mysignificand==0) {
3048 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3051 }
else if (myexponent==0x7fff && mysignificand!=0x8000000000000000ULL) {
3054 significandParts()[0] = mysignificand;
3055 significandParts()[1] = 0;
3058 exponent = myexponent - 16383;
3059 significandParts()[0] = mysignificand;
3060 significandParts()[1] = 0;
3066 void IEEEFloat::initFromPPCDoubleDoubleAPInt(
const APInt &api) {
3074 initFromDoubleAPInt(
APInt(64, i1));
3090 void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3094 uint64_t myexponent = (i2 >> 48) & 0x7fff;
3095 uint64_t mysignificand = i1;
3096 uint64_t mysignificand2 = i2 & 0xffffffffffffLL;
3101 sign =
static_cast<unsigned int>(i2>>63);
3102 if (myexponent==0 &&
3103 (mysignificand==0 && mysignificand2==0)) {
3106 }
else if (myexponent==0x7fff &&
3107 (mysignificand==0 && mysignificand2==0)) {
3110 }
else if (myexponent==0x7fff &&
3111 (mysignificand!=0 || mysignificand2 !=0)) {
3114 significandParts()[0] = mysignificand;
3115 significandParts()[1] = mysignificand2;
3118 exponent = myexponent - 16383;
3119 significandParts()[0] = mysignificand;
3120 significandParts()[1] = mysignificand2;
3124 significandParts()[1] |= 0x1000000000000LL;
3128 void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3131 uint64_t myexponent = (i >> 52) & 0x7ff;
3132 uint64_t mysignificand = i & 0xfffffffffffffLL;
3137 sign =
static_cast<unsigned int>(i>>63);
3138 if (myexponent==0 && mysignificand==0) {
3141 }
else if (myexponent==0x7ff && mysignificand==0) {
3144 }
else if (myexponent==0x7ff && mysignificand!=0) {
3147 *significandParts() = mysignificand;
3150 exponent = myexponent - 1023;
3151 *significandParts() = mysignificand;
3155 *significandParts() |= 0x10000000000000LL;
3159 void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3162 uint32_t myexponent = (i >> 23) & 0xff;
3163 uint32_t mysignificand = i & 0x7fffff;
3169 if (myexponent==0 && mysignificand==0) {
3172 }
else if (myexponent==0xff && mysignificand==0) {
3175 }
else if (myexponent==0xff && mysignificand!=0) {
3178 *significandParts() = mysignificand;
3181 exponent = myexponent - 127;
3182 *significandParts() = mysignificand;
3186 *significandParts() |= 0x800000;
3190 void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3193 uint32_t myexponent = (i >> 10) & 0x1f;
3194 uint32_t mysignificand = i & 0x3ff;
3200 if (myexponent==0 && mysignificand==0) {
3203 }
else if (myexponent==0x1f && mysignificand==0) {
3206 }
else if (myexponent==0x1f && mysignificand!=0) {
3209 *significandParts() = mysignificand;
3212 exponent = myexponent - 15;
3213 *significandParts() = mysignificand;
3217 *significandParts() |= 0x400;
3227 return initFromHalfAPInt(api);
3229 return initFromFloatAPInt(api);
3231 return initFromDoubleAPInt(api);
3233 return initFromF80LongDoubleAPInt(api);
3235 return initFromQuadrupleAPInt(api);
3237 return initFromPPCDoubleDoubleAPInt(api);
3255 unsigned PartCount = partCount();
3256 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
3260 const unsigned NumUnusedHighBits =
3261 PartCount*integerPartWidth - semantics->
precision;
3295 initFromAPInt(&Sem, API);
3313 void AdjustToPrecision(
APInt &significand,
3314 int &exp,
unsigned FormatPrecision) {
3318 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
3320 if (bits <= bitsRequired)
return;
3322 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
3323 if (!tensRemovable)
return;
3325 exp += tensRemovable;
3330 if (tensRemovable & 1)
3332 tensRemovable >>= 1;
3333 if (!tensRemovable)
break;
3337 significand = significand.
udiv(divisor);
3345 int &exp,
unsigned FormatPrecision) {
3346 unsigned N = buffer.
size();
3347 if (N <= FormatPrecision)
return;
3350 unsigned FirstSignificant = N - FormatPrecision;
3357 if (buffer[FirstSignificant - 1] <
'5') {
3358 while (FirstSignificant < N && buffer[FirstSignificant] ==
'0')
3361 exp += FirstSignificant;
3362 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
3368 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
3369 if (buffer[
I] ==
'9') {
3378 if (FirstSignificant == N) {
3379 exp += FirstSignificant;
3385 exp += FirstSignificant;
3386 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
3391 unsigned FormatMaxPadding,
bool TruncateZero)
const {
3395 return append(Str,
"-Inf");
3397 return append(Str,
"+Inf");
3405 if (!FormatMaxPadding) {
3410 if (FormatPrecision > 1)
3411 Str.
append(FormatPrecision - 1,
'0');
3426 int exp = exponent - ((int) semantics->
precision - 1);
3433 if (!FormatPrecision) {
3441 FormatPrecision = 2 + semantics->
precision * 59 / 196;
3446 exp += trailingZeros;
3452 }
else if (exp > 0) {
3455 significand <<= exp;
3469 unsigned precision = semantics->
precision + (137 * texp + 136) / 59;
3473 significand = significand.
zext(precision);
3474 APInt five_to_the_i(precision, 5);
3476 if (texp & 1) significand *= five_to_the_i;
3480 five_to_the_i *= five_to_the_i;
3484 AdjustToPrecision(significand, exp, FormatPrecision);
3490 APInt ten(precision, 10);
3491 APInt digit(precision, 0);
3493 bool inTrail =
true;
3494 while (significand != 0) {
3502 if (inTrail && !d) exp++;
3509 assert(!buffer.
empty() &&
"no characters in buffer!");
3513 AdjustToPrecision(buffer, exp, FormatPrecision);
3515 unsigned NDigits = buffer.
size();
3518 bool FormatScientific;
3519 if (!FormatMaxPadding)
3520 FormatScientific =
true;
3526 FormatScientific = ((
unsigned) exp > FormatMaxPadding ||
3527 NDigits + (
unsigned) exp > FormatPrecision);
3530 int MSD = exp + (int) (NDigits - 1);
3533 FormatScientific =
false;
3537 FormatScientific = ((
unsigned) -MSD) > FormatMaxPadding;
3543 if (FormatScientific) {
3544 exp += (NDigits - 1);
3548 if (NDigits == 1 && TruncateZero)
3551 for (
unsigned I = 1;
I != NDigits; ++
I)
3554 if (!TruncateZero && FormatPrecision > NDigits - 1)
3555 Str.
append(FormatPrecision - NDigits + 1,
'0');
3557 Str.
push_back(TruncateZero ?
'E' :
'e');
3560 if (exp < 0) exp = -exp;
3563 expbuf.
push_back((
char) (
'0' + (exp % 10)));
3567 if (!TruncateZero && expbuf.
size() < 2)
3569 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
3576 for (
unsigned I = 0;
I != NDigits; ++
I)
3586 int NWholeDigits = exp + (int) NDigits;
3589 if (NWholeDigits > 0) {
3590 for (; I != (
unsigned) NWholeDigits; ++
I)
3594 unsigned NZeros = 1 + (
unsigned) -NWholeDigits;
3598 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
3602 for (; I != NDigits; ++
I)
3613 if (significandLSB() != semantics->
precision - 1)
3627 reciprocal.significandLSB() == reciprocal.semantics->
precision - 1);
3630 *inv =
APFloat(reciprocal, *semantics);
3705 bool WillCrossBinadeBoundary =
3706 exponent != semantics->
minExponent && isSignificandAllZeros();
3724 if (WillCrossBinadeBoundary) {
3740 bool WillCrossBinadeBoundary = !
isDenormal() && isSignificandAllOnes();
3742 if (WillCrossBinadeBoundary) {
3747 "We can not increment an exponent beyond the maxExponent allowed"
3748 " by the given floating point semantics.");
3751 incrementSignificand();
3791 return Arg.exponent;
3796 Normalized.exponent += SignificandBits;
3798 return Normalized.exponent - SignificandBits;
3812 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
3838 return scalbn(Val, -Exp, RM);
3871 Floats(new
APFloat[2]{std::move(First), std::move(Second)}) {
3878 : Semantics(RHS.Semantics),
3886 : Semantics(RHS.Semantics),
Floats(std::move(RHS.
Floats)) {
3892 if (Semantics == RHS.Semantics && RHS.Floats) {
3893 Floats[0] = RHS.Floats[0];
3894 Floats[1] = RHS.Floats[1];
3895 }
else if (
this != &RHS) {
3910 Status |= z.
add(c, RM);
3913 Floats[0] = std::move(z);
3914 Floats[1].makeZero(
false);
3918 auto AComparedToC = a.compareAbsoluteValue(c);
3920 Status |= z.
add(aa, RM);
3923 Status |= z.
add(c, RM);
3924 Status |= z.
add(a, RM);
3927 Status |= z.
add(a, RM);
3928 Status |= z.
add(c, RM);
3931 Floats[0] = std::move(z);
3932 Floats[1].makeZero(
false);
3937 Status |= zz.
add(cc, RM);
3941 Status |= Floats[1].subtract(z, RM);
3942 Status |= Floats[1].add(c, RM);
3943 Status |= Floats[1].add(zz, RM);
3947 Status |= Floats[1].subtract(z, RM);
3948 Status |= Floats[1].add(a, RM);
3949 Status |= Floats[1].add(zz, RM);
3959 Status |= zz.
add(c, RM);
3960 Status |= q.
add(z, RM);
3963 Status |= zz.
add(q, RM);
3964 Status |= zz.
add(aa, RM);
3965 Status |= zz.
add(cc, RM);
3967 Floats[0] = std::move(z);
3968 Floats[1].makeZero(
false);
3972 Status |= Floats[0].add(zz, RM);
3973 if (!Floats[0].isFinite()) {
3974 Floats[1].makeZero(
false);
3977 Floats[1] = std::move(z);
3978 Status |= Floats[1].subtract(Floats[0], RM);
3979 Status |= Floats[1].add(zz, RM);
3985 const DoubleAPFloat &RHS,
3988 if (LHS.getCategory() ==
fcNaN) {
3992 if (RHS.getCategory() ==
fcNaN) {
3996 if (LHS.getCategory() ==
fcZero) {
4000 if (RHS.getCategory() ==
fcZero) {
4005 LHS.isNegative() != RHS.isNegative()) {
4006 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4019 APFloat A(LHS.Floats[0]), AA(LHS.Floats[1]),
C(RHS.Floats[0]),
4027 return Out.addImpl(
A, AA,
C, CC, RM);
4032 return addWithSpecial(*
this, RHS, *
this, RM);
4045 const auto &LHS = *
this;
4062 if (LHS.getCategory() ==
fcNaN) {
4072 Out.makeNaN(
false,
false,
nullptr);
4084 "Special cases not handled exhaustively");
4087 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0], D = RHS.Floats[1];
4093 Floats[1].makeZero(
false);
4109 Status |= V.
add(W, RM);
4111 Status |= Tau.
add(V, RM);
4115 Status |= U.
add(Tau, RM);
4119 Floats[1].makeZero(
false);
4123 Status |= T.
add(Tau, RM);
4178 Floats[0].changeSign();
4179 Floats[1].changeSign();
4184 auto Result = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
4187 Result = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
4189 auto Against = Floats[0].isNegative() ^ Floats[1].isNegative();
4190 auto RHSAgainst = RHS.Floats[0].isNegative() ^ RHS.Floats[1].isNegative();
4191 if (Against && !RHSAgainst)
4193 if (!Against && RHSAgainst)
4195 if (!Against && !RHSAgainst)
4197 if (Against && RHSAgainst)
4204 return Floats[0].getCategory();
4210 Floats[0].makeInf(Neg);
4211 Floats[1].makeZero(
false);
4215 Floats[0].makeZero(Neg);
4216 Floats[1].makeZero(
false);
4229 Floats[0].makeSmallest(Neg);
4230 Floats[1].makeZero(
false);
4237 Floats[0].changeSign();
4238 Floats[1].makeZero(
false);
4242 Floats[0].makeNaN(SNaN, Neg, fill);
4243 Floats[1].makeZero(
false);
4247 auto Result = Floats[0].compare(RHS.Floats[0]);
4250 return Floats[1].compare(RHS.Floats[1]);
4255 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
4256 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
4268 Floats[0].bitcastToAPInt().getRawData()[0],
4269 Floats[1].bitcastToAPInt().getRawData()[0],
4271 return APInt(128, 2, Data);
4286 auto Ret = Tmp.
next(nextDown);
4293 unsigned int Width,
bool IsSigned,
4297 .convertToInteger(Input, Width, IsSigned, RM, IsExact);
4312 unsigned int InputSize,
4323 unsigned int InputSize,
4333 unsigned int HexDigits,
4338 .convertToHexString(DST, HexDigits, UpperCase, RM);
4343 (Floats[0].isDenormal() || Floats[1].isDenormal() ||
4345 Floats[0].compare(Floats[0] + Floats[1]) !=
cmpEqual);
4373 unsigned FormatPrecision,
4374 unsigned FormatMaxPadding,
4375 bool TruncateZero)
const {
4378 .toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
4395 scalbn(Arg.Floats[1], Exp, RM));
4402 APFloat Second = Arg.Floats[1];
4404 Second =
scalbn(Second, -Exp, RM);
4410 APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
4411 if (usesLayout<IEEEFloat>(Semantics)) {
4412 new (&
IEEE) IEEEFloat(std::move(F));
4415 if (usesLayout<DoubleAPFloat>(Semantics)) {
4417 DoubleAPFloat(Semantics,
APFloat(std::move(F), F.getSemantics()),
4429 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
4431 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
4446 usesLayout<IEEEFloat>(ToSemantics))
4447 return U.IEEE.convert(ToSemantics, RM, losesInfo);
4449 usesLayout<DoubleAPFloat>(ToSemantics)) {
4452 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
4456 usesLayout<IEEEFloat>(ToSemantics)) {
4457 auto Ret = getIEEE().
convert(ToSemantics, RM, losesInfo);
4458 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
4489 OS << Buffer <<
"\n";
4492 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4506 bool *isExact)
const {
4510 rounding_mode, isExact);
4512 result =
APInt(bitWidth, parts);
4518 #undef APFLOAT_DISPATCH_ON_SEMANTICS
opStatus roundToIntegral(roundingMode RM)
static APFloatBase::integerPart ulpsFromBoundary(const APFloatBase::integerPart *parts, unsigned int bits, bool isNearest)
static StringRef::iterator skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot)
DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
static const fltSemantics & IEEEquad() LLVM_READNONE
fltCategory
Category of internally-represented number.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
static bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
void makeNaN(bool SNaN, bool Neg, const APInt *fill)
static unsigned int partAsHex(char *dst, APFloatBase::integerPart part, unsigned int count, const char *hexDigitChars)
static unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
uint64_t getZExtValue() const
Get zero extended value.
MutableArrayRef< T > makeMutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
const unsigned int maxPowerOfFiveParts
void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void makeSmallest(bool Neg)
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...
opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
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 tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Converts this value into a decimal string.
opStatus roundToIntegral(roundingMode)
opStatus remainder(const DoubleAPFloat &RHS)
static lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
static int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
assert &[0] Floats()==&semIEEEdouble
static void tcSetLeastSignificantBits(WordType *, unsigned, unsigned bits)
Set the least significant BITS and clear the rest.
bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
void makeInf(bool Neg=false)
APInt bitcastToAPInt() const
static int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
hash_code hash_value(const IEEEFloat &Arg)
bool getExactInverse(APFloat *inv) const
opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
bool isFiniteNonZero() const
opStatus next(bool nextDown)
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.
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
opStatus divide(const APFloat &RHS, roundingMode RM)
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 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, unsigned FormatMaxPadding, bool TruncateZero=true) const
bool isFiniteNonZero() const
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
APInt bitcastToAPInt() 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...
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
void makeSmallestNormalized(bool Neg)
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, 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.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
static unsigned int powerOf5(APFloatBase::integerPart *dst, unsigned int power)
zlib-gnu style compression
LLVM_NODISCARD bool empty() const
void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
IEEEFloat & operator=(const IEEEFloat &)
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
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 convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
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...
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
static const fltSemantics & IEEEdouble() LLVM_READNONE
DoubleAPFloat(const fltSemantics &S)
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
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.
size_t size() const
size - Get the array size.
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
static ExponentType semanticsMinExponent(const fltSemantics &)
const fltSemantics & getSemantics() const
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
cmpResult compareAbsoluteValue(const IEEEFloat &) const
static const unsigned integerPartWidth
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.
bool getExactInverse(APFloat *inv) const
If this value has an exact multiplicative inverse, store it in inv and return true.
cmpResult compare(const DoubleAPFloat &RHS) const
Function Alias Analysis false
static char * writeUnsignedDecimal(char *dst, unsigned int n)
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
APInt trunc(unsigned width) const
Truncate to new width.
void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
opStatus mod(const DoubleAPFloat &RHS)
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
static void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
static const fltSemantics semPPCDoubleDoubleLegacy
static WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
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 maxPowerOfFiveExponent
This file declares a class to represent arbitrary precision floating point values and provide a varie...
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.
opStatus multiply(const APFloat &RHS, roundingMode RM)
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
const unsigned int maxPrecision
opStatus roundToIntegral(roundingMode RM)
static const fltSemantics semIEEEdouble
friend int ilogb(const IEEEFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
iterator erase(const_iterator CI)
static unsigned int partCountForBits(unsigned int bits)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts...
void makeLargest(bool Neg)
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)
static const fltSemantics & IEEEsingle() LLVM_READNONE
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
static const fltSemantics & IEEEhalf() LLVM_READNONE
opStatus add(const IEEEFloat &, roundingMode)
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
static void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
opStatus next(bool nextDown)
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 lostFraction lostFractionThroughTruncation(const APFloatBase::integerPart *parts, unsigned int partCount, unsigned int bits)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
APInt::WordType integerPart
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.
opStatus mod(const APFloat &RHS)
An opaque object representing a hash code.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
const char * lastSigDigit
static const fltSemantics semIEEEsingle
APFloatBase::ExponentType maxExponent
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant)
static const fltSemantics semIEEEquad
double bitsToDouble() const
Converts APInt bits to a double.
llvm_unreachable("Unknown RegBank!")
static char * writeSignedDecimal(char *dst, int value)
static void tcNegate(WordType *, unsigned)
Negate a bignum in-place.
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
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.
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
bool needsCleanup() const
Returns whether this instance allocated memory.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
static void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
static const fltSemantics semPPCDoubleDouble
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.
static unsigned int decDigitValue(unsigned int c)
float convertToFloat() const
const unsigned int maxExponent
opStatus divide(const IEEEFloat &, roundingMode)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
opStatus remainder(const APFloat &RHS)
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.
static unsigned tcMSB(const WordType *parts, unsigned n)
APInt bitcastToAPInt() const
opStatus multiply(const IEEEFloat &, roundingMode)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
This class implements an extremely fast bulk output stream that can only output to a stream...
friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Returns: X * 2^Exp for integral exponents.
static void interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
static void tcSetBit(WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
StringRef - Represent a constant reference to a string, i.e.
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...
#define PackCategoriesIntoKey(_lhs, _rhs)
A macro used to combine two fcCategory enums into one key which can be used in a switch statement to ...
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
APInt zext(unsigned width) const
Zero extend to a new width.
bool getExactInverse(APFloat *inv) const
static void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
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.
static APInt floatToBits(float V)
Converts a float to APInt bits.
const fltSemantics & getSemantics() const
static const fltSemantics semIEEEhalf
opStatus convertFromString(StringRef, roundingMode)
int ilogb(const IEEEFloat &Arg)
float bitsToFloat() const
Converts APInt bits to a double.
unsigned getNumWords() const
Get the number of words.