clang-formatted APInt.h

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182685 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Gottesman 2013-05-24 22:38:49 +00:00
parent 927d8dcb47
commit 612ca08e66

View File

@ -32,16 +32,15 @@ namespace llvm {
class hash_code; class hash_code;
class raw_ostream; class raw_ostream;
template<typename T> template <typename T> class SmallVectorImpl;
class SmallVectorImpl;
// An unsigned host type used as a single part of a multi-part // An unsigned host type used as a single part of a multi-part
// bignum. // bignum.
typedef uint64_t integerPart; typedef uint64_t integerPart;
const unsigned int host_char_bit = 8; const unsigned int host_char_bit = 8;
const unsigned int integerPartWidth = host_char_bit * const unsigned int integerPartWidth =
static_cast<unsigned int>(sizeof(integerPart)); host_char_bit * static_cast<unsigned int>(sizeof(integerPart));
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// APInt Class // APInt Class
@ -86,8 +85,8 @@ class APInt {
/// This enum is used to hold the constants we needed for APInt. /// This enum is used to hold the constants we needed for APInt.
enum { enum {
/// Bits in a word /// Bits in a word
APINT_BITS_PER_WORD = static_cast<unsigned int>(sizeof(uint64_t)) * APINT_BITS_PER_WORD =
CHAR_BIT, static_cast<unsigned int>(sizeof(uint64_t)) * CHAR_BIT,
/// Byte size of a word /// Byte size of a word
APINT_WORD_SIZE = static_cast<unsigned int>(sizeof(uint64_t)) APINT_WORD_SIZE = static_cast<unsigned int>(sizeof(uint64_t))
}; };
@ -101,9 +100,7 @@ class APInt {
/// \brief Determine if this APInt just has one word to store value. /// \brief Determine if this APInt just has one word to store value.
/// ///
/// \returns true if the number of bits <= 64, false otherwise. /// \returns true if the number of bits <= 64, false otherwise.
bool isSingleWord() const { bool isSingleWord() const { return BitWidth <= APINT_BITS_PER_WORD; }
return BitWidth <= APINT_BITS_PER_WORD;
}
/// \brief Determine which word a bit is in. /// \brief Determine which word a bit is in.
/// ///
@ -180,9 +177,8 @@ class APInt {
/// provides a more convenient form of divide for internal use since KnuthDiv /// provides a more convenient form of divide for internal use since KnuthDiv
/// has specific constraints on its inputs. If those constraints are not met /// has specific constraints on its inputs. If those constraints are not met
/// then it provides a simpler form of divide. /// then it provides a simpler form of divide.
static void divide(const APInt LHS, unsigned lhsWords, static void divide(const APInt LHS, unsigned lhsWords, const APInt &RHS,
const APInt &RHS, unsigned rhsWords, unsigned rhsWords, APInt *Quotient, APInt *Remainder);
APInt *Quotient, APInt *Remainder);
/// out-of-line slow case for inline constructor /// out-of-line slow case for inline constructor
void initSlowCase(unsigned numBits, uint64_t val, bool isSigned); void initSlowCase(unsigned numBits, uint64_t val, bool isSigned);
@ -280,8 +276,7 @@ public:
/// Simply makes *this a copy of that. /// Simply makes *this a copy of that.
/// @brief Copy Constructor. /// @brief Copy Constructor.
APInt(const APInt& that) APInt(const APInt &that) : BitWidth(that.BitWidth), VAL(0) {
: BitWidth(that.BitWidth), VAL(0) {
assert(BitWidth && "bitwidth too small"); assert(BitWidth && "bitwidth too small");
if (isSingleWord()) if (isSingleWord())
VAL = that.VAL; VAL = that.VAL;
@ -321,16 +316,12 @@ public:
/// This tests the high bit of this APInt to determine if it is set. /// This tests the high bit of this APInt to determine if it is set.
/// ///
/// \returns true if this APInt is negative, false otherwise /// \returns true if this APInt is negative, false otherwise
bool isNegative() const { bool isNegative() const { return (*this)[BitWidth - 1]; }
return (*this)[BitWidth - 1];
}
/// \brief Determine if this APInt Value is non-negative (>= 0) /// \brief Determine if this APInt Value is non-negative (>= 0)
/// ///
/// This tests the high bit of the APInt to determine if it is unset. /// This tests the high bit of the APInt to determine if it is unset.
bool isNonNegative() const { bool isNonNegative() const { return !isNegative(); }
return !isNegative();
}
/// \brief Determine if this APInt Value is positive. /// \brief Determine if this APInt Value is positive.
/// ///
@ -338,41 +329,33 @@ public:
/// that 0 is not a positive value. /// that 0 is not a positive value.
/// ///
/// \returns true if this APInt is positive. /// \returns true if this APInt is positive.
bool isStrictlyPositive() const { bool isStrictlyPositive() const { return isNonNegative() && !!*this; }
return isNonNegative() && !!*this;
}
/// \brief Determine if all bits are set /// \brief Determine if all bits are set
/// ///
/// This checks to see if the value has all bits of the APInt are set or not. /// This checks to see if the value has all bits of the APInt are set or not.
bool isAllOnesValue() const { bool isAllOnesValue() const { return countPopulation() == BitWidth; }
return countPopulation() == BitWidth;
}
/// \brief Determine if this is the largest unsigned value. /// \brief Determine if this is the largest unsigned value.
/// ///
/// This checks to see if the value of this APInt is the maximum unsigned /// This checks to see if the value of this APInt is the maximum unsigned
/// value for the APInt's bit width. /// value for the APInt's bit width.
bool isMaxValue() const { bool isMaxValue() const { return countPopulation() == BitWidth; }
return countPopulation() == BitWidth;
}
/// \brief Determine if this is the largest signed value. /// \brief Determine if this is the largest signed value.
/// ///
/// This checks to see if the value of this APInt is the maximum signed /// This checks to see if the value of this APInt is the maximum signed
/// value for the APInt's bit width. /// value for the APInt's bit width.
bool isMaxSignedValue() const { bool isMaxSignedValue() const {
return BitWidth == 1 ? VAL == 0 : return BitWidth == 1 ? VAL == 0
!isNegative() && countPopulation() == BitWidth - 1; : !isNegative() && countPopulation() == BitWidth - 1;
} }
/// \brief Determine if this is the smallest unsigned value. /// \brief Determine if this is the smallest unsigned value.
/// ///
/// This checks to see if the value of this APInt is the minimum unsigned /// This checks to see if the value of this APInt is the minimum unsigned
/// value for the APInt's bit width. /// value for the APInt's bit width.
bool isMinValue() const { bool isMinValue() const { return !*this; }
return !*this;
}
/// \brief Determine if this is the smallest signed value. /// \brief Determine if this is the smallest signed value.
/// ///
@ -411,15 +394,13 @@ public:
/// \brief Convert APInt to a boolean value. /// \brief Convert APInt to a boolean value.
/// ///
/// This converts the APInt to a boolean value as a test against zero. /// This converts the APInt to a boolean value as a test against zero.
bool getBoolValue() const { bool getBoolValue() const { return !!*this; }
return !!*this;
}
/// If this value is smaller than the specified limit, return it, otherwise /// If this value is smaller than the specified limit, return it, otherwise
/// return the limit value. This causes the value to saturate to the limit. /// return the limit value. This causes the value to saturate to the limit.
uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
return (getActiveBits() > 64 || getZExtValue() > Limit) ? return (getActiveBits() > 64 || getZExtValue() > Limit) ? Limit
Limit : getZExtValue(); : getZExtValue();
} }
/// @} /// @}
@ -439,9 +420,7 @@ public:
} }
/// \brief Gets minimum unsigned value of APInt for a specific bit width. /// \brief Gets minimum unsigned value of APInt for a specific bit width.
static APInt getMinValue(unsigned numBits) { static APInt getMinValue(unsigned numBits) { return APInt(numBits, 0); }
return APInt(numBits, 0);
}
/// \brief Gets minimum signed value of APInt for a specific bit width. /// \brief Gets minimum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits) { static APInt getSignedMinValue(unsigned numBits) {
@ -468,9 +447,7 @@ public:
/// \brief Get the '0' value. /// \brief Get the '0' value.
/// ///
/// \returns the '0' value for an APInt of the specified bit-width. /// \returns the '0' value for an APInt of the specified bit-width.
static APInt getNullValue(unsigned numBits) { static APInt getNullValue(unsigned numBits) { return APInt(numBits, 0); }
return APInt(numBits, 0);
}
/// \brief Compute an APInt containing numBits highbits from this APInt. /// \brief Compute an APInt containing numBits highbits from this APInt.
/// ///
@ -637,9 +614,7 @@ public:
/// Negates *this using two's complement logic. /// Negates *this using two's complement logic.
/// ///
/// \returns An APInt value representing the negation of *this. /// \returns An APInt value representing the negation of *this.
APInt operator-() const { APInt operator-() const { return APInt(BitWidth, 0) - (*this); }
return APInt(BitWidth, 0) - (*this);
}
/// \brief Logical negation operator. /// \brief Logical negation operator.
/// ///
@ -783,9 +758,7 @@ public:
return APInt(getBitWidth(), VAL & RHS.VAL); return APInt(getBitWidth(), VAL & RHS.VAL);
return AndSlowCase(RHS); return AndSlowCase(RHS);
} }
APInt And(const APInt& RHS) const { APInt And(const APInt &RHS) const { return this->operator&(RHS); }
return this->operator&(RHS);
}
/// \brief Bitwise OR operator. /// \brief Bitwise OR operator.
/// ///
@ -805,9 +778,7 @@ public:
/// calling operator|. /// calling operator|.
/// ///
/// \returns An APInt value representing the bitwise OR of *this and RHS. /// \returns An APInt value representing the bitwise OR of *this and RHS.
APInt Or(const APInt& RHS) const { APInt Or(const APInt &RHS) const { return this->operator|(RHS); }
return this->operator|(RHS);
}
/// \brief Bitwise XOR operator. /// \brief Bitwise XOR operator.
/// ///
@ -827,9 +798,7 @@ public:
/// through the usage of operator^. /// through the usage of operator^.
/// ///
/// \returns An APInt value representing the bitwise XOR of *this and RHS. /// \returns An APInt value representing the bitwise XOR of *this and RHS.
APInt Xor(const APInt& RHS) const { APInt Xor(const APInt &RHS) const { return this->operator^(RHS); }
return this->operator^(RHS);
}
/// \brief Multiplication operator. /// \brief Multiplication operator.
/// ///
@ -840,31 +809,23 @@ public:
/// ///
/// Adds RHS to this APInt and returns the result. /// Adds RHS to this APInt and returns the result.
APInt operator+(const APInt &RHS) const; APInt operator+(const APInt &RHS) const;
APInt operator+(uint64_t RHS) const { APInt operator+(uint64_t RHS) const { return (*this) + APInt(BitWidth, RHS); }
return (*this) + APInt(BitWidth, RHS);
}
/// \brief Subtraction operator. /// \brief Subtraction operator.
/// ///
/// Subtracts RHS from this APInt and returns the result. /// Subtracts RHS from this APInt and returns the result.
APInt operator-(const APInt &RHS) const; APInt operator-(const APInt &RHS) const;
APInt operator-(uint64_t RHS) const { APInt operator-(uint64_t RHS) const { return (*this) - APInt(BitWidth, RHS); }
return (*this) - APInt(BitWidth, RHS);
}
/// \brief Left logical shift operator. /// \brief Left logical shift operator.
/// ///
/// Shifts this APInt left by \p Bits and returns the result. /// Shifts this APInt left by \p Bits and returns the result.
APInt operator<<(unsigned Bits) const { APInt operator<<(unsigned Bits) const { return shl(Bits); }
return shl(Bits);
}
/// \brief Left logical shift operator. /// \brief Left logical shift operator.
/// ///
/// Shifts this APInt left by \p Bits and returns the result. /// Shifts this APInt left by \p Bits and returns the result.
APInt operator<<(const APInt &Bits) const { APInt operator<<(const APInt &Bits) const { return shl(Bits); }
return shl(Bits);
}
/// \brief Arithmetic right-shift function. /// \brief Arithmetic right-shift function.
/// ///
@ -952,12 +913,11 @@ public:
/// computation making it a little more efficient. The pair of input arguments /// computation making it a little more efficient. The pair of input arguments
/// may overlap with the pair of output arguments. It is safe to call /// may overlap with the pair of output arguments. It is safe to call
/// udivrem(X, Y, X, Y), for example. /// udivrem(X, Y, X, Y), for example.
static void udivrem(const APInt &LHS, const APInt &RHS, static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient,
APInt &Quotient, APInt &Remainder); APInt &Remainder);
static void sdivrem(const APInt &LHS, const APInt &RHS,
APInt &Quotient, APInt &Remainder);
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient,
APInt &Remainder);
// Operations that return overflow indicators. // Operations that return overflow indicators.
APInt sadd_ov(const APInt &RHS, bool &Overflow) const; APInt sadd_ov(const APInt &RHS, bool &Overflow) const;
@ -975,7 +935,8 @@ public:
bool operator[](unsigned bitPosition) const { bool operator[](unsigned bitPosition) const {
assert(bitPosition < getBitWidth() && "Bit position out of bounds!"); assert(bitPosition < getBitWidth() && "Bit position out of bounds!");
return (maskBit(bitPosition) & return (maskBit(bitPosition) &
(isSingleWord() ? VAL : pVal[whichWord(bitPosition)])) != 0; (isSingleWord() ? VAL : pVal[whichWord(bitPosition)])) !=
0;
} }
/// @} /// @}
@ -1011,9 +972,7 @@ public:
/// relationship. /// relationship.
/// ///
/// \returns true if *this == Val /// \returns true if *this == Val
bool eq(const APInt &RHS) const { bool eq(const APInt &RHS) const { return (*this) == RHS; }
return (*this) == RHS;
}
/// \brief Inequality operator. /// \brief Inequality operator.
/// ///
@ -1021,9 +980,7 @@ public:
/// relationship. /// relationship.
/// ///
/// \returns true if *this != Val /// \returns true if *this != Val
bool operator!=(const APInt& RHS) const { bool operator!=(const APInt &RHS) const { return !((*this) == RHS); }
return !((*this) == RHS);
}
/// \brief Inequality operator. /// \brief Inequality operator.
/// ///
@ -1031,9 +988,7 @@ public:
/// relationship. /// relationship.
/// ///
/// \returns true if *this != Val /// \returns true if *this != Val
bool operator!=(uint64_t Val) const { bool operator!=(uint64_t Val) const { return !((*this) == Val); }
return !((*this) == Val);
}
/// \brief Inequality comparison /// \brief Inequality comparison
/// ///
@ -1041,9 +996,7 @@ public:
/// relationship. /// relationship.
/// ///
/// \returns true if *this != Val /// \returns true if *this != Val
bool ne(const APInt &RHS) const { bool ne(const APInt &RHS) const { return !((*this) == RHS); }
return !((*this) == RHS);
}
/// \brief Unsigned less than comparison /// \brief Unsigned less than comparison
/// ///
@ -1059,9 +1012,7 @@ public:
/// the validity of the less-than relationship. /// the validity of the less-than relationship.
/// ///
/// \returns true if *this < RHS when considered unsigned. /// \returns true if *this < RHS when considered unsigned.
bool ult(uint64_t RHS) const { bool ult(uint64_t RHS) const { return ult(APInt(getBitWidth(), RHS)); }
return ult(APInt(getBitWidth(), RHS));
}
/// \brief Signed less than comparison /// \brief Signed less than comparison
/// ///
@ -1077,9 +1028,7 @@ public:
/// the validity of the less-than relationship. /// the validity of the less-than relationship.
/// ///
/// \returns true if *this < RHS when considered signed. /// \returns true if *this < RHS when considered signed.
bool slt(uint64_t RHS) const { bool slt(uint64_t RHS) const { return slt(APInt(getBitWidth(), RHS)); }
return slt(APInt(getBitWidth(), RHS));
}
/// \brief Unsigned less or equal comparison /// \brief Unsigned less or equal comparison
/// ///
@ -1087,9 +1036,7 @@ public:
/// validity of the less-or-equal relationship. /// validity of the less-or-equal relationship.
/// ///
/// \returns true if *this <= RHS when both are considered unsigned. /// \returns true if *this <= RHS when both are considered unsigned.
bool ule(const APInt& RHS) const { bool ule(const APInt &RHS) const { return ult(RHS) || eq(RHS); }
return ult(RHS) || eq(RHS);
}
/// \brief Unsigned less or equal comparison /// \brief Unsigned less or equal comparison
/// ///
@ -1097,9 +1044,7 @@ public:
/// the validity of the less-or-equal relationship. /// the validity of the less-or-equal relationship.
/// ///
/// \returns true if *this <= RHS when considered unsigned. /// \returns true if *this <= RHS when considered unsigned.
bool ule(uint64_t RHS) const { bool ule(uint64_t RHS) const { return ule(APInt(getBitWidth(), RHS)); }
return ule(APInt(getBitWidth(), RHS));
}
/// \brief Signed less or equal comparison /// \brief Signed less or equal comparison
/// ///
@ -1107,9 +1052,7 @@ public:
/// validity of the less-or-equal relationship. /// validity of the less-or-equal relationship.
/// ///
/// \returns true if *this <= RHS when both are considered signed. /// \returns true if *this <= RHS when both are considered signed.
bool sle(const APInt& RHS) const { bool sle(const APInt &RHS) const { return slt(RHS) || eq(RHS); }
return slt(RHS) || eq(RHS);
}
/// \brief Signed less or equal comparison /// \brief Signed less or equal comparison
/// ///
@ -1117,9 +1060,7 @@ public:
/// validity of the less-or-equal relationship. /// validity of the less-or-equal relationship.
/// ///
/// \returns true if *this <= RHS when considered signed. /// \returns true if *this <= RHS when considered signed.
bool sle(uint64_t RHS) const { bool sle(uint64_t RHS) const { return sle(APInt(getBitWidth(), RHS)); }
return sle(APInt(getBitWidth(), RHS));
}
/// \brief Unsigned greather than comparison /// \brief Unsigned greather than comparison
/// ///
@ -1127,9 +1068,7 @@ public:
/// the validity of the greater-than relationship. /// the validity of the greater-than relationship.
/// ///
/// \returns true if *this > RHS when both are considered unsigned. /// \returns true if *this > RHS when both are considered unsigned.
bool ugt(const APInt& RHS) const { bool ugt(const APInt &RHS) const { return !ult(RHS) && !eq(RHS); }
return !ult(RHS) && !eq(RHS);
}
/// \brief Unsigned greater than comparison /// \brief Unsigned greater than comparison
/// ///
@ -1137,9 +1076,7 @@ public:
/// the validity of the greater-than relationship. /// the validity of the greater-than relationship.
/// ///
/// \returns true if *this > RHS when considered unsigned. /// \returns true if *this > RHS when considered unsigned.
bool ugt(uint64_t RHS) const { bool ugt(uint64_t RHS) const { return ugt(APInt(getBitWidth(), RHS)); }
return ugt(APInt(getBitWidth(), RHS));
}
/// \brief Signed greather than comparison /// \brief Signed greather than comparison
/// ///
@ -1147,9 +1084,7 @@ public:
/// validity of the greater-than relationship. /// validity of the greater-than relationship.
/// ///
/// \returns true if *this > RHS when both are considered signed. /// \returns true if *this > RHS when both are considered signed.
bool sgt(const APInt& RHS) const { bool sgt(const APInt &RHS) const { return !slt(RHS) && !eq(RHS); }
return !slt(RHS) && !eq(RHS);
}
/// \brief Signed greater than comparison /// \brief Signed greater than comparison
/// ///
@ -1157,9 +1092,7 @@ public:
/// the validity of the greater-than relationship. /// the validity of the greater-than relationship.
/// ///
/// \returns true if *this > RHS when considered signed. /// \returns true if *this > RHS when considered signed.
bool sgt(uint64_t RHS) const { bool sgt(uint64_t RHS) const { return sgt(APInt(getBitWidth(), RHS)); }
return sgt(APInt(getBitWidth(), RHS));
}
/// \brief Unsigned greater or equal comparison /// \brief Unsigned greater or equal comparison
/// ///
@ -1167,9 +1100,7 @@ public:
/// validity of the greater-or-equal relationship. /// validity of the greater-or-equal relationship.
/// ///
/// \returns true if *this >= RHS when both are considered unsigned. /// \returns true if *this >= RHS when both are considered unsigned.
bool uge(const APInt& RHS) const { bool uge(const APInt &RHS) const { return !ult(RHS); }
return !ult(RHS);
}
/// \brief Unsigned greater or equal comparison /// \brief Unsigned greater or equal comparison
/// ///
@ -1177,9 +1108,7 @@ public:
/// the validity of the greater-or-equal relationship. /// the validity of the greater-or-equal relationship.
/// ///
/// \returns true if *this >= RHS when considered unsigned. /// \returns true if *this >= RHS when considered unsigned.
bool uge(uint64_t RHS) const { bool uge(uint64_t RHS) const { return uge(APInt(getBitWidth(), RHS)); }
return uge(APInt(getBitWidth(), RHS));
}
/// \brief Signed greather or equal comparison /// \brief Signed greather or equal comparison
/// ///
@ -1187,9 +1116,7 @@ public:
/// validity of the greater-or-equal relationship. /// validity of the greater-or-equal relationship.
/// ///
/// \returns true if *this >= RHS when both are considered signed. /// \returns true if *this >= RHS when both are considered signed.
bool sge(const APInt& RHS) const { bool sge(const APInt &RHS) const { return !slt(RHS); }
return !slt(RHS);
}
/// \brief Signed greater or equal comparison /// \brief Signed greater or equal comparison
/// ///
@ -1197,15 +1124,11 @@ public:
/// the validity of the greater-or-equal relationship. /// the validity of the greater-or-equal relationship.
/// ///
/// \returns true if *this >= RHS when considered signed. /// \returns true if *this >= RHS when considered signed.
bool sge(uint64_t RHS) const { bool sge(uint64_t RHS) const { return sge(APInt(getBitWidth(), RHS)); }
return sge(APInt(getBitWidth(), RHS));
}
/// This operation tests if there are any pairs of corresponding bits /// This operation tests if there are any pairs of corresponding bits
/// between this APInt and RHS that are both set. /// between this APInt and RHS that are both set.
bool intersects(const APInt &RHS) const { bool intersects(const APInt &RHS) const { return (*this & RHS) != 0; }
return (*this & RHS) != 0;
}
/// @} /// @}
/// \name Resizing Operators /// \name Resizing Operators
@ -1313,18 +1236,14 @@ public:
/// @{ /// @{
/// \brief Return the number of bits in the APInt. /// \brief Return the number of bits in the APInt.
unsigned getBitWidth() const { unsigned getBitWidth() const { return BitWidth; }
return BitWidth;
}
/// \brief Get the number of words. /// \brief Get the number of words.
/// ///
/// Here one word's bitwidth equals to that of uint64_t. /// Here one word's bitwidth equals to that of uint64_t.
/// ///
/// \returns the number of words to hold the integer value of this APInt. /// \returns the number of words to hold the integer value of this APInt.
unsigned getNumWords() const { unsigned getNumWords() const { return getNumWords(BitWidth); }
return getNumWords(BitWidth);
}
/// \brief Get the number of words. /// \brief Get the number of words.
/// ///
@ -1341,9 +1260,7 @@ public:
/// This function returns the number of active bits which is defined as the /// This function returns the number of active bits which is defined as the
/// bit width minus the number of leading zeros. This is used in several /// bit width minus the number of leading zeros. This is used in several
/// computations to see how "wide" the value is. /// computations to see how "wide" the value is.
unsigned getActiveBits() const { unsigned getActiveBits() const { return BitWidth - countLeadingZeros(); }
return BitWidth - countLeadingZeros();
}
/// \brief Compute the number of active words in the value of this APInt. /// \brief Compute the number of active words in the value of this APInt.
/// ///
@ -1503,14 +1420,10 @@ public:
double roundToDouble(bool isSigned) const; double roundToDouble(bool isSigned) const;
/// \brief Converts this unsigned APInt to a double value. /// \brief Converts this unsigned APInt to a double value.
double roundToDouble() const { double roundToDouble() const { return roundToDouble(false); }
return roundToDouble(false);
}
/// \brief Converts this signed APInt to a double value. /// \brief Converts this signed APInt to a double value.
double signedRoundToDouble() const { double signedRoundToDouble() const { return roundToDouble(true); }
return roundToDouble(true);
}
/// \brief Converts APInt bits to a double /// \brief Converts APInt bits to a double
/// ///
@ -1571,9 +1484,7 @@ public:
/// @{ /// @{
/// \returns the floor log base 2 of this APInt. /// \returns the floor log base 2 of this APInt.
unsigned logBase2() const { unsigned logBase2() const { return BitWidth - 1 - countLeadingZeros(); }
return BitWidth - 1 - countLeadingZeros();
}
/// \returns the ceil log base 2 of this APInt. /// \returns the ceil log base 2 of this APInt.
unsigned ceilLogBase2() const { unsigned ceilLogBase2() const {
@ -1643,8 +1554,8 @@ public:
/// significant bit of DST. All high bits above srcBITS in DST are /// significant bit of DST. All high bits above srcBITS in DST are
/// zero-filled. /// zero-filled.
static void tcExtract(integerPart *, unsigned int dstCount, static void tcExtract(integerPart *, unsigned int dstCount,
const integerPart *, const integerPart *, unsigned int srcBits,
unsigned int srcBits, unsigned int srcLSB); unsigned int srcLSB);
/// Set the given bit of a bignum. Zero-based. /// Set the given bit of a bignum. Zero-based.
static void tcSetBit(integerPart *, unsigned int bit); static void tcSetBit(integerPart *, unsigned int bit);
@ -1687,8 +1598,8 @@ public:
/// filled with the least significant parts of the result. Returns one if /// filled with the least significant parts of the result. Returns one if
/// overflow occurred, otherwise zero. DST must be disjoint from both /// overflow occurred, otherwise zero. DST must be disjoint from both
/// operands. /// operands.
static int tcMultiply(integerPart *, const integerPart *, static int tcMultiply(integerPart *, const integerPart *, const integerPart *,
const integerPart *, unsigned); unsigned);
/// DST = LHS * RHS, where DST has width the sum of the widths of the /// DST = LHS * RHS, where DST has width the sum of the widths of the
/// operands. No overflow occurs. DST must be disjoint from both /// operands. No overflow occurs. DST must be disjoint from both
@ -1726,8 +1637,7 @@ public:
static void tcComplement(integerPart *, unsigned int); static void tcComplement(integerPart *, unsigned int);
/// Comparison (unsigned) of two bignums. /// Comparison (unsigned) of two bignums.
static int tcCompare(const integerPart *, const integerPart *, static int tcCompare(const integerPart *, const integerPart *, unsigned int);
unsigned int);
/// Increment a bignum in-place. Return the carry flag. /// Increment a bignum in-place. Return the carry flag.
static integerPart tcIncrement(integerPart *, unsigned int); static integerPart tcIncrement(integerPart *, unsigned int);
@ -1755,13 +1665,9 @@ struct APInt::mu {
unsigned s; ///< shift amount unsigned s; ///< shift amount
}; };
inline bool operator==(uint64_t V1, const APInt& V2) { inline bool operator==(uint64_t V1, const APInt &V2) { return V2 == V1; }
return V2 == V1;
}
inline bool operator!=(uint64_t V1, const APInt& V2) { inline bool operator!=(uint64_t V1, const APInt &V2) { return V2 != V1; }
return V2 != V1;
}
inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) { inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) {
I.print(OS, true); I.print(OS, true);
@ -1771,29 +1677,19 @@ inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) {
namespace APIntOps { namespace APIntOps {
/// \brief Determine the smaller of two APInts considered to be signed. /// \brief Determine the smaller of two APInts considered to be signed.
inline APInt smin(const APInt &A, const APInt &B) { inline APInt smin(const APInt &A, const APInt &B) { return A.slt(B) ? A : B; }
return A.slt(B) ? A : B;
}
/// \brief Determine the larger of two APInts considered to be signed. /// \brief Determine the larger of two APInts considered to be signed.
inline APInt smax(const APInt &A, const APInt &B) { inline APInt smax(const APInt &A, const APInt &B) { return A.sgt(B) ? A : B; }
return A.sgt(B) ? A : B;
}
/// \brief Determine the smaller of two APInts considered to be signed. /// \brief Determine the smaller of two APInts considered to be signed.
inline APInt umin(const APInt &A, const APInt &B) { inline APInt umin(const APInt &A, const APInt &B) { return A.ult(B) ? A : B; }
return A.ult(B) ? A : B;
}
/// \brief Determine the larger of two APInts considered to be unsigned. /// \brief Determine the larger of two APInts considered to be unsigned.
inline APInt umax(const APInt &A, const APInt &B) { inline APInt umax(const APInt &A, const APInt &B) { return A.ugt(B) ? A : B; }
return A.ugt(B) ? A : B;
}
/// \brief Check if the specified APInt has a N-bits unsigned integer value. /// \brief Check if the specified APInt has a N-bits unsigned integer value.
inline bool isIntN(unsigned N, const APInt& APIVal) { inline bool isIntN(unsigned N, const APInt &APIVal) { return APIVal.isIntN(N); }
return APIVal.isIntN(N);
}
/// \brief Check if the specified APInt has a N-bits signed integer value. /// \brief Check if the specified APInt has a N-bits signed integer value.
inline bool isSignedIntN(unsigned N, const APInt &APIVal) { inline bool isSignedIntN(unsigned N, const APInt &APIVal) {
@ -1814,14 +1710,10 @@ inline bool isShiftedMask(unsigned numBits, const APInt& APIVal) {
} }
/// \brief Returns a byte-swapped representation of the specified APInt Value. /// \brief Returns a byte-swapped representation of the specified APInt Value.
inline APInt byteSwap(const APInt& APIVal) { inline APInt byteSwap(const APInt &APIVal) { return APIVal.byteSwap(); }
return APIVal.byteSwap();
}
/// \brief Returns the floor log base 2 of the specified APInt value. /// \brief Returns the floor log base 2 of the specified APInt value.
inline unsigned logBase2(const APInt& APIVal) { inline unsigned logBase2(const APInt &APIVal) { return APIVal.logBase2(); }
return APIVal.logBase2();
}
/// \brief Compute GCD of two APInt values. /// \brief Compute GCD of two APInt values.
/// ///
@ -1893,80 +1785,58 @@ inline APInt shl(const APInt& LHS, unsigned shiftAmt) {
/// \brief Signed division function for APInt. /// \brief Signed division function for APInt.
/// ///
/// Signed divide APInt LHS by APInt RHS. /// Signed divide APInt LHS by APInt RHS.
inline APInt sdiv(const APInt& LHS, const APInt& RHS) { inline APInt sdiv(const APInt &LHS, const APInt &RHS) { return LHS.sdiv(RHS); }
return LHS.sdiv(RHS);
}
/// \brief Unsigned division function for APInt. /// \brief Unsigned division function for APInt.
/// ///
/// Unsigned divide APInt LHS by APInt RHS. /// Unsigned divide APInt LHS by APInt RHS.
inline APInt udiv(const APInt& LHS, const APInt& RHS) { inline APInt udiv(const APInt &LHS, const APInt &RHS) { return LHS.udiv(RHS); }
return LHS.udiv(RHS);
}
/// \brief Function for signed remainder operation. /// \brief Function for signed remainder operation.
/// ///
/// Signed remainder operation on APInt. /// Signed remainder operation on APInt.
inline APInt srem(const APInt& LHS, const APInt& RHS) { inline APInt srem(const APInt &LHS, const APInt &RHS) { return LHS.srem(RHS); }
return LHS.srem(RHS);
}
/// \brief Function for unsigned remainder operation. /// \brief Function for unsigned remainder operation.
/// ///
/// Unsigned remainder operation on APInt. /// Unsigned remainder operation on APInt.
inline APInt urem(const APInt& LHS, const APInt& RHS) { inline APInt urem(const APInt &LHS, const APInt &RHS) { return LHS.urem(RHS); }
return LHS.urem(RHS);
}
/// \brief Function for multiplication operation. /// \brief Function for multiplication operation.
/// ///
/// Performs multiplication on APInt values. /// Performs multiplication on APInt values.
inline APInt mul(const APInt& LHS, const APInt& RHS) { inline APInt mul(const APInt &LHS, const APInt &RHS) { return LHS * RHS; }
return LHS * RHS;
}
/// \brief Function for addition operation. /// \brief Function for addition operation.
/// ///
/// Performs addition on APInt values. /// Performs addition on APInt values.
inline APInt add(const APInt& LHS, const APInt& RHS) { inline APInt add(const APInt &LHS, const APInt &RHS) { return LHS + RHS; }
return LHS + RHS;
}
/// \brief Function for subtraction operation. /// \brief Function for subtraction operation.
/// ///
/// Performs subtraction on APInt values. /// Performs subtraction on APInt values.
inline APInt sub(const APInt& LHS, const APInt& RHS) { inline APInt sub(const APInt &LHS, const APInt &RHS) { return LHS - RHS; }
return LHS - RHS;
}
/// \brief Bitwise AND function for APInt. /// \brief Bitwise AND function for APInt.
/// ///
/// Performs bitwise AND operation on APInt LHS and /// Performs bitwise AND operation on APInt LHS and
/// APInt RHS. /// APInt RHS.
inline APInt And(const APInt& LHS, const APInt& RHS) { inline APInt And(const APInt &LHS, const APInt &RHS) { return LHS & RHS; }
return LHS & RHS;
}
/// \brief Bitwise OR function for APInt. /// \brief Bitwise OR function for APInt.
/// ///
/// Performs bitwise OR operation on APInt LHS and APInt RHS. /// Performs bitwise OR operation on APInt LHS and APInt RHS.
inline APInt Or(const APInt& LHS, const APInt& RHS) { inline APInt Or(const APInt &LHS, const APInt &RHS) { return LHS | RHS; }
return LHS | RHS;
}
/// \brief Bitwise XOR function for APInt. /// \brief Bitwise XOR function for APInt.
/// ///
/// Performs bitwise XOR operation on APInt. /// Performs bitwise XOR operation on APInt.
inline APInt Xor(const APInt& LHS, const APInt& RHS) { inline APInt Xor(const APInt &LHS, const APInt &RHS) { return LHS ^ RHS; }
return LHS ^ RHS;
}
/// \brief Bitwise complement function. /// \brief Bitwise complement function.
/// ///
/// Performs a bitwise complement operation on APInt. /// Performs a bitwise complement operation on APInt.
inline APInt Not(const APInt& APIVal) { inline APInt Not(const APInt &APIVal) { return ~APIVal; }
return ~APIVal;
}
} // End of APIntOps namespace } // End of APIntOps namespace