16 #ifndef LLVM_ADT_APINT_H 17 #define LLVM_ADT_APINT_H 27 class FoldingSetNodeID;
32 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 WORD_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 = WORD_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()) {
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; }
397 return U.VAL == WORD_MAX >> (APINT_BITS_PER_WORD - BitWidth);
398 return countTrailingOnesSlowCase() == BitWidth;
413 return countLeadingZerosSlowCase() == BitWidth - 1;
428 return U.VAL == ((WordType(1) << (BitWidth - 1)) - 1);
429 return !isNegative() && countTrailingOnesSlowCase() == BitWidth - 1;
444 return U.VAL == (WordType(1) << (BitWidth - 1));
445 return isNegative() && countTrailingZerosSlowCase() == BitWidth - 1;
450 assert(N &&
"N == 0 ???");
451 return getActiveBits() <=
N;
456 assert(N &&
"N == 0 ???");
457 return getMinSignedBits() <=
N;
466 return countPopulationSlowCase() == 1;
482 return ugt(Limit) ? Limit : getZExtValue();
490 bool isSplat(
unsigned SplatSizeInBits)
const;
495 assert(numBits != 0 &&
"numBits must be non-zero");
496 assert(numBits <= BitWidth &&
"numBits out of range");
498 return U.VAL == (WORD_MAX >> (APINT_BITS_PER_WORD - numBits));
499 unsigned Ones = countTrailingOnesSlowCase();
500 return (numBits == Ones) &&
501 ((Ones + countLeadingZerosSlowCase()) == BitWidth);
510 unsigned Ones = countTrailingOnesSlowCase();
511 return (Ones > 0) && ((Ones + countLeadingZerosSlowCase()) == BitWidth);
519 unsigned Ones = countPopulationSlowCase();
520 unsigned LeadZ = countLeadingZerosSlowCase();
530 return getAllOnesValue(numBits);
535 APInt API = getAllOnesValue(numBits);
545 APInt API(numBits, 0);
555 return getSignedMinValue(BitWidth);
562 return APInt(numBits, WORD_MAX,
true);
576 APInt getHiBits(
unsigned numBits)
const;
584 APInt getLoBits(
unsigned numBits)
const;
588 APInt Res(numBits, 0);
607 APInt Res(numBits, 0);
624 APInt Res(numBits, 0);
636 APInt Res(numBits, 0);
648 APInt Res(numBits, 0);
654 static APInt getSplat(
unsigned NewLen,
const APInt &V);
724 return countLeadingZerosSlowCase() == BitWidth;
736 if (isSingleWord() && RHS.isSingleWord()) {
738 BitWidth = RHS.BitWidth;
739 return clearUnusedBits();
753 assert(
this != &that &&
"Self-move not supported");
759 memcpy(&U, &that.U,
sizeof(U));
761 BitWidth = that.BitWidth;
775 if (isSingleWord()) {
780 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
792 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
796 AndAssignSlowCase(RHS);
806 if (isSingleWord()) {
811 memset(U.pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
822 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
826 OrAssignSlowCase(RHS);
836 if (isSingleWord()) {
852 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
856 XorAssignSlowCase(RHS);
866 if (isSingleWord()) {
881 APInt &operator*=(uint64_t RHS);
897 APInt &operator-=(uint64_t RHS);
905 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
906 if (isSingleWord()) {
907 if (ShiftAmt == BitWidth)
911 return clearUnusedBits();
913 shlSlowCase(ShiftAmt);
954 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
955 if (isSingleWord()) {
957 if (ShiftAmt == BitWidth)
958 U.VAL = SExtVAL >> (APINT_BITS_PER_WORD - 1);
960 U.VAL = SExtVAL >> ShiftAmt;
964 ashrSlowCase(ShiftAmt);
978 assert(ShiftAmt <= BitWidth &&
"Invalid shift amount");
979 if (isSingleWord()) {
980 if (ShiftAmt == BitWidth)
986 lshrSlowCase(ShiftAmt);
999 APInt rotl(
unsigned rotateAmt)
const;
1002 APInt rotr(
unsigned rotateAmt)
const;
1014 void ashrInPlace(
const APInt &shiftAmt);
1026 void lshrInPlace(
const APInt &ShiftAmt);
1051 APInt udiv(uint64_t RHS)
const;
1059 APInt sdiv(int64_t RHS)
const;
1071 uint64_t urem(uint64_t RHS)
const;
1077 int64_t srem(int64_t RHS)
const;
1086 static void udivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1088 static void udivrem(
const APInt &LHS, uint64_t RHS,
APInt &Quotient,
1089 uint64_t &Remainder);
1091 static void sdivrem(
const APInt &LHS,
const APInt &RHS,
APInt &Quotient,
1093 static void sdivrem(
const APInt &LHS, int64_t RHS,
APInt &Quotient,
1094 int64_t &Remainder);
1097 APInt sadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1098 APInt uadd_ov(
const APInt &RHS,
bool &Overflow)
const;
1099 APInt ssub_ov(
const APInt &RHS,
bool &Overflow)
const;
1100 APInt usub_ov(
const APInt &RHS,
bool &Overflow)
const;
1101 APInt sdiv_ov(
const APInt &RHS,
bool &Overflow)
const;
1102 APInt smul_ov(
const APInt &RHS,
bool &Overflow)
const;
1104 APInt sshl_ov(
const APInt &Amt,
bool &Overflow)
const;
1105 APInt ushl_ov(
const APInt &Amt,
bool &Overflow)
const;
1112 return (maskBit(bitPosition) & getWord(bitPosition)) != 0;
1124 assert(BitWidth == RHS.BitWidth &&
"Comparison requires equal bit widths");
1126 return U.VAL == RHS.U.
VAL;
1127 return EqualSlowCase(RHS);
1137 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() == Val;
1146 bool eq(
const APInt &RHS)
const {
return (*
this) == RHS; }
1162 bool operator!=(uint64_t Val)
const {
return !((*this) == Val); }
1170 bool ne(
const APInt &RHS)
const {
return !((*this) == RHS); }
1186 bool ult(uint64_t RHS)
const {
1188 return (isSingleWord() || getActiveBits() <= 64) && getZExtValue() < RHS;
1197 bool slt(
const APInt &RHS)
const {
return compareSigned(RHS) < 0; }
1206 return (!isSingleWord() && getMinSignedBits() > 64) ? isNegative()
1207 : getSExtValue() < RHS;
1224 bool ule(uint64_t RHS)
const {
return !ugt(RHS); }
1232 bool sle(
const APInt &RHS)
const {
return compareSigned(RHS) <= 0; }
1240 bool sle(uint64_t RHS)
const {
return !sgt(RHS); }
1256 bool ugt(uint64_t RHS)
const {
1258 return (!isSingleWord() && getActiveBits() > 64) || getZExtValue() > RHS;
1276 return (!isSingleWord() && getMinSignedBits() > 64) ? !isNegative()
1277 : getSExtValue() > RHS;
1294 bool uge(uint64_t RHS)
const {
return !ult(RHS); }
1310 bool sge(int64_t RHS)
const {
return !slt(RHS); }
1315 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1317 return (U.VAL & RHS.U.
VAL) != 0;
1318 return intersectsSlowCase(RHS);
1323 assert(BitWidth == RHS.BitWidth &&
"Bit widths must be the same");
1325 return (U.VAL & ~RHS.U.
VAL) == 0;
1326 return isSubsetOfSlowCase(RHS);
1337 APInt trunc(
unsigned width)
const;
1345 APInt sext(
unsigned width)
const;
1352 APInt zext(
unsigned width)
const;
1358 APInt sextOrTrunc(
unsigned width)
const;
1364 APInt zextOrTrunc(
unsigned width)
const;
1370 APInt sextOrSelf(
unsigned width)
const;
1376 APInt zextOrSelf(
unsigned width)
const;
1388 memset(U.pVal, -1, getNumWords() * APINT_WORD_SIZE);
1397 assert(BitPosition <= BitWidth &&
"BitPosition out of range");
1398 WordType
Mask = maskBit(BitPosition);
1402 U.pVal[whichWord(BitPosition)] |=
Mask;
1407 setBit(BitWidth - 1);
1412 assert(hiBit <= BitWidth &&
"hiBit out of range");
1413 assert(loBit <= BitWidth &&
"loBit out of range");
1414 assert(loBit <= hiBit &&
"loBit greater than hiBit");
1417 if (loBit < APINT_BITS_PER_WORD && hiBit <= APINT_BITS_PER_WORD) {
1418 uint64_t mask = WORD_MAX >> (APINT_BITS_PER_WORD - (hiBit - loBit));
1425 setBitsSlowCase(loBit, hiBit);
1431 return setBits(loBit, BitWidth);
1436 return setBits(0, loBits);
1441 return setBits(BitWidth - hiBits, BitWidth);
1449 memset(U.pVal, 0, getNumWords() * APINT_WORD_SIZE);
1456 assert(BitPosition <= BitWidth &&
"BitPosition out of range");
1457 WordType
Mask = ~maskBit(BitPosition);
1461 U.pVal[whichWord(BitPosition)] &=
Mask;
1466 clearBit(BitWidth - 1);
1471 if (isSingleWord()) {
1475 flipAllBitsSlowCase();
1483 void flipBit(
unsigned bitPosition);
1492 void insertBits(
const APInt &SubBits,
unsigned bitPosition);
1495 APInt extractBits(
unsigned numBits,
unsigned bitPosition)
const;
1518 return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
1533 unsigned numActiveBits = getActiveBits();
1534 return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
1548 return getActiveBits() + 1;
1559 assert(getActiveBits() <= 64 &&
"Too many bits for uint64_t");
1571 assert(getMinSignedBits() <= 64 &&
"Too many bits for int64_t");
1572 return int64_t(U.pVal[0]);
1579 static unsigned getBitsNeeded(
StringRef str, uint8_t radix);
1590 if (isSingleWord()) {
1591 unsigned unusedBits = APINT_BITS_PER_WORD - BitWidth;
1594 return countLeadingZerosSlowCase();
1608 return countLeadingOnesSlowCase();
1628 return countTrailingZerosSlowCase();
1642 return countTrailingOnesSlowCase();
1654 return countPopulationSlowCase();
1665 bool formatAsCLiteral =
false)
const;
1670 toString(Str, Radix,
false,
false);
1684 std::string
toString(
unsigned Radix,
bool Signed)
const;
1687 APInt byteSwap()
const;
1694 double roundToDouble(
bool isSigned)
const;
1741 unsigned logBase2()
const {
return getActiveBits() - 1; }
1775 unsigned lg = logBase2();
1776 return lg +
unsigned((*
this)[lg - 1]);
1800 APInt multiplicativeInverse(
const APInt &modulo)
const;
1812 mu magicu(
unsigned LeadingZeros = 0)
const;
1826 static void tcSet(WordType *, WordType,
unsigned);
1829 static void tcAssign(WordType *,
const WordType *,
unsigned);
1832 static bool tcIsZero(
const WordType *,
unsigned);
1835 static int tcExtractBit(
const WordType *,
unsigned bit);
1841 static void tcExtract(WordType *,
unsigned dstCount,
1842 const WordType *,
unsigned srcBits,
1846 static void tcSetBit(WordType *,
unsigned bit);
1849 static void tcClearBit(WordType *,
unsigned bit);
1853 static unsigned tcLSB(
const WordType *,
unsigned n);
1854 static unsigned tcMSB(
const WordType *parts,
unsigned n);
1857 static void tcNegate(WordType *,
unsigned);
1860 static WordType tcAdd(WordType *,
const WordType *,
1861 WordType carry,
unsigned);
1863 static WordType tcAddPart(WordType *, WordType,
unsigned);
1866 static WordType tcSubtract(WordType *,
const WordType *,
1867 WordType carry,
unsigned);
1869 static WordType tcSubtractPart(WordType *, WordType,
unsigned);
1881 static int tcMultiplyPart(WordType *dst,
const WordType *src,
1882 WordType multiplier, WordType carry,
1883 unsigned srcParts,
unsigned dstParts,
1890 static int tcMultiply(WordType *,
const WordType *,
const WordType *,
1895 static void tcFullMultiply(WordType *,
const WordType *,
1896 const WordType *,
unsigned,
unsigned);
1907 static int tcDivide(WordType *lhs,
const WordType *rhs,
1913 static void tcShiftLeft(WordType *,
unsigned Words,
unsigned Count);
1917 static void tcShiftRight(WordType *,
unsigned Words,
unsigned Count);
1920 static void tcAnd(WordType *,
const WordType *,
unsigned);
1921 static void tcOr(WordType *,
const WordType *,
unsigned);
1922 static void tcXor(WordType *,
const WordType *,
unsigned);
1923 static void tcComplement(WordType *,
unsigned);
1926 static int tcCompare(
const WordType *,
const WordType *,
unsigned);
1930 return tcAddPart(dst, 1, parts);
1935 return tcSubtractPart(dst, 1, parts);
1939 static void tcSetLeastSignificantBits(WordType *,
unsigned,
unsigned bits);
1979 return std::move(b);
1999 return std::move(b);
2019 return std::move(b);
2049 return std::move(b);
2070 return std::move(b);
2095 namespace APIntOps {
2099 return A.
slt(B) ? A :
B;
2104 return A.
sgt(B) ? A :
B;
2109 return A.
ult(B) ? A :
B;
2114 return A.
ugt(B) ? A :
B;
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
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.
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.
static bool isSigned(Value *V)
Can the given value generate sign bits.
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.