Changes in directory llvm/include/llvm/ADT:
APInt.h updated: 1.67 -> 1.68 --- Log message: 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. --- Diffs of the changes: (+39 -0) APInt.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.67 llvm/include/llvm/ADT/APInt.h:1.68 --- llvm/include/llvm/ADT/APInt.h:1.67 Thu May 3 12:09:36 2007 +++ llvm/include/llvm/ADT/APInt.h Sun May 13 18:44:59 2007 @@ -567,6 +567,12 @@ /// @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 @@ 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 @@ 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; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits