Skip to content

Commit 5bef24d

Browse files
committed
Use a more canonical way of computing a mask with N trailing 1s. NFC.
llvm-svn: 222137
1 parent 9dfcaf4 commit 5bef24d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

llvm/include/llvm/Bitcode/BitstreamReader.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,14 @@ class BitstreamCursor {
338338
}
339339

340340
word_t Read(unsigned NumBits) {
341-
static const unsigned BitsInWord = sizeof(word_t) * 8;
342-
343-
assert(NumBits && NumBits <= BitsInWord &&
341+
assert(NumBits && NumBits <= sizeof(word_t) * 8 &&
344342
"Cannot return zero or more than BitsInWord bits!");
345343

346344
static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
347345

348346
// If the field is fully contained by CurWord, return it quickly.
349347
if (BitsInCurWord >= NumBits) {
350-
word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
348+
word_t R = CurWord & ((word_t(1) << NumBits) - 1);
351349

352350
// Use a mask to avoid undefined behavior.
353351
CurWord >>= (NumBits & Mask);
@@ -365,7 +363,7 @@ class BitstreamCursor {
365363
if (BitsLeft > BitsInCurWord)
366364
return 0;
367365

368-
word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
366+
word_t R2 = CurWord & ((word_t(1) << BitsLeft) - 1);
369367

370368
// Use a mask to avoid undefined behavior.
371369
CurWord >>= (BitsLeft & Mask);

0 commit comments

Comments
 (0)