[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
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
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.66 - 1.67 --- Log message: remove useless type qualifiers --- Diffs of the changes: (+2 -2) APInt.h |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.66 llvm/include/llvm/ADT/APInt.h:1.67 --- llvm/include/llvm/ADT/APInt.h:1.66 Fri Apr 13 14:19:07 2007 +++ llvm/include/llvm/ADT/APInt.h Thu May 3 12:09:36 2007 @@ -1038,13 +1038,13 @@ /// @returns true if the argument APInt value is a sequence of ones /// starting at the least significant bit with the remainder zero. -inline const bool isMask(uint32_t numBits, const APInt APIVal) { +inline bool isMask(uint32_t numBits, const APInt APIVal) { return APIVal.getBoolValue() ((APIVal + APInt(numBits,1)) APIVal) == 0; } /// @returns true if the argument APInt value contains a sequence of ones /// with the remainder zero. -inline const bool isShiftedMask(uint32_t numBits, const APInt APIVal) { +inline bool isShiftedMask(uint32_t numBits, const APInt APIVal) { return isMask(numBits, (APIVal - APInt(numBits,1)) | APIVal); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.65 - 1.66 --- Log message: Implement a getBitsNeeded method to determine how many bits are needed to represent a string in binary form by an APInt. --- Diffs of the changes: (+6 -0) APInt.h |6 ++ 1 files changed, 6 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.65 llvm/include/llvm/ADT/APInt.h:1.66 --- llvm/include/llvm/ADT/APInt.h:1.65 Tue Apr 10 11:33:06 2007 +++ llvm/include/llvm/ADT/APInt.h Fri Apr 13 14:19:07 2007 @@ -840,6 +840,12 @@ assert(getActiveBits() = 64 Too many bits for int64_t); return int64_t(pVal[0]); } + + /// This method determines how many bits are required to hold the APInt + /// equivalent of the string given by \p str of length \p slen. + /// @brief Get bits required for string value. + static uint32_t getBitsNeeded(const char* str, uint32_t slen, uint8_t radix); + /// countLeadingZeros - This function is an APInt version of the /// countLeadingZeros_{32,64} functions in MathExtras.h. It counts the number /// of zeros from the most significant bit to the first one bit. ___ llvm-commits mailing list [EMAIL PROTECTED] http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.63 - 1.64 --- Log message: add a method --- Diffs of the changes: (+7 -0) APInt.h |7 +++ 1 files changed, 7 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.63 llvm/include/llvm/ADT/APInt.h:1.64 --- llvm/include/llvm/ADT/APInt.h:1.63 Wed Apr 4 01:18:21 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Apr 10 01:43:18 2007 @@ -281,6 +281,13 @@ return *this != 0; } + /// getLimitedValue - Return this value, or return all ones if it is too large + /// to return. + uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { +return (getActiveBits() 64 || getZExtValue() Limit) ? + Limit : getZExtValue(); + } + /// @} /// @name Value Generators /// @{ ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Chris, On Tue, 2007-04-10 at 01:43 -0500, Chris Lattner wrote: Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.63 - 1.64 --- Log message: add a method --- Diffs of the changes: (+7 -0) APInt.h |7 +++ 1 files changed, 7 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.63 llvm/include/llvm/ADT/APInt.h:1.64 --- llvm/include/llvm/ADT/APInt.h:1.63Wed Apr 4 01:18:21 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Apr 10 01:43:18 2007 @@ -281,6 +281,13 @@ return *this != 0; } + /// getLimitedValue - Return this value, or return all ones if it is too large + /// to return. The comment here doesn't match the action of the function. The Limit parameter is returned not all ones. All ones is only the default Limit. Reid. + uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { +return (getActiveBits() 64 || getZExtValue() Limit) ? + Limit : getZExtValue(); + } + /// @} /// @name Value Generators /// @{ ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.64 - 1.65 --- Log message: fix a comment bug Reid noticed --- Diffs of the changes: (+3 -2) APInt.h |5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.64 llvm/include/llvm/ADT/APInt.h:1.65 --- llvm/include/llvm/ADT/APInt.h:1.64 Tue Apr 10 01:43:18 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Apr 10 11:33:06 2007 @@ -281,8 +281,9 @@ return *this != 0; } - /// getLimitedValue - Return this value, or return all ones if it is too large - /// to return. + /// getLimitedValue - 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. uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { return (getActiveBits() 64 || getZExtValue() Limit) ? Limit : getZExtValue(); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.62 - 1.63 --- Log message: trivial optimization --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.62 llvm/include/llvm/ADT/APInt.h:1.63 --- llvm/include/llvm/ADT/APInt.h:1.62 Mon Apr 2 23:25:46 2007 +++ llvm/include/llvm/ADT/APInt.h Wed Apr 4 01:18:21 2007 @@ -278,7 +278,7 @@ /// This converts the APInt to a boolean value as a test against zero. /// @brief Boolean conversion function. inline bool getBoolValue() const { -return countLeadingZeros() != BitWidth; +return *this != 0; } /// @} ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.61 - 1.62 --- Log message: add missing operator --- Diffs of the changes: (+4 -0) APInt.h |4 1 files changed, 4 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.61 llvm/include/llvm/ADT/APInt.h:1.62 --- llvm/include/llvm/ADT/APInt.h:1.61 Mon Apr 2 00:41:00 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Apr 2 23:25:46 2007 @@ -542,6 +542,10 @@ APInt operator-(uint64_t RHS) const { return (*this) - APInt(BitWidth, RHS); } + + APInt operator(unsigned Bits) const { +return shl(Bits); + } /// Arithmetic right-shift this APInt by shiftAmt. /// @brief Arithmetic right-shift function. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.59 - 1.60 --- Log message: Remove unused methods. --- Diffs of the changes: (+0 -18) APInt.h | 18 -- 1 files changed, 18 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.59 llvm/include/llvm/ADT/APInt.h:1.60 --- llvm/include/llvm/ADT/APInt.h:1.59 Fri Mar 30 01:39:42 2007 +++ llvm/include/llvm/ADT/APInt.h Sun Apr 1 07:45:33 2007 @@ -396,15 +396,6 @@ return pVal[0]; } - /// @brief Set a sepcific word in the value to a new value. - inline void setWordToValue(uint32_t idx, uint64_t Val) { -assert(idx getNumWords() Invalid word array index); -if (isSingleWord()) - VAL = Val; -else - pVal[idx] = Val; - } - /// @} /// @name Unary Operators /// @{ @@ -743,15 +734,6 @@ /// @brief Zero extend or truncate to width APInt zextOrTrunc(uint32_t width); - /// This is a help function for convenience. If the given \p width equals to - /// this APInt's BitWidth, just return this APInt, otherwise, just zero - /// extend it. - inline APInt zextOrCopy(uint32_t width) { -if (width == BitWidth) - return *this; -return zext(width); - } - /// @} /// @name Bit Manipulation Operators /// @{ ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.60 - 1.61 --- Log message: add a helper function. --- Diffs of the changes: (+3 -0) APInt.h |3 +++ 1 files changed, 3 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.60 llvm/include/llvm/ADT/APInt.h:1.61 --- llvm/include/llvm/ADT/APInt.h:1.60 Sun Apr 1 07:45:33 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Apr 2 00:41:00 2007 @@ -272,6 +272,9 @@ /// @returns true if the argument APInt value is a power of two 0. bool isPowerOf2() const; + /// isSignBit - Return true if this is the value returned by getSignBit. + bool isSignBit() const { return isMinSignedValue(); } + /// This converts the APInt to a boolean value as a test against zero. /// @brief Boolean conversion function. inline bool getBoolValue() const { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.58 - 1.59 --- Log message: Correct typo. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.58 llvm/include/llvm/ADT/APInt.h:1.59 --- llvm/include/llvm/ADT/APInt.h:1.58 Sun Mar 25 16:58:42 2007 +++ llvm/include/llvm/ADT/APInt.h Fri Mar 30 01:39:42 2007 @@ -272,7 +272,7 @@ /// @returns true if the argument APInt value is a power of two 0. bool isPowerOf2() const; - /// This converts the APInt to a boolean valy as a test against zero. + /// This converts the APInt to a boolean value as a test against zero. /// @brief Boolean conversion function. inline bool getBoolValue() const { return countLeadingZeros() != BitWidth; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.57 - 1.58 --- Log message: Compute getLowBitsSet correctly. Using the complement of a 64-bit value and shifting down without regard for the bitwidth of the APInt can lead to incorrect initialization values. Instead, check for the word size case (to avoid undef results from shift) and then do (1 loBitsSet) - 1 --- Diffs of the changes: (+5 -4) APInt.h |9 + 1 files changed, 5 insertions(+), 4 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.57 llvm/include/llvm/ADT/APInt.h:1.58 --- llvm/include/llvm/ADT/APInt.h:1.57 Sat Mar 24 20:13:46 2007 +++ llvm/include/llvm/ADT/APInt.h Sun Mar 25 16:58:42 2007 @@ -374,11 +374,12 @@ // Handle a degenerate case, to avoid shifting by word size if (loBitsSet == 0) return APInt(numBits, 0); -uint32_t shiftAmt = numBits - loBitsSet; +if (loBitsSet == APINT_BITS_PER_WORD) + return APInt(numBits, -1ULL); // For small values, return quickly -if (numBits = APINT_BITS_PER_WORD) - return APInt(numBits, ~0ULL shiftAmt); -return (~APInt(numBits, 0)).lshr(shiftAmt); +if (numBits APINT_BITS_PER_WORD) + return APInt(numBits, (1ULL loBitsSet) - 1); +return (~APInt(numBits, 0)).lshr(numBits - loBitsSet); } /// The hash value is computed as the sum of the words and the bit width. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.46 - 1.47 --- Log message: Clean up this interface: 1. Group similar methods into doxygen groups 2. Reorganize the groups into a consist flow. 3. Significantly improve the quality of the documentation on several methods 4. Rewrite srem and sdiv to eliminate a copy and improve readability. 5. Eliminate unneeded forward references. --- Diffs of the changes: (+457 -312) APInt.h | 769 ++-- 1 files changed, 457 insertions(+), 312 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.46 llvm/include/llvm/ADT/APInt.h:1.47 --- llvm/include/llvm/ADT/APInt.h:1.46 Wed Mar 21 17:22:19 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 13:09:18 2007 @@ -8,7 +8,7 @@ //===--===// // // This file implements a class to represent arbitrary precision integral -// constant values. +// constant values and operations on them. // //===--===// @@ -21,13 +21,6 @@ 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 Class //===--===// @@ -63,20 +56,21 @@ uint32_t BitWidth; /// The number of bits in this APInt. /// This union is used to store the integer value. When the - /// integer bit-width = 64, it uses VAL; - /// otherwise it uses the pVal. + /// integer bit-width = 64, it uses VAL, otherwise it uses pVal. union { uint64_t VAL;/// Used to store the = 64 bits integer value. uint64_t *pVal; /// Used to store the 64 bits integer value. }; - /// This enum is just used to hold a constant we needed for APInt. + /// This enum is used to hold the constants we needed for APInt. enum { -APINT_BITS_PER_WORD = sizeof(uint64_t) * 8, -APINT_WORD_SIZE = sizeof(uint64_t) +APINT_BITS_PER_WORD = sizeof(uint64_t) * 8, /// Bits in a word +APINT_WORD_SIZE = sizeof(uint64_t) /// Byte size of a word }; - // Fast internal constructor + /// This constructor is used only internally for speed of construction of + /// temporaries. It is unsafe for general use so it is not public. + /// @brief Fast internal constructor APInt(uint64_t* val, uint32_t bits) : BitWidth(bits), pVal(val) { } /// @returns true if the number of bits = 64, false otherwise. @@ -86,26 +80,32 @@ } /// @returns the word position for the specified bit position. + /// @brief Determine which word a bit is in. static inline uint32_t whichWord(uint32_t bitPosition) { return bitPosition / APINT_BITS_PER_WORD; } /// @returns the bit position in a word for the specified bit position - /// in APInt. + /// in the APInt. + /// @brief Determine which bit in a word a bit is in. static inline uint32_t whichBit(uint32_t bitPosition) { return bitPosition % APINT_BITS_PER_WORD; } - /// @returns a uint64_t type integer with just bit position at - /// whichBit(bitPosition) setting, others zero. + /// This method generates and returns a uint64_t (word) mask for a single + /// bit at a specific bit position. This is used to mask the bit in the + /// corresponding word. + /// @returns a uint64_t with only bit at whichBit(bitPosition) set + /// @brief Get a single bit mask. static inline uint64_t maskBit(uint32_t bitPosition) { return 1ULL whichBit(bitPosition); } - /// This method is used internally to clear the to N bits that are not used - /// by the APInt. This is needed after the most significant word is assigned - /// a value to ensure that those bits are zero'd out. - /// @brief Clear high order bits + /// This method is used internally to clear the to N bits in the high order + /// word that are not used by the APInt. This is needed after the most + /// significant word is assigned a value to ensure that those bits are + /// zero'd out. + /// @brief Clear unused high order bits inline APInt clearUnusedBits() { // Compute how many bits are used in the final word uint32_t wordBits = BitWidth % APINT_BITS_PER_WORD; @@ -131,8 +131,8 @@ } /// This is used by the constructors that take string arguments. - /// @brief Converts a char array into an APInt - void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, + /// @brief Convert a char array into an APInt + void fromString(uint32_t numBits, const char *strStart, uint32_t slen, uint8_t radix); /// This is used by the toString method to divide by the radix. It simply @@ -150,36 +150,237
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.47 - 1.48 --- Log message: Correct the implementation of srem to be remainder, not modulus. The sign of the result must follow the sign of the divisor. --- Diffs of the changes: (+2 -2) APInt.h |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.47 llvm/include/llvm/ADT/APInt.h:1.48 --- llvm/include/llvm/ADT/APInt.h:1.47 Sat Mar 24 13:09:18 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 16:56:22 2007 @@ -564,9 +564,9 @@ inline APInt srem(const APInt RHS) const { if (isNegative()) if (RHS.isNegative()) -return (-(*this)).urem(-RHS); +return -((-(*this)).urem(-RHS)); else -return -((-(*this)).urem(RHS)); +return (-(*this)).urem(RHS); else if (RHS.isNegative()) return -(this-urem(-RHS)); return this-urem(RHS); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.48 - 1.49 --- Log message: Undo the last change and make this really implement remainder and not modulus. The previous change was a result of incorrect documentation in the LangRef.html. --- Diffs of the changes: (+6 -4) APInt.h | 10 ++ 1 files changed, 6 insertions(+), 4 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.48 llvm/include/llvm/ADT/APInt.h:1.49 --- llvm/include/llvm/ADT/APInt.h:1.48 Sat Mar 24 16:56:22 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 17:37:23 2007 @@ -552,9 +552,11 @@ return this-udiv(RHS); } - /// Perform an Unsigned remainder operation on this APInt with RHS being the + /// Perform an unsigned remainder operation on this APInt with RHS being the /// divisor. Both this and RHS are treated as unsigned quantities for purposes - /// of this operation. + /// of this operation. Note that this is a true remainder operation and not + /// a modulo operation because the sign follows the sign of the dividend + /// which is *this. /// @returns a new APInt value containing the remainder result /// @brief Unsigned remainder operation. APInt urem(const APInt RHS) const; @@ -566,9 +568,9 @@ if (RHS.isNegative()) return -((-(*this)).urem(-RHS)); else -return (-(*this)).urem(RHS); +return -(-(*this)).urem(RHS); else if (RHS.isNegative()) - return -(this-urem(-RHS)); + return this-urem(-RHS); return this-urem(RHS); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.49 - 1.50 --- Log message: Get the signs in the right place! --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.49 llvm/include/llvm/ADT/APInt.h:1.50 --- llvm/include/llvm/ADT/APInt.h:1.49 Sat Mar 24 17:37:23 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 17:50:43 2007 @@ -568,7 +568,7 @@ if (RHS.isNegative()) return -((-(*this)).urem(-RHS)); else -return -(-(*this)).urem(RHS); +return -((-(*this)).urem(RHS)); else if (RHS.isNegative()) return this-urem(-RHS); return this-urem(RHS); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.50 - 1.51 --- Log message: Implement the getHighBitsSet and getLowBitsSet functions. --- Diffs of the changes: (+16 -2) APInt.h | 18 -- 1 files changed, 16 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.50 llvm/include/llvm/ADT/APInt.h:1.51 --- llvm/include/llvm/ADT/APInt.h:1.50 Sat Mar 24 17:50:43 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 18:05:35 2007 @@ -346,13 +346,27 @@ /// @param numBits the bitwidth of the result /// @param hiBitsSet the number of high-order bits set in the result. /// @brief Get a value with high bits set - static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet); + static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { +assert(hiBitsSet = numBits Too many bits to set!); +uint32_t mvBits = numBits - hiBitsSet; +// For small values, return quickly +if (numBits = APINT_BITS_PER_WORD) + return APInt(numBits, ((1ULL hiBitsSet) - 1) mvBits); +APInt Result(numBits, 1); +return (APInt(numBits, 1).shl(hiBitsSet) - APInt(numBits, 1)).shl(mvBits); + } /// Constructs an APInt value that has the bottom loBitsSet bits set. /// @param numBits the bitwidth of the result /// @param loBitsSet the number of low-order bits set in the result. /// @brief Get a value with low bits set - static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet); + static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { +assert(loBitsSet = numBits Too many bits to set!); +// For small values, return quickly +if (numBits = APINT_BITS_PER_WORD) + return APInt(numBits, (1ULL loBitsSet) - 1ULL); +return APInt(numBits, 1).shl(loBitsSet) - APInt(numBits, 1); + } /// The hash value is computed as the sum of the words and the bit width. /// @returns A hash value computed from the sum of the APInt words. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Implement the getHighBitsSet and getLowBitsSet functions. /// @param numBits the bitwidth of the result /// @param hiBitsSet the number of high-order bits set in the result. /// @brief Get a value with high bits set - static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet); + static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { +assert(hiBitsSet = numBits Too many bits to set!); +uint32_t mvBits = numBits - hiBitsSet; +// For small values, return quickly +if (numBits = APINT_BITS_PER_WORD) + return APInt(numBits, ((1ULL hiBitsSet) - 1) mvBits); If hiBitsSet == numBIts == 64, this invokes undefined behavior. +APInt Result(numBits, 1); +return (APInt(numBits, 1).shl(hiBitsSet) - APInt(numBits, 1)).shl(mvBits); likewise. + } /// Constructs an APInt value that has the bottom loBitsSet bits set. /// @param numBits the bitwidth of the result /// @param loBitsSet the number of low-order bits set in the result. /// @brief Get a value with low bits set - static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet); + static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { +assert(loBitsSet = numBits Too many bits to set!); +// For small values, return quickly +if (numBits = APINT_BITS_PER_WORD) + return APInt(numBits, (1ULL loBitsSet) - 1ULL); +return APInt(numBits, 1).shl(loBitsSet) - APInt(numBits, 1); likewise. -Chris + } /// The hash value is computed as the sum of the words and the bit width. /// @returns A hash value computed from the sum of the APInt words. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.51 - 1.52 --- Log message: Implement the getBitsSet function. --- Diffs of the changes: (+10 -1) APInt.h | 11 ++- 1 files changed, 10 insertions(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.51 llvm/include/llvm/ADT/APInt.h:1.52 --- llvm/include/llvm/ADT/APInt.h:1.51 Sat Mar 24 18:05:35 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 18:27:48 2007 @@ -340,7 +340,16 @@ /// @param loBit the index of the lowest bit set. /// @returns An APInt value with the requested bits set. /// @brief Get a value with a block of bits set. - static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0); + static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0){ +assert(hiBit numBits hiBit out of range); +assert(loBit numBits loBit out of range); +if (hiBit loBit) + return getLowBitsSet(numBits, hiBit+1) | + getHighBitsSet(numBits, numBits-loBit+1); +else if (loBit == 0) + return getLowBitsSet(numBits, hiBit+1); +return getLowBitsSet(numBits, hiBit-loBit+1).shl(loBit); + } /// Constructs an APInt value that has the top hiBitsSet bits set. /// @param numBits the bitwidth of the result ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
/// @param loBit the index of the lowest bit set. /// @returns An APInt value with the requested bits set. /// @brief Get a value with a block of bits set. - static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0); + static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0){ +assert(hiBit numBits hiBit out of range); +assert(loBit numBits loBit out of range); +if (hiBit loBit) Hrm? Why would you allow hiBit loBit? This seems like something that should be asserted against. + return getLowBitsSet(numBits, hiBit+1) | + getHighBitsSet(numBits, numBits-loBit+1); +else if (loBit == 0) + return getLowBitsSet(numBits, hiBit+1); Do you need this special case for correctness? -Chris +return getLowBitsSet(numBits, hiBit-loBit+1).shl(loBit); + } /// Constructs an APInt value that has the top hiBitsSet bits set. /// @param numBits the bitwidth of the result ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.52 - 1.53 --- Log message: Don't invoke undefined behavior in shifts in the functions getHighBitsSet and getLowBitsSet. --- Diffs of the changes: (+6 -6) APInt.h | 12 ++-- 1 files changed, 6 insertions(+), 6 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.52 llvm/include/llvm/ADT/APInt.h:1.53 --- llvm/include/llvm/ADT/APInt.h:1.52 Sat Mar 24 18:27:48 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 18:35:54 2007 @@ -357,12 +357,11 @@ /// @brief Get a value with high bits set static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { assert(hiBitsSet = numBits Too many bits to set!); -uint32_t mvBits = numBits - hiBitsSet; +uint32_t shiftAmt = numBits - hiBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) - return APInt(numBits, ((1ULL hiBitsSet) - 1) mvBits); -APInt Result(numBits, 1); -return (APInt(numBits, 1).shl(hiBitsSet) - APInt(numBits, 1)).shl(mvBits); + return APInt(numBits, ~0ULL shiftAmt); +return (~APInt(numBits, 0)).shl(shiftAmt); } /// Constructs an APInt value that has the bottom loBitsSet bits set. @@ -371,10 +370,11 @@ /// @brief Get a value with low bits set static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { assert(loBitsSet = numBits Too many bits to set!); +uint32_t shiftAmt = numBits - loBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) - return APInt(numBits, (1ULL loBitsSet) - 1ULL); -return APInt(numBits, 1).shl(loBitsSet) - APInt(numBits, 1); + return APInt(numBits, ~0ULL shiftAmt); +return (~APInt(numBits, 0)).lshr(shiftAmt); } /// The hash value is computed as the sum of the words and the bit width. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
On Mar 24, 2007, at 4:36 PM, Reid Spencer wrote: /// @brief Get a value with high bits set static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { assert(hiBitsSet = numBits Too many bits to set!); -uint32_t mvBits = numBits - hiBitsSet; +uint32_t shiftAmt = numBits - hiBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) + return APInt(numBits, ~0ULL shiftAmt); Now we get undefined behavior if hibitsset = 0, no? -Chris +return (~APInt(numBits, 0)).shl(shiftAmt); } /// Constructs an APInt value that has the bottom loBitsSet bits set. @@ -371,10 +370,11 @@ /// @brief Get a value with low bits set static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { assert(loBitsSet = numBits Too many bits to set!); +uint32_t shiftAmt = numBits - loBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) - return APInt(numBits, (1ULL loBitsSet) - 1ULL); -return APInt(numBits, 1).shl(loBitsSet) - APInt(numBits, 1); + return APInt(numBits, ~0ULL shiftAmt); +return (~APInt(numBits, 0)).lshr(shiftAmt); } /// The hash value is computed as the sum of the words and the bit width. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
On Mar 24, 2007, at 4:37 PM, Reid Spencer wrote: On Sat, 2007-03-24 at 16:31 -0700, Chris Lattner wrote: /// @param loBit the index of the lowest bit set. /// @returns An APInt value with the requested bits set. /// @brief Get a value with a block of bits set. - static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0); + static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0){ +assert(hiBit numBits hiBit out of range); +assert(loBit numBits loBit out of range); +if (hiBit loBit) Hrm? Why would you allow hiBit loBit? This seems like something that should be asserted against. Read the definition of the function in the documentation. It allows you to construct things like: 0xFFFF with getBitsSet(32, 8, 24); Ah, ok, makes sense! + return getLowBitsSet(numBits, hiBit+1) | + getHighBitsSet(numBits, numBits-loBit+1); +else if (loBit == 0) + return getLowBitsSet(numBits, hiBit+1); Do you need this special case for correctness? No, I was trying to saves a rather expensive shl for a common case. However, I decided that before I wrote getLowBitsSet (which is the equivalent). I'll remove that case and the default parameter. Thanks, -Chris ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.53 - 1.54 --- Log message: In the getBitsSet function, don't optimize for a common case that is already covered by getLowBitsSet (i.e. when loBits==0). Consequently, remove the default value for loBits and reorder the arguments to the more natural loBits, hiBits order. This makes it more clear that this function is for bit groups in the middle of the bit width and not towards one end or the other. --- Diffs of the changes: (+2 -4) APInt.h |6 ++ 1 files changed, 2 insertions(+), 4 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.53 llvm/include/llvm/ADT/APInt.h:1.54 --- llvm/include/llvm/ADT/APInt.h:1.53 Sat Mar 24 18:35:54 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 18:42:47 2007 @@ -336,18 +336,16 @@ /// less than loBit then the set bits wrap. For example, with /// parameters (32, 3, 28), you would get 0xF00F. /// @param numBits the intended bit width of the result - /// @param hiBit the index of the highest bit set. /// @param loBit the index of the lowest bit set. + /// @param hiBit the index of the highest bit set. /// @returns An APInt value with the requested bits set. /// @brief Get a value with a block of bits set. - static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t loBit = 0){ + static APInt getBitsSet(uint32_t numBits, uint32_t loBit, uint32_t hiBit) { assert(hiBit numBits hiBit out of range); assert(loBit numBits loBit out of range); if (hiBit loBit) return getLowBitsSet(numBits, hiBit+1) | getHighBitsSet(numBits, numBits-loBit+1); -else if (loBit == 0) - return getLowBitsSet(numBits, hiBit+1); return getLowBitsSet(numBits, hiBit-loBit+1).shl(loBit); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.54 - 1.55 --- Log message: Make it illegal to set 0 bits in getHighBitsSet and getLowBitsSet. For that they should have used the uint64_t constructor. This avoids causing undefined results via shifts by the word size when the bit width is an exact multiple of the word size. --- Diffs of the changes: (+2 -0) APInt.h |2 ++ 1 files changed, 2 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.54 llvm/include/llvm/ADT/APInt.h:1.55 --- llvm/include/llvm/ADT/APInt.h:1.54 Sat Mar 24 18:42:47 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 18:47:58 2007 @@ -355,6 +355,7 @@ /// @brief Get a value with high bits set static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { assert(hiBitsSet = numBits Too many bits to set!); +assert(hiBitsSet 0 You must set SOME bits); uint32_t shiftAmt = numBits - hiBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) @@ -368,6 +369,7 @@ /// @brief Get a value with low bits set static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { assert(loBitsSet = numBits Too many bits to set!); +assert(loBitsSet 0 You must set SOME bits); uint32_t shiftAmt = numBits - loBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.55 - 1.56 --- Log message: Actually, for getHighBitsSet and getLowBitsSet, don't make a 0 bit size illegal. Instead do the 0 valued construction for the user. This is because the caller may not know (or care to check) that the number of bits set is zero. --- Diffs of the changes: (+6 -2) APInt.h |8 ++-- 1 files changed, 6 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.55 llvm/include/llvm/ADT/APInt.h:1.56 --- llvm/include/llvm/ADT/APInt.h:1.55 Sat Mar 24 18:47:58 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 19:01:47 2007 @@ -355,7 +355,9 @@ /// @brief Get a value with high bits set static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) { assert(hiBitsSet = numBits Too many bits to set!); -assert(hiBitsSet 0 You must set SOME bits); +// Handle a degenerate case, to avoid shifting by word size +if (hiBitsSet == 0) + return APInt(numBits, 0); uint32_t shiftAmt = numBits - hiBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) @@ -369,7 +371,9 @@ /// @brief Get a value with low bits set static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) { assert(loBitsSet = numBits Too many bits to set!); -assert(loBitsSet 0 You must set SOME bits); +// Handle a degenerate case, to avoid shifting by word size +if (loBitsSet == 0) + return APInt(numBits, 0); uint32_t shiftAmt = numBits - loBitsSet; // For small values, return quickly if (numBits = APINT_BITS_PER_WORD) ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.56 - 1.57 --- Log message: Fix a typo in a comment. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.56 llvm/include/llvm/ADT/APInt.h:1.57 --- llvm/include/llvm/ADT/APInt.h:1.56 Sat Mar 24 19:01:47 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 24 20:13:46 2007 @@ -726,7 +726,7 @@ /// @brief Sign extend to a new width. APInt sext(uint32_t width); - /// This operation zero extends the APInt to a new width. Thie high order bits + /// This operation zero extends the APInt to a new width. The high order bits /// are filled with 0 bits. It is an error to specify a width that is less /// than or equal to the current width. /// @brief Zero extend to a new width. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.45 - 1.46 --- Log message: Fix a comment. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.45 llvm/include/llvm/ADT/APInt.h:1.46 --- llvm/include/llvm/ADT/APInt.h:1.45 Mon Mar 19 21:18:16 2007 +++ llvm/include/llvm/ADT/APInt.h Wed Mar 21 17:22:19 2007 @@ -633,7 +633,7 @@ !isNegative() countPopulation() == BitWidth - 1; } - /// This checks to see if the value of this APInt is the minimum signed + /// This checks to see if the value of this APInt is the minimum unsigned /// value for the APInt's bit width. /// @brief Determine if this is the smallest unsigned value. bool isMinValue() const { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Add isStrictPositive() to APInt to determine if this APInt Value 0. Shouldn't this be isStrictlyPositive? Duncan. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
On Mon, 2007-03-19 at 10:11 +0100, Duncan Sands wrote: Add isStrictPositive() to APInt to determine if this APInt Value 0. Shouldn't this be isStrictlyPositive? Yes, it Should. Sheng, please correct the name of this function as Duncan suggested. Thanks, Reid. Duncan. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.43 - 1.44 --- Log message: Add an indication of signedness to the uint64_t constructor so sign bits can be extended. This helps fix test/Assembler/2007-03-19-NegValue.ll --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.43 llvm/include/llvm/ADT/APInt.h:1.44 --- llvm/include/llvm/ADT/APInt.h:1.43 Mon Mar 19 00:22:18 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Mar 19 15:36:48 2007 @@ -151,7 +151,7 @@ public: /// @brief Create a new APInt of numBits width, initialized as val. - APInt(uint32_t numBits, uint64_t val); + APInt(uint32_t numBits, uint64_t val, bool isSigned = false); /// Note that numWords can be smaller or larger than the corresponding bit /// width but any extraneous bits will be dropped. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.44 - 1.45 --- Log message: Correct the name: isStrictPositive -- isStrictlyPositive. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.44 llvm/include/llvm/ADT/APInt.h:1.45 --- llvm/include/llvm/ADT/APInt.h:1.44 Mon Mar 19 15:36:48 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Mar 19 21:18:16 2007 @@ -376,7 +376,7 @@ /// This just tests if the value of this APInt is strictly positive ( 0). /// @brief Determine if this APInt Value is strictly positive. - inline bool isStrictPositive() const { + inline bool isStrictlyPositive() const { return isPositive() (*this) != 0; } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.42 - 1.43 --- Log message: Add isStrictPositive() to APInt to determine if this APInt Value 0. --- Diffs of the changes: (+6 -0) APInt.h |6 ++ 1 files changed, 6 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.42 llvm/include/llvm/ADT/APInt.h:1.43 --- llvm/include/llvm/ADT/APInt.h:1.42 Tue Mar 13 01:16:26 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Mar 19 00:22:18 2007 @@ -374,6 +374,12 @@ return !isNegative(); } + /// This just tests if the value of this APInt is strictly positive ( 0). + /// @brief Determine if this APInt Value is strictly positive. + inline bool isStrictPositive() const { +return isPositive() (*this) != 0; + } + /// Arithmetic right-shift this APInt by shiftAmt. /// @brief Arithmetic right-shift function. APInt ashr(uint32_t shiftAmt) const; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.41 - 1.42 --- Log message: Add zextOrCopy() into APInt for convenience. --- Diffs of the changes: (+9 -0) APInt.h |9 + 1 files changed, 9 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.41 llvm/include/llvm/ADT/APInt.h:1.42 --- llvm/include/llvm/ADT/APInt.h:1.41 Sun Mar 11 01:16:10 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Mar 13 01:16:26 2007 @@ -450,6 +450,15 @@ /// @brief Zero extend or truncate to width APInt zextOrTrunc(uint32_t width); + /// This is a help function for convenience. If the given \p width equals to + /// this APInt's BitWidth, just return this APInt, otherwise, just zero + /// extend it. + inline APInt zextOrCopy(uint32_t width) { +if (width == BitWidth) + return *this; +return zext(width); + } + /// @brief Set every bit to 1. APInt set(); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.39 - 1.40 --- Log message: Correct the calculation in APInt::logBase2(). --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.39 llvm/include/llvm/ADT/APInt.h:1.40 --- llvm/include/llvm/ADT/APInt.h:1.39 Sat Mar 3 02:34:02 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Mar 5 10:42:58 2007 @@ -697,7 +697,7 @@ /// @returns the floor log base 2 of this APInt. inline uint32_t logBase2() const { -return getNumWords() * APINT_BITS_PER_WORD - 1 - countLeadingZeros(); +return BitWidth - 1 - countLeadingZeros(); } /// @brief Converts this APInt to a double value. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.38 - 1.39 --- Log message: Regularize the interface for conversion functions to/from float/double. --- Diffs of the changes: (+9 -3) APInt.h | 12 +--- 1 files changed, 9 insertions(+), 3 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.38 llvm/include/llvm/ADT/APInt.h:1.39 --- llvm/include/llvm/ADT/APInt.h:1.38 Sat Mar 3 00:17:23 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 3 02:34:02 2007 @@ -865,14 +865,20 @@ return float(RoundAPIntToDouble(APIVal)); } +/// Treast the APInt as a signed value for conversion purposes. +/// @brief Converts the given APInt to a float value. +inline float RoundSignedAPIntToFloat(const APInt APIVal) { + return float(APIVal.signedRoundToDouble()); +} + /// RoundDoubleToAPInt - This function convert a double value to an APInt value. /// @brief Converts the given double value into a APInt. -APInt RoundDoubleToAPInt(double Double, uint32_t width = 64); +APInt RoundDoubleToAPInt(double Double, uint32_t width); /// RoundFloatToAPInt - Converts a float value into an APInt value. /// @brief Converts a float value into a APInt. -inline APInt RoundFloatToAPInt(float Float) { - return RoundDoubleToAPInt(double(Float)); +inline APInt RoundFloatToAPInt(float Float, uint32_t width) { + return RoundDoubleToAPInt(double(Float), width); } /// Arithmetic right-shift the APInt by shiftAmt. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.35 - 1.36 --- Log message: Add isPositive for symmetry with isNegative. --- Diffs of the changes: (+8 -1) APInt.h |9 - 1 files changed, 8 insertions(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.35 llvm/include/llvm/ADT/APInt.h:1.36 --- llvm/include/llvm/ADT/APInt.h:1.35 Thu Mar 1 17:37:09 2007 +++ llvm/include/llvm/ADT/APInt.h Fri Mar 2 18:24:39 2007 @@ -106,7 +106,7 @@ /// @returns a uint64_t type integer with just bit position at /// whichBit(bitPosition) setting, others zero. static inline uint64_t maskBit(uint32_t bitPosition) { -return (static_castuint64_t(1)) whichBit(bitPosition); +return 1ULL whichBit(bitPosition); } /// This method is used internally to clear the to N bits that are not used @@ -365,6 +365,13 @@ return (*this)[BitWidth - 1]; } + /// This just tests the high bit of the APInt to determine if the value is + /// positove or not. + /// @brief Determine if this APInt Value is positive. + bool isPositive() const { +return !isNegative(); + } + /// Arithmetic right-shift this APInt by shiftAmt. /// @brief Arithmetic right-shift function. APInt ashr(uint32_t shiftAmt) const; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.36 - 1.37 --- Log message: Add names for some of the operators. This is needed for the macros in the Interpreter. --- Diffs of the changes: (+9 -0) APInt.h |9 + 1 files changed, 9 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.36 llvm/include/llvm/ADT/APInt.h:1.37 --- llvm/include/llvm/ADT/APInt.h:1.36 Fri Mar 2 18:24:39 2007 +++ llvm/include/llvm/ADT/APInt.h Fri Mar 2 23:37:23 2007 @@ -248,14 +248,23 @@ /// the given APInt RHS. /// @brief Bitwise AND operator. APInt operator(const APInt RHS) const; + APInt And(const APInt RHS) const { +return this-operator(RHS); + } /// Performs bitwise OR operation on this APInt and the given APInt RHS. /// @brief Bitwise OR operator. APInt operator|(const APInt RHS) const; + APInt Or(const APInt RHS) const { +return this-operator|(RHS); + } /// Performs bitwise XOR operation on this APInt and the given APInt RHS. /// @brief Bitwise XOR operator. APInt operator^(const APInt RHS) const; + APInt Xor(const APInt RHS) const { +return this-operator^(RHS); + } /// Performs logical negation operation on this APInt. /// @brief Logical negation operator. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.37 - 1.38 --- Log message: Make getNumWords public so that those using getRawData stand a chance of not reading beyond the end of the buffer returned. --- Diffs of the changes: (+7 -7) APInt.h | 14 +++--- 1 files changed, 7 insertions(+), 7 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.37 llvm/include/llvm/ADT/APInt.h:1.38 --- llvm/include/llvm/ADT/APInt.h:1.37 Fri Mar 2 23:37:23 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Mar 3 00:17:23 2007 @@ -79,13 +79,6 @@ // Fast internal constructor APInt(uint64_t* val, uint32_t bits) : BitWidth(bits), pVal(val) { } - /// Here one word's bitwidth equals to that of uint64_t. - /// @returns the number of words to hold the integer value of this APInt. - /// @brief Get the number of words. - inline uint32_t getNumWords() const { -return (BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD; - } - /// @returns true if the number of bits = 64, false otherwise. /// @brief Determine if this APInt just has one word to store value. inline bool isSingleWord() const { @@ -486,6 +479,13 @@ return whichWord(getActiveBits()-1) + 1; } + /// Here one word's bitwidth equals to that of uint64_t. + /// @returns the number of words to hold the integer value of this APInt. + /// @brief Get the number of words. + inline uint32_t getNumWords() const { +return (BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD; + } + /// This function returns a pointer to the internal storage of the APInt. /// This is useful for writing out the APInt in binary form without any /// conversions. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.31 - 1.32 --- Log message: Add methods for bit width modification: sextOrTrunc, zextOrTrunc. --- Diffs of the changes: (+10 -0) APInt.h | 10 ++ 1 files changed, 10 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.31 llvm/include/llvm/ADT/APInt.h:1.32 --- llvm/include/llvm/ADT/APInt.h:1.31 Wed Feb 28 23:39:56 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Mar 1 11:15:32 2007 @@ -423,6 +423,16 @@ /// @brief Zero extend to a new width. APInt zext(uint32_t width); + /// Make this APInt have the bit width given by \p width. The value is sign + /// extended, truncated, or left alone to make it that width. + /// @brief Sign extend or truncate to width + APInt sextOrTrunc(uint32_t width); + + /// Make this APInt have the bit width given by \p width. The value is zero + /// extended, truncated, or left alone to make it that width. + /// @brief Zero extend or truncate to width + APInt zextOrTrunc(uint32_t width); + /// @brief Set every bit to 1. APInt set(); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.32 - 1.33 --- Log message: Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP. --- Diffs of the changes: (+26 -0) APInt.h | 26 ++ 1 files changed, 26 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.32 llvm/include/llvm/ADT/APInt.h:1.33 --- llvm/include/llvm/ADT/APInt.h:1.32 Thu Mar 1 11:15:32 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Mar 1 14:06:51 2007 @@ -697,6 +697,32 @@ return roundToDouble(true); } + /// The conversion does not do a translation from integer to double, it just + /// re-interprets the bits as a double. Note that it is valid to do this on + /// any bit width. Exactly 64 bits will be translated. + /// @brief Converts APInt bits to a double + double bitsToDouble() const { +union { + uint64_t I; + double D; +} T; +T.I = (isSingleWord() ? VAL : pVal[0]); +return T.D; + } + + /// The conversion does not do a translation from integer to float, it just + /// re-interprets the bits as a float. Note that it is valid to do this on + /// any bit width. Exactly 32 bits will be translated. + /// @brief Converts APInt bits to a double + float bitsToFloat() const { +union { + uint32_t I; + float F; +} T; +T.I = uint32_t((isSingleWord() ? VAL : pVal[0])); +return T.F; + } + /// @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
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.33 - 1.34 --- Log message: Add doubleToBits and floatToBits methods. --- Diffs of the changes: (+34 -0) APInt.h | 34 ++ 1 files changed, 34 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.33 llvm/include/llvm/ADT/APInt.h:1.34 --- llvm/include/llvm/ADT/APInt.h:1.33 Thu Mar 1 14:06:51 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Mar 1 14:39:01 2007 @@ -723,6 +723,40 @@ return T.F; } + /// The conversion does not do a translation from double to integer, it just + /// re-interprets the bits of the double. Note that it is valid to do this on + /// any bit width but bits from V may get truncated. + /// @brief Converts a double to APInt bits. + APInt doubleToBits(double V) { +union { + uint64_t I; + double D; +} T; +T.D = V; +if (isSingleWord()) + VAL = T.I; +else + pVal[0] = T.I; +return clearUnusedBits(); + } + + /// The conversion does not do a translation from float to integer, it just + /// re-interprets the bits of the float. Note that it is valid to do this on + /// any bit width but bits from V may get truncated. + /// @brief Converts a float to APInt bits. + APInt floatToBits(float V) { +union { + uint32_t I; + float F; +} T; +T.F = V; +if (isSingleWord()) + VAL = T.I; +else + pVal[0] = T.I; +return clearUnusedBits(); + } + /// @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
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Add doubleToBits and floatToBits methods. These shouldn't be needed. bitstodouble only works with a 64-bit source integer, and bitstofloat only works with a 32-bit source integer. MathExtras.h should be sufficient here, -Chris --- Diffs of the changes: (+34 -0) APInt.h | 34 ++ 1 files changed, 34 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.33 llvm/include/llvm/ADT/ APInt.h:1.34 --- llvm/include/llvm/ADT/APInt.h:1.33Thu Mar 1 14:06:51 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Mar 1 14:39:01 2007 @@ -723,6 +723,40 @@ return T.F; } + /// The conversion does not do a translation from double to integer, it just + /// re-interprets the bits of the double. Note that it is valid to do this on + /// any bit width but bits from V may get truncated. + /// @brief Converts a double to APInt bits. + APInt doubleToBits(double V) { +union { + uint64_t I; + double D; +} T; +T.D = V; +if (isSingleWord()) + VAL = T.I; +else + pVal[0] = T.I; +return clearUnusedBits(); + } + + /// The conversion does not do a translation from float to integer, it just + /// re-interprets the bits of the float. Note that it is valid to do this on + /// any bit width but bits from V may get truncated. + /// @brief Converts a float to APInt bits. + APInt floatToBits(float V) { +union { + uint32_t I; + float F; +} T; +T.F = V; +if (isSingleWord()) + VAL = T.I; +else + pVal[0] = T.I; +return clearUnusedBits(); + } + /// @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 ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP. Likewise, these shouldn't be needed. -Chris --- Diffs of the changes: (+26 -0) APInt.h | 26 ++ 1 files changed, 26 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.32 llvm/include/llvm/ADT/ APInt.h:1.33 --- llvm/include/llvm/ADT/APInt.h:1.32Thu Mar 1 11:15:32 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Mar 1 14:06:51 2007 @@ -697,6 +697,32 @@ return roundToDouble(true); } + /// The conversion does not do a translation from integer to double, it just + /// re-interprets the bits as a double. Note that it is valid to do this on + /// any bit width. Exactly 64 bits will be translated. + /// @brief Converts APInt bits to a double + double bitsToDouble() const { +union { + uint64_t I; + double D; +} T; +T.I = (isSingleWord() ? VAL : pVal[0]); +return T.D; + } + + /// The conversion does not do a translation from integer to float, it just + /// re-interprets the bits as a float. Note that it is valid to do this on + /// any bit width. Exactly 32 bits will be translated. + /// @brief Converts APInt bits to a double + float bitsToFloat() const { +union { + uint32_t I; + float F; +} T; +T.I = uint32_t((isSingleWord() ? VAL : pVal[0])); +return T.F; + } + /// @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 ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.34 - 1.35 --- Log message: Add an abs() function to get the absolute value. --- Diffs of the changes: (+8 -0) APInt.h |8 1 files changed, 8 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.34 llvm/include/llvm/ADT/APInt.h:1.35 --- llvm/include/llvm/ADT/APInt.h:1.34 Thu Mar 1 14:39:01 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Mar 1 17:37:09 2007 @@ -759,6 +759,14 @@ /// @brief Compute the square root APInt sqrt() const; + + /// If *this is 0 then return -(*this), otherwise *this; + /// @brief Get the absolute value; + APInt abs() const { +if (isNegative()) + return -(*this); +return *this; + } }; inline bool operator==(uint64_t V1, const APInt V2) { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.29 - 1.30 --- Log message: Make APInt a little more friendly to its users: * Add support for + and - of a uint64_t. * Make trunc/sext/zext return *this so it can be chained with other ops * Add smin, smax, umin, umax functions for getting min/max values. --- Diffs of the changes: (+30 -3) APInt.h | 33 ++--- 1 files changed, 30 insertions(+), 3 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.29 llvm/include/llvm/ADT/APInt.h:1.30 --- llvm/include/llvm/ADT/APInt.h:1.29 Tue Feb 27 20:20:49 2007 +++ llvm/include/llvm/ADT/APInt.h Wed Feb 28 11:33:36 2007 @@ -268,10 +268,17 @@ /// Adds this APInt by the given APInt RHS. /// @brief Addition operator. APInt operator+(const APInt RHS) const; + APInt operator+(uint64_t RHS) const { +return (*this) + APInt(BitWidth, RHS); + } + /// Subtracts this APInt by the given APInt RHS /// @brief Subtraction operator. APInt operator-(const APInt RHS) const; + APInt operator-(uint64_t RHS) const { +return (*this) - APInt(BitWidth, RHS); + } /// @brief Unary negation operator inline APInt operator-() const { @@ -401,20 +408,20 @@ /// Truncate the APInt to a specified width. It is an error to specify a width /// that is greater than or equal to the current width. /// @brief Truncate to new width. - void trunc(uint32_t width); + APInt trunc(uint32_t width); /// This operation sign extends the APInt to a new width. If the high order /// bit is set, the fill on the left will be done with 1 bits, otherwise zero. /// It is an error to specify a width that is less than or equal to the /// current width. /// @brief Sign extend to a new width. - void sext(uint32_t width); + APInt sext(uint32_t width); /// This operation zero extends the APInt to a new width. Thie high order bits /// are filled with 0 bits. It is an error to specify a width that is less /// than or equal to the current width. /// @brief Zero extend to a new width. - void zext(uint32_t width); + APInt zext(uint32_t width); /// @brief Set every bit to 1. APInt set(); @@ -691,6 +698,26 @@ namespace APIntOps { +/// @brief Determine the smaller of two APInts considered to be signed. +inline APInt smin(const APInt A, const APInt B) { + return A.slt(B) ? A : B; +} + +/// @brief Determine the larger of two APInts considered to be signed. +inline APInt smax(const APInt A, const APInt B) { + return A.sgt(B) ? A : B; +} + +/// @brief Determine the smaller of two APInts considered to be signed. +inline APInt umin(const APInt A, const APInt B) { + return A.ult(B) ? A : B; +} + +/// @brief Determine the larger of two APInts considered to be unsigned. +inline APInt umax(const APInt A, const APInt B) { + return A.ugt(B) ? A : B; +} + /// @brief Check if the specified APInt has a N-bits integer value. inline bool isIntN(uint32_t N, const APInt APIVal) { return APIVal.isIntN(N); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.30 - 1.31 --- Log message: Add a square root function. --- Diffs of the changes: (+3 -0) APInt.h |3 +++ 1 files changed, 3 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.30 llvm/include/llvm/ADT/APInt.h:1.31 --- llvm/include/llvm/ADT/APInt.h:1.30 Wed Feb 28 11:33:36 2007 +++ llvm/include/llvm/ADT/APInt.h Wed Feb 28 23:39:56 2007 @@ -686,6 +686,9 @@ double signedRoundToDouble() const { return roundToDouble(true); } + + /// @brief Compute the square root + APInt sqrt() const; }; inline bool operator==(uint64_t V1, const APInt V2) { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.24 - 1.25 --- Log message: Allow the RoundDoubleToAPInt function to specify a width to use. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.24 llvm/include/llvm/ADT/APInt.h:1.25 --- llvm/include/llvm/ADT/APInt.h:1.24 Mon Feb 26 15:06:05 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 27 12:22:31 2007 @@ -654,7 +654,7 @@ /// RoundDoubleToAPInt - This function convert a double value to an APInt value. /// @brief Converts the given double value into a APInt. -APInt RoundDoubleToAPInt(double Double); +APInt RoundDoubleToAPInt(double Double, uint32_t width = 64); /// RoundFloatToAPInt - Converts a float value into an APInt value. /// @brief Converts a float value into a APInt. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.25 - 1.26 --- Log message: Improve APInt interface: 1. Add unsigned and signed versions of methods so a bool argument doesn't need to be passed in. 2. Make the various getMin/getMax functions all be inline since they are so simple. 3. Simplify sdiv and srem code. --- Diffs of the changes: (+67 -22) APInt.h | 89 1 files changed, 67 insertions(+), 22 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.25 llvm/include/llvm/ADT/APInt.h:1.26 --- llvm/include/llvm/ADT/APInt.h:1.25 Tue Feb 27 12:22:31 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 27 14:24:31 2007 @@ -59,7 +59,6 @@ /// /// @brief Class for arbitrary precision integers. class APInt { -public: uint32_t BitWidth; /// The number of bits in this APInt. @@ -374,8 +373,8 @@ /// Signed divide this APInt by APInt RHS. /// @brief Signed division function for APInt. inline APInt sdiv(const APInt RHS) const { -bool isNegativeLHS = (*this)[BitWidth - 1]; -bool isNegativeRHS = RHS[RHS.BitWidth - 1]; +bool isNegativeLHS = isNegative(); +bool isNegativeRHS = RHS.isNegative(); APInt Result = APIntOps::udiv( isNegativeLHS ? -(*this) : (*this), isNegativeRHS ? -RHS : RHS); return isNegativeLHS != isNegativeRHS ? -Result : Result; @@ -388,8 +387,8 @@ /// Signed remainder operation on APInt. /// @brief Function for signed remainder operation. inline APInt srem(const APInt RHS) const { -bool isNegativeLHS = (*this)[BitWidth - 1]; -bool isNegativeRHS = RHS[RHS.BitWidth - 1]; +bool isNegativeLHS = isNegative(); +bool isNegativeRHS = RHS.isNegative(); APInt Result = APIntOps::urem( isNegativeLHS ? -(*this) : (*this), isNegativeRHS ? -RHS : RHS); return isNegativeLHS ? -Result : Result; @@ -470,24 +469,37 @@ return int64_t(pVal[0]); } - /// @returns the largest value for an APInt of the specified bit-width and - /// if isSign == true, it should be largest signed value, otherwise largest - /// unsigned value. - /// @brief Gets max value of the APInt with bitwidth = 64. - static APInt getMaxValue(uint32_t numBits, bool isSigned); - - /// @returns the smallest value for an APInt of the given bit-width and - /// if isSign == true, it should be smallest signed value, otherwise zero. - /// @brief Gets min value of the APInt with bitwidth = 64. - static APInt getMinValue(uint32_t numBits, bool isSigned); + /// @brief Gets maximum unsigned value of APInt for specific bit width. + static APInt getMaxValue(uint32_t numBits) { +return APInt(numBits, 0).set(); + } + + /// @brief Gets maximum signed value of APInt for a specific bit width. + static APInt getSignedMaxValue(uint32_t numBits) { +return APInt(numBits, 0).set().clear(numBits - 1); + } + + /// @brief Gets minimum unsigned value of APInt for a specific bit width. + static APInt getMinValue(uint32_t numBits) { +return APInt(numBits, 0); + } + + /// @brief Gets minimum signed value of APInt for a specific bit width. + static APInt getSignedMinValue(uint32_t numBits) { +return APInt(numBits, 0).set(numBits - 1); + } /// @returns the all-ones value for an APInt of the specified bit-width. /// @brief Get the all-ones value. - static APInt getAllOnesValue(uint32_t numBits); + static APInt getAllOnesValue(uint32_t numBits) { +return APInt(numBits, 0).set(); + } /// @returns the '0' value for an APInt of the specified bit-width. /// @brief Get the '0' value. - static APInt getNullValue(uint32_t numBits); + static APInt getNullValue(uint32_t numBits) { +return APInt(numBits, 0); + } /// The hash value is computed as the sum of the words and the bit width. /// @returns A hash value computed from the sum of the APInt words. @@ -536,8 +548,25 @@ isNegative() countPopulation() == 1; } - /// @returns a character interpretation of the APInt. - std::string toString(uint8_t radix = 10, bool wantSigned = true) const; + /// This is used internally to convert an APInt to a string. + /// @brief Converts an APInt to a std::string + std::string toString(uint8_t radix, bool wantSigned) const; + + /// Considers the APInt to be unsigned and converts it into a string in the + /// radix given. The radix can be 2, 8, 10 or 16. + /// @returns a character interpretation of the APInt + /// @brief Convert unsigned APInt to string representation. + inline std::string toString(uint8_t radix = 10) const { +return toString(radix, false); + } + + /// Considers the APInt to be unsigned and converts it into a string in the + /// radix given. The radix can be 2, 8, 10 or 16. + /// @returns a character interpretation of the APInt + /// @brief Convert unsigned APInt to string representation. + inline std::string toStringSigned(uint8_t
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.26 - 1.27 --- Log message: Implement countLeadingOnes() and getMinSignedBits(). This helps to minimize the bit width of negative numbers by computing the minimum bit width for a negative value. E.g. 0x1800 could be just 0x8000 --- Diffs of the changes: (+14 -1) APInt.h | 15 ++- 1 files changed, 14 insertions(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.26 llvm/include/llvm/ADT/APInt.h:1.27 --- llvm/include/llvm/ADT/APInt.h:1.26 Tue Feb 27 14:24:31 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 27 15:59:26 2007 @@ -446,6 +446,12 @@ return BitWidth - countLeadingZeros(); } + inline uint32_t getMinSignedBits() const { +if (isNegative()) + return BitWidth - countLeadingOnes() + 1; +return getActiveBits(); + } + /// This method attempts to return the value of this APInt as a zero extended /// uint64_t. The bitwidth must be = 64 or the value must fit within a /// uint64_t. Otherwise an assertion will result. @@ -587,9 +593,16 @@ /// @returns getNumWords() * APINT_BITS_PER_WORD if the value is zero. /// @returns the number of zeros from the most significant bit to the first /// one bits. - /// @brief Count the number of trailing one bits. + /// @brief Count the number of leading one bits. uint32_t countLeadingZeros() const; + /// countLeadingOnes - This function counts the number of contiguous 1 bits + /// in the high order bits. The count stops when the first 0 bit is reached. + /// @returns 0 if the high order bit is not set + /// @returns the number of 1 bits from the most significant to the least + /// @brief Count the number of leading one bits. + uint32_t countLeadingOnes() const; + /// countTrailingZeros - This function is an APInt version of the /// countTrailingZoers_{32,64} functions in MathExtras.h. It counts /// the number of zeros from the least significant bit to the first one bit. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.27 - 1.28 --- Log message: Add some syntactic sugar. --- Diffs of the changes: (+31 -0) APInt.h | 31 +++ 1 files changed, 31 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.27 llvm/include/llvm/ADT/APInt.h:1.28 --- llvm/include/llvm/ADT/APInt.h:1.27 Tue Feb 27 15:59:26 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 27 17:47:33 2007 @@ -446,6 +446,29 @@ return BitWidth - countLeadingZeros(); } + /// This function returns the number of active words in the value of this + /// APInt. This is used in conjunction with getActiveData to extract the raw + /// value of the APInt. + inline uint32_t getActiveWords() const { +return whichWord(getActiveBits()-1); + } + + /// This function returns a pointer to the internal storage of the APInt. + /// This is useful for writing out the APInt in binary form without any + /// conversions. + inline const uint64_t* getRawData() const { +if (isSingleWord()) + return VAL; +return pVal[0]; + } + + /// Computes the minimum bit width for this APInt while considering it to be + /// a signed (and probably negative) value. If the value is not negative, + /// this function returns the same value as getActiveBits(). Otherwise, it + /// returns the smallest bit width that will retain the negative value. For + /// example, -1 can be written as 0b1 or 0xFF. 0b1 is shorter and so + /// for -1, this function will always return 1. + /// @brief Get the minimum bit size for this signed APInt inline uint32_t getMinSignedBits() const { if (isNegative()) return BitWidth - countLeadingOnes() + 1; @@ -658,6 +681,14 @@ } }; +inline bool operator==(uint64_t V1, const APInt V2) { + return V2 == V1; +} + +inline bool operator!=(uint64_t V1, const APInt V2) { + return V2 != V1; +} + namespace APIntOps { /// @brief Check if the specified APInt has a N-bits integer value. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.28 - 1.29 --- Log message: getActiveWords should return the number of words, not the index of the highest active words. Increment its result by one. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.28 llvm/include/llvm/ADT/APInt.h:1.29 --- llvm/include/llvm/ADT/APInt.h:1.28 Tue Feb 27 17:47:33 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 27 20:20:49 2007 @@ -450,7 +450,7 @@ /// APInt. This is used in conjunction with getActiveData to extract the raw /// value of the APInt. inline uint32_t getActiveWords() const { -return whichWord(getActiveBits()-1); +return whichWord(getActiveBits()-1) + 1; } /// This function returns a pointer to the internal storage of the APInt. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.21 - 1.22 --- Log message: Implement inline methods that make transition of ConstantInt to use APInt easier to comprehend and might be useful elsewhere. --- Diffs of the changes: (+38 -2) APInt.h | 40 ++-- 1 files changed, 38 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.21 llvm/include/llvm/ADT/APInt.h:1.22 --- llvm/include/llvm/ADT/APInt.h:1.21 Mon Feb 26 01:45:40 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Feb 26 11:50:32 2007 @@ -463,12 +463,12 @@ /// if isSign == true, it should be largest signed value, otherwise largest /// unsigned value. /// @brief Gets max value of the APInt with bitwidth = 64. - static APInt getMaxValue(uint32_t numBits, bool isSign); + static APInt getMaxValue(uint32_t numBits, bool isSigned); /// @returns the smallest value for an APInt of the given bit-width and /// if isSign == true, it should be smallest signed value, otherwise zero. /// @brief Gets min value of the APInt with bitwidth = 64. - static APInt getMinValue(uint32_t numBits, bool isSign); + static APInt getMinValue(uint32_t numBits, bool isSigned); /// @returns the all-ones value for an APInt of the specified bit-width. /// @brief Get the all-ones value. @@ -484,6 +484,42 @@ return countLeadingZeros() != BitWidth; } + /// This checks to see if the value has all bits of the APInt are set or not. + /// @brief Determine if all bits are set + inline bool isAllOnesValue() const { +return countPopulation() == BitWidth; + } + + /// This checks to see if the value of this APInt is the maximum unsigned + /// value for the APInt's bit width. + /// @brief Determine if this is the largest unsigned value. + bool isMaxValue() const { +return countPopulation() == BitWidth; + } + + /// This checks to see if the value of this APInt is the maximum signed + /// value for the APInt's bit width. + /// @brief Determine if this is the largest signed value. + bool isMaxSignedValue() const { +return BitWidth == 1 ? VAL == 0 : + !isNegative() countPopulation() == BitWidth - 1; + } + + /// This checks to see if the value of this APInt is the minimum signed + /// value for the APInt's bit width. + /// @brief Determine if this is the smallest unsigned value. + bool isMinValue() const { +return countPopulation() == 0; + } + + /// This checks to see if the value of this APInt is the minimum signed + /// value for the APInt's bit width. + /// @brief Determine if this is the smallest signed value. + bool isMinSignedValue() const { +return BitWidth == 1 ? VAL == 1 : + isNegative() countPopulation() == 1; + } + /// @returns a character interpretation of the APInt. std::string toString(uint8_t radix = 10, bool wantSigned = true) const; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.23 - 1.24 --- Log message: Fix indentation. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.23 llvm/include/llvm/ADT/APInt.h:1.24 --- llvm/include/llvm/ADT/APInt.h:1.23 Mon Feb 26 14:57:12 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Feb 26 15:06:05 2007 @@ -467,7 +467,7 @@ return int64_t(VAL (APINT_BITS_PER_WORD - BitWidth)) (APINT_BITS_PER_WORD - BitWidth); assert(getActiveBits() = 64 Too many bits for int64_t); - return int64_t(pVal[0]); +return int64_t(pVal[0]); } /// @returns the largest value for an APInt of the specified bit-width and ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.18 - 1.19 --- Log message: Fix clearUnusedBits to not depend on undefined behavior of operator when the bit size is equal to the word size. This happens to work out okay on x86, but might not on other platforms. The change just detects when there are no bits to clear (because BitWidth is a multiple of the word size) and returns early. Also, move some comments from .cpp file into header. --- Diffs of the changes: (+40 -9) APInt.h | 49 - 1 files changed, 40 insertions(+), 9 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.18 llvm/include/llvm/ADT/APInt.h:1.19 --- llvm/include/llvm/ADT/APInt.h:1.18 Sun Feb 25 01:29:03 2007 +++ llvm/include/llvm/ADT/APInt.h Sun Feb 25 13:26:01 2007 @@ -114,12 +114,22 @@ /// by the APInt. This is needed after the most significant word is assigned /// a value to ensure that those bits are zero'd out. /// @brief Clear high order bits - inline void clearUnusedBits() { + inline APInt clearUnusedBits() { +// Compute how many bits are used in the final word +uint32_t wordBits = BitWidth % APINT_BITS_PER_WORD; +if (wordBits == 0) + // If all bits are used, we want to leave the value alone. This also + // avoids the undefined behavior of when the shfit is the same size as + // the word size (64). + return *this; + +// Mask out the hight bits. +uint64_t mask = ~uint64_t(0ULL) (APINT_BITS_PER_WORD - wordBits); if (isSingleWord()) - VAL = ~uint64_t(0ULL) (APINT_BITS_PER_WORD - BitWidth); + VAL = mask; else - pVal[getNumWords() - 1] = ~uint64_t(0ULL) -(APINT_BITS_PER_WORD - (whichBit(BitWidth - 1) + 1)); + pVal[getNumWords() - 1] = mask; +return *this; } /// @returns the corresponding word for the specified bit position. @@ -134,7 +144,9 @@ uint8_t radix); /// This is used by the toString method to divide by the radix. It simply - /// provides a more convenient form of divide for internal use. + /// provides a more convenient form of divide for internal use since KnuthDiv + /// has specific constraints on its inputs. If those constraints are not met + /// then it provides a simpler form of divide. /// @brief An internal division function for dividing APInts. static void divide(const APInt LHS, uint32_t lhsWords, const APInt RHS, uint32_t rhsWords, @@ -481,15 +493,30 @@ /// @returns true if the argument APInt value is a power of two 0. bool isPowerOf2() const; + /// countLeadingZeros - This function is an APInt version of the + /// countLeadingZeros_{32,64} functions in MathExtras.h. It counts the number + /// of zeros from the most significant bit to the first one bit. + /// @returns getNumWords() * APINT_BITS_PER_WORD if the value is zero. /// @returns the number of zeros from the most significant bit to the first /// one bits. + /// @brief Count the number of trailing one bits. uint32_t countLeadingZeros() const; + /// countTrailingZeros - This function is an APInt version of the + /// countTrailingZoers_{32,64} functions in MathExtras.h. It counts + /// the number of zeros from the least significant bit to the first one bit. + /// @returns getNumWords() * APINT_BITS_PER_WORD if the value is zero. /// @returns the number of zeros from the least significant bit to the first /// one bit. + /// @brief Count the number of trailing zero bits. uint32_t countTrailingZeros() const; + /// countPopulation - This function is an APInt version of the + /// countPopulation_{32,64} functions in MathExtras.h. It counts the number + /// of 1 bits in the APInt value. + /// @returns 0 if the value is zero. /// @returns the number of set bits. + /// @brief Count the number of bits set. uint32_t countPopulation() const; /// @returns the total number of bits. @@ -550,9 +577,11 @@ return APIVal.logBase2(); } -/// @returns the greatest common divisor of the two values -/// using Euclid's algorithm. -APInt GreatestCommonDivisor(const APInt API1, const APInt API2); +/// GreatestCommonDivisor - This function returns the greatest common +/// divisor of the two APInt values using Enclid's algorithm. +/// @returns the greatest common divisor of Val1 and Val2 +/// @brief Compute GCD of two APInt values. +APInt GreatestCommonDivisor(const APInt Val1, const APInt Val2); /// @brief Converts the given APInt to a double value. inline double RoundAPIntToDouble(const APInt APIVal, bool isSigned = false) { @@ -564,10 +593,12 @@ return float(RoundAPIntToDouble(APIVal)); } +/// RoundDoubleToAPInt - This function convert a double value to an APInt value. /// @brief Converts the given double value into a APInt. APInt RoundDoubleToAPInt(double Double); -/// @brief Converts the given float value into a APInt. +///
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.20 - 1.21 --- Log message: Make isNegative() a const function since it doesn't modify the APInt. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.20 llvm/include/llvm/ADT/APInt.h:1.21 --- llvm/include/llvm/ADT/APInt.h:1.20 Sun Feb 25 19:20:59 2007 +++ llvm/include/llvm/ADT/APInt.h Mon Feb 26 01:45:40 2007 @@ -355,7 +355,7 @@ /// This just tests the high bit of this APInt to determine if it is negative. /// @returns true if this APInt is negative, false otherwise /// @brief Determine sign of this APInt. - bool isNegative() { + bool isNegative() const { return (*this)[BitWidth - 1]; } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.16 - 1.17 --- Log message: Improve documentation. Make divide function internal (it was briefly external for testing). --- Diffs of the changes: (+16 -12) APInt.h | 28 1 files changed, 16 insertions(+), 12 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.16 llvm/include/llvm/ADT/APInt.h:1.17 --- llvm/include/llvm/ADT/APInt.h:1.16 Tue Feb 20 21:56:12 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Feb 24 03:50:13 2007 @@ -107,8 +107,8 @@ } /// This method is used internally to clear the to N bits that are not used - /// by the APInt. This is needed after a word is assigned a value to ensure - /// that those bits are zero'd out. + /// by the APInt. This is needed after the most significant word is assigned + /// a value to ensure that those bits are zero'd out. /// @brief Clear high order bits inline void clearUnusedBits() { if (isSingleWord()) @@ -119,31 +119,35 @@ } /// @returns the corresponding word for the specified bit position. - /// This is a constant version. + /// @brief Get the word corresponding to a bit position inline uint64_t getWord(uint32_t bitPosition) const { return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; } - /// @brief Converts a char array into an integer. + /// This is used by the constructors that take string arguments. + /// @brief Converts a char array into an APInt void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, uint8_t radix); + /// This is used by the toString method to divide by the radix. It simply + /// provides a more convenient form of divide for internal use. + /// @brief An internal division function for dividing APInts. + static void divide(const APInt LHS, uint32_t lhsWords, + const APInt RHS, uint32_t rhsWords, + APInt *Quotient, APInt *Remainder); + #ifndef NDEBUG /// @brief debug method void dump() const; #endif public: - /// @brief An internal division function for dividing APInts. - static void divide(const APInt LHS, uint32_t lhsWords, - const APInt RHS, uint32_t rhsWords, - APInt *Quotient, APInt *Remainder); - - /// @brief Create a new APInt of numBits bit-width, and initialized as val. + /// @brief Create a new APInt of numBits width, initialized as val. APInt(uint32_t numBits, uint64_t val); - /// @brief Create a new APInt of numBits bit-width, and initialized as - /// bigVal[]. + /// Note that numWords can be smaller or larger than the corresponding bit + /// width but any extraneous bits will be dropped. + /// @brief Create a new APInt of numBits width, initialized as bigVal[]. APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[]); /// @brief Create a new APInt by translating the string represented ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.17 - 1.18 --- Log message: Add a private constructor for efficiency. --- Diffs of the changes: (+4 -0) APInt.h |4 1 files changed, 4 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.17 llvm/include/llvm/ADT/APInt.h:1.18 --- llvm/include/llvm/ADT/APInt.h:1.17 Sat Feb 24 03:50:13 2007 +++ llvm/include/llvm/ADT/APInt.h Sun Feb 25 01:29:03 2007 @@ -60,6 +60,7 @@ /// @brief Class for arbitrary precision integers. class APInt { public: + uint32_t BitWidth; /// The number of bits in this APInt. /// This union is used to store the integer value. When the @@ -76,6 +77,9 @@ APINT_WORD_SIZE = sizeof(uint64_t) }; + // Fast internal constructor + APInt(uint64_t* val, uint32_t bits) : BitWidth(bits), pVal(val) { } + /// Here one word's bitwidth equals to that of uint64_t. /// @returns the number of words to hold the integer value of this APInt. /// @brief Get the number of words. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.14 - 1.15 --- Log message: Add an internal convenience method for division that urem and udiv use. --- Diffs of the changes: (+5 -0) APInt.h |5 + 1 files changed, 5 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.14 llvm/include/llvm/ADT/APInt.h:1.15 --- llvm/include/llvm/ADT/APInt.h:1.14 Sun Feb 18 21:18:22 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 20 02:43:42 2007 @@ -128,6 +128,11 @@ void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, uint8_t radix); + /// @brief An internal division function for dividing APInts. + static void divide(const APInt LHS, uint32_t lhsWords, + const APInt RHS, uint32_t rhsWords, + APInt *Quotient, APInt *Remainder); + public: /// @brief Create a new APInt of numBits bit-width, and initialized as val. APInt(uint32_t numBits, uint64_t val); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.15 - 1.16 --- Log message: Add a dump() method for debugging. --- Diffs of the changes: (+7 -2) APInt.h |9 +++-- 1 files changed, 7 insertions(+), 2 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.15 llvm/include/llvm/ADT/APInt.h:1.16 --- llvm/include/llvm/ADT/APInt.h:1.15 Tue Feb 20 02:43:42 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 20 21:56:12 2007 @@ -128,12 +128,17 @@ void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, uint8_t radix); +#ifndef NDEBUG + /// @brief debug method + void dump() const; +#endif + +public: /// @brief An internal division function for dividing APInts. static void divide(const APInt LHS, uint32_t lhsWords, const APInt RHS, uint32_t rhsWords, APInt *Quotient, APInt *Remainder); -public: /// @brief Create a new APInt of numBits bit-width, and initialized as val. APInt(uint32_t numBits, uint64_t val); @@ -412,7 +417,7 @@ /// computations to see how wide the value is. /// @brief Compute the number of active bits in the value inline uint32_t getActiveBits() const { -return getNumWords() * APINT_BITS_PER_WORD - countLeadingZeros(); +return BitWidth - countLeadingZeros(); } /// @returns a uint64_t value from this APInt. If this APInt contains a single ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.12 - 1.13 --- Log message: 1. unsigned - uint32_t to gaurantee its bit width on all platforms. Size matters in this case. 2. Remove the unused whichByte private function, which was also broken. 3. Remove the non-const overload of the getWord function, getWord() is never used as an lvalue. 4. Rename some local variables for clarity (e.g. API - Result). --- Diffs of the changes: (+47 -56) APInt.h | 103 +--- 1 files changed, 47 insertions(+), 56 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.12 llvm/include/llvm/ADT/APInt.h:1.13 --- llvm/include/llvm/ADT/APInt.h:1.12 Sat Feb 17 18:44:22 2007 +++ llvm/include/llvm/ADT/APInt.h Sun Feb 18 12:42:35 2007 @@ -59,7 +59,8 @@ /// /// @brief Class for arbitrary precision integers. class APInt { - unsigned BitWidth; /// The number of bits in this APInt. +public: + uint32_t BitWidth; /// The number of bits in this APInt. /// This union is used to store the integer value. When the /// integer bit-width = 64, it uses VAL; @@ -77,7 +78,7 @@ /// Here one word's bitwidth equals to that of uint64_t. /// @returns the number of words to hold the integer value of this APInt. /// @brief Get the number of words. - inline unsigned getNumWords() const { + inline uint32_t getNumWords() const { return (BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD; } @@ -88,24 +89,19 @@ } /// @returns the word position for the specified bit position. - static inline unsigned whichWord(unsigned bitPosition) { + static inline uint32_t whichWord(uint32_t bitPosition) { return bitPosition / APINT_BITS_PER_WORD; } - /// @returns the byte position for the specified bit position. - static inline unsigned whichByte(unsigned bitPosition) { -return (bitPosition % APINT_BITS_PER_WORD) / 8; - } - /// @returns the bit position in a word for the specified bit position /// in APInt. - static inline unsigned whichBit(unsigned bitPosition) { + static inline uint32_t whichBit(uint32_t bitPosition) { return bitPosition % APINT_BITS_PER_WORD; } /// @returns a uint64_t type integer with just bit position at /// whichBit(bitPosition) setting, others zero. - static inline uint64_t maskBit(unsigned bitPosition) { + static inline uint64_t maskBit(uint32_t bitPosition) { return (static_castuint64_t(1)) whichBit(bitPosition); } @@ -122,35 +118,30 @@ } /// @returns the corresponding word for the specified bit position. - inline uint64_t getWord(unsigned bitPosition) { -return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; - } - - /// @returns the corresponding word for the specified bit position. /// This is a constant version. - inline uint64_t getWord(unsigned bitPosition) const { + inline uint64_t getWord(uint32_t bitPosition) const { return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; } /// @brief Converts a char array into an integer. - void fromString(unsigned numBits, const char *StrStart, unsigned slen, + void fromString(uint32_t numBits, const char *StrStart, uint32_t slen, uint8_t radix); public: /// @brief Create a new APInt of numBits bit-width, and initialized as val. - APInt(unsigned numBits, uint64_t val); + APInt(uint32_t numBits, uint64_t val); /// @brief Create a new APInt of numBits bit-width, and initialized as /// bigVal[]. - APInt(unsigned numBits, unsigned numWords, uint64_t bigVal[]); + APInt(uint32_t numBits, uint32_t numWords, uint64_t bigVal[]); /// @brief Create a new APInt by translating the string represented /// integer value. - APInt(unsigned numBits, const std::string Val, uint8_t radix); + APInt(uint32_t numBits, const std::string Val, uint8_t radix); /// @brief Create a new APInt by translating the char array represented /// integer value. - APInt(unsigned numBits, const char StrStart[], unsigned slen, uint8_t radix); + APInt(uint32_t numBits, const char StrStart[], uint32_t slen, uint8_t radix); /// @brief Copy Constructor. APInt(const APInt API); @@ -258,7 +249,7 @@ } /// @brief Array-indexing support. - bool operator[](unsigned bitPosition) const; + bool operator[](uint32_t bitPosition) const; /// Compare this APInt with the given APInt RHS /// for the validity of the equality relationship. @@ -332,24 +323,24 @@ /// Arithmetic right-shift this APInt by shiftAmt. /// @brief Arithmetic right-shift function. - APInt ashr(unsigned shiftAmt) const; + APInt ashr(uint32_t shiftAmt) const; /// Logical right-shift this APInt by shiftAmt. /// @brief Logical right-shift function. - APInt lshr(unsigned shiftAmt) const; + APInt lshr(uint32_t shiftAmt) const; /// Left-shift this APInt by shiftAmt. /// @brief Left-shift
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.13 - 1.14 --- Log message: Add some new constants. --- Diffs of the changes: (+2 -1) APInt.h |3 ++- 1 files changed, 2 insertions(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.13 llvm/include/llvm/ADT/APInt.h:1.14 --- llvm/include/llvm/ADT/APInt.h:1.13 Sun Feb 18 12:42:35 2007 +++ llvm/include/llvm/ADT/APInt.h Sun Feb 18 21:18:22 2007 @@ -72,7 +72,8 @@ /// This enum is just used to hold a constant we needed for APInt. enum { -APINT_BITS_PER_WORD = sizeof(uint64_t) * 8 +APINT_BITS_PER_WORD = sizeof(uint64_t) * 8, +APINT_WORD_SIZE = sizeof(uint64_t) }; /// Here one word's bitwidth equals to that of uint64_t. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.11 - 1.12 --- Log message: Implement signed output for toString. Fix bugs in countLeadingZeros and countTrailingZeros. --- Diffs of the changes: (+1 -1) APInt.h |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.11 llvm/include/llvm/ADT/APInt.h:1.12 --- llvm/include/llvm/ADT/APInt.h:1.11 Fri Feb 16 18:18:01 2007 +++ llvm/include/llvm/ADT/APInt.h Sat Feb 17 18:44:22 2007 @@ -456,7 +456,7 @@ } /// @returns a character interpretation of the APInt. - std::string toString(uint8_t radix = 10) const; + std::string toString(uint8_t radix = 10, bool wantSigned = true) const; /// Get an APInt with the same BitWidth as this APInt, just zero mask /// the low bits and right shift to the least significant bit. ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.10 - 1.11 --- Log message: Fix bugs introduced by constructor parameter order change. --- Diffs of the changes: (+3 -3) APInt.h |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.10 llvm/include/llvm/ADT/APInt.h:1.11 --- llvm/include/llvm/ADT/APInt.h:1.10 Fri Feb 16 16:36:51 2007 +++ llvm/include/llvm/ADT/APInt.h Fri Feb 16 18:18:01 2007 @@ -254,7 +254,7 @@ /// @brief Unary negation operator inline APInt operator-() const { -return APInt(0, BitWidth) - (*this); +return APInt(BitWidth, 0) - (*this); } /// @brief Array-indexing support. @@ -469,7 +469,7 @@ APInt getLoBits(unsigned numBits) const; /// @returns true if the argument APInt value is a power of two 0. - inline bool isPowerOf2() const; + bool isPowerOf2() const; /// @returns the number of zeros from the most significant bit to the first /// one bits. @@ -483,7 +483,7 @@ unsigned countPopulation() const; /// @returns the total number of bits. - inline unsigned getNumBits() const { + inline unsigned getBitWidth() const { return BitWidth; } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.8 - 1.9 --- Log message: Fix some buges: 1. Make getMinValue() returns the right value. 2. Fix the ByteSwap() crash problem. 3. Make Postfix increment work correctly. 4. Fix some bugs in LogBase2, Hi/LoBits and UDiv. --- Diffs of the changes: (+9 -6) APInt.h | 15 +-- 1 files changed, 9 insertions(+), 6 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.8 llvm/include/llvm/ADT/APInt.h:1.9 --- llvm/include/llvm/ADT/APInt.h:1.8 Tue Feb 13 16:41:58 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Feb 15 00:36:31 2007 @@ -143,7 +143,8 @@ /// @brief Postfix increment operator. inline const APInt operator++(int) { APInt API(*this); -return ++API; +++(*this); +return API; } /// Increments the APInt by one. @@ -154,7 +155,8 @@ /// @brief Postfix decrement operator. inline const APInt operator--(int) { APInt API(*this); -return --API; +--(*this); +return API; } /// Decrements the APInt by one. @@ -286,9 +288,9 @@ /// @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() const { + inline uint64_t getValue(bool isSigned = false) const { if (isSingleWord()) - return VAL; + return isSigned ? int64_t(VAL (64 - BitsNum)) (64 - BitsNum) : VAL; unsigned n = getNumWords() * 64 - CountLeadingZeros(); if (n = 64) return pVal[0]; @@ -371,8 +373,9 @@ /// @brief Check if this APInt has a N-bits integer value. inline bool IsIntN(unsigned N) const { +assert(N N == 0 ???); if (isSingleWord()) { - return VAL == VAL (~uint64_t(0ULL) (64 - N)); + return VAL == (VAL (~0ULL (64 - N))); } else { APInt Tmp(N, pVal); return Tmp == (*this); @@ -384,7 +387,7 @@ /// @returns the floor log base 2 of this APInt. inline unsigned LogBase2() const { -return getNumWords() * APINT_BITS_PER_WORD - +return getNumWords() * APINT_BITS_PER_WORD - 1 - CountLeadingZeros(); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.7 - 1.8 --- Log message: Make some minor improvements to APInt: 1. Make all the operators use uppercase 2. Rename APIntRoundToDouble method just RoundToDouble, the APInt is redundant. 3. Turn the class on for compilation. --- Diffs of the changes: (+37 -37) APInt.h | 74 1 files changed, 37 insertions(+), 37 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.7 llvm/include/llvm/ADT/APInt.h:1.8 --- llvm/include/llvm/ADT/APInt.h:1.7 Mon Feb 12 14:02:55 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 13 16:41:58 2007 @@ -24,8 +24,8 @@ /// 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 @@ /// @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 @@ /// @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 @@ /// @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 @@ { 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 @@ } /// @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 @@ /// @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 @@ /// @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
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.4 - 1.5 --- Log message: As Chris and Reid suggested, remove isSigned field from APInt, instead, add some signed/unsigned arithmetic operation functions into APInt.h to handle the signed/unsigned issue. These functions will be defined inside a namespace APIntOps which is inside llvm namespace. --- Diffs of the changes: (+92 -48) APInt.h | 140 ++-- 1 files changed, 92 insertions(+), 48 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.4 llvm/include/llvm/ADT/APInt.h:1.5 --- llvm/include/llvm/ADT/APInt.h:1.4 Wed Feb 7 10:59:17 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Feb 8 08:30:42 2007 @@ -21,6 +21,21 @@ namespace llvm { +/// Forward declaration. +class APInt; +namespace APIntOps { + bool isIntN(unsigned N, const APInt APIVal); + APInt ByteSwap(const APInt APIVal); + APInt LogBase2(const APInt APIVal); + APInt ashr(const APInt LHS, unsigned shiftAmt); + APInt lshr(const APInt LHS, unsigned shiftAmt); + APInt shl(const APInt LHS, unsigned shiftAmt); + APInt sdiv(const APInt LHS, const APInt RHS); + APInt udiv(const APInt LHS, const APInt RHS); + APInt srem(const APInt LHS, const APInt RHS); + APInt urem(const APInt LHS, const APInt RHS); +} + //===--===// // APInt Class //===--===// @@ -40,14 +55,18 @@ class APInt { /// Friend Functions of APInt declared here. For detailed comments, /// see bottom of this file. - friend bool isIntN(unsigned N, const APInt APIVal); - friend APInt ByteSwap(const APInt APIVal); - friend APInt LogBase2(const APInt APIVal); - friend double APIntToDouble(const APInt APIVal); - friend float APIntToFloat(const APInt APIVal); + friend bool APIntOps::isIntN(unsigned N, const APInt APIVal); + friend APInt APIntOps::ByteSwap(const APInt APIVal); + friend APInt APIntOps::LogBase2(const APInt APIVal); + friend APInt APIntOps::ashr(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::lshr(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::shl(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::sdiv(const APInt LHS, const APInt RHS); + friend APInt APIntOps::udiv(const APInt LHS, const APInt RHS); + friend APInt APIntOps::srem(const APInt LHS, const APInt RHS); + friend APInt APIntOps::urem(const APInt LHS, const APInt RHS); unsigned BitsNum; /// The number of bits. - bool isSigned; /// The sign flag for this APInt. /// This union is used to store the integer value. When the /// integer bit-width = 64, it uses VAL; @@ -114,20 +133,19 @@ public: /// @brief Create a new APInt of numBits bit-width, and initialized as val. - APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD, -bool sign = false); + APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD); /// @brief Create a new APInt of numBits bit-width, and initialized as /// bigVal[]. - APInt(unsigned numBits, uint64_t bigVal[], bool sign = false); + APInt(unsigned numBits, uint64_t bigVal[]); /// @brief Create a new APInt by translating the string represented /// integer value. - APInt(const std::string Val, uint8_t radix = 10, bool sign = false); + APInt(const std::string Val, uint8_t radix = 10); /// @brief Create a new APInt by translating the char array represented /// integer value. - APInt(const char StrStart[], unsigned slen, uint8_t radix, bool sign = false); + APInt(const char StrStart[], unsigned slen, uint8_t radix); /// @brief Copy Constructor. APInt(const APInt API); @@ -179,14 +197,6 @@ /// @brief Bitwise XOR assignment operator. APInt operator^=(const APInt RHS); - /// Left-shift the APInt by shiftAmt and assigns the result to this APInt. - /// @brief Left-shift assignment operator. - APInt operator=(unsigned shiftAmt); - - /// Right-shift the APInt by shiftAmt and assigns the result to this APInt. - /// @brief Right-shift assignment operator. - APInt operator=(unsigned shiftAmt); - /// Performs a bitwise complement operation on this APInt. /// @brief Bitwise complement operator. APInt operator~() const; @@ -196,11 +206,6 @@ /// @brief Multiplication assignment operator. APInt operator*=(const APInt RHS); - /// Divides this APInt by the given APInt RHS and - /// assigns the result to this APInt. - /// @brief Division assignment operator. - APInt operator/=(const APInt RHS); - /// Adds this APInt by the given APInt RHS and /// assigns the result to this APInt. /// @brief Addition assignment operator. @@ -211,11 +216,6 @@ /// @brief Subtraction assignment operator. APInt operator-=(const APInt RHS); - /// Yields the remainder from the division
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Sheng, Some feedback for you ... On Thu, 2007-02-08 at 08:30 -0600, Zhou Sheng wrote: Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.4 - 1.5 --- Log message: As Chris and Reid suggested, remove isSigned field from APInt, instead, add some signed/unsigned arithmetic operation functions into APInt.h to handle the signed/unsigned issue. These functions will be defined inside a namespace APIntOps which is inside llvm namespace. --- Diffs of the changes: (+92 -48) APInt.h | 140 ++-- 1 files changed, 92 insertions(+), 48 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.4 llvm/include/llvm/ADT/APInt.h:1.5 --- llvm/include/llvm/ADT/APInt.h:1.4 Wed Feb 7 10:59:17 2007 +++ llvm/include/llvm/ADT/APInt.h Thu Feb 8 08:30:42 2007 @@ -21,6 +21,21 @@ namespace llvm { +/// Forward declaration. +class APInt; +namespace APIntOps { + bool isIntN(unsigned N, const APInt APIVal); + APInt ByteSwap(const APInt APIVal); + APInt LogBase2(const APInt APIVal); + APInt ashr(const APInt LHS, unsigned shiftAmt); + APInt lshr(const APInt LHS, unsigned shiftAmt); + APInt shl(const APInt LHS, unsigned shiftAmt); + APInt sdiv(const APInt LHS, const APInt RHS); + APInt udiv(const APInt LHS, const APInt RHS); + APInt srem(const APInt LHS, const APInt RHS); + APInt urem(const APInt LHS, const APInt RHS); +} + //===--===// // APInt Class //===--===// @@ -40,14 +55,18 @@ class APInt { /// Friend Functions of APInt declared here. For detailed comments, /// see bottom of this file. - friend bool isIntN(unsigned N, const APInt APIVal); - friend APInt ByteSwap(const APInt APIVal); - friend APInt LogBase2(const APInt APIVal); - friend double APIntToDouble(const APInt APIVal); - friend float APIntToFloat(const APInt APIVal); + friend bool APIntOps::isIntN(unsigned N, const APInt APIVal); + friend APInt APIntOps::ByteSwap(const APInt APIVal); + friend APInt APIntOps::LogBase2(const APInt APIVal); + friend APInt APIntOps::ashr(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::lshr(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::shl(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::sdiv(const APInt LHS, const APInt RHS); + friend APInt APIntOps::udiv(const APInt LHS, const APInt RHS); + friend APInt APIntOps::srem(const APInt LHS, const APInt RHS); + friend APInt APIntOps::urem(const APInt LHS, const APInt RHS); There's a lot of friend functions here. Perhaps these could go at the bottom of the class declaration instead of the top. unsigned BitsNum; /// The number of bits. How about width - bool isSigned; /// The sign flag for this APInt. /// This union is used to store the integer value. When the /// integer bit-width = 64, it uses VAL; @@ -114,20 +133,19 @@ public: /// @brief Create a new APInt of numBits bit-width, and initialized as val. - APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD, -bool sign = false); + APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD); /// @brief Create a new APInt of numBits bit-width, and initialized as /// bigVal[]. - APInt(unsigned numBits, uint64_t bigVal[], bool sign = false); + APInt(unsigned numBits, uint64_t bigVal[]); /// @brief Create a new APInt by translating the string represented /// integer value. - APInt(const std::string Val, uint8_t radix = 10, bool sign = false); + APInt(const std::string Val, uint8_t radix = 10); /// @brief Create a new APInt by translating the char array represented /// integer value. - APInt(const char StrStart[], unsigned slen, uint8_t radix, bool sign = false); + APInt(const char StrStart[], unsigned slen, uint8_t radix); /// @brief Copy Constructor. APInt(const APInt API); @@ -179,14 +197,6 @@ /// @brief Bitwise XOR assignment operator. APInt operator^=(const APInt RHS); - /// Left-shift the APInt by shiftAmt and assigns the result to this APInt. - /// @brief Left-shift assignment operator. - APInt operator=(unsigned shiftAmt); - - /// Right-shift the APInt by shiftAmt and assigns the result to this APInt. - /// @brief Right-shift assignment operator. - APInt operator=(unsigned shiftAmt); - /// Performs a bitwise complement operation on this APInt. /// @brief Bitwise complement operator. APInt operator~() const; @@ -196,11 +206,6 @@ /// @brief Multiplication assignment operator. APInt operator*=(const APInt RHS); - /// Divides this APInt by the given APInt RHS and - /// assigns the result to this APInt. - /// @brief Division
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
// ===-- ===// // APInt Class // ===-- ===// @@ -40,14 +55,18 @@ class APInt { /// Friend Functions of APInt declared here. For detailed comments, /// see bottom of this file. - friend bool isIntN(unsigned N, const APInt APIVal); - friend APInt ByteSwap(const APInt APIVal); - friend APInt LogBase2(const APInt APIVal); - friend double APIntToDouble(const APInt APIVal); - friend float APIntToFloat(const APInt APIVal); + friend bool APIntOps::isIntN(unsigned N, const APInt APIVal); + friend APInt APIntOps::ByteSwap(const APInt APIVal); + friend APInt APIntOps::LogBase2(const APInt APIVal); + friend APInt APIntOps::ashr(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::lshr(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::shl(const APInt LHS, unsigned shiftAmt); + friend APInt APIntOps::sdiv(const APInt LHS, const APInt RHS); + friend APInt APIntOps::udiv(const APInt LHS, const APInt RHS); + friend APInt APIntOps::srem(const APInt LHS, const APInt RHS); + friend APInt APIntOps::urem(const APInt LHS, const APInt RHS); There's a lot of friend functions here. Perhaps these could go at the bottom of the class declaration instead of the top. Actually, please make each of these a public method. This provides the ugly X = X.udiv(Y) syntax. Then add the namespace versions as simple inline functions that that just call the method version. -Chris ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.5 - 1.6 --- Log message: Eliminates friend function declaration inside APInt, instead, adds public methods as those global function's internal implementation. --- Diffs of the changes: (+103 -43) APInt.h | 146 +--- 1 files changed, 103 insertions(+), 43 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.5 llvm/include/llvm/ADT/APInt.h:1.6 --- llvm/include/llvm/ADT/APInt.h:1.5 Thu Feb 8 08:30:42 2007 +++ llvm/include/llvm/ADT/APInt.h Fri Feb 9 01:47:22 2007 @@ -24,15 +24,7 @@ /// Forward declaration. class APInt; namespace APIntOps { - bool isIntN(unsigned N, const APInt APIVal); - APInt ByteSwap(const APInt APIVal); - APInt LogBase2(const APInt APIVal); - APInt ashr(const APInt LHS, unsigned shiftAmt); - APInt lshr(const APInt LHS, unsigned shiftAmt); - APInt shl(const APInt LHS, unsigned shiftAmt); - APInt sdiv(const APInt LHS, const APInt RHS); APInt udiv(const APInt LHS, const APInt RHS); - APInt srem(const APInt LHS, const APInt RHS); APInt urem(const APInt LHS, const APInt RHS); } @@ -53,19 +45,6 @@ /// Note: In this class, all bit/byte/word positions are zero-based. /// class APInt { - /// Friend Functions of APInt declared here. For detailed comments, - /// see bottom of this file. - friend bool APIntOps::isIntN(unsigned N, const APInt APIVal); - friend APInt APIntOps::ByteSwap(const APInt APIVal); - friend APInt APIntOps::LogBase2(const APInt APIVal); - friend APInt APIntOps::ashr(const APInt LHS, unsigned shiftAmt); - friend APInt APIntOps::lshr(const APInt LHS, unsigned shiftAmt); - friend APInt APIntOps::shl(const APInt LHS, unsigned shiftAmt); - friend APInt APIntOps::sdiv(const APInt LHS, const APInt RHS); - friend APInt APIntOps::udiv(const APInt LHS, const APInt RHS); - friend APInt APIntOps::srem(const APInt LHS, const APInt RHS); - friend APInt APIntOps::urem(const APInt LHS, const APInt RHS); - unsigned BitsNum; /// The number of bits. /// This union is used to store the integer value. When the @@ -387,19 +366,68 @@ inline unsigned getNumBits() const { return BitsNum; } + /// @brief Check if this APInt has a N-bits integer value. + inline bool isIntN(unsigned N) const { +if (isSingleWord()) { + return VAL == VAL (~uint64_t(0ULL) (64 - N)); +} else { + APInt Tmp(N, pVal); + return Tmp == (*this); +} + } + + /// @returns a byte-swapped representation of this APInt Value. + APInt ByteSwap() const; + + /// @returns the floor log base 2 of this APInt. + inline unsigned LogBase2() const { +return getNumWords() * APINT_BITS_PER_WORD - + CountLeadingZeros(); + } + + /// Arithmetic right-shift this APInt by shiftAmt. + /// @brief Arithmetic right-shift function. + APInt ashr(unsigned shiftAmt) const; + + /// Logical right-shift this APInt by shiftAmt. + /// @brief Logical right-shift function. + APInt lshr(unsigned shiftAmt) const; + + /// Left-shift this APInt by shiftAmt. + /// @brief Left-shift function. + 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 { +bool isSignedLHS = (*this)[BitsNum - 1], isSignedRHS = RHS[RHS.BitsNum - 1]; +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; + + /// Signed remainder operation on APInt. + /// @brief Function for signed remainder operation. + 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); +return isSignedLHS ? -API : API; + } + + /// Unsigned remainder operation on APInt. + /// @brief Function for unsigned remainder operation. + APInt urem(const APInt RHS) const; + }; namespace APIntOps { /// @brief Check if the specified APInt has a N-bits integer value. inline bool isIntN(unsigned N, const APInt APIVal) { - if (APIVal.isSingleWord()) { -APInt Tmp(N, APIVal.VAL); -return Tmp == APIVal; - } else { -APInt Tmp(N, APIVal.pVal); -return Tmp == APIVal; - } + return APIVal.isIntN(N); } /// @returns true if the argument APInt value is a sequence of ones @@ -415,12 +443,13 @@ } /// @returns a byte-swapped representation of the specified APInt Value. -APInt ByteSwap(const APInt APIVal); +inline APInt ByteSwap(const APInt APIVal) { + return APIVal.ByteSwap(); +} /// @returns the floor log base 2 of the specified APInt value. -inline APInt LogBase2(const APInt APIVal) { - return
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.3 - 1.4 --- Log message: Fix build error. include/llvm/ADT/APInt.h:326: error: âassertâ was not declared in this scope --- Diffs of the changes: (+1 -0) APInt.h |1 + 1 files changed, 1 insertion(+) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.3 llvm/include/llvm/ADT/APInt.h:1.4 --- llvm/include/llvm/ADT/APInt.h:1.3 Tue Feb 6 23:58:38 2007 +++ llvm/include/llvm/ADT/APInt.h Wed Feb 7 10:59:17 2007 @@ -16,6 +16,7 @@ #define LLVM_APINT_H #include llvm/Support/DataTypes.h +#include cassert #include string namespace llvm { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h updated: 1.2 - 1.3 --- Log message: As Chris suggested, fixed some problems. (This is the first part.) --- Diffs of the changes: (+47 -21) APInt.h | 68 1 files changed, 47 insertions(+), 21 deletions(-) Index: llvm/include/llvm/ADT/APInt.h diff -u llvm/include/llvm/ADT/APInt.h:1.2 llvm/include/llvm/ADT/APInt.h:1.3 --- llvm/include/llvm/ADT/APInt.h:1.2 Mon Feb 5 23:59:47 2007 +++ llvm/include/llvm/ADT/APInt.h Tue Feb 6 23:58:38 2007 @@ -45,7 +45,7 @@ friend double APIntToDouble(const APInt APIVal); friend float APIntToFloat(const APInt APIVal); - unsigned bitsnum; /// The number of bits. + unsigned BitsNum; /// The number of bits. bool isSigned; /// The sign flag for this APInt. /// This union is used to store the integer value. When the @@ -64,22 +64,22 @@ /// Here one word's bitwidth equals to that of uint64_t. /// @returns the number of words to hold the integer value of this APInt. /// @brief Get the number of words. - inline unsigned numWords() const { -return bitsnum 1 ? 0 : (bitsnum + APINT_BITS_PER_WORD - 1) / - APINT_BITS_PER_WORD; + inline unsigned getNumWords() const { +return (BitsNum + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD; } /// @returns true if the number of bits = 64, false otherwise. /// @brief Determine if this APInt just has one word to store value. inline bool isSingleWord() const - { return bitsnum = APINT_BITS_PER_WORD; } + { return BitsNum = APINT_BITS_PER_WORD; } /// @returns the word position for the specified bit position. static inline unsigned whichWord(unsigned bitPosition) { return bitPosition / APINT_BITS_PER_WORD; } /// @returns the byte position for the specified bit position. - static inline unsigned whichByte(unsigned bitPosition); + static inline unsigned whichByte(unsigned bitPosition) + { return (bitPosition % APINT_BITS_PER_WORD) / 8; } /// @returns the bit position in a word for the specified bit position /// in APInt. @@ -93,10 +93,10 @@ inline void TruncToBits() { if (isSingleWord()) - VAL = ~uint64_t(0ULL) (APINT_BITS_PER_WORD - bitsnum); + VAL = ~uint64_t(0ULL) (APINT_BITS_PER_WORD - BitsNum); else - pVal[numWords() - 1] = ~uint64_t(0ULL) -(APINT_BITS_PER_WORD - (whichBit(bitsnum - 1) + 1)); + pVal[getNumWords() - 1] = ~uint64_t(0ULL) +(APINT_BITS_PER_WORD - (whichBit(BitsNum - 1) + 1)); } /// @returns the corresponding word for the specified bit position. @@ -108,6 +108,9 @@ inline uint64_t getWord(unsigned bitPosition) const { return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; } + /// @brief Converts a char array into an integer. + void StrToAPInt(const char *StrStart, unsigned slen, uint8_t radix); + public: /// @brief Create a new APInt of numBits bit-width, and initialized as val. APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD, @@ -119,7 +122,11 @@ /// @brief Create a new APInt by translating the string represented /// integer value. - APInt(std::string Val, uint8_t radix = 10, bool sign = false); + APInt(const std::string Val, uint8_t radix = 10, bool sign = false); + + /// @brief Create a new APInt by translating the char array represented + /// integer value. + APInt(const char StrStart[], unsigned slen, uint8_t radix, bool sign = false); /// @brief Copy Constructor. APInt(const APInt API); @@ -136,7 +143,10 @@ /// Increments the APInt by one. /// @brief Postfix increment operator. - const APInt operator++(int); + inline const APInt operator++(int) { +APInt API(*this); +return ++API; + } /// Increments the APInt by one. /// @brief Prefix increment operator. @@ -144,7 +154,10 @@ /// Decrements the APInt by one. /// @brief Postfix decrement operator. - const APInt operator--(int); + inline const APInt operator--(int) { +APInt API(*this); +return --API; + } /// Decrements the APInt by one. /// @brief Prefix decrement operator. @@ -264,11 +277,25 @@ /// @brief Equality operator. bool operator==(const APInt RHS) const; + /// Compare this APInt with the given uint64_t value + /// for the validity of the equality relationship. + /// @brief Equality operator. + bool operator==(uint64_t Val) const; + /// Compare this APInt with the given APInt RHS /// for the validity of the inequality relationship. /// @brief Inequality operator. - bool operator!=(const APInt RHS) const; + inline bool operator!=(const APInt RHS) const { +return !((*this) == RHS); + } + /// Compare this APInt with the given uint64_t value + /// for the validity of the inequality relationship. + /// @brief Inequality operator. + inline bool operator!=(uint64_t Val) const { +return !((*this) == Val);
[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Changes in directory llvm/include/llvm/ADT: APInt.h added (r1.1) --- Log message: Add a class APInt to represent arbitrary precision constant integral values. It is a functional replacement for common case integer type like unsigned, uint64_t, but also allows non-byte-width integer type and large integer value types such as 3-bits, 15-bits, or more than 64-bits of precision. For more details, see pr1043: http://llvm.org/PR1043 . --- Diffs of the changes: (+489 -0) APInt.h | 489 1 files changed, 489 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -c /dev/null llvm/include/llvm/ADT/APInt.h:1.1 *** /dev/null Mon Feb 5 11:29:26 2007 --- llvm/include/llvm/ADT/APInt.h Mon Feb 5 11:29:16 2007 *** *** 0 --- 1,489 + //===-- llvm/Support/APInt.h - For Arbitrary Precision Integer -*- C++ -*--===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by Sheng Zhou and is distributed under the + // University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===--===// + // + // This file implements a class to represent arbitrary precision integral + // constant values. + // + //===--===// + + #ifndef LLVM_APINT_H + #define LLVM_APINT_H + + #include llvm/Support/DataTypes.h + #include string + + namespace llvm { + + //===--===// + // APInt Class + //===--===// + + /// APInt - This class represents arbitrary precision constant integral values. + /// It is a functional replacement for common case unsigned integer type like + /// unsigned, unsigned long or uint64_t, but also allows non-byte-width + /// integer type and large integer value types such as 3-bits, 15-bits, or more + /// than 64-bits of precision. APInt provides a variety of arithmetic operators + /// and methods to manipulate integer values of any bit-width. It supports not + /// only all the operations of uint64_t but also bitwise manipulation. + /// + /// @brief Class for arbitrary precision integers. + /// + class APInt { + /// Friend Functions of APInt Declared here. For detailed comments, + /// see bottom of this file. + friend bool isIntN(unsigned N, const APInt APIVal); + friend APInt ByteSwap(const APInt APIVal); + friend APInt LogBase2(const APInt APIVal); + friend double APIntToDouble(const APInt APIVal); + friend float APIntToFloat(const APInt APIVal); + + unsigned bitsnum; /// The number of bits. + bool isSigned; /// The sign flag for this APInt. + + /// This union is used to store the integer value. When the + /// integer bit-width = 64, it is used as an uint64_t; + /// otherwise it uses an uint64_t array. + union { + uint64_t VAL;/// Used to store the = 64 bits integer value. + uint64_t *pVal; /// Used to store the 64 bits integer value. + }; + + /// This enum is just used to hold constant we needed for APInt. + enum { + APINT_BITS_PER_WORD = sizeof(uint64_t) * 8 + }; + + /// @returns the number of words to hold the integer value of this APInt. + /// Here one word's bitwidth equals to that of uint64_t. + /// @brief Get the number of the words. + inline unsigned numWords() const { + return bitsnum 1 ? 0 : (bitsnum + APINT_BITS_PER_WORD - 1) / + APINT_BITS_PER_WORD; + } + + /// @returns true if the number of bits = 64, false otherwise. + /// @brief Determine if this APInt just has one word to store value. + inline bool isSingleWord() const + { return bitsnum = APINT_BITS_PER_WORD; } + + /// @returns the word position for the specified bit position. + /// Note: the bitPosition and the return value are zero-based. + static inline unsigned whichWord(unsigned bitPosition) + { return bitPosition / APINT_BITS_PER_WORD; } + + /// @returns the byte position for the specified bit position. + /// Note: the bitPosition and the return value are zero-based. + static inline unsigned whichByte(unsigned bitPosition); + + /// @returns the bit position in a word for the specified bit position + /// in APInt. + /// Note: the bitPosition and the return value are zero-based. + static inline unsigned whichBit(unsigned bitPosition) + { return bitPosition % APINT_BITS_PER_WORD; } + + /// @returns a uint64_t type integer with just bit position at + /// whichBit(bitPosition) setting, others zero. + /// Note: the bitPosition and the return value are zero-based. + static inline uint64_t maskBit(unsigned bitPosition) + { return (static_castuint64_t(1)) whichBit(bitPosition); } + + inline void TruncToBits() { + if
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Sheng, Some comments for you .. On Mon, 2007-02-05 at 11:29 -0600, Zhou Sheng wrote: Changes in directory llvm/include/llvm/ADT: APInt.h added (r1.1) --- Log message: Add a class APInt to represent arbitrary precision constant integral values. It is a functional replacement for common case integer type like unsigned, uint64_t, but also allows non-byte-width integer type and large integer value types such as 3-bits, 15-bits, or more than 64-bits of precision. For more details, see pr1043: http://llvm.org/PR1043 . --- Diffs of the changes: (+489 -0) APInt.h | 489 1 files changed, 489 insertions(+) Index: llvm/include/llvm/ADT/APInt.h diff -c /dev/null llvm/include/llvm/ADT/APInt.h:1.1 *** /dev/null Mon Feb 5 11:29:26 2007 --- llvm/include/llvm/ADT/APInt.h Mon Feb 5 11:29:16 2007 *** *** 0 --- 1,489 + //===-- llvm/Support/APInt.h - For Arbitrary Precision Integer -*- C++ -*--===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by Sheng Zhou and is distributed under the + // University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===--===// + // + // This file implements a class to represent arbitrary precision integral + // constant values. + // + //===--===// + + #ifndef LLVM_APINT_H + #define LLVM_APINT_H + + #include llvm/Support/DataTypes.h + #include string + + namespace llvm { + + //===--===// + // APInt Class + //===--===// + + /// APInt - This class represents arbitrary precision constant integral values. + /// It is a functional replacement for common case unsigned integer type like + /// unsigned, unsigned long or uint64_t, but also allows non-byte-width + /// integer type and large integer value types such as 3-bits, 15-bits, or more + /// than 64-bits of precision. APInt provides a variety of arithmetic operators + /// and methods to manipulate integer values of any bit-width. It supports not + /// only all the operations of uint64_t but also bitwise manipulation. + /// + /// @brief Class for arbitrary precision integers. + /// + class APInt { + /// Friend Functions of APInt Declared here. For detailed comments, Declared - declared + /// see bottom of this file. + friend bool isIntN(unsigned N, const APInt APIVal); + friend APInt ByteSwap(const APInt APIVal); + friend APInt LogBase2(const APInt APIVal); + friend double APIntToDouble(const APInt APIVal); + friend float APIntToFloat(const APInt APIVal); + + unsigned bitsnum; /// The number of bits. + bool isSigned; /// The sign flag for this APInt. + + /// This union is used to store the integer value. When the + /// integer bit-width = 64, it is used as an uint64_t; it is used as an uint64_t - it uses VAL + /// otherwise it uses an uint64_t array. an uint64_t - the PVal + union { + uint64_t VAL;/// Used to store the = 64 bits integer value. + uint64_t *pVal; /// Used to store the 64 bits integer value. + }; + + /// This enum is just used to hold constant we needed for APInt. hold constant - hold a constant + enum { + APINT_BITS_PER_WORD = sizeof(uint64_t) * 8 + }; + + /// @returns the number of words to hold the integer value of this APInt. + /// Here one word's bitwidth equals to that of uint64_t. I think this line needs to go above @returns or else it gets included in @returns. + /// @brief Get the number of the words. of the words - of words + inline unsigned numWords() const { + return bitsnum 1 ? 0 : (bitsnum + APINT_BITS_PER_WORD - 1) / + APINT_BITS_PER_WORD; + } + + /// @returns true if the number of bits = 64, false otherwise. + /// @brief Determine if this APInt just has one word to store value. + inline bool isSingleWord() const + { return bitsnum = APINT_BITS_PER_WORD; } + + /// @returns the word position for the specified bit position. + /// Note: the bitPosition and the return value are zero-based. + static inline unsigned whichWord(unsigned bitPosition) + { return bitPosition / APINT_BITS_PER_WORD; } + + /// @returns the byte position for the specified bit position. + /// Note: the bitPosition and the return value are zero-based. + static inline unsigned whichByte(unsigned bitPosition); + + /// @returns the bit position in a word for the specified bit position + /// in APInt. + /// Note: the bitPosition and the return value are zero-based. + static inline
Re: [llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h
Hi Sheng/Reid, Some comments about the approach, on top of what Reid already sent. The most significant is that isSigned should go away: + class APInt { + /// Friend Functions of APInt Declared here. For detailed comments, + /// see bottom of this file. + friend bool isIntN(unsigned N, const APInt APIVal); + friend APInt ByteSwap(const APInt APIVal); + friend APInt LogBase2(const APInt APIVal); + friend double APIntToDouble(const APInt APIVal); + friend float APIntToFloat(const APInt APIVal); Instead of making these things friends, why not just add accessors for whatever they need? + unsigned bitsnum; /// The number of bits. Please name this 'NumBits' or something like that. + bool isSigned; /// The sign flag for this APInt. Why do you need isSigned? This seems very strange. It would be better to keep the value in 2s complement form and add an accessor to get the sign-bit if needed. Having the sign bit be explicit makes sizeof(APInt) = 16 instead of 12. + /// @returns the number of words to hold the integer value of this APInt. + /// Here one word's bitwidth equals to that of uint64_t. + /// @brief Get the number of the words. + inline unsigned numWords() const { getNumWords() + return bitsnum 1 ? 0 : (bitsnum + APINT_BITS_PER_WORD - 1) / + APINT_BITS_PER_WORD; You don't need the special case for bitsnum 1. + /// Create a new APInt by translating the string represented integer value. + APInt(std::string Val, uint8_t radix = 10, bool sign = false); the string should be 'const'. It would also be useful to have a version that takes a character range: APInt(const char *StrStart, const char *StrEnd, uint8_t radix = 10); which would allow construction of an APInt without copying the string data. + /// @brief Postfix increment operator. Increments the APInt by one. + const APInt operator++(int); + /// @brief Postfix decrement operator. Decrements the APInt by one. + const APInt operator--(int); Postfix ++/-- operations are typically declared inline, as trivial wrappers around the prefix version. + /// @brief Equality operator. Compare this APInt with the given APInt RHS + /// for the validity of the equality relationship. + bool operator==(const APInt RHS) const; == and != are often used to compare against specific values. We should have specialized versions that take 'uint64_t', do you agree? We don't want to bloat the API and do this for every method, but I think equality comparisons are worthwhile. + /// @brief Inequality operator. Compare this APInt with the given APInt RHS + /// for the validity of the inequality relationship. + bool operator!=(const APInt RHS) const; This should be an inline wrapper that calls !operator==. + /// @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() { + if (isSingleWord()) + return isSigned ? ((int64_t(VAL) (APINT_BITS_PER_WORD - bitsnum)) + (APINT_BITS_PER_WORD - bitsnum)) : + VAL; + else + return pVal[0]; + } This should assert if there are more than 64 bits. Not doing so will make client errors very difficult to track down. + + /// @returns the largest value for an APInt of the specified bit-width and + /// if isSign == true, it should be largest signed value, otherwise largest + /// unsigned value. + /// @brief Gets max value of the APInt with bitwidth = 64. + static APInt getMaxValue(unsigned numBits, bool isSign); + static APInt getMinValue(unsigned numBits, bool isSign); It makes sense for these to have 'isSign' but not for APInt itself. + /// @returns the all-ones value for an APInt of the specified bit-width. + /// @brief Get the all-ones value. + static APInt getAllOnesValue(unsigned numBits); + + /// @brief Set every bit to 1. + APInt set(); + /// @brief Set every bit to 0. + APInt clear(); These seems extraneous. + /// @brief Toggle every bit to its opposite value. + APInt flip(); Isn't this just operator~ ? + /// @brief Check if the specified APInt has a N-bits integer value. + inline bool isIntN(unsigned N, const APInt APIVal) { Please eliminate this and just allow operator== to take a uint64_t operand. + /// @returns true if the argument APInt value is a sequence of ones + /// starting at the least significant bit with the remainder zero. + inline const bool isMask(unsigned numBits, const APInt APIVal) { + return APIVal ((APIVal + 1) APIVal) == 0; + } I'm not sure what this does. + /// @returns the bit equivalent double. + /// If the APInt numBits 64, truncated first and then convert to double. + inline double APIntToDouble(const APInt APIVal) { + uint64_t value =