16 #ifndef LLVM_ADT_APINT_H
17 #define LLVM_ADT_APINT_H
27 class FoldingSetNodeID;
32 template <
typename T>
class SmallVectorImpl;
78 APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT
101 APInt(uint64_t *val,
unsigned bits) : BitWidth(bits) {
108 bool isSingleWord()
const {
return BitWidth <= APINT_BITS_PER_WORD; }
113 static unsigned whichWord(
unsigned bitPosition) {
114 return bitPosition / APINT_BITS_PER_WORD;
121 static unsigned whichBit(
unsigned bitPosition) {
122 return bitPosition % APINT_BITS_PER_WORD;
131 static uint64_t maskBit(
unsigned bitPosition) {
132 return 1ULL << whichBit(bitPosition);
141 APInt &clearUnusedBits() {
143 unsigned WordBits = ((BitWidth-1) % APINT_BITS_PER_WORD) + 1;
146 uint64_t mask = WORD_MAX >> (APINT_BITS_PER_WORD - WordBits);
150 U.pVal[getNumWords() - 1] &= mask;
156 uint64_t getWord(
unsigned bitPosition)
const {
157 return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)];
163 void reallocate(
unsigned NewBitWidth);
177 void fromString(
unsigned numBits, StringRef str, uint8_t radix);
185 static void divide(
const WordType *LHS,
unsigned lhsWords,
186 const WordType *RHS,
unsigned rhsWords, WordType *Quotient,
187 WordType *Remainder);
190 void initSlowCase(uint64_t val,
bool isSigned);
193 void initFromArray(ArrayRef<uint64_t>
array);
196 void initSlowCase(
const APInt &that);
199 void shlSlowCase(
unsigned ShiftAmt);
202 void lshrSlowCase(
unsigned ShiftAmt);
205 void ashrSlowCase(
unsigned ShiftAmt);
208 void AssignSlowCase(
const APInt &RHS);
214 unsigned countLeadingZerosSlowCase()
const LLVM_READONLY;
217 unsigned countLeadingOnesSlowCase()
const LLVM_READONLY;
220 unsigned countTrailingZerosSlowCase()
const LLVM_READONLY;
223 unsigned countTrailingOnesSlowCase()
const LLVM_READONLY;
226 unsigned countPopulationSlowCase()
const LLVM_READONLY;
229 bool intersectsSlowCase(
const APInt &RHS)
const LLVM_READONLY;
232 bool isSubsetOfSlowCase(
const APInt &RHS)
const LLVM_READONLY;
235 void setBitsSlowCase(
unsigned loBit,
unsigned hiBit);
238 void flipAllBitsSlowCase();
241 void AndAssignSlowCase(
const APInt& RHS);
244 void OrAssignSlowCase(
const APInt& RHS);
247 void XorAssignSlowCase(
const APInt& RHS);
255 int compareSigned(
const APInt &RHS)
const LLVM_READONLY;
272 : BitWidth(numBits) {
273 assert(BitWidth &&
"bitwidth too small");
274 if (isSingleWord()) {
278 initSlowCase(val, isSigned);
298 APInt(
unsigned numBits,
unsigned numWords,
const uint64_t bigVal[]);
324 memcpy(&U, &that.U,
sizeof(U));
339 explicit APInt() : BitWidth(1) { U.VAL = 0; }
391 return U.VAL == WORD_MAX >> (APINT_BITS_PER_WORD - BitWidth);
392 return countTrailingOnesSlowCase() == BitWidth;
407 return countLeadingZerosSlowCase() == BitWidth - 1;
422 return U.VAL == ((
WordType(1) << (BitWidth - 1)) - 1);
423 return !isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
438 return U.VAL == (
WordType(1) << (BitWidth - 1));
439 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
444 assert(N &&
"N == 0 ???");
445 return getActiveBits() <=
N;
450 assert(N &&
"N == 0 ???");
451 return getMinSignedBits() <=
N;
460 return countPopulationSlowCase() == 1;
476 return ugt(Limit) ? Limit : getZExtValue();
484 bool isSplat(
unsigned SplatSizeInBits)
const;
489 assert(numBits != 0 &&
"numBits must be non-zero");
490 assert(numBits <= BitWidth &&
"numBits out of range");
492 return U.VAL == (WORD_MAX >> (APINT_BITS_PER_WORD - numBits));
493 unsigned Ones = countTrailingOnesSlowCase();
494 return (numBits == Ones) &&
495 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
504 unsigned Ones = countTrailingOnesSlowCase();
505 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
513 unsigned Ones = countPopulationSlowCase();
514 unsigned LeadZ = countLeadingZerosSlowCase();
524 return getAllOnesValue(numBits);
529 APInt API = getAllOnesValue(numBits);
539 APInt API(numBits, 0);
549 return getSignedMinValue(BitWidth);
556 return APInt(numBits, WORD_MAX,
true);
570 APInt getHiBits(
unsigned numBits)
const;
578 APInt getLoBits(
unsigned numBits)
const;
582 APInt Res(numBits, 0);
601 APInt Res(numBits, 0);
618 APInt Res(numBits, 0);
630 APInt Res(numBits, 0);
642 APInt Res(numBits, 0);
648 static APInt getSplat(
unsigned NewLen,
const APInt &V);
718 return countLeadingZerosSlowCase() == BitWidth;
730 if (isSingleWord() && RHS.isSingleWord()) {
732 BitWidth = RHS.BitWidth;
733 return clearUnusedBits();
742 assert(
this != &that &&
"Self-move not supported");
748 memcpy(&U, &that.U,
sizeof(U));
750 BitWidth = that.BitWidth;
764 if (isSingleWord()) {
769 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
781 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
785 AndAssignSlowCase(RHS);
795 if (isSingleWord()) {
800 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
811 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
815 OrAssignSlowCase(RHS);
825 if (isSingleWord()) {
841 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
845 XorAssignSlowCase(RHS);
855 if (isSingleWord()) {
870 APInt &operator*=(uint64_t RHS);
886 APInt &operator-=(uint64_t RHS);
894 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
895 if (isSingleWord()) {
896 if (ShiftAmt == BitWidth)
900 return clearUnusedBits();
902 shlSlowCase(ShiftAmt);
943 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
944 if (isSingleWord()) {
946 if (ShiftAmt == BitWidth)
947 U.VAL = SExtVAL >> (APINT_BITS_PER_WORD - 1);
949 U.VAL = SExtVAL >> ShiftAmt;
953 ashrSlowCase(ShiftAmt);
967 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
968 if (isSingleWord()) {
969 if (ShiftAmt == BitWidth)
975 lshrSlowCase(ShiftAmt);
988 APInt rotl(
unsigned rotateAmt)
const;
991 APInt rotr(
unsigned rotateAmt)
const;
1003 void ashrInPlace(
const APInt &shiftAmt);
1015 void lshrInPlace(
const APInt &ShiftAmt);
1039 APInt udiv(uint64_t RHS)
const;
1045 APInt sdiv(int64_t RHS)
const;
1057 uint64_t urem(uint64_t RHS)
const;
1063 int64_t srem(int64_t RHS)
const;
1072 static void udivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1074 static void udivrem(
const APInt &LHS, uint64_t RHS,
APInt &Quotient,
1075 uint64_t &Remainder);
1077 static void sdivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1079 static void sdivrem(
const APInt &LHS, int64_t RHS,
APInt &Quotient,
1080 int64_t &Remainder);
1083 APInt sadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1084 APInt uadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1085 APInt ssub_ov(
const APInt &RHS,
bool &Overflow)
const;
1086 APInt usub_ov(
const APInt &RHS,
bool &Overflow)
const;
1087 APInt sdiv_ov(
const APInt &RHS,
bool &Overflow)
const;
1088 APInt smul_ov(
const APInt &RHS,
bool &Overflow)
const;
1090 APInt sshl_ov(
const APInt &Amt,
bool &Overflow)
const;
1091 APInt ushl_ov(
const APInt &Amt,
bool &Overflow)
const;
1098 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1110 assert(BitWidth == RHS.BitWidth &&
"Comparison requires equal bit widths");
1112 return U.VAL == RHS.U.
VAL;
1113 return EqualSlowCase(RHS);
1123 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() == Val;
1132 bool eq(
const APInt &RHS)
const {
return (*
this) == RHS; }
1148 bool operator!=(uint64_t Val)
const {
return !((*this) == Val); }
1156 bool ne(
const APInt &RHS)
const {
return !((*this) == RHS); }
1172 bool ult(uint64_t RHS)
const {
1174 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
1183 bool slt(
const APInt &RHS)
const {
return compareSigned(RHS) < 0; }
1192 return (!isSingleWord() && getMinSignedBits() > 64) ? isNegative()
1193 : getSExtValue() < RHS;
1210 bool ule(uint64_t RHS)
const {
return !ugt(RHS); }
1218 bool sle(
const APInt &RHS)
const {
return compareSigned(RHS) <= 0; }
1226 bool sle(uint64_t RHS)
const {
return !sgt(RHS); }
1242 bool ugt(uint64_t RHS)
const {
1244 return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
1262 return (!isSingleWord() && getMinSignedBits() > 64) ? !isNegative()
1263 : getSExtValue() > RHS;
1280 bool uge(uint64_t RHS)
const {
return !ult(RHS); }
1296 bool sge(int64_t RHS)
const {
return !slt(RHS); }
1301 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1303 return (U.VAL & RHS.U.
VAL) != 0;
1304 return intersectsSlowCase(RHS);
1309 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1311 return (U.VAL & ~RHS.U.
VAL) == 0;
1312 return isSubsetOfSlowCase(RHS);
1323 APInt trunc(
unsigned width)
const;
1331 APInt sext(
unsigned width)
const;
1338 APInt zext(
unsigned width)
const;
1344 APInt sextOrTrunc(
unsigned width)
const;
1350 APInt zextOrTrunc(
unsigned width)
const;
1356 APInt sextOrSelf(
unsigned width)
const;
1362 APInt zextOrSelf(
unsigned width)
const;
1374 memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
1383 assert(BitPosition <= BitWidth &&
"BitPosition out of range");
1388 U.pVal[whichWord(BitPosition)] |=
Mask;
1393 setBit(BitWidth - 1);
1398 assert(hiBit <= BitWidth &&
"hiBit out of range");
1399 assert(loBit <= BitWidth &&
"loBit out of range");
1400 assert(loBit <= hiBit &&
"loBit greater than hiBit");
1403 if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
1404 uint64_t mask = WORD_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1411 setBitsSlowCase(loBit, hiBit);
1417 return setBits(loBit, BitWidth);
1422 return setBits(0, loBits);
1427 return setBits(BitWidth - hiBits, BitWidth);
1435 memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE);
1442 assert(BitPosition <= BitWidth &&
"BitPosition out of range");
1447 U.pVal[whichWord(BitPosition)] &=
Mask;
1452 clearBit(BitWidth - 1);
1457 if (isSingleWord()) {
1461 flipAllBitsSlowCase();
1469 void flipBit(
unsigned bitPosition);
1478 void insertBits(
const APInt &SubBits,
unsigned bitPosition);
1481 APInt extractBits(
unsigned numBits,
unsigned bitPosition)
const;
1504 return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
1519 unsigned numActiveBits = getActiveBits();
1520 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1534 return getActiveBits() + 1;
1545 assert(getActiveBits() <= 64 &&
"Too many bits for uint64_t");
1557 assert(getMinSignedBits() <= 64 &&
"Too many bits for int64_t");
1558 return int64_t(U.pVal[0]);
1565 static unsigned getBitsNeeded(
StringRef str, uint8_t radix);
1576 if (isSingleWord()) {
1577 unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1580 return countLeadingZerosSlowCase();
1594 return countLeadingOnesSlowCase();
1614 return countTrailingZerosSlowCase();
1628 return countTrailingOnesSlowCase();
1640 return countPopulationSlowCase();
1651 bool formatAsCLiteral =
false)
const;
1656 toString(Str, Radix,
false,
false);
1673 APInt byteSwap()
const;
1680 double roundToDouble(
bool isSigned)
const;
1761 unsigned lg = logBase2();
1762 return lg +
unsigned((*
this)[lg - 1]);
1786 APInt multiplicativeInverse(
const APInt &modulo)
const;
1798 mu magicu(
unsigned LeadingZeros = 0)
const;
1812 static void tcSet(WordType *, WordType,
unsigned);
1815 static void tcAssign(WordType *,
const WordType *,
unsigned);
1818 static bool tcIsZero(
const WordType *,
unsigned);
1821 static int tcExtractBit(
const WordType *,
unsigned bit);
1827 static void tcExtract(WordType *,
unsigned dstCount,
1828 const WordType *,
unsigned srcBits,
1832 static void tcSetBit(WordType *,
unsigned bit);
1835 static void tcClearBit(WordType *,
unsigned bit);
1839 static unsigned tcLSB(
const WordType *,
unsigned n);
1840 static unsigned tcMSB(
const WordType *parts,
unsigned n);
1843 static void tcNegate(WordType *,
unsigned);
1846 static WordType tcAdd(WordType *,
const WordType *,
1847 WordType carry,
unsigned);
1849 static WordType tcAddPart(WordType *, WordType,
unsigned);
1852 static WordType tcSubtract(WordType *,
const WordType *,
1853 WordType carry,
unsigned);
1855 static WordType tcSubtractPart(WordType *, WordType,
unsigned);
1867 static int tcMultiplyPart(WordType *dst,
const WordType *src,
1868 WordType multiplier, WordType carry,
1869 unsigned srcParts,
unsigned dstParts,
1876 static int tcMultiply(WordType *,
const WordType *,
const WordType *,
1881 static void tcFullMultiply(WordType *,
const WordType *,
1882 const WordType *,
unsigned,
unsigned);
1893 static int tcDivide(WordType *lhs,
const WordType *rhs,
1894 WordType *remainder, WordType *scratch,
1899 static void tcShiftLeft(WordType *,
unsigned Words,
unsigned Count);
1903 static void tcShiftRight(WordType *,
unsigned Words,
unsigned Count);
1906 static void tcAnd(WordType *,
const WordType *,
unsigned);
1907 static void tcOr(WordType *,
const WordType *,
unsigned);
1908 static void tcXor(WordType *,
const WordType *,
unsigned);
1909 static void tcComplement(WordType *,
unsigned);
1912 static int tcCompare(
const WordType *,
const WordType *,
unsigned);
1916 return tcAddPart(dst, 1, parts);
1921 return tcSubtractPart(dst, 1, parts);
1925 static void tcSetLeastSignificantBits(WordType *,
unsigned,
unsigned bits);
1965 return std::move(b);
1985 return std::move(b);
2005 return std::move(b);
2035 return std::move(b);
2056 return std::move(b);
2081 namespace APIntOps {
2085 return A.
slt(B) ? A :
B;
2090 return A.
sgt(B) ? A :
B;
2095 return A.
ult(B) ? A :
B;
2100 return A.
ugt(B) ? A :
B;
void clearAllBits()
Set every bit to 0.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
std::string & operator+=(std::string &buffer, StringRef string)
void setSignBit()
Set the sign bit to 1.
double signedRoundToDouble() const
Converts this signed APInt to a double value.
void flipAllBits()
Toggle every bit to its opposite value.
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.
uint64_t getZExtValue() const
Get zero extended value.
APInt operator+(APInt a, const APInt &b)
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
double RoundAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
float RoundAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float vlalue.
bool isOneValue() const
Determine if this is a value of 1.
bool operator!() const
Logical negation operator.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
void print(raw_ostream &OS, bool isSigned) const
APInt lshr(const APInt &ShiftAmt) const
Logical right-shift function.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
bool ule(uint64_t RHS) const
Unsigned less or equal comparison.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
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.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
APInt operator^(APInt a, const APInt &b)
APInt & operator|=(const APInt &RHS)
Bitwise OR assignment operator.
void setAllBits()
Set every bit to 1.
bool slt(int64_t RHS) const
Signed less than comparison.
double roundToDouble(bool isSigned) const
Converts this APInt to a double value.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
bool operator!=(uint64_t Val) const
Inequality operator.
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
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...
bool uge(uint64_t RHS) const
Unsigned greater or equal comparison.
Magic data for optimising unsigned division by a constant.
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 APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
bool isNegative() const
Determine sign of this APInt.
bool sgt(int64_t RHS) const
Signed greater than comparison.
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.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
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.
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...
uint64_t VAL
Used to store the <= 64 bits integer value.
bool isMask(unsigned numBits) const
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
APInt operator*(APInt a, uint64_t RHS)
bool getBoolValue() const
Convert APInt to a boolean value.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
APInt shl(unsigned shiftAmt) const
Left-shift function.
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.
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.
APInt shl(const APInt &ShiftAmt) const
Left-shift function.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getActiveBits() const
Compute the number of active bits in the value.
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.
float RoundSignedAPIntToFloat(const APInt &APIVal)
Converts the given APInt to a float value.
APInt operator~(APInt v)
Unary bitwise complement operator.
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
bool operator==(uint64_t Val) const
Equality operator.
bool needsCleanup() const
Returns whether this instance allocated memory.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
bool operator==(const APInt &RHS) const
Equality operator.
Function Alias Analysis false
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
bool eq(const APInt &RHS) const
Equality comparison.
bool ugt(uint64_t RHS) const
Unsigned greater than comparison.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
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 & operator&=(uint64_t RHS)
Bitwise AND assignment operator.
APInt & operator&=(const APInt &RHS)
Bitwise AND assignment operator.
APInt operator<<(const APInt &Bits) const
Left logical shift operator.
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
int64_t getSExtValue() const
Get sign extended value.
unsigned countLeadingOnes() const
Count the number of leading one bits.
APInt operator&(APInt a, const APInt &b)
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.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
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.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
bool isMaxValue() const
Determine if this is the largest unsigned value.
static unsigned getNumWords(unsigned BitWidth)
Get the number of words.
unsigned countPopulation() const
Count the number of bits set.
void clearSignBit()
Set the sign bit to 0.
bool sge(int64_t RHS) const
Signed greater or equal 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 ...
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
double roundToDouble() const
Converts this unsigned APInt to a double value.
unsigned countPopulation(T Value)
Count the number of set bits in a value.
unsigned logBase2() const
APInt(const APInt &that)
Simply makes *this a copy of that.
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
void negate()
Negate this APInt in place.
int32_t exactLogBase2() const
uint64_t DoubleToBits(double Double)
This function takes a double and returns the bit equivalent 64-bit integer.
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
unsigned ceilLogBase2() const
Class for arbitrary precision integers.
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
APInt operator<<(unsigned Bits) const
Left logical shift operator.
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.
bool isMinValue() const
Determine if this is the smallest unsigned value.
double bitsToDouble() const
Converts APInt bits to a double.
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.
bool sle(uint64_t RHS) const
Signed less or equal comparison.
bool ult(uint64_t RHS) const
Unsigned less than comparison.
bool operator!=(uint64_t V1, const APInt &V2)
bool isAllOnesValue() const
Determine if all bits are set.
bool operator!=(const APInt &RHS) const
Inequality operator.
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 isMinSignedValue() const
Determine if this is the smallest signed value.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
bool isShiftedMask() const
Return true if this APInt value contains a sequence of ones with the remainder zero.
APInt & operator|=(uint64_t RHS)
Bitwise OR assignment operator.
APInt & operator^=(const APInt &RHS)
Bitwise XOR assignment operator.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
APInt & operator=(uint64_t RHS)
Assignment operator.
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.
static bool isSplat(ArrayRef< Value * > VL)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
bool operator[](unsigned bitPosition) const
Array-indexing support.
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.
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.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
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.
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
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.
APInt zext(unsigned width) const
Zero extend to a new width.
bool isNullValue() const
Determine if all bits are clear.
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 abs() const
Get the absolute value;.
APInt RoundDoubleToAPInt(double Double, unsigned width)
Converts the given double value into a APInt.
T reverseBits(T Val)
Reverse the bits in Val.
unsigned nearestLogBase2() const
static APInt floatToBits(float V)
Converts a float to APInt bits.
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
double RoundSignedAPIntToDouble(const APInt &APIVal)
Converts the given APInt to a double value.
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.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
uint64_t * pVal
Used to store the >64 bits integer value.
bool ne(const APInt &RHS) const
Inequality comparison.
float bitsToFloat() const
Converts APInt bits to a double.
APInt ashr(const APInt &ShiftAmt) const
Arithmetic right-shift function.
bool slt(const APInt &RHS) const
Signed less than comparison.
unsigned getNumWords() const
Get the number of words.