OSDN Git Service

Make some minor improvements to APInt:
authorReid Spencer <rspencer@reidspencer.com>
Tue, 13 Feb 2007 22:41:58 +0000 (22:41 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 13 Feb 2007 22:41:58 +0000 (22:41 +0000)
1. Make all the operators use uppercase
2. Rename APIntRoundToDouble method just RoundToDouble, the APInt is
   redundant.
3. Turn the class on for compilation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34253 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
lib/Support/APInt.cpp

index 7c100a2..4c398db 100644 (file)
@@ -24,8 +24,8 @@ namespace llvm {
 /// Forward declaration.
 class APInt;
 namespace APIntOps {
-  APInt udiv(const APInt& LHS, const APInt& RHS);
-  APInt urem(const APInt& LHS, const APInt& RHS);
+  APInt UDiv(const APInt& LHS, const APInt& RHS);
+  APInt URem(const APInt& LHS, const APInt& RHS);
 }
 
 //===----------------------------------------------------------------------===//
@@ -286,7 +286,7 @@ public:
 
   /// @returns a uint64_t value from this APInt. If this APInt contains a single
   /// word, just returns VAL, otherwise pVal[0].
-  inline uint64_t getValue() {
+  inline uint64_t getValue() const {
     if (isSingleWord())
       return VAL;
     unsigned n = getNumWords() * 64 - CountLeadingZeros();
@@ -310,6 +310,10 @@ public:
   /// @brief Get the all-ones value.
   static APInt getAllOnesValue(unsigned numBits);
 
+  /// @returns the '0' value for an APInt of the specified bit-width.
+  /// @brief Get the '0' value.
+  static APInt getNullValue(unsigned numBits);
+
   /// @brief Set every bit to 1.
   APInt& set();
 
@@ -317,10 +321,6 @@ public:
   /// @brief Set a given bit to 1.
   APInt& set(unsigned bitPosition);
 
-  /// @returns the '0' value for an APInt of the specified bit-width.
-  /// @brief Get the '0' value.
-  static APInt getNullValue(unsigned numBits);
-
   /// @brief Set every bit to 0.
   APInt& clear();
 
@@ -370,7 +370,7 @@ public:
   { return BitsNum; }
 
   /// @brief Check if this APInt has a N-bits integer value.
-  inline bool isIntN(unsigned N) const {
+  inline bool IsIntN(unsigned N) const {
     if (isSingleWord()) {
       return VAL == VAL & (~uint64_t(0ULL) >> (64 - N));
     } else {
@@ -389,43 +389,43 @@ public:
   }
 
   /// @brief Converts this APInt to a double value.
-  double APIntRoundToDouble(bool isSigned = false) const;
+  double RoundToDouble(bool isSigned = false) const;
 
   /// Arithmetic right-shift this APInt by shiftAmt.
   /// @brief Arithmetic right-shift function.
-  APInt ashr(unsigned shiftAmt) const;
+  APInt AShr(unsigned shiftAmt) const;
 
   /// Logical right-shift this APInt by shiftAmt.
   /// @brief Logical right-shift function.
-  APInt lshr(unsigned shiftAmt) const;
+  APInt LShr(unsigned shiftAmt) const;
 
   /// Left-shift this APInt by shiftAmt.
   /// @brief Left-shift function.
-  APInt shl(unsigned shiftAmt) const;
+  APInt Shl(unsigned shiftAmt) const;
 
   /// Signed divide this APInt by APInt RHS.
   /// @brief Signed division function for APInt.
-  inline APInt sdiv(const APInt& RHS) const {
+  inline APInt SDiv(const APInt& RHS) const {
     bool isSignedLHS = (*this)[BitsNum - 1], isSignedRHS = RHS[RHS.BitsNum - 1];
-    APInt API = APIntOps::udiv(isSignedLHS ? -(*this) : (*this), isSignedRHS ? -RHS : RHS);
+    APInt API = APIntOps::UDiv(isSignedLHS ? -(*this) : (*this), isSignedRHS ? -RHS : RHS);
     return isSignedLHS != isSignedRHS ? -API : API;;
   }
 
   /// Unsigned divide this APInt by APInt RHS.
   /// @brief Unsigned division function for APInt.
-  APInt udiv(const APInt& RHS) const;
+  APInt UDiv(const APInt& RHS) const;
 
   /// Signed remainder operation on APInt.
   /// @brief Function for signed remainder operation.
-  inline APInt srem(const APInt& RHS) const {
+  inline APInt SRem(const APInt& RHS) const {
     bool isSignedLHS = (*this)[BitsNum - 1], isSignedRHS = RHS[RHS.BitsNum - 1];
-    APInt API = APIntOps::urem(isSignedLHS ? -(*this) : (*this), isSignedRHS ? -RHS : RHS);
+    APInt API = APIntOps::URem(isSignedLHS ? -(*this) : (*this), isSignedRHS ? -RHS : RHS);
     return isSignedLHS ? -API : API;
   }
 
   /// Unsigned remainder operation on APInt.
   /// @brief Function for unsigned remainder operation.
-  APInt urem(const APInt& RHS) const;
+  APInt URem(const APInt& RHS) const;
 
 };
 
@@ -433,7 +433,7 @@ namespace APIntOps {
 
 /// @brief Check if the specified APInt has a N-bits integer value.
 inline bool isIntN(unsigned N, const APInt& APIVal) {
-  return APIVal.isIntN(N);
+  return APIVal.IsIntN(N);
 }
 
 /// @returns true if the argument APInt value is a sequence of ones
@@ -464,7 +464,7 @@ APInt GreatestCommonDivisor(const APInt& API1, const APInt& API2);
 
 /// @brief Converts the given APInt to a double value.
 inline double APIntRoundToDouble(const APInt& APIVal, bool isSigned = false) {
-  return APIVal.APIntRoundToDouble(isSigned);
+  return APIVal.RoundToDouble(isSigned);
 }
 
 /// @brief Converts the given APInt to a float vlalue.
@@ -482,61 +482,61 @@ inline APInt FloatRoundToAPInt(float Float) {
 
 /// Arithmetic right-shift the APInt by shiftAmt.
 /// @brief Arithmetic right-shift function.
-inline APInt ashr(const APInt& LHS, unsigned shiftAmt) {
-  return LHS.ashr(shiftAmt);
+inline APInt AShr(const APInt& LHS, unsigned shiftAmt) {
+  return LHS.AShr(shiftAmt);
 }
 
 /// Logical right-shift the APInt by shiftAmt.
 /// @brief Logical right-shift function.
-inline APInt lshr(const APInt& LHS, unsigned shiftAmt) {
-  return LHS.lshr(shiftAmt);
+inline APInt LShr(const APInt& LHS, unsigned shiftAmt) {
+  return LHS.LShr(shiftAmt);
 }
 
 /// Left-shift the APInt by shiftAmt.
 /// @brief Left-shift function.
-inline APInt shl(const APInt& LHS, unsigned shiftAmt) {
-  return LHS.shl(shiftAmt);
+inline APInt Shl(const APInt& LHS, unsigned shiftAmt) {
+  return LHS.Shl(shiftAmt);
 }
 
 /// Signed divide APInt LHS by APInt RHS.
 /// @brief Signed division function for APInt.
-inline APInt sdiv(const APInt& LHS, const APInt& RHS) {
-  return LHS.sdiv(RHS);
+inline APInt SDiv(const APInt& LHS, const APInt& RHS) {
+  return LHS.SDiv(RHS);
 }
 
 /// Unsigned divide APInt LHS by APInt RHS.
 /// @brief Unsigned division function for APInt.
-inline APInt udiv(const APInt& LHS, const APInt& RHS) {
-  return LHS.udiv(RHS);
+inline APInt UDiv(const APInt& LHS, const APInt& RHS) {
+  return LHS.UDiv(RHS);
 }
 
 /// Signed remainder operation on APInt.
 /// @brief Function for signed remainder operation.
-inline APInt srem(const APInt& LHS, const APInt& RHS) {
-  return LHS.srem(RHS);
+inline APInt SRem(const APInt& LHS, const APInt& RHS) {
+  return LHS.SRem(RHS);
 }
 
 /// Unsigned remainder operation on APInt.
 /// @brief Function for unsigned remainder operation.
-inline APInt urem(const APInt& LHS, const APInt& RHS) {
-  return LHS.urem(RHS);
+inline APInt URem(const APInt& LHS, const APInt& RHS) {
+  return LHS.URem(RHS);
 }
 
 /// Performs multiplication on APInt values.
 /// @brief Function for multiplication operation.
-inline APInt mul(const APInt& LHS, const APInt& RHS) {
+inline APInt Mul(const APInt& LHS, const APInt& RHS) {
   return LHS * RHS;
 }
 
 /// Performs addition on APInt values.
 /// @brief Function for addition operation.
-inline APInt add(const APInt& LHS, const APInt& RHS) {
+inline APInt Add(const APInt& LHS, const APInt& RHS) {
   return LHS + RHS;
 }
 
 /// Performs subtraction on APInt values.
 /// @brief Function for subtraction operation.
-inline APInt sub(const APInt& LHS, const APInt& RHS) {
+inline APInt Sub(const APInt& LHS, const APInt& RHS) {
   return LHS - RHS;
 }
 
index d81fb09..cbd2b34 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "llvm/ADT/APInt.h"
 
-#if 0
 #include "llvm/DerivedTypes.h"
 #include "llvm/Support/MathExtras.h"
 #include <cstring>
@@ -878,12 +877,12 @@ APInt APInt::getNullValue(unsigned numBits) {
 
 /// HiBits - This function returns the high "numBits" bits of this APInt.
 APInt APInt::HiBits(unsigned numBits) const {
-  return APIntOps::lshr(*this, BitsNum - numBits);
+  return APIntOps::LShr(*this, BitsNum - numBits);
 }
 
 /// LoBits - This function returns the low "numBits" bits of this APInt.
 APInt APInt::LoBits(unsigned numBits) const {
-  return APIntOps::lshr(APIntOps::shl(*this, BitsNum - numBits), 
+  return APIntOps::LShr(APIntOps::Shl(*this, BitsNum - numBits), 
                         BitsNum - numBits);
 }
 
@@ -949,7 +948,7 @@ APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1,
   APInt A = API1, B = API2;
   while (!!B) {
     APInt T = B;
-    B = APIntOps::urem(A, B);
+    B = APIntOps::URem(A, B);
     A = T;
   }
   return A;
@@ -972,18 +971,18 @@ APInt llvm::APIntOps::DoubleRoundToAPInt(double Double) {
     return isNeg ? -APInt(mantissa >> (52 - exp)) : 
                     APInt(mantissa >> (52 - exp));
   APInt Tmp(mantissa, exp + 1);
-  Tmp = Tmp.shl(exp - 52);
+  Tmp = Tmp.Shl(exp - 52);
   return isNeg ? -Tmp : Tmp;
 }
 
-/// APIntRoundToDouble - This function convert this APInt to a double.
+/// RoundToDouble - This function convert this APInt to a double.
 /// The layout for double is as following (IEEE Standard 754):
 ///  --------------------------------------
 /// |  Sign    Exponent    Fraction    Bias |
 /// |-------------------------------------- |
 /// |  1[63]   11[62-52]   52[51-00]   1023 |
 ///  -------------------------------------- 
-double APInt::APIntRoundToDouble(bool isSigned) const {
+double APInt::RoundToDouble(bool isSigned) const {
   bool isNeg = isSigned ? (*this)[BitsNum-1] : false;
   APInt Tmp(isNeg ? -(*this) : (*this));
   if (Tmp.isSingleWord())
@@ -1020,7 +1019,7 @@ double APInt::APIntRoundToDouble(bool isSigned) const {
 
 /// Arithmetic right-shift this APInt by shiftAmt.
 /// @brief Arithmetic right-shift function.
-APInt APInt::ashr(unsigned shiftAmt) const {
+APInt APInt::AShr(unsigned shiftAmt) const {
   APInt API(*this);
   if (API.isSingleWord())
     API.VAL = (((int64_t(API.VAL) << (64 - API.BitsNum)) >> (64 - API.BitsNum))
@@ -1046,7 +1045,7 @@ APInt APInt::ashr(unsigned shiftAmt) const {
 
 /// Logical right-shift this APInt by shiftAmt.
 /// @brief Logical right-shift function.
-APInt APInt::lshr(unsigned shiftAmt) const {
+APInt APInt::LShr(unsigned shiftAmt) const {
   APInt API(*this);
   if (API.isSingleWord())
     API.VAL >>= shiftAmt;
@@ -1065,7 +1064,7 @@ APInt APInt::lshr(unsigned shiftAmt) const {
 
 /// Left-shift this APInt by shiftAmt.
 /// @brief Left-shift function.
-APInt APInt::shl(unsigned shiftAmt) const {
+APInt APInt::Shl(unsigned shiftAmt) const {
   APInt API(*this);
   if (API.isSingleWord())
     API.VAL <<= shiftAmt;
@@ -1089,7 +1088,7 @@ APInt APInt::shl(unsigned shiftAmt) const {
 
 /// Unsigned divide this APInt by APInt RHS.
 /// @brief Unsigned division function for APInt.
-APInt APInt::udiv(const APInt& RHS) const {
+APInt APInt::UDiv(const APInt& RHS) const {
   APInt API(*this);
   unsigned first = RHS.getNumWords() * APInt::APINT_BITS_PER_WORD - 
                    RHS.CountLeadingZeros();
@@ -1134,7 +1133,7 @@ APInt APInt::udiv(const APInt& RHS) const {
 
 /// Unsigned remainder operation on APInt.
 /// @brief Function for unsigned remainder operation.
-APInt APInt::urem(const APInt& RHS) const {
+APInt APInt::URem(const APInt& RHS) const {
   APInt API(*this);
   unsigned first = RHS.getNumWords() * APInt::APINT_BITS_PER_WORD -
                    RHS.CountLeadingZeros();
@@ -1176,6 +1175,3 @@ APInt APInt::urem(const APInt& RHS) const {
   }
   return API;
 }
-
-#endif
-