16 #ifndef LLVM_ADT_APINT_H 17 #define LLVM_ADT_APINT_H 27 class FoldingSetNodeID;
32 template <
typename T>
class SmallVectorImpl;
77 APINT_WORD_SIZE =
sizeof(WordType),
79 APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT
88 static const WordType WORDTYPE_MAX = ~WordType(0);
108 APInt(uint64_t *val,
unsigned bits) : BitWidth(bits) {
115 bool isSingleWord()
const {
return BitWidth <= APINT_BITS_PER_WORD; }
120 static unsigned whichWord(
unsigned bitPosition) {
121 return bitPosition / APINT_BITS_PER_WORD;
128 static unsigned whichBit(
unsigned bitPosition) {
129 return bitPosition % APINT_BITS_PER_WORD;
138 static uint64_t maskBit(
unsigned bitPosition) {
139 return 1ULL << whichBit(bitPosition);
148 APInt &clearUnusedBits() {
150 unsigned WordBits = ((BitWidth-1) % APINT_BITS_PER_WORD) + 1;
153 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - WordBits);
157 U.pVal[getNumWords() - 1] &= mask;
163 uint64_t getWord(
unsigned bitPosition)
const {
164 return isSingleWord() ? U.VAL : U.pVal[whichWord(bitPosition)];
170 void reallocate(
unsigned NewBitWidth);
192 static void divide(
const WordType *LHS,
unsigned lhsWords,
193 const WordType *RHS,
unsigned rhsWords, WordType *Quotient,
194 WordType *Remainder);
197 void initSlowCase(uint64_t val,
bool isSigned);
203 void initSlowCase(
const APInt &that);
206 void shlSlowCase(
unsigned ShiftAmt);
209 void lshrSlowCase(
unsigned ShiftAmt);
212 void ashrSlowCase(
unsigned ShiftAmt);
215 void AssignSlowCase(
const APInt &RHS);
221 unsigned countLeadingZerosSlowCase()
const LLVM_READONLY;
224 unsigned countLeadingOnesSlowCase()
const LLVM_READONLY;
227 unsigned countTrailingZerosSlowCase()
const LLVM_READONLY;
230 unsigned countTrailingOnesSlowCase()
const LLVM_READONLY;
233 unsigned countPopulationSlowCase()
const LLVM_READONLY;
242 void setBitsSlowCase(
unsigned loBit,
unsigned hiBit);
245 void flipAllBitsSlowCase();
279 : BitWidth(numBits) {
280 assert(BitWidth &&
"bitwidth too small");
281 if (isSingleWord()) {
285 initSlowCase(val, isSigned);
305 APInt(
unsigned numBits,
unsigned numWords,
const uint64_t bigVal[]);
331 memcpy(&U, &that.U,
sizeof(U));
346 explicit APInt() : BitWidth(1) { U.VAL = 0; }
398 return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
399 return countTrailingOnesSlowCase() == BitWidth;
414 return countLeadingZerosSlowCase() == BitWidth - 1;
429 return U.VAL == ((WordType(1) << (BitWidth - 1)) - 1);
430 return !isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
445 return U.VAL == (WordType(1) << (BitWidth - 1));
446 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
451 assert(N &&
"N == 0 ???");
452 return getActiveBits() <=
N;
457 assert(N &&
"N == 0 ???");
458 return getMinSignedBits() <=
N;
467 return countPopulationSlowCase() == 1;
483 return ugt(Limit) ? Limit : getZExtValue();
491 bool isSplat(
unsigned SplatSizeInBits)
const;
496 assert(numBits != 0 &&
"numBits must be non-zero");
497 assert(numBits <= BitWidth &&
"numBits out of range");
499 return U.VAL == (WORDTYPE_MAX >> (APINT_BITS_PER_WORD - numBits));
500 unsigned Ones = countTrailingOnesSlowCase();
501 return (numBits == Ones) &&
502 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
511 unsigned Ones = countTrailingOnesSlowCase();
512 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
520 unsigned Ones = countPopulationSlowCase();
521 unsigned LeadZ = countLeadingZerosSlowCase();
531 return getAllOnesValue(numBits);
536 APInt API = getAllOnesValue(numBits);
546 APInt API(numBits, 0);
556 return getSignedMinValue(BitWidth);
563 return APInt(numBits, WORDTYPE_MAX,
true);
577 APInt getHiBits(
unsigned numBits)
const;
585 APInt getLoBits(
unsigned numBits)
const;
589 APInt Res(numBits, 0);
608 APInt Res(numBits, 0);
625 APInt Res(numBits, 0);
637 APInt Res(numBits, 0);
649 APInt Res(numBits, 0);
655 static APInt getSplat(
unsigned NewLen,
const APInt &V);
725 return countLeadingZerosSlowCase() == BitWidth;
737 if (isSingleWord() && RHS.isSingleWord()) {
739 BitWidth = RHS.BitWidth;
740 return clearUnusedBits();
754 assert(
this != &that &&
"Self-move not supported");
760 memcpy(&U, &that.U,
sizeof(U));
762 BitWidth = that.BitWidth;
776 if (isSingleWord()) {
781 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
793 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
797 AndAssignSlowCase(RHS);
807 if (isSingleWord()) {
812 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
823 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
827 OrAssignSlowCase(RHS);
837 if (isSingleWord()) {
853 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
857 XorAssignSlowCase(RHS);
867 if (isSingleWord()) {
882 APInt &operator*=(uint64_t RHS);
898 APInt &operator-=(uint64_t RHS);
906 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
907 if (isSingleWord()) {
908 if (ShiftAmt == BitWidth)
912 return clearUnusedBits();
914 shlSlowCase(ShiftAmt);
955 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
956 if (isSingleWord()) {
958 if (ShiftAmt == BitWidth)
959 U.VAL = SExtVAL >> (APINT_BITS_PER_WORD - 1);
961 U.VAL = SExtVAL >> ShiftAmt;
965 ashrSlowCase(ShiftAmt);
979 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
980 if (isSingleWord()) {
981 if (ShiftAmt == BitWidth)
987 lshrSlowCase(ShiftAmt);
1000 APInt rotl(
unsigned rotateAmt)
const;
1003 APInt rotr(
unsigned rotateAmt)
const;
1015 void ashrInPlace(
const APInt &shiftAmt);
1027 void lshrInPlace(
const APInt &ShiftAmt);
1052 APInt udiv(uint64_t RHS)
const;
1060 APInt sdiv(int64_t RHS)
const;
1072 uint64_t urem(uint64_t RHS)
const;
1078 int64_t srem(int64_t RHS)
const;
1087 static void udivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1089 static void udivrem(
const APInt &LHS, uint64_t RHS,
APInt &Quotient,
1090 uint64_t &Remainder);
1092 static void sdivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1094 static void sdivrem(
const APInt &LHS, int64_t RHS,
APInt &Quotient,
1095 int64_t &Remainder);
1098 APInt sadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1099 APInt uadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1100 APInt ssub_ov(
const APInt &RHS,
bool &Overflow)
const;
1101 APInt usub_ov(
const APInt &RHS,
bool &Overflow)
const;
1102 APInt sdiv_ov(
const APInt &RHS,
bool &Overflow)
const;
1103 APInt smul_ov(
const APInt &RHS,
bool &Overflow)
const;
1105 APInt sshl_ov(
const APInt &Amt,
bool &Overflow)
const;
1106 APInt ushl_ov(
const APInt &Amt,
bool &Overflow)
const;
1119 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1131 assert(BitWidth == RHS.BitWidth &&
"Comparison requires equal bit widths");
1133 return U.VAL == RHS.U.
VAL;
1134 return EqualSlowCase(RHS);
1144 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() == Val;
1153 bool eq(
const APInt &RHS)
const {
return (*
this) == RHS; }
1169 bool operator!=(uint64_t Val)
const {
return !((*this) == Val); }
1177 bool ne(
const APInt &RHS)
const {
return !((*this) == RHS); }
1193 bool ult(uint64_t RHS)
const {
1195 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
1204 bool slt(
const APInt &RHS)
const {
return compareSigned(RHS) < 0; }
1213 return (!isSingleWord() && getMinSignedBits() > 64) ? isNegative()
1214 : getSExtValue() < RHS;
1231 bool ule(uint64_t RHS)
const {
return !ugt(RHS); }
1239 bool sle(
const APInt &RHS)
const {
return compareSigned(RHS) <= 0; }
1247 bool sle(uint64_t RHS)
const {
return !sgt(RHS); }
1263 bool ugt(uint64_t RHS)
const {
1265 return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
1283 return (!isSingleWord() && getMinSignedBits() > 64) ? !isNegative()
1284 : getSExtValue() > RHS;
1301 bool uge(uint64_t RHS)
const {
return !ult(RHS); }
1317 bool sge(int64_t RHS)
const {
return !slt(RHS); }
1322 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1324 return (U.VAL & RHS.U.
VAL) != 0;
1325 return intersectsSlowCase(RHS);
1330 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1332 return (U.VAL & ~RHS.U.
VAL) == 0;
1333 return isSubsetOfSlowCase(RHS);
1352 APInt sext(
unsigned width)
const;
1359 APInt zext(
unsigned width)
const;
1365 APInt sextOrTrunc(
unsigned width)
const;
1371 APInt zextOrTrunc(
unsigned width)
const;
1377 APInt sextOrSelf(
unsigned width)
const;
1383 APInt zextOrSelf(
unsigned width)
const;
1392 U.VAL = WORDTYPE_MAX;
1395 memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
1404 assert(BitPosition < BitWidth &&
"BitPosition out of range");
1405 WordType
Mask = maskBit(BitPosition);
1409 U.pVal[whichWord(BitPosition)] |=
Mask;
1414 setBit(BitWidth - 1);
1419 assert(hiBit <= BitWidth &&
"hiBit out of range");
1420 assert(loBit <= BitWidth &&
"loBit out of range");
1421 assert(loBit <= hiBit &&
"loBit greater than hiBit");
1424 if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
1425 uint64_t mask = WORDTYPE_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1432 setBitsSlowCase(loBit, hiBit);
1438 return setBits(loBit, BitWidth);
1443 return setBits(0, loBits);
1448 return setBits(BitWidth - hiBits, BitWidth);
1456 memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE);
1463 assert(BitPosition < BitWidth &&
"BitPosition out of range");
1464 WordType
Mask = ~maskBit(BitPosition);
1468 U.pVal[whichWord(BitPosition)] &=
Mask;
1473 clearBit(BitWidth - 1);
1478 if (isSingleWord()) {
1479 U.VAL ^= WORDTYPE_MAX;
1482 flipAllBitsSlowCase();
1490 void flipBit(
unsigned bitPosition);
1499 void insertBits(
const APInt &SubBits,
unsigned bitPosition);
1502 APInt extractBits(
unsigned numBits,
unsigned bitPosition)
const;
1525 return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
1540 unsigned numActiveBits = getActiveBits();
1541 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1555 return getActiveBits() + 1;
1566 assert(getActiveBits() <= 64 &&
"Too many bits for uint64_t");
1578 assert(getMinSignedBits() <= 64 &&
"Too many bits for int64_t");
1579 return int64_t(U.pVal[0]);
1586 static unsigned getBitsNeeded(
StringRef str, uint8_t radix);
1597 if (isSingleWord()) {
1598 unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1601 return countLeadingZerosSlowCase();
1615 return countLeadingOnesSlowCase();
1635 return countTrailingZerosSlowCase();
1649 return countTrailingOnesSlowCase();
1661 return countPopulationSlowCase();
1672 bool formatAsCLiteral =
false)
const;
1677 toString(Str, Radix,
false,
false);
1691 std::string
toString(
unsigned Radix,
bool Signed)
const;
1694 APInt byteSwap()
const;
1701 double roundToDouble(
bool isSigned)
const;
1748 unsigned logBase2()
const {
return getActiveBits() - 1; }
1782 unsigned lg = logBase2();
1783 return lg +
unsigned((*
this)[lg - 1]);
1807 APInt multiplicativeInverse(
const APInt &modulo)
const;
1819 mu magicu(
unsigned LeadingZeros = 0)
const;
1833 static void tcSet(WordType *, WordType,
unsigned);
1836 static void tcAssign(WordType *,
const WordType *,
unsigned);
1839 static bool tcIsZero(
const WordType *,
unsigned);
1842 static int tcExtractBit(
const WordType *,
unsigned bit);
1848 static void tcExtract(WordType *,
unsigned dstCount,
1849 const WordType *,
unsigned srcBits,
1853 static void tcSetBit(WordType *,
unsigned bit);
1856 static void tcClearBit(WordType *,
unsigned bit);
1860 static unsigned tcLSB(
const WordType *,
unsigned n);
1861 static unsigned tcMSB(
const WordType *parts,
unsigned n);
1864 static void tcNegate(WordType *,
unsigned);
1867 static WordType tcAdd(WordType *,
const WordType *,
1868 WordType carry,
unsigned);
1870 static WordType tcAddPart(WordType *, WordType,
unsigned);
1873 static WordType tcSubtract(WordType *,
const WordType *,
1874 WordType carry,
unsigned);
1876 static WordType tcSubtractPart(WordType *, WordType,
unsigned);
1888 static int tcMultiplyPart(WordType *dst,
const WordType *src,
1889 WordType multiplier, WordType carry,
1890 unsigned srcParts,
unsigned dstParts,
1897 static int tcMultiply(WordType *,
const WordType *,
const WordType *,
1902 static void tcFullMultiply(WordType *,
const WordType *,
1903 const WordType *,
unsigned,
unsigned);
1914 static int tcDivide(WordType *lhs,
const WordType *rhs,
1920 static void tcShiftLeft(WordType *,
unsigned Words,
unsigned Count);
1924 static void tcShiftRight(WordType *,
unsigned Words,
unsigned Count);
1927 static void tcAnd(WordType *,
const WordType *,
unsigned);
1928 static void tcOr(WordType *,
const WordType *,
unsigned);
1929 static void tcXor(WordType *,
const WordType *,
unsigned);
1930 static void tcComplement(WordType *,
unsigned);
1933 static int tcCompare(
const WordType *,
const WordType *,
unsigned);
1937 return tcAddPart(dst, 1, parts);
1942 return tcSubtractPart(dst, 1, parts);
1946 static void tcSetLeastSignificantBits(WordType *,
unsigned,
unsigned bits);
1986 return std::move(b);
2006 return std::move(b);
2026 return std::move(b);
2056 return std::move(b);
2077 return std::move(b);
2102 namespace APIntOps {
2106 return A.
slt(B) ? A :
B;
2111 return A.
sgt(B) ? A :
B;
2116 return A.
ult(B) ? A :
B;
2121 return A.
ugt(B) ? A :
B;
2210 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.
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 getNumWords() const
Get the number of words.
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 greather 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.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
APInt GreatestCommonDivisor(APInt A, APInt B)
Compute GCD of two unsigned APInt values.
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
Magic data for optimising unsigned division by a constant.
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() const
Count the number of trailing zero bits.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
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...
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 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.
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.
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.
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...
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.
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 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.
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.
amdgpu Simplify well known AMD library false Value Value * Arg
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 greather 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< 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 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.
int compare(DigitsT LDigits, int16_t LScale, DigitsT RDigits, int16_t RScale)
Compare two scaled numbers.
float bitsToFloat() const
Converts APInt bits to a double.
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)
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.
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.
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.