21 #include "llvm/Config/llvm-config.h" 32 #define DEBUG_TYPE "apint" 37 uint64_t *result =
new uint64_t[numWords];
38 memset(result, 0, numWords *
sizeof(uint64_t));
44 inline static uint64_t*
getMemory(
unsigned numWords) {
45 return new uint64_t[numWords];
49 inline static unsigned getDigit(
char cdigit, uint8_t radix) {
52 if (radix == 16 || radix == 36) {
76 void APInt::initSlowCase(uint64_t val,
bool isSigned) {
79 if (isSigned && int64_t(val) < 0)
85 void APInt::initSlowCase(
const APInt& that) {
91 assert(BitWidth &&
"Bitwidth too small");
92 assert(bigVal.
data() &&
"Null pointer detected!");
108 : BitWidth(numBits) {
109 initFromArray(bigVal);
112 APInt::APInt(
unsigned numBits,
unsigned numWords,
const uint64_t bigVal[])
113 : BitWidth(numBits) {
118 : BitWidth(numbits) {
119 assert(BitWidth &&
"Bitwidth too small");
120 fromString(numbits, Str, radix);
123 void APInt::reallocate(
unsigned NewBitWidth) {
126 BitWidth = NewBitWidth;
135 BitWidth = NewBitWidth;
142 void APInt::AssignSlowCase(
const APInt& RHS) {
161 if (isSingleWord()) {
167 for (
unsigned i = 0; i < NumWords; ++i)
177 return clearUnusedBits();
186 return clearUnusedBits();
193 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
198 return clearUnusedBits();
206 return clearUnusedBits();
213 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
218 return clearUnusedBits();
226 return clearUnusedBits();
230 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
232 return APInt(BitWidth, U.VAL * RHS.U.
VAL);
238 Result.clearUnusedBits();
242 void APInt::AndAssignSlowCase(
const APInt& RHS) {
246 void APInt::OrAssignSlowCase(
const APInt& RHS) {
250 void APInt::XorAssignSlowCase(
const APInt& RHS) {
255 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
261 if (isSingleWord()) {
265 tcMultiplyPart(U.pVal, U.pVal, RHS, 0, NumWords, NumWords,
false);
267 return clearUnusedBits();
270 bool APInt::EqualSlowCase(
const APInt& RHS)
const {
274 int APInt::compare(
const APInt& RHS)
const {
275 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be same for comparison");
277 return U.VAL < RHS.U.
VAL ? -1 : U.VAL > RHS.U.
VAL;
282 int APInt::compareSigned(
const APInt& RHS)
const {
283 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be same for comparison");
284 if (isSingleWord()) {
287 return lhsSext < rhsSext ? -1 : lhsSext > rhsSext;
294 if (lhsNeg != rhsNeg)
295 return lhsNeg ? -1 : 1;
302 void APInt::setBitsSlowCase(
unsigned loBit,
unsigned hiBit) {
303 unsigned loWord = whichWord(loBit);
304 unsigned hiWord = whichWord(hiBit);
307 uint64_t loMask =
WORD_MAX << whichBit(loBit);
310 unsigned hiShiftAmt = whichBit(hiBit);
311 if (hiShiftAmt != 0) {
316 if (hiWord == loWord)
319 U.pVal[hiWord] |= hiMask;
322 U.pVal[loWord] |= loMask;
325 for (
unsigned word = loWord + 1; word < hiWord; ++word)
330 void APInt::flipAllBitsSlowCase() {
339 assert(bitPosition < BitWidth &&
"Out of the bit-width range!");
340 if ((*
this)[bitPosition])
clearBit(bitPosition);
346 assert(0 < subBitWidth && (subBitWidth + bitPosition) <= BitWidth &&
347 "Illegal bit insertion");
350 if (subBitWidth == BitWidth) {
356 if (isSingleWord()) {
358 U.VAL &= ~(mask << bitPosition);
359 U.VAL |= (subBits.U.
VAL << bitPosition);
363 unsigned loBit = whichBit(bitPosition);
364 unsigned loWord = whichWord(bitPosition);
365 unsigned hi1Word = whichWord(bitPosition + subBitWidth - 1);
368 if (loWord == hi1Word) {
370 U.pVal[loWord] &= ~(mask << loBit);
371 U.pVal[loWord] |= (subBits.U.
VAL << loBit);
384 if (remainingBits != 0) {
386 U.pVal[hi1Word] &= ~mask;
387 U.pVal[hi1Word] |= subBits.getWord(subBitWidth - 1);
395 for (
unsigned i = 0; i != subBitWidth; ++i) {
404 assert(numBits > 0 &&
"Can't extract zero bits");
405 assert(bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth &&
406 "Illegal bit extraction");
409 return APInt(numBits, U.VAL >> bitPosition);
411 unsigned loBit = whichBit(bitPosition);
412 unsigned loWord = whichWord(bitPosition);
413 unsigned hiWord = whichWord(bitPosition + numBits - 1);
416 if (loWord == hiWord)
417 return APInt(numBits, U.pVal[loWord] >> loBit);
429 uint64_t *DestPtr = Result.isSingleWord() ? &Result.U.
VAL : Result.U.
pVal;
430 for (
unsigned word = 0; word < NumDstWords; ++word) {
431 uint64_t w0 = U.pVal[loWord + word];
433 (loWord + word + 1) < NumSrcWords ? U.pVal[loWord + word + 1] : 0;
437 return Result.clearUnusedBits();
442 assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
444 "Radix should be 2, 8, 10, 16, or 36!");
446 size_t slen = str.
size();
451 if (*p ==
'-' || *p ==
'+') {
454 assert(slen &&
"String is only a sign, needs a value.");
477 = radix == 10? (slen == 1 ? 4 : slen * 64/18)
478 : (slen == 1 ? 7 : slen * 16/3);
486 if (log == (
unsigned)-1) {
487 return isNegative + 1;
489 return isNegative + log + 1;
494 if (Arg.isSingleWord())
502 "SplatSizeInBits must divide width!");
505 return *
this ==
rotl(SplatSizeInBits);
510 return this->
lshr(BitWidth - numBits);
531 unsigned APInt::countLeadingZerosSlowCase()
const {
534 uint64_t V = U.pVal[i];
548 unsigned APInt::countLeadingOnesSlowCase()
const {
559 if (Count == highWordBits) {
560 for (i--; i >= 0; --i) {
572 unsigned APInt::countTrailingZerosSlowCase()
const {
579 return std::min(Count, BitWidth);
582 unsigned APInt::countTrailingOnesSlowCase()
const {
589 assert(Count <= BitWidth);
593 unsigned APInt::countPopulationSlowCase()
const {
600 bool APInt::intersectsSlowCase(
const APInt &RHS)
const {
601 for (
unsigned i = 0, e =
getNumWords(); i != e; ++i)
602 if ((U.pVal[i] & RHS.U.
pVal[i]) != 0)
608 bool APInt::isSubsetOfSlowCase(
const APInt &RHS)
const {
609 for (
unsigned i = 0, e =
getNumWords(); i != e; ++i)
610 if ((U.pVal[i] & ~RHS.U.
pVal[i]) != 0)
617 assert(BitWidth >= 16 && BitWidth % 16 == 0 &&
"Cannot byteswap!");
622 if (BitWidth == 48) {
623 unsigned Tmp1 =
unsigned(U.VAL >> 16);
625 uint16_t Tmp2 = uint16_t(U.VAL);
627 return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
635 if (Result.BitWidth != BitWidth) {
637 Result.BitWidth = BitWidth;
645 return APInt(BitWidth, llvm::reverseBits<uint64_t>(U.VAL));
647 return APInt(BitWidth, llvm::reverseBits<uint32_t>(U.VAL));
649 return APInt(BitWidth, llvm::reverseBits<uint16_t>(U.VAL));
651 return APInt(BitWidth, llvm::reverseBits<uint8_t>(U.VAL));
657 APInt Reversed(BitWidth, 0);
658 unsigned S = BitWidth;
672 if (A == B)
return A;
683 if (Pow2_A > Pow2_B) {
686 }
else if (Pow2_B > Pow2_A) {
721 bool isNeg =
T.I >> 63;
724 int64_t exp = ((
T.I >> 52) & 0x7ff) - 1023;
728 return APInt(width, 0u);
731 uint64_t mantissa = (
T.I & (~0ULL >> 12)) | 1ULL << 52;
735 return isNeg ? -
APInt(width, mantissa >> (52 - exp)) :
736 APInt(width, mantissa >> (52 - exp));
740 if (width <= exp - 52)
741 return APInt(width, 0);
744 APInt Tmp(width, mantissa);
746 return isNeg ? -Tmp : Tmp;
765 return double(getWord(0));
769 bool isNeg = isSigned ? (*this)[BitWidth-1] :
false;
772 APInt Tmp(isNeg ? -(*
this) : (*
this));
784 if (!isSigned || !isNeg)
785 return std::numeric_limits<double>::infinity();
787 return -std::numeric_limits<double>::infinity();
794 unsigned hiWord = whichWord(n-1);
796 mantissa = Tmp.U.
pVal[0];
800 assert(hiWord > 0 &&
"huh?");
803 mantissa = hibits | lobits;
812 T.I = sign | (exp << 52) | mantissa;
818 assert(width < BitWidth &&
"Invalid APInt Truncate request");
819 assert(width &&
"Can't truncate to 0 bits");
829 Result.U.
pVal[i] = U.pVal[i];
841 assert(Width > BitWidth &&
"Invalid APInt SignExtend request");
859 Result.clearUnusedBits();
865 assert(width > BitWidth &&
"Invalid APInt ZeroExtend request");
868 return APInt(width, U.VAL);
883 if (BitWidth < width)
885 if (BitWidth > width)
891 if (BitWidth < width)
893 if (BitWidth > width)
899 if (BitWidth < width)
905 if (BitWidth < width)
918 void APInt::ashrSlowCase(
unsigned ShiftAmt) {
931 if (WordsToMove != 0) {
938 std::memmove(U.pVal, U.pVal + WordShift, WordsToMove *
APINT_WORD_SIZE);
941 for (
unsigned i = 0; i != WordsToMove - 1; ++i)
942 U.pVal[i] = (U.pVal[i + WordShift] >> BitShift) |
946 U.pVal[WordsToMove - 1] = U.pVal[WordShift + WordsToMove - 1] >> BitShift;
948 U.pVal[WordsToMove - 1] =
954 std::memset(U.pVal + WordsToMove, Negative ? -1 : 0,
967 void APInt::lshrSlowCase(
unsigned ShiftAmt) {
979 void APInt::shlSlowCase(
unsigned ShiftAmt) {
987 APInt rot = rotateAmt;
988 if (rotBitWidth < BitWidth) {
991 rot = rotateAmt.
zext(BitWidth);
1002 rotateAmt %= BitWidth;
1005 return shl(rotateAmt) |
lshr(BitWidth - rotateAmt);
1013 rotateAmt %= BitWidth;
1016 return lshr(rotateAmt) |
shl(BitWidth - rotateAmt);
1033 if (magnitude <= 5) {
1034 static const uint8_t results[32] = {
1039 4, 4, 4, 4, 4, 4, 4, 4,
1040 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1043 return APInt(BitWidth, results[ (isSingleWord() ? U.VAL : U.pVal[0]) ]);
1050 if (magnitude < 52) {
1051 return APInt(BitWidth,
1052 uint64_t(::
round(::
sqrt(
double(isSingleWord() ? U.VAL
1061 unsigned nbits = BitWidth, i = 4;
1062 APInt testy(BitWidth, 16);
1063 APInt x_old(BitWidth, 1);
1064 APInt x_new(BitWidth, 0);
1065 APInt two(BitWidth, 2);
1068 for (;; i += 2, testy = testy.
shl(2))
1069 if (i >= nbits || this->
ule(testy)) {
1070 x_old = x_old.
shl(i / 2);
1076 x_new = (this->
udiv(x_old) + x_old).
udiv(two);
1077 if (x_old.
ule(x_new))
1088 APInt square(x_old * x_old);
1089 APInt nextSquare((x_old + 1) * (x_old +1));
1090 if (this->
ult(square))
1092 assert(this->
ule(nextSquare) &&
"Error in APInt::sqrt computation");
1093 APInt midpoint((nextSquare - square).
udiv(two));
1094 APInt offset(*
this - square);
1095 if (offset.
ult(midpoint))
1106 assert(
ult(modulo) &&
"This APInt must be smaller than the modulo");
1116 APInt r[2] = { modulo, *
this };
1118 APInt q(BitWidth, 0);
1121 for (i = 0; r[i^1] != 0; i ^= 1) {
1126 udivrem(r[i], r[i^1], q, r[i]);
1135 return APInt(BitWidth, 0);
1144 return std::move(t[i]);
1152 const APInt& d = *
this;
1154 APInt ad, anc, delta, q1,
r1, q2,
r2, t;
1160 anc = t - 1 - t.
urem(ad);
1162 q1 = signedMin.
udiv(anc);
1163 r1 = signedMin - q1*anc;
1164 q2 = signedMin.
udiv(ad);
1165 r2 = signedMin - q2*ad;
1181 }
while (q1.
ult(delta) || (q1 == delta && r1 == 0));
1196 const APInt& d = *
this;
1205 nc = allOnes - (allOnes - d).
urem(d);
1207 q1 = signedMin.
udiv(nc);
1208 r1 = signedMin - q1*nc;
1209 q2 = signedMax.
udiv(d);
1210 r2 = signedMax - q2*d;
1213 if (r1.
uge(nc - r1)) {
1221 if ((r2 + 1).uge(d - r2)) {
1222 if (q2.
uge(signedMax)) magu.
a = 1;
1227 if (q2.
uge(signedMin)) magu.
a = 1;
1232 }
while (p < d.getBitWidth()*2 &&
1233 (q1.
ult(delta) || (q1 == delta && r1 == 0)));
1235 magu.
s = p - d.getBitWidth();
1244 unsigned m,
unsigned n) {
1245 assert(u &&
"Must provide dividend");
1246 assert(v &&
"Must provide divisor");
1247 assert(q &&
"Must provide quotient");
1248 assert(u != v && u != q && v != q &&
"Must use different memory");
1249 assert(n>1 &&
"n must be > 1");
1252 const uint64_t b = uint64_t(1) << 32;
1256 #pragma push_macro("LLVM_DEBUG") 1259 #define LLVM_DEBUG(X) \ 1266 LLVM_DEBUG(
for (
int i = m + n; i >= 0; i--)
dbgs() <<
" " << u[i]);
1268 LLVM_DEBUG(
for (
int i = n; i > 0; i--)
dbgs() <<
" " << v[i - 1]);
1282 for (
unsigned i = 0; i < m+n; ++i) {
1283 uint32_t u_tmp = u[i] >> (32 - shift);
1284 u[i] = (u[i] << shift) | u_carry;
1287 for (
unsigned i = 0; i < n; ++i) {
1288 uint32_t v_tmp = v[i] >> (32 - shift);
1289 v[i] = (v[i] << shift) | v_carry;
1296 LLVM_DEBUG(
for (
int i = m + n; i >= 0; i--)
dbgs() <<
" " << u[i]);
1298 LLVM_DEBUG(
for (
int i = n; i > 0; i--)
dbgs() <<
" " << v[i - 1]);
1313 uint64_t dividend =
Make_64(u[j+n], u[j+n-1]);
1314 LLVM_DEBUG(
dbgs() <<
"KnuthDiv: dividend == " << dividend <<
'\n');
1315 uint64_t qp = dividend / v[n-1];
1316 uint64_t rp = dividend % v[n-1];
1317 if (qp == b || qp*v[n-2] > b*rp + u[j+n-2]) {
1320 if (rp < b && (qp == b || qp*v[n-2] > b*rp + u[j+n-2]))
1323 LLVM_DEBUG(
dbgs() <<
"KnuthDiv: qp == " << qp <<
", rp == " << rp <<
'\n');
1334 for (
unsigned i = 0; i < n; ++i) {
1335 uint64_t p = uint64_t(qp) * uint64_t(v[i]);
1336 int64_t subres = int64_t(u[j+i]) - borrow -
Lo_32(p);
1337 u[j+i] =
Lo_32(subres);
1340 <<
", borrow = " << borrow <<
'\n');
1342 bool isNeg = u[j+n] < borrow;
1343 u[j+n] -=
Lo_32(borrow);
1346 LLVM_DEBUG(
for (
int i = m + n; i >= 0; i--)
dbgs() <<
" " << u[i]);
1361 for (
unsigned i = 0; i < n; i++) {
1362 uint32_t limit = std::min(u[j+i],v[i]);
1363 u[j+i] += v[i] + carry;
1364 carry = u[j+i] < limit || (carry && u[j+i] == limit);
1369 LLVM_DEBUG(
for (
int i = m + n; i >= 0; i--)
dbgs() <<
" " << u[i]);
1370 LLVM_DEBUG(
dbgs() <<
"\nKnuthDiv: digit result = " << q[j] <<
'\n');
1389 for (
int i = n-1; i >= 0; i--) {
1390 r[i] = (u[i] >> shift) | carry;
1391 carry = u[i] << (32 - shift);
1395 for (
int i = n-1; i >= 0; i--) {
1404 #pragma pop_macro("LLVM_DEBUG") 1407 void APInt::divide(
const WordType *LHS,
unsigned lhsWords,
const WordType *RHS,
1409 assert(lhsWords >= rhsWords &&
"Fractional result");
1418 unsigned n = rhsWords * 2;
1419 unsigned m = (lhsWords * 2) - n;
1428 if ((Remainder?4:3)*n+2*m+1 <= 128) {
1431 Q = &SPACE[(m+n+1) + n];
1433 R = &SPACE[(m+n+1) + n + (m+n)];
1443 memset(U, 0, (m+n+1)*
sizeof(
uint32_t));
1444 for (
unsigned i = 0; i < lhsWords; ++i) {
1445 uint64_t tmp = LHS[i];
1446 U[i * 2] =
Lo_32(tmp);
1447 U[i * 2 + 1] =
Hi_32(tmp);
1452 memset(V, 0, (n)*
sizeof(
uint32_t));
1453 for (
unsigned i = 0; i < rhsWords; ++i) {
1454 uint64_t tmp = RHS[i];
1455 V[i * 2] =
Lo_32(tmp);
1456 V[i * 2 + 1] =
Hi_32(tmp);
1460 memset(Q, 0, (m+n) *
sizeof(
uint32_t));
1462 memset(R, 0, n *
sizeof(
uint32_t));
1468 for (
unsigned i = n; i > 0 && V[i-1] == 0; i--) {
1472 for (
unsigned i = m+n; i > 0 && U[i-1] == 0; i--)
1481 assert(n != 0 &&
"Divide by zero?");
1485 for (
int i = m; i >= 0; i--) {
1486 uint64_t partial_dividend =
Make_64(remainder, U[i]);
1487 if (partial_dividend == 0) {
1490 }
else if (partial_dividend < divisor) {
1492 remainder =
Lo_32(partial_dividend);
1493 }
else if (partial_dividend == divisor) {
1497 Q[i] =
Lo_32(partial_dividend / divisor);
1498 remainder =
Lo_32(partial_dividend - (Q[i] * divisor));
1511 for (
unsigned i = 0; i < lhsWords; ++i)
1512 Quotient[i] =
Make_64(Q[i*2+1], Q[i*2]);
1517 for (
unsigned i = 0; i < rhsWords; ++i)
1518 Remainder[i] =
Make_64(R[i*2+1], R[i*2]);
1522 if (U != &SPACE[0]) {
1531 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1534 if (isSingleWord()) {
1535 assert(RHS.U.
VAL != 0 &&
"Divide by zero?");
1536 return APInt(BitWidth, U.VAL / RHS.U.
VAL);
1543 assert(rhsWords &&
"Divided by zero???");
1548 return APInt(BitWidth, 0);
1552 if (lhsWords < rhsWords || this->
ult(RHS))
1554 return APInt(BitWidth, 0);
1557 return APInt(BitWidth, 1);
1560 return APInt(BitWidth, this->U.pVal[0] / RHS.U.
pVal[0]);
1563 APInt Quotient(BitWidth, 0);
1564 divide(U.pVal, lhsWords, RHS.U.
pVal, rhsWords, Quotient.U.
pVal,
nullptr);
1569 assert(RHS != 0 &&
"Divide by zero?");
1573 return APInt(BitWidth, U.VAL / RHS);
1581 return APInt(BitWidth, 0);
1587 return APInt(BitWidth, 0);
1590 return APInt(BitWidth, 1);
1593 return APInt(BitWidth, this->U.pVal[0] / RHS);
1596 APInt Quotient(BitWidth, 0);
1597 divide(U.pVal, lhsWords, &RHS, 1, Quotient.U.
pVal,
nullptr);
1604 return (-(*
this)).
udiv(-RHS);
1605 return -((-(*this)).
udiv(RHS));
1608 return -(this->
udiv(-RHS));
1609 return this->
udiv(RHS);
1615 return (-(*
this)).
udiv(-RHS);
1616 return -((-(*this)).
udiv(RHS));
1619 return -(this->
udiv(-RHS));
1620 return this->
udiv(RHS);
1624 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1625 if (isSingleWord()) {
1626 assert(RHS.U.
VAL != 0 &&
"Remainder by zero?");
1627 return APInt(BitWidth, U.VAL % RHS.U.
VAL);
1636 assert(rhsWords &&
"Performing remainder operation by zero ???");
1641 return APInt(BitWidth, 0);
1644 return APInt(BitWidth, 0);
1645 if (lhsWords < rhsWords || this->
ult(RHS))
1650 return APInt(BitWidth, 0);
1653 return APInt(BitWidth, U.pVal[0] % RHS.U.
pVal[0]);
1656 APInt Remainder(BitWidth, 0);
1657 divide(U.pVal, lhsWords, RHS.U.
pVal, rhsWords,
nullptr, Remainder.U.
pVal);
1662 assert(RHS != 0 &&
"Remainder by zero?");
1685 return U.pVal[0] % RHS;
1689 divide(U.pVal, lhsWords, &RHS, 1,
nullptr, &Remainder);
1696 return -((-(*
this)).urem(-RHS));
1697 return -((-(*this)).
urem(RHS));
1700 return this->
urem(-RHS);
1701 return this->
urem(RHS);
1707 return -((-(*this)).
urem(-RHS));
1708 return -((-(*this)).
urem(RHS));
1711 return this->
urem(-RHS);
1712 return this->
urem(RHS);
1717 assert(LHS.BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1718 unsigned BitWidth = LHS.BitWidth;
1721 if (LHS.isSingleWord()) {
1722 assert(RHS.U.
VAL != 0 &&
"Divide by zero?");
1723 uint64_t QuotVal = LHS.U.
VAL / RHS.U.
VAL;
1724 uint64_t RemVal = LHS.U.
VAL % RHS.U.
VAL;
1725 Quotient =
APInt(BitWidth, QuotVal);
1726 Remainder =
APInt(BitWidth, RemVal);
1734 assert(rhsWords &&
"Performing divrem operation by zero ???");
1737 if (lhsWords == 0) {
1738 Quotient =
APInt(BitWidth, 0);
1739 Remainder =
APInt(BitWidth, 0);
1745 Remainder =
APInt(BitWidth, 0);
1748 if (lhsWords < rhsWords || LHS.
ult(RHS)) {
1750 Quotient =
APInt(BitWidth, 0);
1755 Quotient =
APInt(BitWidth, 1);
1756 Remainder =
APInt(BitWidth, 0);
1764 Quotient.reallocate(BitWidth);
1765 Remainder.reallocate(BitWidth);
1767 if (lhsWords == 1) {
1769 uint64_t lhsValue = LHS.U.
pVal[0];
1770 uint64_t rhsValue = RHS.U.
pVal[0];
1771 Quotient = lhsValue / rhsValue;
1772 Remainder = lhsValue % rhsValue;
1777 divide(LHS.U.
pVal, lhsWords, RHS.U.
pVal, rhsWords, Quotient.U.
pVal,
1780 std::memset(Quotient.U.
pVal + lhsWords, 0,
1782 std::memset(Remainder.U.
pVal + rhsWords, 0,
1783 (
getNumWords(BitWidth) - rhsWords) * APINT_WORD_SIZE);
1787 uint64_t &Remainder) {
1788 assert(RHS != 0 &&
"Divide by zero?");
1789 unsigned BitWidth = LHS.BitWidth;
1792 if (LHS.isSingleWord()) {
1793 uint64_t QuotVal = LHS.U.
VAL / RHS;
1794 Remainder = LHS.U.
VAL % RHS;
1795 Quotient =
APInt(BitWidth, QuotVal);
1803 if (lhsWords == 0) {
1804 Quotient =
APInt(BitWidth, 0);
1817 Quotient =
APInt(BitWidth, 0);
1822 Quotient =
APInt(BitWidth, 1);
1830 Quotient.reallocate(BitWidth);
1832 if (lhsWords == 1) {
1834 uint64_t lhsValue = LHS.U.
pVal[0];
1835 Quotient = lhsValue / RHS;
1836 Remainder = lhsValue % RHS;
1841 divide(LHS.U.
pVal, lhsWords, &RHS, 1, Quotient.U.
pVal, &Remainder);
1843 std::memset(Quotient.U.
pVal + lhsWords, 0,
1866 APInt &Quotient, int64_t &Remainder) {
1867 uint64_t
R = Remainder;
1876 }
else if (RHS < 0) {
1886 APInt Res = *
this+RHS;
1893 APInt Res = *
this+RHS;
1894 Overflow = Res.
ult(RHS);
1899 APInt Res = *
this - RHS;
1906 APInt Res = *
this-RHS;
1907 Overflow = Res.
ugt(*
this);
1918 APInt Res = *
this * RHS;
1920 if (*
this != 0 && RHS != 0)
1921 Overflow = Res.
sdiv(RHS) != *
this || Res.
sdiv(*
this) != RHS;
1928 APInt Res = *
this * RHS;
1930 if (*
this != 0 && RHS != 0)
1931 Overflow = Res.
udiv(RHS) != *
this || Res.
udiv(*
this) != RHS;
1940 return APInt(BitWidth, 0);
1947 return *
this << ShAmt;
1953 return APInt(BitWidth, 0);
1957 return *
this << ShAmt;
1966 assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
1968 "Radix should be 2, 8, 10, 16, or 36!");
1971 size_t slen = str.
size();
1972 bool isNeg = *p ==
'-';
1973 if (*p ==
'-' || *p ==
'+') {
1976 assert(slen &&
"String is only a sign, needs a value.");
1978 assert((slen <= numbits || radix != 2) &&
"Insufficient bit width");
1979 assert(((slen-1)*3 <= numbits || radix != 8) &&
"Insufficient bit width");
1980 assert(((slen-1)*4 <= numbits || radix != 16) &&
"Insufficient bit width");
1981 assert((((slen-1)*64)/22 <= numbits || radix != 10) &&
1982 "Insufficient bit width");
1991 unsigned shift = (radix == 16 ? 4 : radix == 8 ? 3 : radix == 2 ? 1 : 0);
1995 unsigned digit =
getDigit(*p, radix);
1996 assert(digit < radix &&
"Invalid character in digit string");
2015 bool Signed,
bool formatAsCLiteral)
const {
2016 assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
2018 "Radix should be 2, 8, 10, 16, or 36!");
2021 if (formatAsCLiteral) {
2051 static const char Digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2053 if (isSingleWord()) {
2076 *--BufPtr = Digits[N % Radix];
2099 unsigned StartDig = Str.
size();
2104 if (Radix == 2 || Radix == 8 || Radix == 16) {
2106 unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
2107 unsigned MaskAmt = Radix - 1;
2117 udivrem(Tmp, Radix, Tmp, Digit);
2118 assert(Digit < Radix &&
"divide failed");
2135 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 2140 dbgs() <<
"APInt(" << BitWidth <<
"b, " 2141 << U <<
"u " << S <<
"s)\n";
2147 this->
toString(S, 10, isSigned,
false);
2157 "Part width must be divisible by 2!");
2197 for (
unsigned i = 1; i < parts; i++)
2203 for (
unsigned i = 0; i < parts; i++)
2209 for (
unsigned i = 0; i < parts; i++)
2218 return (parts[whichWord(bit)] & maskBit(bit)) != 0;
2223 parts[whichWord(bit)] |= maskBit(bit);
2228 parts[whichWord(bit)] &= ~maskBit(bit);
2234 for (
unsigned i = 0; i < n; i++) {
2235 if (parts[i] != 0) {
2236 unsigned lsb =
partLSB(parts[i]);
2251 if (parts[n] != 0) {
2252 unsigned msb =
partMSB(parts[n]);
2267 unsigned srcBits,
unsigned srcLSB) {
2269 assert(dstParts <= dstCount);
2272 tcAssign (dst, src + firstSrcPart, dstParts);
2283 dst[dstParts - 1] |= ((src[firstSrcPart + dstParts] & mask)
2285 }
else if (n > srcBits) {
2287 dst[dstParts - 1] &=
lowBitMask (srcBits % APINT_BITS_PER_WORD);
2291 while (dstParts < dstCount)
2292 dst[dstParts++] = 0;
2300 for (
unsigned i = 0; i < parts; i++) {
2303 dst[i] += rhs[i] + 1;
2320 for (
unsigned i = 0; i < parts; ++i) {
2335 for (
unsigned i = 0; i < parts; i++) {
2338 dst[i] -= rhs[i] + 1;
2358 for (
unsigned i = 0; i < parts; ++i) {
2388 unsigned srcParts,
unsigned dstParts,
2391 assert(dst <= src || dst >= src + srcParts);
2392 assert(dstParts <= srcParts + 1);
2395 unsigned n = std::min(dstParts, srcParts);
2397 for (
unsigned i = 0; i < n; i++) {
2410 if (multiplier == 0 || srcPart == 0) {
2420 if (low + mid < low)
2427 if (low + mid < low)
2432 if (low + carry < low)
2439 if (low + dst[i] < low)
2448 if (srcParts < dstParts) {
2450 assert(srcParts + 1 == dstParts);
2451 dst[srcParts] = carry;
2463 for (
unsigned i = dstParts; i < srcParts; i++)
2476 const WordType *rhs,
unsigned parts) {
2477 assert(dst != lhs && dst != rhs);
2480 tcSet(dst, 0, parts);
2482 for (
unsigned i = 0; i < parts; i++)
2492 const WordType *rhs,
unsigned lhsParts,
2493 unsigned rhsParts) {
2495 if (lhsParts > rhsParts)
2498 assert(dst != lhs && dst != rhs);
2500 tcSet(dst, 0, rhsParts);
2502 for (
unsigned i = 0; i < lhsParts; i++)
2503 tcMultiplyPart(&dst[i], rhs, lhs[i], 0, rhsParts, rhsParts + 1,
true);
2519 assert(lhs != remainder && lhs != srhs && remainder != srhs);
2521 unsigned shiftCount =
tcMSB(rhs, parts) + 1;
2522 if (shiftCount == 0)
2532 tcSet(lhs, 0, parts);
2543 if (shiftCount == 0)
2547 if ((mask >>= 1) == 0) {
2548 mask = (
WordType) 1 << (APINT_BITS_PER_WORD - 1);
2568 if (BitShift == 0) {
2569 std::memmove(Dst + WordShift, Dst, (Words - WordShift) *
APINT_WORD_SIZE);
2571 while (Words-- > WordShift) {
2572 Dst[Words] = Dst[Words - WordShift] << BitShift;
2573 if (Words > WordShift)
2594 unsigned WordsToMove = Words - WordShift;
2596 if (BitShift == 0) {
2599 for (
unsigned i = 0; i != WordsToMove; ++i) {
2600 Dst[i] = Dst[i + WordShift] >> BitShift;
2601 if (i + 1 != WordsToMove)
2612 for (
unsigned i = 0; i < parts; i++)
2618 for (
unsigned i = 0; i < parts; i++)
2624 for (
unsigned i = 0; i < parts; i++)
2630 for (
unsigned i = 0; i < parts; i++)
2639 if (lhs[parts] != rhs[parts])
2640 return (lhs[parts] > rhs[parts]) ? 1 : -1;
APInt abs() const
Get the absolute value;.
static void tcOr(WordType *, const WordType *, unsigned)
void push_back(const T &Elt)
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 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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
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 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.
APInt trunc(unsigned width) const
Truncate to new width.
APInt ushl_ov(const APInt &Amt, bool &Overflow) const
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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.
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.
static const WordType WORD_MAX
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")
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
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.
#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.
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.
static bool isSigned(Value *V)
Can the given value generate sign bits.
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
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.
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 & 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 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.
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