llvm.org GIT mirror llvm / d5b5eb6
Revert commits r222146 and r222137. They were producing the wrong result if NumBits == BitsInWord. The old mask produced -1, the new mask 0. This should fix the 32 bit bots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222166 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
1 changed file(s) with 5 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
337337 }
338338
339339 word_t Read(unsigned NumBits) {
340 assert(NumBits && NumBits <= sizeof(word_t) * 8 &&
340 static const unsigned BitsInWord = sizeof(word_t) * 8;
341
342 assert(NumBits && NumBits <= BitsInWord &&
341343 "Cannot return zero or more than BitsInWord bits!");
342344
343345 static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
344346
345347 // If the field is fully contained by CurWord, return it quickly.
346348 if (BitsInCurWord >= NumBits) {
347 word_t R = CurWord & ((word_t(1) << (NumBits & Mask)) - 1);
349 word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
348350
349351 // Use a mask to avoid undefined behavior.
350352 CurWord >>= (NumBits & Mask);
362364 if (BitsLeft > BitsInCurWord)
363365 return 0;
364366
365 word_t R2 = CurWord & ((word_t(1) << (BitsLeft & Mask)) - 1);
367 word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
366368
367369 // Use a mask to avoid undefined behavior.
368370 CurWord >>= (BitsLeft & Mask);