15 #ifndef LLVM_ADT_APINT_H 16 #define LLVM_ADT_APINT_H 26 class FoldingSetNodeID;
31 template <
typename T>
class SmallVectorImpl;
76 APINT_WORD_SIZE =
sizeof(WordType),
78 APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT
87 static const WordType WORDTYPE_MAX = ~WordType(0);
107 APInt(uint64_t *val,
unsigned bits) : BitWidth(bits) {
114 bool isSingleWord()
const {
return BitWidth <= APINT_BITS_PER_WORD; }
119 static unsigned whichWord(
unsigned bitPosition) {
120 return bitPosition / APINT_BITS_PER_WORD;
127 static unsigned whichBit(
unsigned bitPosition) {
128 return bitPosition % APINT_BITS_PER_WORD;
137 static uint64_t maskBit(
unsigned bitPosition) {
138 return 1ULL << whichBit(bitPosition);
147 APInt &clearUnusedBits() {
149 unsigned WordBits = ((BitWidth-1) % APINT_BITS_PER_WORD) + 1;
152 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - WordBits);
156 U.pVal[getNumWords() - 1] &= mask;
162 uint64_t getWord(
unsigned bitPosition)
const {
163 return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)];
169 void reallocate(
unsigned NewBitWidth);
191 static void divide(
const WordType *LHS,
unsigned lhsWords,
192 const WordType *RHS,
unsigned rhsWords, WordType *Quotient,
193 WordType *Remainder);
196 void initSlowCase(uint64_t val,
bool isSigned);
202 void initSlowCase(
const APInt &that);
205 void shlSlowCase(
unsigned ShiftAmt);
208 void lshrSlowCase(
unsigned ShiftAmt);
211 void ashrSlowCase(
unsigned ShiftAmt);
214 void AssignSlowCase(
const APInt &RHS);
220 unsigned countLeadingZerosSlowCase()
const LLVM_READONLY;
223 unsigned countLeadingOnesSlowCase()
const LLVM_READONLY;
226 unsigned countTrailingZerosSlowCase()
const LLVM_READONLY;
229 unsigned countTrailingOnesSlowCase()
const LLVM_READONLY;
232 unsigned countPopulationSlowCase()
const LLVM_READONLY;
241 void setBitsSlowCase(
unsigned loBit,
unsigned hiBit);
244 void flipAllBitsSlowCase();
278 : BitWidth(numBits) {
279 assert(BitWidth &&
"bitwidth too small");
280 if (isSingleWord()) {
284 initSlowCase(val, isSigned);
304 APInt(
unsigned numBits,
unsigned numWords,
const uint64_t bigVal[]);
330 memcpy(&U, &that.U,
sizeof(U));
345 explicit APInt() : BitWidth(1) { U.VAL = 0; }
402 return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
403 return countTrailingOnesSlowCase() == BitWidth;
418 return countLeadingZerosSlowCase() == BitWidth - 1;
433 return U.VAL == ((WordType(1) << (BitWidth - 1)) - 1);
434 return !isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
449 return U.VAL == (WordType(1) << (BitWidth - 1));
450 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
455 assert(N &&
"N == 0 ???");
456 return getActiveBits() <=
N;
461 assert(N &&
"N == 0 ???");
462 return getMinSignedBits() <=
N;
471 return countPopulationSlowCase() == 1;
487 return ugt(Limit) ? Limit : getZExtValue();
495 bool isSplat(
unsigned SplatSizeInBits)
const;
500 assert(numBits != 0 &&
"numBits must be non-zero");
501 assert(numBits <= BitWidth &&
"numBits out of range");
503 return U.VAL == (WORDTYPE_MAX >> (APINT_BITS_PER_WORD - numBits));
504 unsigned Ones = countTrailingOnesSlowCase();
505 return (numBits == Ones) &&
506 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
515 unsigned Ones = countTrailingOnesSlowCase();
516 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
524 unsigned Ones = countPopulationSlowCase();
525 unsigned LeadZ = countLeadingZerosSlowCase();
535 return getAllOnesValue(numBits);
540 APInt API = getAllOnesValue(numBits);
550 APInt API(numBits, 0);
560 return getSignedMinValue(BitWidth);
567 return APInt(numBits, WORDTYPE_MAX,
true);
581 APInt getHiBits(
unsigned numBits)
const;
589 APInt getLoBits(
unsigned numBits)
const;
593 APInt Res(numBits, 0);
612 assert(loBit <= hiBit &&
"loBit greater than hiBit");
613 APInt Res(numBits, 0);
624 APInt Res(numBits, 0);
641 APInt Res(numBits, 0);
653 APInt Res(numBits, 0);
665 APInt Res(numBits, 0);
671 static APInt getSplat(
unsigned NewLen,
const APInt &V);
741 return countLeadingZerosSlowCase() == BitWidth;
753 if (isSingleWord() && RHS.isSingleWord()) {
755 BitWidth = RHS.BitWidth;
756 return clearUnusedBits();
770 assert(
this != &that &&
"Self-move not supported");
776 memcpy(&U, &that.U,
sizeof(U));
778 BitWidth = that.BitWidth;
792 if (isSingleWord()) {
797 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
809 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
813 AndAssignSlowCase(RHS);
823 if (isSingleWord()) {
828 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
839 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
843 OrAssignSlowCase(RHS);
853 if (isSingleWord()) {
869 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
873 XorAssignSlowCase(RHS);
883 if (isSingleWord()) {
898 APInt &operator*=(uint64_t RHS);
914 APInt &operator-=(uint64_t RHS);
922 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
923 if (isSingleWord()) {
924 if (ShiftAmt == BitWidth)
928 return clearUnusedBits();
930 shlSlowCase(ShiftAmt);
971 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
972 if (isSingleWord()) {
974 if (ShiftAmt == BitWidth)
975 U.VAL = SExtVAL >> (APINT_BITS_PER_WORD - 1);
977 U.VAL = SExtVAL >> ShiftAmt;
981 ashrSlowCase(ShiftAmt);
995 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
996 if (isSingleWord()) {
997 if (ShiftAmt == BitWidth)
1003 lshrSlowCase(ShiftAmt);
1016 APInt rotl(
unsigned rotateAmt)
const;
1019 APInt rotr(
unsigned rotateAmt)
const;
1031 void ashrInPlace(
const APInt &shiftAmt);
1043 void lshrInPlace(
const APInt &ShiftAmt);
1068 APInt udiv(uint64_t RHS)
const;
1076 APInt sdiv(int64_t RHS)
const;
1088 uint64_t urem(uint64_t RHS)
const;
1094 int64_t srem(int64_t RHS)
const;
1103 static void udivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1105 static void udivrem(
const APInt &LHS, uint64_t RHS,
APInt &Quotient,
1106 uint64_t &Remainder);
1108 static void sdivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1110 static void sdivrem(
const APInt &LHS, int64_t RHS,
APInt &Quotient,
1111 int64_t &Remainder);
1114 APInt sadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1115 APInt uadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1116 APInt ssub_ov(
const APInt &RHS,
bool &Overflow)
const;
1117 APInt usub_ov(
const APInt &RHS,
bool &Overflow)
const;
1118 APInt sdiv_ov(
const APInt &RHS,
bool &Overflow)
const;
1119 APInt smul_ov(
const APInt &RHS,
bool &Overflow)
const;
1121 APInt sshl_ov(
const APInt &Amt,
bool &Overflow)
const;
1122 APInt ushl_ov(
const APInt &Amt,
bool &Overflow)
const;
1139 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1151 assert(BitWidth == RHS.BitWidth &&
"Comparison requires equal bit widths");
1153 return U.VAL == RHS.U.
VAL;
1154 return EqualSlowCase(RHS);
1164 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() == Val;
1173 bool eq(
const APInt &RHS)
const {
return (*
this) == RHS; }
1189 bool operator!=(uint64_t Val)
const {
return !((*this) == Val); }
1197 bool ne(
const APInt &RHS)
const {
return !((*this) == RHS); }
1213 bool ult(uint64_t RHS)
const {
1215 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
1224 bool slt(
const APInt &RHS)
const {
return compareSigned(RHS) < 0; }
1233 return (!isSingleWord() && getMinSignedBits() > 64) ? isNegative()
1234 : getSExtValue() < RHS;
1251 bool ule(uint64_t RHS)
const {
return !ugt(RHS); }
1259 bool sle(
const APInt &RHS)
const {
return compareSigned(RHS) <= 0; }
1267 bool sle(uint64_t RHS)
const {
return !sgt(RHS); }
1283 bool ugt(uint64_t RHS)
const {
1285 return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
1303 return (!isSingleWord() && getMinSignedBits() > 64) ? !isNegative()
1304 : getSExtValue() > RHS;
1321 bool uge(uint64_t RHS)
const {
return !ult(RHS); }
1337 bool sge(int64_t RHS)
const {
return !slt(RHS); }
1342 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1344 return (U.VAL & RHS.U.
VAL) != 0;
1345 return intersectsSlowCase(RHS);
1350 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1352 return (U.VAL & ~RHS.U.
VAL) == 0;
1353 return isSubsetOfSlowCase(RHS);
1364 APInt trunc(
unsigned width)
const;
1370 APInt truncUSat(
unsigned width)
const;
1377 APInt truncSSat(
unsigned width)
const;
1385 APInt sext(
unsigned width)
const;
1392 APInt zext(
unsigned width)
const;
1398 APInt sextOrTrunc(
unsigned width)
const;
1404 APInt zextOrTrunc(
unsigned width)
const;
1410 APInt sextOrSelf(
unsigned width)
const;
1416 APInt zextOrSelf(
unsigned width)
const;
1425 U.VAL = WORDTYPE_MAX;
1428 memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
1437 assert(BitPosition < BitWidth &&
"BitPosition out of range");
1438 WordType
Mask = maskBit(BitPosition);
1442 U.pVal[whichWord(BitPosition)] |=
Mask;
1447 setBit(BitWidth - 1);
1454 assert(hiBit <= BitWidth &&
"hiBit out of range");
1455 assert(loBit <= BitWidth &&
"loBit out of range");
1456 if (loBit <= hiBit) {
1457 setBits(loBit, hiBit);
1461 setHighBits(BitWidth - loBit);
1467 assert(hiBit <= BitWidth &&
"hiBit out of range");
1468 assert(loBit <= BitWidth &&
"loBit out of range");
1469 assert(loBit <= hiBit &&
"loBit greater than hiBit");
1472 if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
1473 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1480 setBitsSlowCase(loBit, hiBit);
1486 return setBits(loBit, BitWidth);
1491 return setBits(0, loBits);
1496 return setBits(BitWidth - hiBits, BitWidth);
1504 memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE);
1511 assert(BitPosition < BitWidth &&
"BitPosition out of range");
1512 WordType
Mask = ~maskBit(BitPosition);
1516 U.pVal[whichWord(BitPosition)] &=
Mask;
1521 assert(loBits <= BitWidth &&
"More bits than bitwidth");
1522 APInt Keep = getHighBitsSet(BitWidth, BitWidth - loBits);
1528 clearBit(BitWidth - 1);
1533 if (isSingleWord()) {
1534 U.VAL ^= WORDTYPE_MAX;
1537 flipAllBitsSlowCase();
1545 void flipBit(
unsigned bitPosition);
1554 void insertBits(
const APInt &SubBits,
unsigned bitPosition);
1555 void insertBits(uint64_t SubBits,
unsigned bitPosition,
unsigned numBits);
1558 APInt extractBits(
unsigned numBits,
unsigned bitPosition)
const;
1559 uint64_t extractBitsAsZExtValue(
unsigned numBits,
unsigned bitPosition)
const;
1582 return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
1597 unsigned numActiveBits = getActiveBits();
1598 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1612 return getActiveBits() + 1;
1623 assert(getActiveBits() <= 64 &&
"Too many bits for uint64_t");
1635 assert(getMinSignedBits() <= 64 &&
"Too many bits for int64_t");
1636 return int64_t(U.pVal[0]);
1643 static unsigned getBitsNeeded(
StringRef str, uint8_t radix);
1654 if (isSingleWord()) {
1655 unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1658 return countLeadingZerosSlowCase();
1672 return countLeadingOnesSlowCase();
1692 return countTrailingZerosSlowCase();
1706 return countTrailingOnesSlowCase();
1718 return countPopulationSlowCase();
1729 bool formatAsCLiteral =
false)
const;
1734 toString(Str, Radix,
false,
false);
1748 std::string
toString(
unsigned Radix,
bool Signed)
const;
1751 APInt byteSwap()
const;
1758 double roundToDouble(
bool isSigned)
const;
1781 return BitsToFloat(static_cast<uint32_t>(getWord(0)));
1805 unsigned logBase2()
const {
return getActiveBits() - 1; }
1839 unsigned lg = logBase2();
1840 return lg +
unsigned((*
this)[lg - 1]);
1864 APInt multiplicativeInverse(
const APInt &modulo)
const;
1876 mu magicu(
unsigned LeadingZeros = 0)
const;
1890 static void tcSet(WordType *, WordType,
unsigned);
1893 static void tcAssign(WordType *,
const WordType *,
unsigned);
1896 static bool tcIsZero(
const WordType *,
unsigned);
1899 static int tcExtractBit(
const WordType *,
unsigned bit);
1905 static void tcExtract(WordType *,
unsigned dstCount,
1906 const WordType *,
unsigned srcBits,
1910 static void tcSetBit(WordType *,
unsigned bit);
1913 static void tcClearBit(WordType *,
unsigned bit);
1917 static unsigned tcLSB(
const WordType *,
unsigned n);
1918 static unsigned tcMSB(
const WordType *parts,
unsigned n);
1921 static void tcNegate(WordType *,
unsigned);
1924 static WordType tcAdd(WordType *,
const WordType *,
1925 WordType carry,
unsigned);
1927 static WordType tcAddPart(WordType *, WordType,
unsigned);
1930 static WordType tcSubtract(WordType *,
const WordType *,
1931 WordType carry,
unsigned);
1933 static WordType tcSubtractPart(WordType *, WordType,
unsigned);
1945 static int tcMultiplyPart(WordType *dst,
const WordType *src,
1946 WordType multiplier, WordType carry,
1947 unsigned srcParts,
unsigned dstParts,
1954 static int tcMultiply(WordType *,
const WordType *,
const WordType *,
1959 static void tcFullMultiply(WordType *,
const WordType *,
1960 const WordType *,
unsigned,
unsigned);
1971 static int tcDivide(WordType *lhs,
const WordType *rhs,
1977 static void tcShiftLeft(WordType *,
unsigned Words,
unsigned Count);
1981 static void tcShiftRight(WordType *,
unsigned Words,
unsigned Count);
1984 static void tcAnd(WordType *,
const WordType *,
unsigned);
1985 static void tcOr(WordType *,
const WordType *,
unsigned);
1986 static void tcXor(WordType *,
const WordType *,
unsigned);
1987 static void tcComplement(WordType *,
unsigned);
1990 static int tcCompare(
const WordType *,
const WordType *,
unsigned);
1994 return tcAddPart(dst, 1, parts);
1999 return tcSubtractPart(dst, 1, parts);
2003 static void tcSetLeastSignificantBits(WordType *,
unsigned,
unsigned bits);
2043 return std::move(b);
2063 return std::move(b);
2083 return std::move(b);
2113 return std::move(b);
2134 return std::move(b);
2159 namespace APIntOps {
2163 return A.
slt(B) ? A :
B;
2168 return A.
sgt(B) ? A :
B;
2173 return A.
ult(B) ? A :
B;
2178 return A.
ugt(B) ? A :
B;
2267 unsigned RangeWidth);
void clearAllBits()
Set every bit to 0.
APInt abs() const
Get the absolute value;.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
std::string & operator+=(std::string &buffer, StringRef string)
void setSignBit()
Set the sign bit to 1.
bool isShiftedMask() const
Return true if this APInt value contains a sequence of ones with the remainder zero.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
bool operator==(uint64_t Val) const
Equality operator.
void flipAllBits()
Toggle every bit to its opposite value.
void setBitsWithWrap(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
uint64_t getZExtValue() const
Get zero extended value.
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.
APInt & operator^=(uint64_t RHS)
Bitwise XOR assignment operator.
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
APInt operator+(APInt a, const APInt &b)
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
This class represents lattice values for constants.
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float vlalue.
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.
unsigned countLeadingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the most significant bit to the first zero bit.
unsigned getNumWords() const
Get the number of words.
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
APInt zext(unsigned width) const
Zero extend to a new width.
bool operator[](unsigned bitPosition) const
Array-indexing support.
bool slt(const APInt &RHS) const
Signed less than comparison.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
float BitsToFloat(uint32_t Bits)
This function takes a 32-bit integer and returns the bit equivalent float.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
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.
APInt operator^(APInt a, const APInt &b)
APInt & operator|=(const APInt &RHS)
Bitwise OR assignment operator.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
void setAllBits()
Set every bit to 1.
APInt operator &(APInt a, const APInt &b)
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A sign-divided by B, rounded by the given rounding mode.
static APInt getBitsSetWithWrap(unsigned numBits, unsigned loBit, unsigned hiBit)
Wrap version of getBitsSet.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
APInt GreatestCommonDivisor(APInt A, APInt B)
Compute GCD of two unsigned APInt values.
Magic data for optimising unsigned division by a constant.
double roundToDouble(bool isSigned) const
Converts this APInt to a double value.
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.
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.
APInt ashr(const APInt &ShiftAmt) const
Arithmetic right-shift function.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
void setBit(unsigned BitPosition)
Set a given bit to 1.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
static APInt doubleToBits(double V)
Converts a double to APInt bits.
APInt shl(unsigned shiftAmt) const
Left-shift function.
APInt()
Default constructor that creates an uninteresting APInt representing a 1-bit zero value...
uint64_t VAL
Used to store the <= 64 bits integer value.
APInt operator<<(unsigned Bits) const
Left logical shift operator.
double roundToDouble() const
Converts this unsigned APInt to a double value.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
APInt operator*(APInt a, uint64_t RHS)
div rem Hoist decompose integer division and remainder
std::error_code fromString(std::string String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
unsigned getActiveBits() const
Compute the number of active bits in the value.
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
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.
bool ne(const APInt &RHS) const
Inequality comparison.
bool operator==(const APInt &RHS) const
Equality operator.
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
void clearBit(unsigned BitPosition)
Set a given bit to 0.
int32_t exactLogBase2() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Get a value with upper bits starting at loBit set.
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...
float RoundSignedAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
APInt operator~(APInt v)
Unary bitwise complement operator.
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
bool slt(int64_t RHS) const
Signed less than comparison.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
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.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
unsigned countPopulation() const
Count the number of bits set.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
bool ugt(uint64_t RHS) const
Unsigned greater than comparison.
bool isMask(unsigned numBits) const
bool isOneValue() const
Determine if this is a value of 1.
bool ult(uint64_t RHS) const
Unsigned less than comparison.
APInt & operator=(const APInt &RHS)
Copy assignment operator.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
unsigned nearestLogBase2() const
bool isMinSignedValue() const
Determine if this is the smallest signed value.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
APInt(APInt &&that)
Move Constructor.
bool sge(int64_t RHS) const
Signed greater or equal comparison.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static unsigned getNumWords(unsigned BitWidth)
Get the number of words.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
APInt operator<<(const APInt &Bits) const
Left logical shift operator.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
void clearSignBit()
Set the sign bit to 0.
bool eq(const APInt &RHS) const
Equality comparison.
static bool isSameValue(const APInt &I1, const APInt &I2)
Determine if two APInts have the same value, after zero-extending one of them (if needed!) to ensure ...
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...
unsigned ceilLogBase2() const
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
bool sgt(int64_t RHS) const
Signed greater than comparison.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool operator!=(const APInt &RHS) const
Inequality operator.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
bool operator!() const
Logical negation operator.
bool ule(uint64_t RHS) const
Unsigned less or equal comparison.
unsigned countPopulation(T Value)
Count the number of set bits in a value.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
APInt shl(const APInt &ShiftAmt) const
Left-shift function.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
bool needsCleanup() const
Returns whether this instance allocated memory.
APInt(const APInt &that)
Simply makes *this a copy of that.
bool isMaxValue() const
Determine if this is the largest unsigned value.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
void negate()
Negate this APInt in place.
bool sle(uint64_t RHS) const
Signed less or equal comparison.
uint64_t DoubleToBits(double Double)
This function takes a double and returns the bit equivalent 64-bit integer.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
void print(raw_ostream &OS, bool isSigned) const
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
unsigned logBase2() const
unsigned countTrailingOnes() const
Count the number of trailing one bits.
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
An opaque object representing a hash code.
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
APInt RoundFloatToAPInt(float Float, unsigned width)
Converts a float value into a APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
bool operator!=(uint64_t V1, const APInt &V2)
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Magic data for optimising signed division by a constant.
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
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 & operator|=(uint64_t RHS)
Bitwise OR assignment operator.
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.
APInt & operator^=(const APInt &RHS)
Bitwise XOR assignment operator.
APInt & operator=(uint64_t RHS)
Assignment operator.
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
bool isMinValue() const
Determine if this is the smallest unsigned value.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
int compare(DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
Compare two scaled numbers.
float bitsToFloat() const
Converts APInt bits to a float.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool uge(uint64_t RHS) const
Unsigned greater or equal comparison.
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
E & operator &=(E &LHS, E RHS)
unsigned countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
const APInt operator--(int)
Postfix decrement operator.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
This class implements an extremely fast bulk output stream that can only output to a stream...
APInt & operator=(APInt &&that)
Move assignment operator.
const APInt operator++(int)
Postfix increment operator.
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 bool isSplat(ArrayRef< Value *> VL)
APInt lshr(const APInt &ShiftAmt) const
Logical right-shift function.
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool operator==(uint64_t V1, const APInt &V2)
static APInt getNullValue(unsigned numBits)
Get the '0' value.
APInt operator|(APInt a, const APInt &b)
APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
T reverseBits(T Val)
Reverse the bits in Val.
static APInt floatToBits(float V)
Converts a float to APInt bits.
double bitsToDouble() const
Converts APInt bits to a double.
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
bool operator!=(uint64_t Val) const
Inequality operator.
double signedRoundToDouble() const
Converts this signed APInt to a double value.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
uint64_t * pVal
Used to store the >64 bits integer value.
bool isNullValue() const
Determine if all bits are clear.