22 #include "llvm/Config/llvm-config.h" 33 #define DEBUG_TYPE "apint" 38 uint64_t *result =
new uint64_t[numWords];
39 memset(result, 0, numWords *
sizeof(uint64_t));
45 inline static uint64_t*
getMemory(
unsigned numWords) {
46 return new uint64_t[numWords];
50 inline static unsigned getDigit(
char cdigit, uint8_t radix) {
53 if (radix == 16 || radix == 36) {
77 void APInt::initSlowCase(uint64_t val,
bool isSigned) {
80 if (isSigned && int64_t(val) < 0)
86 void APInt::initSlowCase(
const APInt& that) {
92 assert(BitWidth &&
"Bitwidth too small");
93 assert(bigVal.
data() &&
"Null pointer detected!");
109 : BitWidth(numBits) {
110 initFromArray(bigVal);
113 APInt::APInt(
unsigned numBits,
unsigned numWords,
const uint64_t bigVal[])
114 : BitWidth(numBits) {
119 : BitWidth(numbits) {
120 assert(BitWidth &&
"Bitwidth too small");
121 fromString(numbits, Str, radix);
124 void APInt::reallocate(
unsigned NewBitWidth) {
127 BitWidth = NewBitWidth;
136 BitWidth = NewBitWidth;
143 void APInt::AssignSlowCase(
const APInt& RHS) {
162 if (isSingleWord()) {
168 for (
unsigned i = 0; i < NumWords; ++i)
178 return clearUnusedBits();
187 return clearUnusedBits();
194 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
199 return clearUnusedBits();
207 return clearUnusedBits();
214 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
219 return clearUnusedBits();
227 return clearUnusedBits();
231 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
233 return APInt(BitWidth, U.VAL * RHS.U.
VAL);
239 Result.clearUnusedBits();
243 void APInt::AndAssignSlowCase(
const APInt& RHS) {
247 void APInt::OrAssignSlowCase(
const APInt& RHS) {
251 void APInt::XorAssignSlowCase(
const APInt& RHS) {
256 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
262 if (isSingleWord()) {
266 tcMultiplyPart(U.pVal, U.pVal, RHS, 0, NumWords, NumWords,
false);
268 return clearUnusedBits();
271 bool APInt::EqualSlowCase(
const APInt& RHS)
const {
275 int APInt::compare(
const APInt& RHS)
const {
276 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be same for comparison");
278 return U.VAL < RHS.U.
VAL ? -1 : U.VAL > RHS.U.
VAL;
283 int APInt::compareSigned(
const APInt& RHS)
const {
284 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be same for comparison");
285 if (isSingleWord()) {
288 return lhsSext < rhsSext ? -1 : lhsSext > rhsSext;
295 if (lhsNeg != rhsNeg)
296 return lhsNeg ? -1 : 1;
303 void APInt::setBitsSlowCase(
unsigned loBit,
unsigned hiBit) {
304 unsigned loWord = whichWord(loBit);
305 unsigned hiWord = whichWord(hiBit);
311 unsigned hiShiftAmt = whichBit(hiBit);
312 if (hiShiftAmt != 0) {
317 if (hiWord == loWord)
320 U.pVal[hiWord] |= hiMask;
323 U.pVal[loWord] |= loMask;
326 for (
unsigned word = loWord + 1; word < hiWord; ++word)
331 void APInt::flipAllBitsSlowCase() {
340 assert(bitPosition < BitWidth &&
"Out of the bit-width range!");
341 if ((*
this)[bitPosition])
clearBit(bitPosition);
347 assert(0 < subBitWidth && (subBitWidth + bitPosition) <= BitWidth &&
348 "Illegal bit insertion");
351 if (subBitWidth == BitWidth) {
357 if (isSingleWord()) {
359 U.VAL &= ~(mask << bitPosition);
360 U.VAL |= (subBits.U.
VAL << bitPosition);
364 unsigned loBit = whichBit(bitPosition);
365 unsigned loWord = whichWord(bitPosition);
366 unsigned hi1Word = whichWord(bitPosition + subBitWidth - 1);
369 if (loWord == hi1Word) {
371 U.pVal[loWord] &= ~(mask << loBit);
372 U.pVal[loWord] |= (subBits.U.
VAL << loBit);
385 if (remainingBits != 0) {
387 U.pVal[hi1Word] &= ~mask;
388 U.pVal[hi1Word] |= subBits.getWord(subBitWidth - 1);
396 for (
unsigned i = 0; i != subBitWidth; ++i) {
405 uint64_t maskBits = maskTrailingOnes<uint64_t>(numBits);
407 if (isSingleWord()) {
408 U.VAL &= ~(maskBits << bitPosition);
409 U.VAL |= subBits << bitPosition;
413 unsigned loBit = whichBit(bitPosition);
414 unsigned loWord = whichWord(bitPosition);
415 unsigned hiWord = whichWord(bitPosition + numBits - 1);
416 if (loWord == hiWord) {
417 U.pVal[loWord] &= ~(maskBits << loBit);
418 U.pVal[loWord] |= subBits << loBit;
422 static_assert(8 *
sizeof(
WordType) <= 64,
"This code assumes only two words affected");
423 unsigned wordBits = 8 *
sizeof(
WordType);
424 U.pVal[loWord] &= ~(maskBits << loBit);
425 U.pVal[loWord] |= subBits << loBit;
427 U.pVal[hiWord] &= ~(maskBits >> (wordBits - loBit));
428 U.pVal[hiWord] |= subBits >> (wordBits - loBit);
432 assert(numBits > 0 &&
"Can't extract zero bits");
433 assert(bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth &&
434 "Illegal bit extraction");
437 return APInt(numBits, U.VAL >> bitPosition);
439 unsigned loBit = whichBit(bitPosition);
440 unsigned loWord = whichWord(bitPosition);
441 unsigned hiWord = whichWord(bitPosition + numBits - 1);
444 if (loWord == hiWord)
445 return APInt(numBits, U.pVal[loWord] >> loBit);
453 APInt Result(numBits, 0);
457 uint64_t *DestPtr = Result.isSingleWord() ? &Result.U.
VAL : Result.U.
pVal;
458 for (
unsigned word = 0; word < NumDstWords; ++word) {
459 uint64_t w0 = U.pVal[loWord + word];
461 (loWord + word + 1) < NumSrcWords ? U.pVal[loWord + word + 1] : 0;
465 return Result.clearUnusedBits();
469 unsigned bitPosition)
const {
470 assert(numBits > 0 &&
"Can't extract zero bits");
471 assert(bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth &&
472 "Illegal bit extraction");
473 assert(numBits <= 64 &&
"Illegal bit extraction");
475 uint64_t maskBits = maskTrailingOnes<uint64_t>(numBits);
477 return (U.VAL >> bitPosition) & maskBits;
479 unsigned loBit = whichBit(bitPosition);
480 unsigned loWord = whichWord(bitPosition);
481 unsigned hiWord = whichWord(bitPosition + numBits - 1);
482 if (loWord == hiWord)
483 return (U.pVal[loWord] >> loBit) & maskBits;
485 static_assert(8 *
sizeof(
WordType) <= 64,
"This code assumes only two words affected");
486 unsigned wordBits = 8 *
sizeof(
WordType);
487 uint64_t retBits = U.pVal[loWord] >> loBit;
488 retBits |= U.pVal[hiWord] << (wordBits - loBit);
495 assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
497 "Radix should be 2, 8, 10, 16, or 36!");
499 size_t slen = str.
size();
504 if (*p ==
'-' || *p ==
'+') {
507 assert(slen &&
"String is only a sign, needs a value.");
530 = radix == 10? (slen == 1 ? 4 : slen * 64/18)
531 : (slen == 1 ? 7 : slen * 16/3);
540 if (log == (
unsigned)-1) {
541 return isNegative + 1;
543 return isNegative + log;
545 return isNegative + log + 1;
550 if (Arg.isSingleWord())
558 "SplatSizeInBits must divide width!");
561 return *
this ==
rotl(SplatSizeInBits);
566 return this->
lshr(BitWidth - numBits);
587 unsigned APInt::countLeadingZerosSlowCase()
const {
590 uint64_t V = U.pVal[i];
604 unsigned APInt::countLeadingOnesSlowCase()
const {
615 if (Count == highWordBits) {
616 for (i--; i >= 0; --i) {
628 unsigned APInt::countTrailingZerosSlowCase()
const {
635 return std::min(Count, BitWidth);
638 unsigned APInt::countTrailingOnesSlowCase()
const {
645 assert(Count <= BitWidth);
649 unsigned APInt::countPopulationSlowCase()
const {
656 bool APInt::intersectsSlowCase(
const APInt &RHS)
const {
658 if ((U.pVal[i] & RHS.U.
pVal[i]) != 0)
664 bool APInt::isSubsetOfSlowCase(
const APInt &RHS)
const {
666 if ((U.pVal[i] & ~RHS.U.
pVal[i]) != 0)
673 assert(BitWidth >= 16 && BitWidth % 16 == 0 &&
"Cannot byteswap!");
678 if (BitWidth == 48) {
679 unsigned Tmp1 =
unsigned(U.VAL >> 16);
683 return APInt(BitWidth, (uint64_t(Tmp2) << 32) | Tmp1);
691 if (Result.BitWidth != BitWidth) {
693 Result.BitWidth = BitWidth;
701 return APInt(BitWidth, llvm::reverseBits<uint64_t>(U.VAL));
703 return APInt(BitWidth, llvm::reverseBits<uint32_t>(U.VAL));
705 return APInt(BitWidth, llvm::reverseBits<uint16_t>(U.VAL));
707 return APInt(BitWidth, llvm::reverseBits<uint8_t>(U.VAL));
713 APInt Reversed(BitWidth, 0);
714 unsigned S = BitWidth;
728 if (A == B)
return A;
739 if (Pow2_A > Pow2_B) {
742 }
else if (Pow2_B > Pow2_A) {
773 bool isNeg = I >> 63;
776 int64_t exp = ((I >> 52) & 0x7ff) - 1023;
780 return APInt(width, 0u);
783 uint64_t mantissa = (I & (~0ULL >> 12)) | 1ULL << 52;
787 return isNeg ? -
APInt(width, mantissa >> (52 - exp)) :
788 APInt(width, mantissa >> (52 - exp));
792 if (width <= exp - 52)
793 return APInt(width, 0);
796 APInt Tmp(width, mantissa);
798 return isNeg ? -Tmp : Tmp;
817 return double(getWord(0));
821 bool isNeg = isSigned ? (*this)[BitWidth-1] :
false;
824 APInt Tmp(isNeg ? -(*
this) : (*
this));
836 if (!isSigned || !isNeg)
837 return std::numeric_limits<double>::infinity();
839 return -std::numeric_limits<double>::infinity();
846 unsigned hiWord = whichWord(n-1);
848 mantissa = Tmp.U.
pVal[0];
852 assert(hiWord > 0 &&
"huh?");
855 mantissa = hibits | lobits;
860 uint64_t
I = sign | (exp << 52) | mantissa;
866 assert(width < BitWidth &&
"Invalid APInt Truncate request");
867 assert(width &&
"Can't truncate to 0 bits");
877 Result.U.
pVal[i] = U.pVal[i];
889 assert(width < BitWidth &&
"Invalid APInt Truncate request");
890 assert(width &&
"Can't truncate to 0 bits");
901 assert(width < BitWidth &&
"Invalid APInt Truncate request");
902 assert(width &&
"Can't truncate to 0 bits");
914 assert(Width > BitWidth &&
"Invalid APInt SignExtend request");
932 Result.clearUnusedBits();
938 assert(width > BitWidth &&
"Invalid APInt ZeroExtend request");
941 return APInt(width, U.VAL);
956 if (BitWidth < width)
958 if (BitWidth > width)
964 if (BitWidth < width)
966 if (BitWidth > width)
972 if (BitWidth < width)
978 if (BitWidth < width)
991 void APInt::ashrSlowCase(
unsigned ShiftAmt) {
1004 if (WordsToMove != 0) {
1010 if (BitShift == 0) {
1011 std::memmove(U.pVal, U.pVal + WordShift, WordsToMove *
APINT_WORD_SIZE);
1014 for (
unsigned i = 0; i != WordsToMove - 1; ++i)
1015 U.pVal[i] = (U.pVal[i + WordShift] >> BitShift) |
1019 U.pVal[WordsToMove - 1] = U.pVal[WordShift + WordsToMove - 1] >> BitShift;
1021 U.pVal[WordsToMove - 1] =
1027 std::memset(U.pVal + WordsToMove, Negative ? -1 : 0,
1040 void APInt::lshrSlowCase(
unsigned ShiftAmt) {
1052 void APInt::shlSlowCase(
unsigned ShiftAmt) {
1060 APInt rot = rotateAmt;
1061 if (rotBitWidth < BitWidth) {
1064 rot = rotateAmt.
zext(BitWidth);
1075 rotateAmt %= BitWidth;
1078 return shl(rotateAmt) |
lshr(BitWidth - rotateAmt);
1086 rotateAmt %= BitWidth;
1089 return lshr(rotateAmt) |
shl(BitWidth - rotateAmt);
1106 if (magnitude <= 5) {
1107 static const uint8_t results[32] = {
1112 4, 4, 4, 4, 4, 4, 4, 4,
1113 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
1116 return APInt(BitWidth, results[ (isSingleWord() ? U.VAL : U.pVal[0]) ]);
1123 if (magnitude < 52) {
1124 return APInt(BitWidth,
1125 uint64_t(::
round(::
sqrt(
double(isSingleWord() ? U.VAL
1134 unsigned nbits = BitWidth, i = 4;
1135 APInt testy(BitWidth, 16);
1136 APInt x_old(BitWidth, 1);
1137 APInt x_new(BitWidth, 0);
1138 APInt two(BitWidth, 2);
1141 for (;; i += 2, testy = testy.
shl(2))
1142 if (i >= nbits || this->
ule(testy)) {
1143 x_old = x_old.
shl(i / 2);
1149 x_new = (this->
udiv(x_old) + x_old).
udiv(two);
1150 if (x_old.
ule(x_new))
1161 APInt square(x_old * x_old);
1162 APInt nextSquare((x_old + 1) * (x_old +1));
1163 if (this->
ult(square))
1165 assert(this->
ule(nextSquare) &&
"Error in APInt::sqrt computation");
1166 APInt midpoint((nextSquare - square).
udiv(two));
1167 APInt offset(*
this - square);
1168 if (offset.
ult(midpoint))
1181 assert(
ult(modulo) &&
"This APInt must be smaller than the modulo");
1191 APInt r[2] = { modulo, *
this };
1193 APInt q(BitWidth, 0);
1196 for (i = 0; r[i^1] != 0; i ^= 1) {
1201 udivrem(r[i], r[i^1], q, r[i]);
1210 return APInt(BitWidth, 0);
1219 return std::move(t[i]);
1227 const APInt& d = *
this;
1229 APInt ad, anc, delta, q1,
r1, q2,
r2, t;
1235 anc = t - 1 - t.
urem(ad);
1237 q1 = signedMin.
udiv(anc);
1238 r1 = signedMin - q1*anc;
1239 q2 = signedMin.
udiv(ad);
1240 r2 = signedMin - q2*ad;
1256 }
while (q1.
ult(delta) || (q1 == delta && r1 == 0));
1271 const APInt& d = *
this;
1280 nc = allOnes - (allOnes - d).
urem(d);
1282 q1 = signedMin.
udiv(nc);
1283 r1 = signedMin - q1*nc;
1284 q2 = signedMax.
udiv(d);
1285 r2 = signedMax - q2*d;
1288 if (r1.
uge(nc - r1)) {
1296 if ((r2 + 1).uge(d - r2)) {
1297 if (q2.
uge(signedMax)) magu.
a = 1;
1302 if (q2.
uge(signedMin)) magu.
a = 1;
1307 }
while (p < d.getBitWidth()*2 &&
1308 (q1.
ult(delta) || (q1 == delta && r1 == 0)));
1310 magu.
s = p - d.getBitWidth();
1319 unsigned m,
unsigned n) {
1320 assert(u &&
"Must provide dividend");
1321 assert(v &&
"Must provide divisor");
1322 assert(q &&
"Must provide quotient");
1323 assert(u != v && u != q && v != q &&
"Must use different memory");
1324 assert(n>1 &&
"n must be > 1");
1327 const uint64_t b = uint64_t(1) << 32;
1332 #define DEBUG_KNUTH(X) LLVM_DEBUG(X) 1334 #define DEBUG_KNUTH(X) do {} while(false) 1355 for (
unsigned i = 0; i < m+n; ++i) {
1356 uint32_t u_tmp = u[i] >> (32 - shift);
1357 u[i] = (u[i] << shift) | u_carry;
1360 for (
unsigned i = 0; i < n; ++i) {
1361 uint32_t v_tmp = v[i] >> (32 - shift);
1362 v[i] = (v[i] << shift) | v_carry;
1386 uint64_t dividend =
Make_64(u[j+n], u[j+n-1]);
1388 uint64_t qp = dividend / v[n-1];
1389 uint64_t rp = dividend % v[n-1];
1390 if (qp == b || qp*v[n-2] > b*rp + u[j+n-2]) {
1393 if (rp < b && (qp == b || qp*v[n-2] > b*rp + u[j+n-2]))
1396 DEBUG_KNUTH(
dbgs() <<
"KnuthDiv: qp == " << qp <<
", rp == " << rp <<
'\n');
1407 for (
unsigned i = 0; i < n; ++i) {
1408 uint64_t p = uint64_t(qp) * uint64_t(v[i]);
1409 int64_t subres = int64_t(u[j+i]) - borrow -
Lo_32(p);
1410 u[j+i] =
Lo_32(subres);
1413 <<
", borrow = " << borrow <<
'\n');
1415 bool isNeg = u[j+n] < borrow;
1416 u[j+n] -=
Lo_32(borrow);
1434 for (
unsigned i = 0; i < n; i++) {
1435 uint32_t limit = std::min(u[j+i],v[i]);
1436 u[j+i] += v[i] + carry;
1437 carry = u[j+i] < limit || (carry && u[j+i] == limit);
1462 for (
int i = n-1; i >= 0; i--) {
1463 r[i] = (u[i] >> shift) | carry;
1464 carry = u[i] << (32 - shift);
1468 for (
int i = n-1; i >= 0; i--) {
1478 void APInt::divide(
const WordType *LHS,
unsigned lhsWords,
const WordType *RHS,
1480 assert(lhsWords >= rhsWords &&
"Fractional result");
1489 unsigned n = rhsWords * 2;
1490 unsigned m = (lhsWords * 2) - n;
1499 if ((Remainder?4:3)*n+2*m+1 <= 128) {
1502 Q = &SPACE[(m+n+1) + n];
1504 R = &SPACE[(m+n+1) + n + (m+n)];
1514 memset(U, 0, (m+n+1)*
sizeof(
uint32_t));
1515 for (
unsigned i = 0; i < lhsWords; ++i) {
1516 uint64_t tmp = LHS[i];
1517 U[i * 2] =
Lo_32(tmp);
1518 U[i * 2 + 1] =
Hi_32(tmp);
1523 memset(V, 0, (n)*
sizeof(
uint32_t));
1524 for (
unsigned i = 0; i < rhsWords; ++i) {
1525 uint64_t tmp = RHS[i];
1526 V[i * 2] =
Lo_32(tmp);
1527 V[i * 2 + 1] =
Hi_32(tmp);
1531 memset(Q, 0, (m+n) *
sizeof(
uint32_t));
1533 memset(R, 0, n *
sizeof(
uint32_t));
1539 for (
unsigned i = n; i > 0 && V[i-1] == 0; i--) {
1543 for (
unsigned i = m+n; i > 0 && U[i-1] == 0; i--)
1552 assert(n != 0 &&
"Divide by zero?");
1556 for (
int i = m; i >= 0; i--) {
1557 uint64_t partial_dividend =
Make_64(remainder, U[i]);
1558 if (partial_dividend == 0) {
1561 }
else if (partial_dividend < divisor) {
1563 remainder =
Lo_32(partial_dividend);
1564 }
else if (partial_dividend == divisor) {
1568 Q[i] =
Lo_32(partial_dividend / divisor);
1569 remainder =
Lo_32(partial_dividend - (Q[i] * divisor));
1582 for (
unsigned i = 0; i < lhsWords; ++i)
1583 Quotient[i] =
Make_64(Q[i*2+1], Q[i*2]);
1588 for (
unsigned i = 0; i < rhsWords; ++i)
1589 Remainder[i] =
Make_64(R[i*2+1], R[i*2]);
1593 if (U != &SPACE[0]) {
1602 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1605 if (isSingleWord()) {
1606 assert(RHS.U.
VAL != 0 &&
"Divide by zero?");
1607 return APInt(BitWidth, U.VAL / RHS.U.
VAL);
1614 assert(rhsWords &&
"Divided by zero???");
1619 return APInt(BitWidth, 0);
1623 if (lhsWords < rhsWords || this->
ult(RHS))
1625 return APInt(BitWidth, 0);
1628 return APInt(BitWidth, 1);
1631 return APInt(BitWidth, this->U.pVal[0] / RHS.U.
pVal[0]);
1634 APInt Quotient(BitWidth, 0);
1635 divide(U.pVal, lhsWords, RHS.U.
pVal, rhsWords, Quotient.U.
pVal,
nullptr);
1640 assert(RHS != 0 &&
"Divide by zero?");
1644 return APInt(BitWidth, U.VAL / RHS);
1652 return APInt(BitWidth, 0);
1658 return APInt(BitWidth, 0);
1661 return APInt(BitWidth, 1);
1664 return APInt(BitWidth, this->U.pVal[0] / RHS);
1667 APInt Quotient(BitWidth, 0);
1668 divide(U.pVal, lhsWords, &RHS, 1, Quotient.U.
pVal,
nullptr);
1675 return (-(*
this)).
udiv(-RHS);
1676 return -((-(*this)).
udiv(RHS));
1679 return -(this->
udiv(-RHS));
1680 return this->
udiv(RHS);
1686 return (-(*
this)).
udiv(-RHS);
1687 return -((-(*this)).
udiv(RHS));
1690 return -(this->
udiv(-RHS));
1691 return this->
udiv(RHS);
1695 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1696 if (isSingleWord()) {
1697 assert(RHS.U.
VAL != 0 &&
"Remainder by zero?");
1698 return APInt(BitWidth, U.VAL % RHS.U.
VAL);
1707 assert(rhsWords &&
"Performing remainder operation by zero ???");
1712 return APInt(BitWidth, 0);
1715 return APInt(BitWidth, 0);
1716 if (lhsWords < rhsWords || this->
ult(RHS))
1721 return APInt(BitWidth, 0);
1724 return APInt(BitWidth, U.pVal[0] % RHS.U.
pVal[0]);
1727 APInt Remainder(BitWidth, 0);
1728 divide(U.pVal, lhsWords, RHS.U.
pVal, rhsWords,
nullptr, Remainder.U.
pVal);
1733 assert(RHS != 0 &&
"Remainder by zero?");
1756 return U.pVal[0] % RHS;
1760 divide(U.pVal, lhsWords, &RHS, 1,
nullptr, &Remainder);
1767 return -((-(*
this)).urem(-RHS));
1768 return -((-(*this)).
urem(RHS));
1771 return this->
urem(-RHS);
1772 return this->
urem(RHS);
1778 return -((-(*this)).
urem(-RHS));
1779 return -((-(*this)).
urem(RHS));
1782 return this->
urem(-RHS);
1783 return this->
urem(RHS);
1788 assert(LHS.BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1789 unsigned BitWidth = LHS.BitWidth;
1792 if (LHS.isSingleWord()) {
1793 assert(RHS.U.
VAL != 0 &&
"Divide by zero?");
1794 uint64_t QuotVal = LHS.U.
VAL / RHS.U.
VAL;
1795 uint64_t RemVal = LHS.U.
VAL % RHS.U.
VAL;
1796 Quotient =
APInt(BitWidth, QuotVal);
1797 Remainder =
APInt(BitWidth, RemVal);
1805 assert(rhsWords &&
"Performing divrem operation by zero ???");
1808 if (lhsWords == 0) {
1809 Quotient =
APInt(BitWidth, 0);
1810 Remainder =
APInt(BitWidth, 0);
1816 Remainder =
APInt(BitWidth, 0);
1819 if (lhsWords < rhsWords || LHS.
ult(RHS)) {
1821 Quotient =
APInt(BitWidth, 0);
1826 Quotient =
APInt(BitWidth, 1);
1827 Remainder =
APInt(BitWidth, 0);
1835 Quotient.reallocate(BitWidth);
1836 Remainder.reallocate(BitWidth);
1838 if (lhsWords == 1) {
1840 uint64_t lhsValue = LHS.U.
pVal[0];
1841 uint64_t rhsValue = RHS.U.
pVal[0];
1842 Quotient = lhsValue / rhsValue;
1843 Remainder = lhsValue % rhsValue;
1848 divide(LHS.U.
pVal, lhsWords, RHS.U.
pVal, rhsWords, Quotient.U.
pVal,
1851 std::memset(Quotient.U.
pVal + lhsWords, 0,
1853 std::memset(Remainder.U.
pVal + rhsWords, 0,
1854 (
getNumWords(BitWidth) - rhsWords) * APINT_WORD_SIZE);
1858 uint64_t &Remainder) {
1859 assert(RHS != 0 &&
"Divide by zero?");
1860 unsigned BitWidth = LHS.BitWidth;
1863 if (LHS.isSingleWord()) {
1864 uint64_t QuotVal = LHS.U.
VAL / RHS;
1865 Remainder = LHS.U.
VAL % RHS;
1866 Quotient =
APInt(BitWidth, QuotVal);
1874 if (lhsWords == 0) {
1875 Quotient =
APInt(BitWidth, 0);
1888 Quotient =
APInt(BitWidth, 0);
1893 Quotient =
APInt(BitWidth, 1);
1901 Quotient.reallocate(BitWidth);
1903 if (lhsWords == 1) {
1905 uint64_t lhsValue = LHS.U.
pVal[0];
1906 Quotient = lhsValue / RHS;
1907 Remainder = lhsValue % RHS;
1912 divide(LHS.U.
pVal, lhsWords, &RHS, 1, Quotient.U.
pVal, &Remainder);
1914 std::memset(Quotient.U.
pVal + lhsWords, 0,
1937 APInt &Quotient, int64_t &Remainder) {
1938 uint64_t
R = Remainder;
1947 }
else if (RHS < 0) {
1957 APInt Res = *
this+RHS;
1964 APInt Res = *
this+RHS;
1965 Overflow = Res.
ult(RHS);
1970 APInt Res = *
this - RHS;
1977 APInt Res = *
this-RHS;
1978 Overflow = Res.
ugt(*
this);
1989 APInt Res = *
this * RHS;
1991 if (*
this != 0 && RHS != 0)
1992 Overflow = Res.
sdiv(RHS) != *
this || Res.
sdiv(*
this) != RHS;
2018 return APInt(BitWidth, 0);
2025 return *
this << ShAmt;
2031 return APInt(BitWidth, 0);
2035 return *
this << ShAmt;
2073 return APInt(BitWidth, 0);
2120 assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
2122 "Radix should be 2, 8, 10, 16, or 36!");
2125 size_t slen = str.
size();
2126 bool isNeg = *p ==
'-';
2127 if (*p ==
'-' || *p ==
'+') {
2130 assert(slen &&
"String is only a sign, needs a value.");
2132 assert((slen <= numbits || radix != 2) &&
"Insufficient bit width");
2133 assert(((slen-1)*3 <= numbits || radix != 8) &&
"Insufficient bit width");
2134 assert(((slen-1)*4 <= numbits || radix != 16) &&
"Insufficient bit width");
2135 assert((((slen-1)*64)/22 <= numbits || radix != 10) &&
2136 "Insufficient bit width");
2145 unsigned shift = (radix == 16 ? 4 : radix == 8 ? 3 : radix == 2 ? 1 : 0);
2149 unsigned digit =
getDigit(*p, radix);
2150 assert(digit < radix &&
"Invalid character in digit string");
2169 bool Signed,
bool formatAsCLiteral)
const {
2170 assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
2172 "Radix should be 2, 8, 10, 16, or 36!");
2175 if (formatAsCLiteral) {
2205 static const char Digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2207 if (isSingleWord()) {
2230 *--BufPtr = Digits[N % Radix];
2253 unsigned StartDig = Str.
size();
2258 if (Radix == 2 || Radix == 8 || Radix == 16) {
2260 unsigned ShiftAmt = (Radix == 16 ? 4 : (Radix == 8 ? 3 : 1));
2261 unsigned MaskAmt = Radix - 1;
2271 udivrem(Tmp, Radix, Tmp, Digit);
2272 assert(Digit < Radix &&
"divide failed");
2289 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 2294 dbgs() <<
"APInt(" << BitWidth <<
"b, " 2295 << U <<
"u " << S <<
"s)\n";
2301 this->
toString(S, 10, isSigned,
false);
2311 "Part width must be divisible by 2!");
2351 for (
unsigned i = 1; i < parts; i++)
2357 for (
unsigned i = 0; i < parts; i++)
2363 for (
unsigned i = 0; i < parts; i++)
2372 return (parts[whichWord(bit)] & maskBit(bit)) != 0;
2377 parts[whichWord(bit)] |= maskBit(bit);
2382 parts[whichWord(bit)] &= ~maskBit(bit);
2388 for (
unsigned i = 0; i < n; i++) {
2389 if (parts[i] != 0) {
2390 unsigned lsb =
partLSB(parts[i]);
2405 if (parts[n] != 0) {
2406 unsigned msb =
partMSB(parts[n]);
2421 unsigned srcBits,
unsigned srcLSB) {
2423 assert(dstParts <= dstCount);
2426 tcAssign (dst, src + firstSrcPart, dstParts);
2437 dst[dstParts - 1] |= ((src[firstSrcPart + dstParts] & mask)
2439 }
else if (n > srcBits) {
2441 dst[dstParts - 1] &=
lowBitMask (srcBits % APINT_BITS_PER_WORD);
2445 while (dstParts < dstCount)
2446 dst[dstParts++] = 0;
2454 for (
unsigned i = 0; i < parts; i++) {
2457 dst[i] += rhs[i] + 1;
2474 for (
unsigned i = 0; i < parts; ++i) {
2489 for (
unsigned i = 0; i < parts; i++) {
2492 dst[i] -= rhs[i] + 1;
2512 for (
unsigned i = 0; i < parts; ++i) {
2542 unsigned srcParts,
unsigned dstParts,
2545 assert(dst <= src || dst >= src + srcParts);
2546 assert(dstParts <= srcParts + 1);
2549 unsigned n = std::min(dstParts, srcParts);
2551 for (
unsigned i = 0; i < n; i++) {
2564 if (multiplier == 0 || srcPart == 0) {
2574 if (low + mid < low)
2581 if (low + mid < low)
2586 if (low + carry < low)
2593 if (low + dst[i] < low)
2602 if (srcParts < dstParts) {
2604 assert(srcParts + 1 == dstParts);
2605 dst[srcParts] = carry;
2617 for (
unsigned i = dstParts; i < srcParts; i++)
2630 const WordType *rhs,
unsigned parts) {
2631 assert(dst != lhs && dst != rhs);
2634 tcSet(dst, 0, parts);
2636 for (
unsigned i = 0; i < parts; i++)
2646 const WordType *rhs,
unsigned lhsParts,
2647 unsigned rhsParts) {
2649 if (lhsParts > rhsParts)
2652 assert(dst != lhs && dst != rhs);
2654 tcSet(dst, 0, rhsParts);
2656 for (
unsigned i = 0; i < lhsParts; i++)
2657 tcMultiplyPart(&dst[i], rhs, lhs[i], 0, rhsParts, rhsParts + 1,
true);
2673 assert(lhs != remainder && lhs != srhs && remainder != srhs);
2675 unsigned shiftCount =
tcMSB(rhs, parts) + 1;
2676 if (shiftCount == 0)
2686 tcSet(lhs, 0, parts);
2697 if (shiftCount == 0)
2701 if ((mask >>= 1) == 0) {
2702 mask = (
WordType) 1 << (APINT_BITS_PER_WORD - 1);
2722 if (BitShift == 0) {
2723 std::memmove(Dst + WordShift, Dst, (Words - WordShift) *
APINT_WORD_SIZE);
2725 while (Words-- > WordShift) {
2726 Dst[Words] = Dst[Words - WordShift] << BitShift;
2727 if (Words > WordShift)
2748 unsigned WordsToMove = Words - WordShift;
2750 if (BitShift == 0) {
2753 for (
unsigned i = 0; i != WordsToMove; ++i) {
2754 Dst[i] = Dst[i + WordShift] >> BitShift;
2755 if (i + 1 != WordsToMove)
2766 for (
unsigned i = 0; i < parts; i++)
2772 for (
unsigned i = 0; i < parts; i++)
2778 for (
unsigned i = 0; i < parts; i++)
2784 for (
unsigned i = 0; i < parts; i++)
2793 if (lhs[parts] != rhs[parts])
2794 return (lhs[parts] > rhs[parts]) ? 1 : -1;
2867 unsigned RangeWidth) {
2870 assert(RangeWidth <= CoeffWidth &&
2871 "Value range width should be less than coefficient width");
2872 assert(RangeWidth > 1 &&
"Value range bit width should be > 1");
2874 LLVM_DEBUG(
dbgs() << __func__ <<
": solving " << A <<
"x^2 + " << B
2875 <<
"x + " << C <<
", rw:" << RangeWidth <<
'\n');
2880 return APInt(CoeffWidth, 0);
2898 A = A.
sext(CoeffWidth);
2899 B = B.
sext(CoeffWidth);
2900 C = C.
sext(CoeffWidth);
2940 if (T.isNullValue())
2947 if (B.isNonNegative()) {
2964 LowkR = RoundUp(LowkR, R);
2974 C -= -RoundUp(-C, R);
2991 LLVM_DEBUG(
dbgs() << __func__ <<
": updated coefficients " << A <<
"x^2 + " 2992 << B <<
"x + " << C <<
", rw:" << RangeWidth <<
'\n');
2999 bool InexactSQ = Q !=
D;
3025 LLVM_DEBUG(
dbgs() << __func__ <<
": solution (root): " << X <<
'\n');
3029 assert((SQ*SQ).
sle(D) &&
"SQ = |_sqrt(D)_|, so SQ*SQ <= D");
3038 APInt VX = (A*X +
B)*X + C;
3039 APInt VY = VX + TwoA*X + A +
B;
3051 LLVM_DEBUG(
dbgs() << __func__ <<
": solution (wrap): " << X <<
'\n');
3066 unsigned StoreBytes) {
3068 const uint8_t *Src = (
const uint8_t *)IntVal.
getRawData();
3073 memcpy(Dst, Src, StoreBytes);
3078 while (StoreBytes >
sizeof(uint64_t)) {
3079 StoreBytes -=
sizeof(uint64_t);
3081 memcpy(Dst + StoreBytes, Src,
sizeof(uint64_t));
3082 Src +=
sizeof(uint64_t);
3085 memcpy(Dst, Src +
sizeof(uint64_t) - StoreBytes, StoreBytes);
3093 uint8_t *Dst =
reinterpret_cast<uint8_t *
>(
3094 const_cast<uint64_t *
>(IntVal.
getRawData()));
3099 memcpy(Dst, Src, LoadBytes);
3105 while (LoadBytes >
sizeof(uint64_t)) {
3106 LoadBytes -=
sizeof(uint64_t);
3108 memcpy(Dst, Src + LoadBytes,
sizeof(uint64_t));
3109 Dst +=
sizeof(uint64_t);
3112 memcpy(Dst +
sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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.
unsigned countLeadingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the most significant bit to the first zero bit.
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.
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 greater than comparison.
APInt trunc(unsigned width) const
Truncate to new width.
APInt ushl_ov(const APInt &Amt, bool &Overflow) const
APInt truncSSat(unsigned width) const
Truncate to new width with signed saturation.
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.
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(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
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...
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.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
static const bool IsLittleEndianHost
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).
static void tcXor(WordType *, const WordType *, unsigned)
LLVM_NODISCARD size_t size() const
size - Get the string size.
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...
void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst, unsigned StoreBytes)
StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst with the integer held in In...
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.
void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes)
LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting from Src into IntVal...
bool isAllOnesValue() const
Determine if all bits are set.
APInt ushl_sat(const APInt &RHS) const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
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.
APInt sshl_sat(const APInt &RHS) const
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.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static WordType tcSubtractPart(WordType *, WordType, unsigned)
DST -= RHS. Returns the carry flag.
static void tcComplement(WordType *, unsigned)
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
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.
unsigned 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...
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 uint64_t add(uint64_t LeftOp, uint64_t RightOp)
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.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
APInt umul_sat(const APInt &RHS) const
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.
uint64_t extractBitsAsZExtValue(unsigned numBits, unsigned bitPosition) const
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 greater than comparison.
Magic data for optimising signed division by a constant.
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< unsigned > GetMostSignificantDifferentBit(const APInt &A, const APInt &B)
Compare two values, and if they are different, return the position of the most significant bit that i...
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.
APInt smul_sat(const APInt &RHS) const
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
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)
unsigned countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
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 truncUSat(unsigned width) const
Truncate to new width with unsigned saturation.
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.
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