[llvm-commits] CVS: llvm/lib/Support/APInt.cpp
Reid Spencer
reid at x10sys.com
Sat Feb 24 12:19:54 PST 2007
Changes in directory llvm/lib/Support:
APInt.cpp updated: 1.34 -> 1.35
---
Log message:
1. Fix a bug in fromString for the <= 64bits case
2. Fix shl when shiftAmount == BitWidth.
---
Diffs of the changes: (+30 -18)
APInt.cpp | 48 ++++++++++++++++++++++++++++++------------------
1 files changed, 30 insertions(+), 18 deletions(-)
Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.34 llvm/lib/Support/APInt.cpp:1.35
--- llvm/lib/Support/APInt.cpp:1.34 Sat Feb 24 04:01:42 2007
+++ llvm/lib/Support/APInt.cpp Sat Feb 24 14:19:37 2007
@@ -945,24 +945,33 @@
/// Left-shift this APInt by shiftAmt.
/// @brief Left-shift function.
APInt APInt::shl(uint32_t shiftAmt) const {
+ assert(shiftAmt <= BitWidth && "Invalid shift amount");
APInt API(*this);
- if (API.isSingleWord())
- API.VAL <<= shiftAmt;
- else if (shiftAmt >= API.BitWidth)
- memset(API.pVal, 0, API.getNumWords() * APINT_WORD_SIZE);
- else {
- if (uint32_t offset = shiftAmt / APINT_BITS_PER_WORD) {
- for (uint32_t i = API.getNumWords() - 1; i > offset - 1; --i)
- API.pVal[i] = API.pVal[i-offset];
- memset(API.pVal, 0, offset * APINT_WORD_SIZE);
- }
- shiftAmt %= APINT_BITS_PER_WORD;
- uint32_t i;
- for (i = API.getNumWords() - 1; i > 0; --i)
- API.pVal[i] = (API.pVal[i] << shiftAmt) |
- (API.pVal[i-1] >> (APINT_BITS_PER_WORD - shiftAmt));
- API.pVal[i] <<= shiftAmt;
- }
+ if (API.isSingleWord()) {
+ if (shiftAmt == BitWidth)
+ API.VAL = 0;
+ else
+ API.VAL <<= shiftAmt;
+ API.clearUnusedBits();
+ return API;
+ }
+
+ if (shiftAmt == BitWidth) {
+ memset(API.pVal, 0, getNumWords() * APINT_WORD_SIZE);
+ return API;
+ }
+
+ if (uint32_t offset = shiftAmt / APINT_BITS_PER_WORD) {
+ for (uint32_t i = API.getNumWords() - 1; i > offset - 1; --i)
+ API.pVal[i] = API.pVal[i-offset];
+ memset(API.pVal, 0, offset * APINT_WORD_SIZE);
+ }
+ shiftAmt %= APINT_BITS_PER_WORD;
+ uint32_t i;
+ for (i = API.getNumWords() - 1; i > 0; --i)
+ API.pVal[i] = (API.pVal[i] << shiftAmt) |
+ (API.pVal[i-1] >> (APINT_BITS_PER_WORD - shiftAmt));
+ API.pVal[i] <<= shiftAmt;
API.clearUnusedBits();
return API;
}
@@ -1423,7 +1432,10 @@
*this *= apradix;
// Add in the digit we just interpreted
- apdigit.pVal[0] = digit;
+ if (apdigit.isSingleWord())
+ apdigit.VAL = digit;
+ else
+ apdigit.pVal[0] = digit;
*this += apdigit;
}
}
More information about the llvm-commits
mailing list