llvm.org GIT mirror llvm / ab9c404
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 Rafael Espindola 6 years ago
1 changed file(s) with 11 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
310310 BitsInCurWord = 0;
311311
312312 // Skip over any bits that are already consumed.
313 if (WordBitNo) {
314 if (sizeof(word_t) > 4)
315 Read64(WordBitNo);
316 else
317 Read(WordBitNo);
318 }
313 if (WordBitNo)
314 Read(WordBitNo);
319315 }
320316
321317 void fillCurWord() {
340336 BitsInCurWord = BytesRead * 8;
341337 }
342338
343 uint32_t Read(unsigned NumBits) {
344 assert(NumBits && NumBits <= 32 &&
345 "Cannot return zero or more than 32 bits!");
339 word_t Read(unsigned NumBits) {
340 static const unsigned BitsInWord = sizeof(word_t) * 8;
341
342 assert(NumBits && NumBits <= BitsInWord &&
343 "Cannot return zero or more than BitsInWord bits!");
346344
347345 static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
348346
349347 // If the field is fully contained by CurWord, return it quickly.
350348 if (BitsInCurWord >= NumBits) {
351 uint32_t R = uint32_t(CurWord) & (~0U >> (32-NumBits));
349 word_t R = CurWord & (~word_t(0) >> (BitsInWord - NumBits));
352350
353351 // Use a mask to avoid undefined behavior.
354352 CurWord >>= (NumBits & Mask);
357355 return R;
358356 }
359357
360 uint32_t R = BitsInCurWord ? uint32_t(CurWord) : 0;
358 word_t R = BitsInCurWord ? CurWord : 0;
361359 unsigned BitsLeft = NumBits - BitsInCurWord;
362360
363361 fillCurWord();
366364 if (BitsLeft > BitsInCurWord)
367365 return 0;
368366
369 uint32_t R2 =
370 uint32_t(CurWord) & (~word_t(0) >> (sizeof(word_t) * 8 - BitsLeft));
367 word_t R2 = CurWord & (~word_t(0) >> (BitsInWord - BitsLeft));
371368
372369 // Use a mask to avoid undefined behavior.
373370 CurWord >>= (BitsLeft & Mask);
374371
375372 BitsInCurWord -= BitsLeft;
376373
377 R |= uint32_t(R2 << (NumBits - BitsLeft));
374 R |= R2 << (NumBits - BitsLeft);
378375
379376 return R;
380 }
381
382 uint64_t Read64(unsigned NumBits) {
383 if (NumBits <= 32) return Read(NumBits);
384
385 uint64_t V = Read(32);
386 return V | (uint64_t)Read(NumBits-32) << 32;
387377 }
388378
389379 uint32_t ReadVBR(unsigned NumBits) {