mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
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
This commit is contained in:
@@ -338,14 +338,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
word_t Read(unsigned NumBits) {
|
word_t Read(unsigned NumBits) {
|
||||||
assert(NumBits && NumBits <= sizeof(word_t) * 8 &&
|
static const unsigned BitsInWord = sizeof(word_t) * 8;
|
||||||
|
|
||||||
|
assert(NumBits && NumBits <= BitsInWord &&
|
||||||
"Cannot return zero or more than BitsInWord bits!");
|
"Cannot return zero or more than BitsInWord bits!");
|
||||||
|
|
||||||
static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
|
static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
|
||||||
|
|
||||||
// If the field is fully contained by CurWord, return it quickly.
|
// If the field is fully contained by CurWord, return it quickly.
|
||||||
if (BitsInCurWord >= NumBits) {
|
if (BitsInCurWord >= NumBits) {
|
||||||
word_t R = CurWord & ((word_t(1) << (NumBits & Mask)) - 1);
|
word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
|
||||||
|
|
||||||
// Use a mask to avoid undefined behavior.
|
// Use a mask to avoid undefined behavior.
|
||||||
CurWord >>= (NumBits & Mask);
|
CurWord >>= (NumBits & Mask);
|
||||||
@@ -363,7 +365,7 @@ public:
|
|||||||
if (BitsLeft > BitsInCurWord)
|
if (BitsLeft > BitsInCurWord)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
word_t R2 = CurWord & ((word_t(1) << (BitsLeft & Mask)) - 1);
|
word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
|
||||||
|
|
||||||
// Use a mask to avoid undefined behavior.
|
// Use a mask to avoid undefined behavior.
|
||||||
CurWord >>= (BitsLeft & Mask);
|
CurWord >>= (BitsLeft & Mask);
|
||||||
|
Reference in New Issue
Block a user