diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-24 20:19:37 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-24 20:19:37 +0000 |
commit | 5bce8547f3ebad55611bfc74f1be0437287fa319 (patch) | |
tree | 92723b1761a3d7267b802b132ad61825eca11271 /lib/Support/APInt.cpp | |
parent | 610fad85d2dcc1b65227f67ae3c86db1d921a4d0 (diff) |
1. Fix a bug in fromString for the <= 64bits case
2. Fix shl when shiftAmount == BitWidth.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34560 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r-- | lib/Support/APInt.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 63bc5f55b3..7f2aa42924 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -945,24 +945,33 @@ APInt APInt::lshr(uint32_t shiftAmt) const { /// 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 @@ void APInt::fromString(uint32_t numbits, const char *str, uint32_t slen, *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; } } |