aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-05-13 23:44:59 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-05-13 23:44:59 +0000
commit19dc32a2d422ac0aafd047514e3e5e727796696e (patch)
tree5fc3fd6136231d28fda221c83f4abe84faeeebd1 /include/llvm/ADT
parent9273418777fb0c25da9067d6eec57402a504e94e (diff)
downloadexternal_llvm-19dc32a2d422ac0aafd047514e3e5e727796696e.zip
external_llvm-19dc32a2d422ac0aafd047514e3e5e727796696e.tar.gz
external_llvm-19dc32a2d422ac0aafd047514e3e5e727796696e.tar.bz2
Add some things needed by the llvm-gcc version supporting bit accurate integer
types: 1. Functions to compute div/rem at the same time. 2. Further assurance that an APInt with 0 bitwidth cannot be constructed. 3. Left and right rotate operations. 4. An exactLogBase2 function which requires an exact power of two or it returns -1. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37025 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/APInt.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 36ced6f..535e5db 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -567,6 +567,12 @@ public:
/// @brief Left-shift function.
APInt shl(uint32_t shiftAmt) const;
+ /// @brief Rotate left by rotateAmt.
+ APInt rotl(uint32_t rotateAmt) const;
+
+ /// @brief Rotate right by rotateAmt.
+ APInt rotr(uint32_t rotateAmt) const;
+
/// Perform an unsigned divide operation on this APInt by RHS. Both this and
/// RHS are treated as unsigned quantities for purposes of this division.
/// @returns a new APInt value containing the division result
@@ -608,6 +614,31 @@ public:
return this->urem(RHS);
}
+ /// Sometimes it is convenient to divide two APInt values and obtain both
+ /// the quotient and remainder. This function does both operations in the
+ /// same computation making it a little more efficient.
+ /// @brief Dual division/remainder interface.
+ static void udivrem(const APInt &LHS, const APInt &RHS,
+ APInt &Quotient, APInt &Remainder);
+
+ static void sdivrem(const APInt &LHS, const APInt &RHS,
+ APInt &Quotient, APInt &Remainder)
+ {
+ if (LHS.isNegative()) {
+ if (RHS.isNegative())
+ APInt::udivrem(-LHS, -RHS, Quotient, Remainder);
+ else
+ APInt::udivrem(-LHS, RHS, Quotient, Remainder);
+ Quotient = -Quotient;
+ Remainder = -Remainder;
+ } else if (RHS.isNegative()) {
+ APInt::udivrem(LHS, -RHS, Quotient, Remainder);
+ Quotient = -Quotient;
+ } else {
+ APInt::udivrem(LHS, RHS, Quotient, Remainder);
+ }
+ }
+
/// @returns the bit value at bitPosition
/// @brief Array-indexing support.
bool operator[](uint32_t bitPosition) const;
@@ -988,6 +1019,14 @@ public:
return BitWidth - 1 - countLeadingZeros();
}
+ /// @returns the log base 2 of this APInt if its an exact power of two, -1
+ /// otherwise
+ inline int32_t exactLogBase2() const {
+ if (!isPowerOf2())
+ return -1;
+ return logBase2();
+ }
+
/// @brief Compute the square root
APInt sqrt() const;