23 #include "llvm/Config/llvm-config.h" 34 #define DEBUG_TYPE "apint" 39 uint64_t *result =
new uint64_t[numWords];
40 memset(result, 0, numWords *
sizeof(uint64_t));
46 inline static uint64_t*
getMemory(
unsigned numWords) {
47 return new uint64_t[numWords];
51 inline static unsigned getDigit(
char cdigit, uint8_t radix) {
54 if (radix == 16 || radix == 36) {
78 void APInt::initSlowCase(uint64_t val,
bool isSigned) {
81 if (isSigned && int64_t(val) < 0)
87 void APInt::initSlowCase(
const APInt& that) {
93 assert(BitWidth &&
"Bitwidth too small");
94 assert(bigVal.
data() &&
"Null pointer detected!");
110 : BitWidth(numBits) {
111 initFromArray(bigVal);
114 APInt::APInt(
unsigned numBits,
unsigned numWords,
const uint64_t bigVal[])
115 : BitWidth(numBits) {
120 : BitWidth(numbits) {
121 assert(BitWidth &&
"Bitwidth too small");
122 fromString(numbits, Str, radix);
125 void APInt::reallocate(
unsigned NewBitWidth) {
128 BitWidth = NewBitWidth;
137 BitWidth = NewBitWidth;
144 void APInt::AssignSlowCase(
const APInt& RHS) {
163 if (isSingleWord()) {
169 for (
unsigned i = 0; i < NumWords; ++i)
179 return clearUnusedBits();
188 return clearUnusedBits();
195 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
200 return clearUnusedBits();
208 return clearUnusedBits();
215 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
220 return clearUnusedBits();
228 return clearUnusedBits();
232 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
234 return APInt(BitWidth, U.VAL * RHS.U.
VAL);
240 Result.clearUnusedBits();
244 void APInt::AndAssignSlowCase(
const APInt& RHS) {
248 void APInt::OrAssignSlowCase(
const APInt& RHS) {
252 void APInt::XorAssignSlowCase(
const APInt& RHS) {
257 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
263 if (isSingleWord()) {
267 tcMultiplyPart(U.pVal, U.pVal, RHS, 0, NumWords, NumWords,
false);
269 return clearUnusedBits();
272 bool APInt::EqualSlowCase(
const APInt& RHS)
const {
276 int APInt::compare(
const APInt& RHS)
const {
277 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be same for comparison");
279 return U.VAL < RHS.U.
VAL ? -1 : U.VAL > RHS.U.
VAL;
284 int APInt::compareSigned(
const APInt& RHS)
const {
285 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be same for comparison");
286 if (isSingleWord()) {
289 return lhsSext < rhsSext ? -1 : lhsSext > rhsSext;
296 if (lhsNeg != rhsNeg)
297 return lhsNeg ? -1 : 1;
304 void APInt::setBitsSlowCase(
unsigned loBit,
unsigned hiBit) {
305 unsigned loWord = whichWord(loBit);
306 unsigned hiWord = whichWord(hiBit);
312 unsigned hiShiftAmt = whichBit(hiBit);
313 if (hiShiftAmt != 0) {
318 if (hiWord == loWord)
321 U.pVal[hiWord] |= hiMask;
324 U.pVal[loWord] |= loMask;
327 for (
unsigned word = loWord + 1; word < hiWord; ++word)
332 void APInt::flipAllBitsSlowCase() {
341 assert(bitPosition < BitWidth &&
"Out of the bit-width range!");
342 if ((*
this)[bitPosition])
clearBit(bitPosition);
348 assert(0 < subBitWidth && (subBitWidth + bitPosition) <= BitWidth &&
349 "Illegal bit insertion");
352 if (subBitWidth == BitWidth) {
358 if (isSingleWord()) {
360 U.VAL &= ~(mask << bitPosition);
361 U.VAL |= (subBits.U.
VAL << bitPosition);
365 unsigned loBit = whichBit(bitPosition);
366 unsigned loWord = whichWord(bitPosition);
367 unsigned hi1Word = whichWord(bitPosition + subBitWidth - 1);
370 if (loWord == hi1Word) {
372 U.pVal[loWord] &= ~(mask << loBit);
373 U.pVal[loWord] |= (subBits.U.
VAL << loBit);
386 if (remainingBits != 0) {
388 U.pVal[hi1Word] &= ~mask;
389 U.pVal[hi1Word] |= subBits.getWord(subBitWidth - 1);
397 for (
unsigned i = 0; i != subBitWidth; ++i) {
406 assert(numBits > 0 &&
"Can't extract zero bits");
407 assert(bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth &&
408 "Illegal bit extraction");
411 return APInt(numBits, U.VAL >> bitPosition);
413 unsigned loBit = whichBit(bitPosition);
414 unsigned loWord = whichWord(bitPosition);
415 unsigned hiWord = whichWord(bitPosition + numBits - 1);
418 if (loWord == hiWord)
419 return APInt(numBits, U.pVal[loWord] >> loBit);
427 APInt Result(numBits, 0);
431 uint64_t *DestPtr = Result.isSingleWord() ? &Result.U.
VAL : Result.U.
pVal;
432 for (
unsigned word = 0; word < NumDstWords; ++word) {
433 uint64_t w0 = U.pVal[loWord + word];
435 (loWord + word + 1) < NumSrcWords ? U.pVal[loWord + word + 1] : 0;
439 return Result.clearUnusedBits();
444 assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
446 "Radix should be 2, 8, 10, 16, or 36!");
448 size_t slen = str.
size();
453 if (*p ==
'-' || *p ==
'+') {
456 assert(slen &&
"String is only a sign, needs a value.");
479 = radix == 10? (slen == 1 ? 4 : slen * 64/18)
480 : (slen == 1 ? 7 : slen * 16/3);
488 if (log == (
unsigned)-1) {
489 return isNegative + 1;
491 return isNegative + log + 1;
496 if (Arg.isSingleWord())
504 "SplatSizeInBits must divide width!");
507 return *
this ==
rotl(SplatSizeInBits);
512 return this->
lshr(BitWidth - numBits);
533 unsigned APInt::countLeadingZerosSlowCase()
const {
536 uint64_t V = U.pVal[i];
550 unsigned APInt::countLeadingOnesSlowCase()
const {
561 if (Count == highWordBits) {
562 for (i--; i >= 0; --i) {
574 unsigned APInt::countTrailingZerosSlowCase()
const {
581 return std::min(Count, BitWidth);
584 unsigned APInt::countTrailingOnesSlowCase()
const {
591 assert(Count <= BitWidth);
595 unsigned APInt::countPopulationSlowCase()
const {
602 bool APInt::intersectsSlowCase(
const APInt &RHS)
const {
603 for (
unsigned i = 0, e =
getNumWords(); i != e; ++i)
604 if ((U.pVal[i] & RHS.U.
pVal[i]) != 0)
610 bool APInt::isSubsetOfSlowCase(
const APInt &RHS)
const {
611 for (
unsigned i = 0, e =
getNumWords(); i != e; ++i)
612 if ((U.pVal[i] & ~RHS.U.
pVal[i]) != 0)
619 assert(BitWidth >= 16 && BitWidth % 16 == 0 &&
"Cannot byteswap!");
624 if (BitWidth == 48) {
625 unsigned Tmp1 =
unsigned(U.VAL >> 16);
627 uint16_t Tmp2 = uint16_t(U.VAL);
629 return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
637 if (Result.BitWidth != BitWidth) {
639 Result.BitWidth = BitWidth;
647 return APInt(BitWidth, llvm::reverseBits<uint64_t>(U.VAL));
649 return APInt(BitWidth, llvm::reverseBits<uint32_t>(U.VAL));
651 return APInt(BitWidth, llvm::reverseBits<uint16_t>(U.VAL));
653 return APInt(BitWidth, llvm::reverseBits<uint8_t>(U.VAL));
659 APInt Reversed(BitWidth, 0);
660 unsigned S = BitWidth;
674 if (A == B)
return A;
685 if (Pow2_A > Pow2_B) {
688 }
else if (Pow2_B > Pow2_A) {
719 bool isNeg = I >> 63;
722 int64_t
exp = ((I >> 52) & 0x7ff) - 1023;
726 return APInt(width, 0u);
729 uint64_t mantissa = (I & (~0ULL >> 12)) | 1ULL << 52;
733 return isNeg ? -
APInt(width, mantissa >> (52 - exp)) :
734 APInt(width, mantissa >> (52 - exp));
738 if (width <= exp - 52)
739 return APInt(width, 0);
742 APInt Tmp(width, mantissa);
744 return isNeg ? -Tmp : Tmp;
763 return double(getWord(0));
767 bool isNeg = isSigned ? (*this)[BitWidth-1] :
false;
770 APInt Tmp(isNeg ? -(*
this) : (*
this));
782 if (!isSigned || !isNeg)
783 return std::numeric_limits<double>::infinity();
785 return -std::numeric_limits<double>::infinity();
792 unsigned hiWord = whichWord(n-1);
794 mantissa = Tmp.U.
pVal[0];
798 assert(hiWord > 0 &&
"huh?");
801 mantissa = hibits | lobits;
806 uint64_t
I = sign | (exp << 52) | mantissa;
812 assert(width < BitWidth &&
"Invalid APInt Truncate request");
813 assert(width &&
"Can't truncate to 0 bits");
823 Result.U.
pVal[i] = U.pVal[i];
835 assert(Width > BitWidth &&
"Invalid APInt SignExtend request");
853 Result.clearUnusedBits();
859 assert(width > BitWidth &&
"Invalid APInt ZeroExtend request");
862 return APInt(width, U.VAL);
877 if (BitWidth < width)
879 if (BitWidth > width)
885 if (BitWidth < width)
887 if (BitWidth > width)
893 if (BitWidth < width)
899 if (BitWidth < width)
912 void APInt::ashrSlowCase(
unsigned ShiftAmt) {
925 if (WordsToMove != 0) {
935 for (
unsigned i = 0; i != WordsToMove - 1; ++i)
936 U.pVal[i] = (U.pVal[i + WordShift] >> BitShift) |
940 U.pVal[WordsToMove - 1] = U.pVal[WordShift + WordsToMove - 1] >> BitShift;
942 U.pVal[WordsToMove - 1] =
948 std::memset(U.pVal + WordsToMove, Negative ? -1 : 0,
961 void APInt::lshrSlowCase(
unsigned ShiftAmt) {
973 void APInt::shlSlowCase(
unsigned ShiftAmt) {
981 APInt rot = rotateAmt;
982 if (rotBitWidth < BitWidth) {
985 rot = rotateAmt.
zext(BitWidth);
996 rotateAmt %= BitWidth;
999 return shl(rotateAmt) |
lshr(BitWidth - rotateAmt);
1007 rotateAmt %= BitWidth;
1010 return lshr(rotateAmt) |
shl(BitWidth - rotateAmt);
1027 if (magnitude <= 5) {
1028 static const uint8_t results[32] = {
1033 4, 4, 4, 4, 4, 4, 4, 4,
1034 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1037 return APInt(BitWidth, results[ (isSingleWord() ? U.VAL : U.pVal[0]) ]);
1044 if (magnitude < 52) {
1045 return APInt(BitWidth,
1046 uint64_t(::
round(::
sqrt(
double(isSingleWord() ? U.VAL
1055 unsigned nbits = BitWidth, i = 4;
1056 APInt testy(BitWidth, 16);
1057 APInt x_old(BitWidth, 1);
1058 APInt x_new(BitWidth, 0);
1059 APInt two(BitWidth, 2);
1062 for (;; i += 2, testy = testy.
shl(2))
1063 if (i >= nbits || this->
ule(testy)) {
1064 x_old = x_old.
shl(i / 2);
1070 x_new = (this->
udiv(x_old) + x_old).
udiv(two);
1071 if (x_old.
ule(x_new))
1082 APInt square(x_old * x_old);
1083 APInt nextSquare((x_old + 1) * (x_old +1));
1084 if (this->
ult(square))
1086 assert(this->
ule(nextSquare) &&
"Error in APInt::sqrt computation");
1087 APInt midpoint((nextSquare - square).
udiv(two));
1088 APInt offset(*
this - square);
1089 if (offset.
ult(midpoint))
1100 assert(
ult(modulo) &&
"This APInt must be smaller than the modulo");
1110 APInt r[2] = { modulo, *
this };
1112 APInt q(BitWidth, 0);
1115 for (i = 0; r[i^1] != 0; i ^= 1) {
1120 udivrem(r[i], r[i^1], q, r[i]);
1129 return APInt(BitWidth, 0);
1138 return std::move(t[i]);
1146 const APInt& d = *
this;
1148 APInt ad, anc, delta, q1,
r1, q2,
r2, t;
1154 anc = t - 1 - t.
urem(ad);
1156 q1 = signedMin.
udiv(anc);
1157 r1 = signedMin - q1*anc;
1158 q2 = signedMin.
udiv(ad);
1159 r2 = signedMin - q2*ad;
1175 }
while (q1.
ult(delta) || (q1 == delta && r1 == 0));
1190 const APInt& d = *
this;
1199 nc = allOnes - (allOnes - d).
urem(d);
1201 q1 = signedMin.
udiv(nc);
1202 r1 = signedMin - q1*nc;
1203 q2 = signedMax.
udiv(d);
1204 r2 = signedMax - q2*d;
1207 if (r1.
uge(nc - r1)) {
1215 if ((r2 + 1).uge(d - r2)) {
1216 if (q2.
uge(signedMax)) magu.
a = 1;
1221 if (q2.
uge(signedMin)) magu.
a = 1;
1226 }
while (p < d.getBitWidth()*2 &&
1227 (q1.
ult(delta) || (q1 == delta && r1 == 0)));
1229 magu.
s = p - d.getBitWidth();
1238 unsigned m,
unsigned n) {
1239 assert(u &&
"Must provide dividend");
1240 assert(v &&
"Must provide divisor");
1241 assert(q &&
"Must provide quotient");
1242 assert(u != v && u != q && v != q &&
"Must use different memory");
1243 assert(n>1 &&
"n must be > 1");
1246 const uint64_t b = uint64_t(1) << 32;
1251 #define DEBUG_KNUTH(X) LLVM_DEBUG(X) 1253 #define DEBUG_KNUTH(X) do {} while(false) 1274 for (
unsigned i = 0; i < m+n; ++i) {
1275 uint32_t u_tmp = u[i] >> (32 - shift);
1276 u[i] = (u[i] << shift) | u_carry;
1279 for (
unsigned i = 0; i < n; ++i) {
1280 uint32_t v_tmp = v[i] >> (32 - shift);
1281 v[i] = (v[i] << shift) | v_carry;
1305 uint64_t dividend =
Make_64(u[j+n], u[j+n-1]);
1307 uint64_t qp = dividend / v[n-1];
1308 uint64_t rp = dividend % v[n-1];
1309 if (qp == b || qp*v[n-2] > b*rp + u[j+n-2]) {
1312 if (rp < b && (qp == b || qp*v[n-2] > b*rp + u[j+n-2]))
1315 DEBUG_KNUTH(
dbgs() <<
"KnuthDiv: qp == " << qp <<
", rp == " << rp <<
'\n');
1326 for (
unsigned i = 0; i < n; ++i) {
1327 uint64_t p = uint64_t(qp) * uint64_t(v[i]);
1328 int64_t subres = int64_t(u[j+i]) - borrow -
Lo_32(p);
1329 u[j+i] =
Lo_32(subres);
1332 <<
", borrow = " << borrow <<
'\n');
1334 bool isNeg = u[j+n] < borrow;
1335 u[j+n] -=
Lo_32(borrow);
1353 for (
unsigned i = 0; i < n; i++) {
1354 uint32_t limit = std::min(u[j+i],v[i]);
1355 u[j+i] += v[i] + carry;
1356 carry = u[j+i] < limit || (carry && u[j+i] == limit);
1381 for (
int i = n-1; i >= 0; i--) {
1382 r[i] = (u[i] >> shift) | carry;
1383 carry = u[i] << (32 - shift);
1387 for (
int i = n-1; i >= 0; i--) {
1397 void APInt::divide(
const WordType *LHS,
unsigned lhsWords,
const WordType *RHS,
1399 assert(lhsWords >= rhsWords &&
"Fractional result");
1408 unsigned n = rhsWords * 2;
1409 unsigned m = (lhsWords * 2) - n;
1418 if ((Remainder?4:3)*n+2*m+1 <= 128) {
1421 Q = &SPACE[(m+n+1) + n];
1423 R = &SPACE[(m+n+1) + n + (m+n)];
1434 for (
unsigned i = 0; i < lhsWords; ++i) {
1435 uint64_t tmp = LHS[i];
1436 U[i * 2] =
Lo_32(tmp);
1437 U[i * 2 + 1] =
Hi_32(tmp);
1443 for (
unsigned i = 0; i < rhsWords; ++i) {
1444 uint64_t tmp = RHS[i];
1445 V[i * 2] =
Lo_32(tmp);
1446 V[i * 2 + 1] =
Hi_32(tmp);
1458 for (
unsigned i = n; i > 0 && V[i-1] == 0; i--) {
1462 for (
unsigned i = m+n; i > 0 && U[i-1] == 0; i--)
1471 assert(n != 0 &&
"Divide by zero?");
1475 for (
int i = m; i >= 0; i--) {
1476 uint64_t partial_dividend =
Make_64(remainder, U[i]);
1477 if (partial_dividend == 0) {
1480 }
else if (partial_dividend < divisor) {
1482 remainder =
Lo_32(partial_dividend);
1483 }
else if (partial_dividend == divisor) {
1487 Q[i] =
Lo_32(partial_dividend / divisor);
1488 remainder =
Lo_32(partial_dividend - (Q[i] * divisor));
1501 for (
unsigned i = 0; i < lhsWords; ++i)
1502 Quotient[i] =
Make_64(Q[i*2+1], Q[i*2]);
1507 for (
unsigned i = 0; i < rhsWords; ++i)
1508 Remainder[i] =
Make_64(R[i*2+1], R[i*2]);
1512 if (U != &SPACE[0]) {
1521 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1524 if (isSingleWord()) {
1525 assert(RHS.U.
VAL != 0 &&
"Divide by zero?");
1526 return APInt(BitWidth, U.VAL / RHS.U.
VAL);
1533 assert(rhsWords &&
"Divided by zero???");
1538 return APInt(BitWidth, 0);
1542 if (lhsWords < rhsWords || this->
ult(RHS))
1544 return APInt(BitWidth, 0);
1547 return APInt(BitWidth, 1);
1550 return APInt(BitWidth, this->U.pVal[0] / RHS.U.
pVal[0]);
1553 APInt Quotient(BitWidth, 0);
1554 divide(U.pVal, lhsWords, RHS.U.
pVal, rhsWords, Quotient.U.
pVal,
nullptr);
1559 assert(RHS != 0 &&
"Divide by zero?");
1563 return APInt(BitWidth, U.VAL / RHS);
1571 return APInt(BitWidth, 0);
1577 return APInt(BitWidth, 0);
1580 return APInt(BitWidth, 1);
1583 return APInt(BitWidth, this->U.pVal[0] / RHS);
1586 APInt Quotient(BitWidth, 0);
1587 divide(U.pVal, lhsWords, &RHS, 1, Quotient.U.
pVal,
nullptr);
1594 return (-(*
this)).
udiv(-RHS);
1595 return -((-(*this)).
udiv(RHS));
1598 return -(this->
udiv(-RHS));
1599 return this->
udiv(RHS);
1605 return (-(*
this)).
udiv(-RHS);
1606 return -((-(*this)).
udiv(RHS));
1609 return -(this->
udiv(-RHS));
1610 return this->
udiv(RHS);
1614 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1615 if (isSingleWord()) {
1616 assert(RHS.U.
VAL != 0 &&
"Remainder by zero?");
1617 return APInt(BitWidth, U.VAL % RHS.U.
VAL);
1626 assert(rhsWords &&
"Performing remainder operation by zero ???");
1631 return APInt(BitWidth, 0);
1634 return APInt(BitWidth, 0);
1635 if (lhsWords < rhsWords || this->
ult(RHS))
1640 return APInt(BitWidth, 0);
1643 return APInt(BitWidth, U.pVal[0] % RHS.U.
pVal[0]);
1646 APInt Remainder(BitWidth, 0);
1647 divide(U.pVal, lhsWords, RHS.U.
pVal, rhsWords,
nullptr, Remainder.U.
pVal);
1652 assert(RHS != 0 &&
"Remainder by zero?");
1675 return U.pVal[0] % RHS;
1679 divide(U.pVal, lhsWords, &RHS, 1,
nullptr, &Remainder);
1686 return -((-(*
this)).urem(-RHS));
1687 return -((-(*this)).
urem(RHS));
1690 return this->
urem(-RHS);
1691 return this->
urem(RHS);
1697 return -((-(*this)).
urem(-RHS));
1698 return -((-(*this)).
urem(RHS));
1701 return this->
urem(-RHS);
1702 return this->
urem(RHS);
1707 assert(LHS.BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1708 unsigned BitWidth = LHS.BitWidth;
1711 if (LHS.isSingleWord()) {
1712 assert(RHS.U.
VAL != 0 &&
"Divide by zero?");
1713 uint64_t QuotVal = LHS.U.
VAL / RHS.U.
VAL;
1714 uint64_t RemVal = LHS.U.
VAL % RHS.U.
VAL;
1715 Quotient =
APInt(BitWidth, QuotVal);
1716 Remainder =
APInt(BitWidth, RemVal);
1724 assert(rhsWords &&
"Performing divrem operation by zero ???");
1727 if (lhsWords == 0) {
1728 Quotient =
APInt(BitWidth, 0);
1729 Remainder =
APInt(BitWidth, 0);
1735 Remainder =
APInt(BitWidth, 0);
1738 if (lhsWords < rhsWords || LHS.
ult(RHS)) {
1740 Quotient =
APInt(BitWidth, 0);
1745 Quotient =
APInt(BitWidth, 1);
1746 Remainder =
APInt(BitWidth, 0);
1754 Quotient.reallocate(BitWidth);
1755 Remainder.reallocate(BitWidth);
1757 if (lhsWords == 1) {
1759 uint64_t lhsValue = LHS.U.
pVal[0];
1760 uint64_t rhsValue = RHS.U.
pVal[0];
1761 Quotient = lhsValue / rhsValue;
1762 Remainder = lhsValue % rhsValue;
1767 divide(LHS.U.
pVal, lhsWords, RHS.U.
pVal, rhsWords, Quotient.U.
pVal,
1773 (
getNumWords(BitWidth) - rhsWords) * APINT_WORD_SIZE);
1777 uint64_t &Remainder) {
1778 assert(RHS != 0 &&
"Divide by zero?");
1779 unsigned BitWidth = LHS.BitWidth;
1782 if (LHS.isSingleWord()) {
1783 uint64_t QuotVal = LHS.U.
VAL / RHS;
1784 Remainder = LHS.U.
VAL % RHS;
1785 Quotient =
APInt(BitWidth, QuotVal);
1793 if (lhsWords == 0) {
1794 Quotient =
APInt(BitWidth, 0);
1807 Quotient =
APInt(BitWidth, 0);
1812 Quotient =
APInt(BitWidth, 1);
1820 Quotient.reallocate(BitWidth);
1822 if (lhsWords == 1) {
1824 uint64_t lhsValue = LHS.U.
pVal[0];
1825 Quotient = lhsValue / RHS;
1826 Remainder = lhsValue % RHS;
1831 divide(LHS.U.
pVal, lhsWords, &RHS, 1, Quotient.U.
pVal, &Remainder);
1856 APInt &Quotient, int64_t &Remainder) {
1857 uint64_t
R = Remainder;
1866 }
else if (RHS < 0) {
1876 APInt Res = *
this+RHS;
1883 APInt Res = *
this+RHS;
1884 Overflow = Res.
ult(RHS);
1889 APInt Res = *
this - RHS;
1896 APInt Res = *
this-RHS;
1897 Overflow = Res.
ugt(*
this);
1908 APInt Res = *
this * RHS;
1910 if (*
this != 0 && RHS != 0)
1911 Overflow = Res.
sdiv(RHS) != *
this || Res.
sdiv(*
this) != RHS;
1918 APInt Res = *
this * RHS;
1920 if (*
this != 0 && RHS != 0)
1921 Overflow = Res.
udiv(RHS) != *
this || Res.
udiv(*
this) != RHS;
1930 return APInt(BitWidth, 0);
1937 return *
this << ShAmt;
1943 return APInt(BitWidth, 0);
1947 return *
this << ShAmt;
1985 return APInt(BitWidth, 0);
1992 assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
1994 "Radix should be 2, 8, 10, 16, or 36!");
1997 size_t slen = str.
size();
1998 bool isNeg = *p ==
'-';
1999 if (*p ==
'-' || *p ==
'+') {
2002 assert(slen &&
"String is only a sign, needs a value.");
2004 assert((slen <= numbits || radix != 2) &&
"Insufficient bit width");
2005 assert(((slen-1)*3 <= numbits || radix != 8) &&
"Insufficient bit width");
2006 assert(((slen-1)*4 <= numbits || radix != 16) &&
"Insufficient bit width");
2007 assert((((slen-1)*64)/22 <= numbits || radix != 10) &&
2008 "Insufficient bit width");
2017 unsigned shift = (radix == 16 ? 4 : radix == 8 ? 3 : radix == 2 ? 1 : 0);
2021 unsigned digit =
getDigit(*p, radix);
2022 assert(digit < radix &&
"Invalid character in digit string");
2041 bool Signed,
bool formatAsCLiteral)
const {
2042 assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
2044 "Radix should be 2, 8, 10, 16, or 36!");
2047 if (formatAsCLiteral) {
2077 static const char Digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2079 if (isSingleWord()) {
2102 *--BufPtr = Digits[N % Radix];
2125 unsigned StartDig = Str.
size();
2130 if (Radix == 2 || Radix == 8 || Radix == 16) {
2132 unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
2133 unsigned MaskAmt = Radix - 1;
2143 udivrem(Tmp, Radix, Tmp, Digit);
2144 assert(Digit < Radix &&
"divide failed");
2161 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 2166 dbgs() <<
"APInt(" << BitWidth <<
"b, " 2167 << U <<
"u " << S <<
"s)\n";
2173 this->
toString(S, 10, isSigned,
false);
2183 "Part width must be divisible by 2!");
2223 for (
unsigned i = 1; i < parts; i++)
2229 for (
unsigned i = 0; i < parts; i++)
2235 for (
unsigned i = 0; i < parts; i++)
2244 return (parts[whichWord(bit)] & maskBit(bit)) != 0;
2249 parts[whichWord(bit)] |= maskBit(bit);
2254 parts[whichWord(bit)] &= ~maskBit(bit);
2260 for (
unsigned i = 0; i < n; i++) {
2261 if (parts[i] != 0) {
2262 unsigned lsb =
partLSB(parts[i]);
2277 if (parts[n] != 0) {
2278 unsigned msb =
partMSB(parts[n]);
2293 unsigned srcBits,
unsigned srcLSB) {
2295 assert(dstParts <= dstCount);
2298 tcAssign (dst, src + firstSrcPart, dstParts);
2309 dst[dstParts - 1] |= ((src[firstSrcPart + dstParts] & mask)
2311 }
else if (n > srcBits) {
2313 dst[dstParts - 1] &=
lowBitMask (srcBits % APINT_BITS_PER_WORD);
2317 while (dstParts < dstCount)
2318 dst[dstParts++] = 0;
2326 for (
unsigned i = 0; i < parts; i++) {
2329 dst[i] += rhs[i] + 1;
2346 for (
unsigned i = 0; i < parts; ++i) {
2361 for (
unsigned i = 0; i < parts; i++) {
2364 dst[i] -= rhs[i] + 1;
2384 for (
unsigned i = 0; i < parts; ++i) {
2414 unsigned srcParts,
unsigned dstParts,
2417 assert(dst <= src || dst >= src + srcParts);
2418 assert(dstParts <= srcParts + 1);
2421 unsigned n = std::min(dstParts, srcParts);
2423 for (
unsigned i = 0; i < n; i++) {
2436 if (multiplier == 0 || srcPart == 0) {
2446 if (low + mid < low)
2453 if (low + mid < low)
2458 if (low + carry < low)
2465 if (low + dst[i] < low)
2474 if (srcParts < dstParts) {
2476 assert(srcParts + 1 == dstParts);
2477 dst[srcParts] = carry;
2489 for (
unsigned i = dstParts; i < srcParts; i++)
2502 const WordType *rhs,
unsigned parts) {
2503 assert(dst != lhs && dst != rhs);
2506 tcSet(dst, 0, parts);
2508 for (
unsigned i = 0; i < parts; i++)
2518 const WordType *rhs,
unsigned lhsParts,
2519 unsigned rhsParts) {
2521 if (lhsParts > rhsParts)
2524 assert(dst != lhs && dst != rhs);
2526 tcSet(dst, 0, rhsParts);
2528 for (
unsigned i = 0; i < lhsParts; i++)
2529 tcMultiplyPart(&dst[i], rhs, lhs[i], 0, rhsParts, rhsParts + 1,
true);
2545 assert(lhs != remainder && lhs != srhs && remainder != srhs);
2547 unsigned shiftCount =
tcMSB(rhs, parts) + 1;
2548 if (shiftCount == 0)
2558 tcSet(lhs, 0, parts);
2569 if (shiftCount == 0)
2573 if ((mask >>= 1) == 0) {
2574 mask = (
WordType) 1 << (APINT_BITS_PER_WORD - 1);
2594 if (BitShift == 0) {
2597 while (Words-- > WordShift) {
2598 Dst[Words] = Dst[Words - WordShift] << BitShift;
2599 if (Words > WordShift)
2620 unsigned WordsToMove = Words - WordShift;
2622 if (BitShift == 0) {
2625 for (
unsigned i = 0; i != WordsToMove; ++i) {
2626 Dst[i] = Dst[i + WordShift] >> BitShift;
2627 if (i + 1 != WordsToMove)
2638 for (
unsigned i = 0; i < parts; i++)
2644 for (
unsigned i = 0; i < parts; i++)
2650 for (
unsigned i = 0; i < parts; i++)
2656 for (
unsigned i = 0; i < parts; i++)
2665 if (lhs[parts] != rhs[parts])
2666 return (lhs[parts] > rhs[parts]) ? 1 : -1;
2739 unsigned RangeWidth) {
2742 assert(RangeWidth <= CoeffWidth &&
2743 "Value range width should be less than coefficient width");
2744 assert(RangeWidth > 1 &&
"Value range bit width should be > 1");
2746 LLVM_DEBUG(
dbgs() << __func__ <<
": solving " << A <<
"x^2 + " << B
2747 <<
"x + " << C <<
", rw:" << RangeWidth <<
'\n');
2752 return APInt(CoeffWidth, 0);
2770 A = A.
sext(CoeffWidth);
2771 B = B.
sext(CoeffWidth);
2772 C = C.
sext(CoeffWidth);
2812 if (T.isNullValue())
2819 if (B.isNonNegative()) {
2836 LowkR = RoundUp(LowkR, R);
2846 C -= -RoundUp(-C, R);
2863 LLVM_DEBUG(
dbgs() << __func__ <<
": updated coefficients " << A <<
"x^2 + " 2864 << B <<
"x + " << C <<
", rw:" << RangeWidth <<
'\n');
2871 bool InexactSQ = Q !=
D;
2897 LLVM_DEBUG(
dbgs() << __func__ <<
": solution (root): " << X <<
'\n');
2901 assert((SQ*SQ).
sle(D) &&
"SQ = |_sqrt(D)_|, so SQ*SQ <= D");
2910 APInt VX = (A*X +
B)*X + C;
2911 APInt VY = VX + TwoA*X + A +
B;
2923 LLVM_DEBUG(
dbgs() << __func__ <<
": solution (wrap): " << X <<
'\n');
APInt abs() const
Get the absolute value;.
static void tcOr(WordType *, const WordType *, unsigned)
static APInt::WordType lowHalf(APInt::WordType part)
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.
static void r2(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
T findLastSet(T Val, ZeroBehavior ZB=ZB_Max)
Get the index of the last set bit starting from the least significant bit.
uint64_t getZExtValue() const
Get zero extended value.
APInt sext(unsigned width) const
Sign extend to a new width.
APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A unsign-divided by B, rounded by the given rounding mode.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
void Profile(FoldingSetNodeID &id) const
Used to insert APInt objects, or objects that contain APInt objects, into FoldingSets.
APInt & operator+=(const APInt &RHS)
Addition assignment operator.
This class represents lattice values for constants.
void toStringUnsigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be unsigned and converts it into a string in the radix given.
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...
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
static uint64_t * getMemory(unsigned numWords)
A utility function for allocating memory and checking for allocation failure.
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
unsigned getNumWords() const
Get the number of words.
static unsigned getBitsNeeded(StringRef str, uint8_t radix)
Get bits required for string value.
void push_back(const T &Elt)
APInt sshl_ov(const APInt &Amt, bool &Overflow) const
static int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
APInt zext(unsigned width) const
Zero extend to a new width.
APInt uadd_sat(const APInt &RHS) const
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static void tcSetLeastSignificantBits(WordType *, unsigned, unsigned bits)
Set the least significant BITS and clear the rest.
static int tcMultiply(WordType *, const WordType *, const WordType *, unsigned)
DST = LHS * RHS, where DST has the same width as the operands and is filled with the least significan...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static uint64_t round(uint64_t Acc, uint64_t Input)
void toStringSigned(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be signed and converts it into a string in the radix given.
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t *r, unsigned m, unsigned n)
Implementation of Knuth's Algorithm D (Division of nonnegative integers) from "Art of Computer Progra...
static int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
APInt trunc(unsigned width) const
Truncate to new width.
APInt ushl_ov(const APInt &Amt, bool &Overflow) const
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A sign-divided by B, rounded by the given rounding mode.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
void dump() const
debug method
APInt GreatestCommonDivisor(APInt A, APInt B)
Compute GCD of two unsigned APInt values.
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
Magic data for optimising unsigned division by a constant.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static uint64_t allOnes(unsigned int Count)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
ms magic() const
Calculate the magic numbers required to implement a signed integer division by a constant as a sequen...
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
void setBit(unsigned BitPosition)
Set a given bit to 1.
APInt & operator*=(const APInt &RHS)
Multiplication assignment operator.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
APInt shl(unsigned shiftAmt) const
Left-shift function.
APInt()
Default constructor that creates an uninteresting APInt representing a 1-bit zero value...
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
APInt rotr(unsigned rotateAmt) const
Rotate right by rotateAmt.
uint64_t VAL
Used to store the <= 64 bits integer value.
static WordType tcAddPart(WordType *, WordType, unsigned)
DST += RHS. Returns the carry flag.
static APInt::WordType lowBitMask(unsigned bits)
double roundToDouble() const
Converts this unsigned APInt to a double value.
void AddInteger(signed I)
uint32_t ByteSwap_32(uint32_t Value)
Return a byte-swapped representation of the 32-bit argument.
APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
This file implements a class to represent arbitrary precision integral constant values and operations...
div rem Hoist decompose integer division and remainder
std::error_code fromString(std::string String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
StringRef str() const
Explicit conversion to StringRef.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
unsigned getActiveBits() const
Compute the number of active bits in the value.
void ashrInPlace(unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
int64_t getSExtValue() const
Get sign extended value.
bool getBoolValue() const
Convert APInt to a boolean value.
uint16_t ByteSwap_16(uint16_t Value)
Return a byte-swapped representation of the 16-bit argument.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static void tcXor(WordType *, const WordType *, unsigned)
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
APInt sqrt() const
Compute the square root.
APInt reverseBits() const
APInt & operator--()
Prefix decrement operator.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
bool isNegative() const
Determine sign of this APInt.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
bool isAllOnesValue() const
Determine if all bits are set.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
size_t size() const
size - Get the array size.
void flipBit(unsigned bitPosition)
Toggles a given bit to its opposite value.
static void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
APInt multiplicativeInverse(const APInt &modulo) const
Computes the multiplicative inverse of this APInt for a given modulo.
static WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
static const WordType WORDTYPE_MAX
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
mu magicu(unsigned LeadingZeros=0) const
Calculate the magic numbers required to implement an unsigned integer division by a constant as a seq...
The returned value is numeric_limits<T>::max()
static int tcDivide(WordType *lhs, const WordType *rhs, WordType *remainder, WordType *scratch, unsigned parts)
If RHS is zero LHS and REMAINDER are left unchanged, return one.
static WordType tcSubtractPart(WordType *, WordType, unsigned)
DST -= RHS. Returns the carry flag.
static void tcComplement(WordType *, unsigned)
static void r1(uint32_t &A, uint32_t &B, uint32_t &C, uint32_t &D, uint32_t &E, int I, uint32_t *Buf)
bool isSplat(unsigned SplatSizeInBits) const
Check if the APInt consists of a repeated bit pattern.
static WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
T findFirstSet(T Val, ZeroBehavior ZB=ZB_Max)
Get the index of the first set bit starting from the least significant bit.
APInt ssub_sat(const APInt &RHS) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts...
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
static unsigned rotateModulo(unsigned BitWidth, const APInt &rotateAmt)
unsigned countPopulation(T Value)
Count the number of set bits in a value.
static unsigned partLSB(APInt::WordType value)
APInt & operator++()
Prefix increment operator.
static void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
static void tcAnd(WordType *, const WordType *, unsigned)
The obvious AND, OR and XOR and complement operations.
APInt rotl(unsigned rotateAmt) const
Rotate left by rotateAmt.
void negate()
Negate this APInt in place.
static APInt::WordType highHalf(APInt::WordType part)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
void print(raw_ostream &OS, bool isSigned) const
unsigned logBase2() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The access may modify the value stored in memory.
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
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.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static unsigned getDigit(char cdigit, uint8_t radix)
A utility function that converts a character to a digit.
APInt & operator-=(const APInt &RHS)
Subtraction assignment operator.
amdgpu Simplify well known AMD library false Value Value * Arg
static void tcNegate(WordType *, unsigned)
Negate a bignum in-place.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
Magic data for optimising signed division by a constant.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
uint64_t ByteSwap_64(uint64_t Value)
Return a byte-swapped representation of the 64-bit argument.
APInt smul_ov(const APInt &RHS, bool &Overflow) const
Optional< APInt > SolveQuadraticEquationWrap(APInt A, APInt B, APInt C, unsigned RangeWidth)
Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
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.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
int compare(DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
Compare two scaled numbers.
To bit_cast(const From &from) noexcept
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
APInt operator*(const APInt &RHS) const
Multiplication operator.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit 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)
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
constexpr uint64_t Make_64(uint32_t High, uint32_t Low)
Make a 64-bit integer from a high / low pair of 32-bit integers.
This class implements an extremely fast bulk output stream that can only output to a stream...
static void tcSetBit(WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
APInt usub_sat(const APInt &RHS) const
APInt & operator<<=(unsigned ShiftAmt)
Left-shift assignment function.
StringRef - Represent a constant reference to a string, i.e.
unsigned countLeadingOnes() const
Count the number of leading one bits.
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...
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
static void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
APInt sadd_sat(const APInt &RHS) const
APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
static unsigned partMSB(APInt::WordType value)
void toString(SmallVectorImpl< char > &Str, unsigned Radix, bool Signed, bool formatAsCLiteral=false) const
Converts an APInt to a string and append it to Str.
std::size_t countLeadingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the most significant bit to the first zero bit.
APInt sextOrSelf(unsigned width) const
Sign extend or truncate to width.
uint64_t * pVal
Used to store the >64 bits integer value.
bool isNullValue() const
Determine if all bits are clear.
static uint64_t * getClearedMemory(unsigned numWords)
A utility function for allocating memory, checking for allocation failures, and ensuring the contents...
APInt sdiv_ov(const APInt &RHS, bool &Overflow) const
APInt usub_ov(const APInt &RHS, bool &Overflow) const