diff options
author | Matthias Braun <matze@braunis.de> | 2016-02-15 20:06:22 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2016-02-15 20:06:22 +0000 |
commit | a6be4e8cdd12e20d511fa0fd5c20fdb2553c41fc (patch) | |
tree | 1aed2e2cc9af589f872ecf8583add2698e1846dd | |
parent | 5117fcdec24454dd8c896a69d15dc1ce870ea7c7 (diff) | |
download | bcm5719-llvm-a6be4e8cdd12e20d511fa0fd5c20fdb2553c41fc.tar.gz bcm5719-llvm-a6be4e8cdd12e20d511fa0fd5c20fdb2553c41fc.zip |
APInt: Slightly simplify countLeadingZerosSlowCase()
We always clear the unused bits in the most signifant word so there is
no need to mask them out in countLeadingZerosSlowCase().
Differential Revision: http://reviews.llvm.org/D16621
llvm-svn: 260911
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 86fde19192b..be1b5567ac4 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -676,30 +676,19 @@ APInt APInt::getLoBits(unsigned numBits) const { } unsigned APInt::countLeadingZerosSlowCase() const { - // Treat the most significand word differently because it might have - // meaningless bits set beyond the precision. - unsigned BitsInMSW = BitWidth % APINT_BITS_PER_WORD; - integerPart MSWMask; - if (BitsInMSW) MSWMask = (integerPart(1) << BitsInMSW) - 1; - else { - MSWMask = ~integerPart(0); - BitsInMSW = APINT_BITS_PER_WORD; - } - - unsigned i = getNumWords(); - integerPart MSW = pVal[i-1] & MSWMask; - if (MSW) - return llvm::countLeadingZeros(MSW) - (APINT_BITS_PER_WORD - BitsInMSW); - - unsigned Count = BitsInMSW; - for (--i; i > 0u; --i) { - if (pVal[i-1] == 0) + unsigned Count = 0; + for (int i = getNumWords()-1; i >= 0; --i) { + integerPart V = pVal[i]; + if (V == 0) Count += APINT_BITS_PER_WORD; else { - Count += llvm::countLeadingZeros(pVal[i-1]); + Count += llvm::countLeadingZeros(V); break; } } + // Adjust for unused bits in the most significant word (they are zero). + unsigned Mod = BitWidth % APINT_BITS_PER_WORD; + Count -= Mod > 0 ? APINT_BITS_PER_WORD - Mod : 0; return Count; } |