Return word_t from read.

This removes the need for a special Read64.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221909 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-11-13 18:44:53 +00:00
parent 8bca5de6a9
commit ab9c404bbd

View File

@ -311,12 +311,8 @@ public:
BitsInCurWord = 0;
// Skip over any bits that are already consumed.
if (WordBitNo) {
if (sizeof(word_t) > 4)
Read64(WordBitNo);
else
Read(WordBitNo);
}
if (WordBitNo)
Read(WordBitNo);
}
void fillCurWord() {
@ -341,15 +337,17 @@ public:
BitsInCurWord = BytesRead * 8;
}
uint32_t Read(unsigned NumBits) {
assert(NumBits && NumBits <= 32 &&
"Cannot return zero or more than 32 bits!");
word_t Read(unsigned NumBits) {
static const unsigned BitsInWord = sizeof(word_t) * 8;
assert(NumBits && NumBits <= BitsInWord &&
"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) {
uint32_t R = uint32_t(CurWord) & (~0U >> (32-NumBits));
word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
// Use a mask to avoid undefined behavior.
CurWord >>= (NumBits & Mask);
@ -358,7 +356,7 @@ public:
return R;
}
uint32_t R = BitsInCurWord ? uint32_t(CurWord) : 0;
word_t R = BitsInCurWord ? CurWord : 0;
unsigned BitsLeft = NumBits - BitsInCurWord;
fillCurWord();
@ -367,26 +365,18 @@ public:
if (BitsLeft > BitsInCurWord)
return 0;
uint32_t R2 =
uint32_t(CurWord) & (~word_t(0) >> (sizeof(word_t) * 8 - BitsLeft));
word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
// Use a mask to avoid undefined behavior.
CurWord >>= (BitsLeft & Mask);
BitsInCurWord -= BitsLeft;
R |= uint32_t(R2 << (NumBits - BitsLeft));
R |= R2 << (NumBits - BitsLeft);
return R;
}
uint64_t Read64(unsigned NumBits) {
if (NumBits <= 32) return Read(NumBits);
uint64_t V = Read(32);
return V | (uint64_t)Read(NumBits-32) << 32;
}
uint32_t ReadVBR(unsigned NumBits) {
uint32_t Piece = Read(NumBits);
if ((Piece & (1U << (NumBits-1))) == 0)