[llvm] r222137 - Use a more canonical way of computing a mask with N trailing 1s. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Mon Nov 17 07:46:21 PST 2014
Author: rafael
Date: Mon Nov 17 09:46:21 2014
New Revision: 222137
URL: http://llvm.org/viewvc/llvm-project?rev=222137&view=rev
Log:
Use a more canonical way of computing a mask with N trailing 1s. NFC.
Modified:
llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=222137&r1=222136&r2=222137&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Mon Nov 17 09:46:21 2014
@@ -338,16 +338,14 @@ public:
}
word_t Read(unsigned NumBits) {
- static const unsigned BitsInWord = sizeof(word_t) * 8;
-
- assert(NumBits && NumBits <= BitsInWord &&
+ assert(NumBits && NumBits <= sizeof(word_t) * 8 &&
"Cannot return zero or more than BitsInWord bits!");
static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
// If the field is fully contained by CurWord, return it quickly.
if (BitsInCurWord >= NumBits) {
- word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
+ word_t R = CurWord & ((word_t(1) << NumBits) - 1);
// Use a mask to avoid undefined behavior.
CurWord >>= (NumBits & Mask);
@@ -365,7 +363,7 @@ public:
if (BitsLeft > BitsInCurWord)
return 0;
- word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
+ word_t R2 = CurWord & ((word_t(1) << BitsLeft) - 1);
// Use a mask to avoid undefined behavior.
CurWord >>= (BitsLeft & Mask);
More information about the llvm-commits
mailing list