| 1 | /* Copyright 2013 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | Distributed under MIT license. |
| 4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 | */ |
| 6 | |
| 7 | /* Bit reading helpers */ |
| 8 | |
| 9 | #ifndef BROTLI_DEC_BIT_READER_H_ |
| 10 | #define BROTLI_DEC_BIT_READER_H_cxx . . $ `c/dec/bit_reader.h:10:9`! |
| 11 | |
| 12 | #include "../common/constants.h"cxx . . $ `<file>/c/common/constants.h`/ |
| 13 | #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/ |
| 14 | |
| 15 | #if defined(__cplusplus) || defined(c_plusplus) |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
| 19 | #define BROTLI_SHORT_FILL_BIT_WINDOW_READcxx . . $ `c/dec/bit_reader.h:19:9`! (sizeof(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!) >> 1) |
| 20 | |
| 21 | /* 162 bits + 7 bytes */ |
| 22 | #define BROTLI_FAST_INPUT_SLACKcxx . . $ `c/dec/bit_reader.h:22:9`! 28 |
| 23 | |
| 24 | BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! extern const brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! kBrotliBitMaskcxx . . $ kBrotliBitMask.[33]; |
| 25 | |
| 26 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(brotli_reg_tcxx . . $ uint64_t# n) { |
| 27 | if (BROTLI_IS_CONSTANTcxx . . $ `c/common/platform.h:451:9`!(n) || BROTLI_HAS_UBFXcxx . . $ `c/common/platform.h:459:9`!) { |
| 28 | /* Masking with this expression turns to a single |
| 29 | "Unsigned Bit Field Extract" UBFX instruction on ARM. */ |
| 30 | return ~(~((brotli_reg_tcxx . . $ uint64_t#)0) << n); |
| 31 | } else { |
| 32 | return kBrotliBitMaskcxx . . $ kBrotliBitMask.[n]; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | typedef structcxx . . $ $anonymous_type_83261257069d1fbd_0# { |
| 37 | brotli_reg_tcxx . . $ uint64_t# val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_.; /* pre-fetched bits */ |
| 38 | brotli_reg_tcxx . . $ uint64_t# bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.; /* current bit-reading position in val_ */ |
| 39 | const uint8_tcxx . . $ uint8_t#* next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.; /* the byte we're reading from */ |
| 40 | const uint8_tcxx . . $ uint8_t#* guard_incxx . . $ $anonymous_type_83261257069d1fbd_0#guard_in.; /* position from which "fast-path" is prohibited */ |
| 41 | const uint8_tcxx . . $ uint8_t#* last_incxx . . $ $anonymous_type_83261257069d1fbd_0#last_in.; /* == next_in + avail_in */ |
| 42 | } BrotliBitReadercxx . . $ BrotliBitReader#; |
| 43 | |
| 44 | typedef structcxx . . $ $anonymous_type_83261257069d1fbd_1# { |
| 45 | brotli_reg_tcxx . . $ uint64_t# val_cxx . . $ $anonymous_type_83261257069d1fbd_1#val_.; |
| 46 | brotli_reg_tcxx . . $ uint64_t# bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_1#bit_pos_.; |
| 47 | const uint8_tcxx . . $ uint8_t#* next_incxx . . $ $anonymous_type_83261257069d1fbd_1#next_in.; |
| 48 | size_tcxx . . $ size_t# avail_incxx . . $ $anonymous_type_83261257069d1fbd_1#avail_in.; |
| 49 | } BrotliBitReaderStatecxx . . $ BrotliBitReaderState#; |
| 50 | |
| 51 | /* Initializes the BrotliBitReader fields. */ |
| 52 | BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! void BrotliInitBitReadercxx . . $ BrotliInitBitReader(165eb0102fa4fad4).(BrotliBitReadercxx . . $ BrotliBitReader#* br); |
| 53 | |
| 54 | /* Ensures that accumulator is not empty. |
| 55 | May consume up to sizeof(brotli_reg_t) - 1 bytes of input. |
| 56 | Returns BROTLI_FALSE if data is required but there is no input available. |
| 57 | For !BROTLI_UNALIGNED_READ_FAST this function also prepares bit reader for |
| 58 | aligned reading. */ |
| 59 | BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliWarmupBitReadercxx . . $ BrotliWarmupBitReader(4966df8ab2ee854a).(BrotliBitReadercxx . . $ BrotliBitReader#* br); |
| 60 | |
| 61 | /* Fallback for BrotliSafeReadBits32. Extracted as noninlined method to unburden |
| 62 | the main code-path. Never called for RFC brotli streams, required only for |
| 63 | "large-window" mode and other extensions. */ |
| 64 | BROTLI_INTERNALcxx . . $ `c/include/brotli/port.h:252:9`! BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliSafeReadBits32Slowcxx . . $ BrotliSafeReadBits32Slow(d859fb483c1e4a60).( |
| 65 | BrotliBitReadercxx . . $ BrotliBitReader#* br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n_bits, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* val); |
| 66 | |
| 67 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_tcxx . . $ size_t# |
| 68 | BrotliBitReaderGetAvailIncxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(BrotliBitReadercxx . . $ BrotliBitReader#* const br) { |
| 69 | return (size_tcxx . . $ size_t#)(br->last_incxx . . $ $anonymous_type_83261257069d1fbd_0#last_in. - br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.); |
| 70 | } |
| 71 | |
| 72 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliBitReaderSaveStatecxx . . $ BrotliBitReaderSaveState(c49e3454873146cb).( |
| 73 | BrotliBitReadercxx . . $ BrotliBitReader#* const from, BrotliBitReaderStatecxx . . $ BrotliBitReaderState#* to) { |
| 74 | to->val_cxx . . $ $anonymous_type_83261257069d1fbd_1#val_. = from->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_.; |
| 75 | to->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_1#bit_pos_. = from->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.; |
| 76 | to->next_incxx . . $ $anonymous_type_83261257069d1fbd_1#next_in. = from->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.; |
| 77 | to->avail_incxx . . $ $anonymous_type_83261257069d1fbd_1#avail_in. = BrotliBitReaderGetAvailIncxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(from); |
| 78 | } |
| 79 | |
| 80 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliBitReaderSetInputcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).( |
| 81 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, const uint8_tcxx . . $ uint8_t#* next_in, size_tcxx . . $ size_t# avail_in) { |
| 82 | br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. = next_in; |
| 83 | br->last_incxx . . $ $anonymous_type_83261257069d1fbd_0#last_in. = (avail_in == 0) ? next_in : (next_in + avail_in); |
| 84 | if (avail_in + 1 > BROTLI_FAST_INPUT_SLACKcxx . . $ `c/dec/bit_reader.h:22:9`!) { |
| 85 | br->guard_incxx . . $ $anonymous_type_83261257069d1fbd_0#guard_in. = next_in + (avail_in + 1 - BROTLI_FAST_INPUT_SLACKcxx . . $ `c/dec/bit_reader.h:22:9`!); |
| 86 | } else { |
| 87 | br->guard_incxx . . $ $anonymous_type_83261257069d1fbd_0#guard_in. = next_in; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliBitReaderRestoreStatecxx . . $ BrotliBitReaderRestoreState(c49e3454873146cb).( |
| 92 | BrotliBitReadercxx . . $ BrotliBitReader#* const to, BrotliBitReaderStatecxx . . $ BrotliBitReaderState#* from) { |
| 93 | to->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. = from->val_cxx . . $ $anonymous_type_83261257069d1fbd_1#val_.; |
| 94 | to->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. = from->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_1#bit_pos_.; |
| 95 | to->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. = from->next_incxx . . $ $anonymous_type_83261257069d1fbd_1#next_in.; |
| 96 | BrotliBitReaderSetInputcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).(to, from->next_incxx . . $ $anonymous_type_83261257069d1fbd_1#next_in., from->avail_incxx . . $ $anonymous_type_83261257069d1fbd_1#avail_in.); |
| 97 | } |
| 98 | |
| 99 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ uint64_t# BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).( |
| 100 | const BrotliBitReadercxx . . $ BrotliBitReader#* br) { |
| 101 | return br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.; |
| 102 | } |
| 103 | |
| 104 | /* Returns amount of unread bytes the bit reader still has buffered from the |
| 105 | BrotliInput, including whole bytes in br->val_. Result is capped with |
| 106 | maximal ring-buffer size (larger number won't be utilized anyway). */ |
| 107 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_tcxx . . $ size_t# BrotliGetRemainingBytescxx . . $ BrotliGetRemainingBytes(a8eec9f290bacd2d).(BrotliBitReadercxx . . $ BrotliBitReader#* br) { |
| 108 | static const size_tcxx . . $ size_t# kCap = (size_tcxx . . $ size_t#)1 << BROTLI_LARGE_MAX_WBITScxx . . $ `c/common/constants.h:55:9`!; |
| 109 | size_tcxx . . $ size_t# avail_in = BrotliBitReaderGetAvailIncxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(br); |
| 110 | if (avail_in > kCap) return kCap; |
| 111 | return avail_in + (BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) >> 3); |
| 112 | } |
| 113 | |
| 114 | /* Checks if there is at least |num| bytes left in the input ring-buffer |
| 115 | (excluding the bits remaining in br->val_). */ |
| 116 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliCheckInputAmountcxx . . $ BrotliCheckInputAmount(4966df8ab2ee854a).( |
| 117 | BrotliBitReadercxx . . $ BrotliBitReader#* const br) { |
| 118 | return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(br->next_in < br->guard_in); |
| 119 | } |
| 120 | |
| 121 | /* Load more bits into accumulator. */ |
| 122 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! BrotliBitReaderLoadBitscxx . . $ BrotliBitReaderLoadBits(8f424044f20ee7cf).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! val, |
| 123 | brotli_reg_tcxx . . $ uint64_t# new_bits, |
| 124 | brotli_reg_tcxx . . $ uint64_t# count, |
| 125 | brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! offset) { |
| 126 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!( |
| 127 | !((val >> offset) & ~new_bits & ~(~((brotli_reg_t)0) << count))); |
| 128 | (void)count; |
| 129 | return val | (new_bits << offset); |
| 130 | } |
| 131 | |
| 132 | /* Guarantees that there are at least |n_bits| + 1 bits in accumulator. |
| 133 | Precondition: accumulator contains at least 1 bit. |
| 134 | |n_bits| should be in the range [1..24] for regular build. For portable |
| 135 | non-64-bit little-endian build only 16 bits are safe to request. */ |
| 136 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).( |
| 137 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ uint64_t# n_bits) { |
| 138 | #if (BROTLI_64_BITScxx . . $ `c/common/platform.h:233:9`!) |
| 139 | if (BROTLI_UNALIGNED_READ_FASTcxx . . $ `c/common/platform.h:278:9`! && BROTLI_IS_CONSTANTcxx . . $ `c/common/platform.h:451:9`!(n_bits) && |
| 140 | (n_bits <= 8)) { |
| 141 | brotli_reg_tcxx . . $ uint64_t# bit_pos = br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.; |
| 142 | if (bit_pos <= 8) { |
| 143 | br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. = BrotliBitReaderLoadBitscxx . . $ BrotliBitReaderLoadBits(8f424044f20ee7cf).(br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_., |
| 144 | BROTLI_UNALIGNED_LOAD64LEcxx . . $ BrotliUnalignedRead64(2e8e543e1193434e).(br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.), 56, bit_pos); |
| 145 | br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. = bit_pos + 56; |
| 146 | br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. += 7; |
| 147 | } |
| 148 | } else if (BROTLI_UNALIGNED_READ_FASTcxx . . $ `c/common/platform.h:278:9`! && BROTLI_IS_CONSTANTcxx . . $ `c/common/platform.h:451:9`!(n_bits) && |
| 149 | (n_bits <= 16)) { |
| 150 | brotli_reg_tcxx . . $ uint64_t# bit_pos = br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.; |
| 151 | if (bit_pos <= 16) { |
| 152 | br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. = BrotliBitReaderLoadBitscxx . . $ BrotliBitReaderLoadBits(8f424044f20ee7cf).(br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_., |
| 153 | BROTLI_UNALIGNED_LOAD64LEcxx . . $ BrotliUnalignedRead64(2e8e543e1193434e).(br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.), 48, bit_pos); |
| 154 | br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. = bit_pos + 48; |
| 155 | br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. += 6; |
| 156 | } |
| 157 | } else { |
| 158 | brotli_reg_tcxx . . $ uint64_t# bit_pos = br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.; |
| 159 | if (bit_pos <= 32) { |
| 160 | br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. = BrotliBitReaderLoadBitscxx . . $ BrotliBitReaderLoadBits(8f424044f20ee7cf).(br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_., |
| 161 | (uint64_tcxx . . $ uint64_t#)BROTLI_UNALIGNED_LOAD32LEcxx . . $ BrotliUnalignedRead32(b11f534102b1ad6).(br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.), 32, bit_pos); |
| 162 | br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. = bit_pos + 32; |
| 163 | br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. += BROTLI_SHORT_FILL_BIT_WINDOW_READcxx . . $ `c/dec/bit_reader.h:19:9`!; |
| 164 | } |
| 165 | } |
| 166 | #else |
| 167 | if (BROTLI_UNALIGNED_READ_FAST && BROTLI_IS_CONSTANT(n_bits) && |
| 168 | (n_bits <= 8)) { |
| 169 | brotli_reg_t bit_pos = br->bit_pos_; |
| 170 | if (bit_pos <= 8) { |
| 171 | br->val_ = BrotliBitReaderLoadBits(br->val_, |
| 172 | BROTLI_UNALIGNED_LOAD32LE(br->next_in), 24, bit_pos); |
| 173 | br->bit_pos_ = bit_pos + 24; |
| 174 | br->next_in += 3; |
| 175 | } |
| 176 | } else { |
| 177 | brotli_reg_t bit_pos = br->bit_pos_; |
| 178 | if (bit_pos <= 16) { |
| 179 | br->val_ = BrotliBitReaderLoadBits(br->val_, |
| 180 | (uint32_t)BROTLI_UNALIGNED_LOAD16LE(br->next_in), 16, bit_pos); |
| 181 | br->bit_pos_ = bit_pos + 16; |
| 182 | br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ; |
| 183 | } |
| 184 | } |
| 185 | #endif |
| 186 | } |
| 187 | |
| 188 | /* Mostly like BrotliFillBitWindow, but guarantees only 16 bits and reads no |
| 189 | more than BROTLI_SHORT_FILL_BIT_WINDOW_READ bytes of input. */ |
| 190 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliFillBitWindow16cxx . . $ BrotliFillBitWindow16(165eb0102fa4fad4).(BrotliBitReadercxx . . $ BrotliBitReader#* const br) { |
| 191 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, 17); |
| 192 | } |
| 193 | |
| 194 | /* Tries to pull one byte of input to accumulator. |
| 195 | Returns BROTLI_FALSE if there is no input available. */ |
| 196 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliPullBytecxx . . $ BrotliPullByte(4966df8ab2ee854a).(BrotliBitReadercxx . . $ BrotliBitReader#* const br) { |
| 197 | if (br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. == br->last_incxx . . $ $anonymous_type_83261257069d1fbd_0#last_in.) { |
| 198 | return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 199 | } |
| 200 | br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. = BrotliBitReaderLoadBitscxx . . $ BrotliBitReaderLoadBits(8f424044f20ee7cf).(br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_., |
| 201 | (brotli_reg_tcxx . . $ uint64_t#)*br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in., 8, br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.); |
| 202 | br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. += 8; |
| 203 | ++br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.; |
| 204 | return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 205 | } |
| 206 | |
| 207 | /* Returns currently available bits. |
| 208 | The number of valid bits could be calculated by BrotliGetAvailableBits. */ |
| 209 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ uint64_t# BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).( |
| 210 | BrotliBitReadercxx . . $ BrotliBitReader#* const br) { |
| 211 | return br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_.; |
| 212 | } |
| 213 | |
| 214 | /* Like BrotliGetBits, but does not mask the result. |
| 215 | The result contains at least 16 valid bits. */ |
| 216 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! BrotliGet16BitsUnmaskedcxx . . $ BrotliGet16BitsUnmasked(a8eec9f290bacd2d).( |
| 217 | BrotliBitReadercxx . . $ BrotliBitReader#* const br) { |
| 218 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, 16); |
| 219 | return (brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br); |
| 220 | } |
| 221 | |
| 222 | /* Returns the specified number of bits from |br| without advancing bit |
| 223 | position. */ |
| 224 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! BrotliGetBitscxx . . $ BrotliGetBits(b970e0c403979745).( |
| 225 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ uint64_t# n_bits) { |
| 226 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, n_bits); |
| 227 | return BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br) & BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(n_bits); |
| 228 | } |
| 229 | |
| 230 | /* Tries to peek the specified amount of bits. Returns BROTLI_FALSE, if there |
| 231 | is not enough input. */ |
| 232 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliSafeGetBitscxx . . $ BrotliSafeGetBits(d859fb483c1e4a60).( |
| 233 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ uint64_t# n_bits, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* val) { |
| 234 | while (BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) < n_bits) { |
| 235 | if (!BrotliPullBytecxx . . $ BrotliPullByte(4966df8ab2ee854a).(br)) { |
| 236 | return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 237 | } |
| 238 | } |
| 239 | *val = BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br) & BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(n_bits); |
| 240 | return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 241 | } |
| 242 | |
| 243 | /* Advances the bit pos by |n_bits|. */ |
| 244 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).( |
| 245 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n_bits) { |
| 246 | br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. -= n_bits; |
| 247 | br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. >>= n_bits; |
| 248 | } |
| 249 | |
| 250 | /* Make sure that there are no spectre bits in accumulator. |
| 251 | This is important for the cases when some bytes are skipped |
| 252 | (i.e. never placed into accumulator). */ |
| 253 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliBitReaderNormalizecxx . . $ BrotliBitReaderNormalize(165eb0102fa4fad4).(BrotliBitReadercxx . . $ BrotliBitReader#* br) { |
| 254 | /* Actually, it is enough to normalize when br->bit_pos_ == 0 */ |
| 255 | if (br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. < (sizeof(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!) << 3u)) { |
| 256 | br->val_cxx . . $ $anonymous_type_83261257069d1fbd_0#val_. &= (((brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)1) << br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_.) - 1; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliBitReaderUnloadcxx . . $ BrotliBitReaderUnload(165eb0102fa4fad4).(BrotliBitReadercxx . . $ BrotliBitReader#* br) { |
| 261 | brotli_reg_tcxx . . $ uint64_t# unused_bytes = BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) >> 3; |
| 262 | brotli_reg_tcxx . . $ uint64_t# unused_bits = unused_bytes << 3; |
| 263 | br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. = |
| 264 | (unused_bytes == 0) ? br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. : (br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. - unused_bytes); |
| 265 | br->bit_pos_cxx . . $ $anonymous_type_83261257069d1fbd_0#bit_pos_. -= unused_bits; |
| 266 | BrotliBitReaderNormalizecxx . . $ BrotliBitReaderNormalize(165eb0102fa4fad4).(br); |
| 267 | } |
| 268 | |
| 269 | /* Reads the specified number of bits from |br| and advances the bit pos. |
| 270 | Precondition: accumulator MUST contain at least |n_bits|. */ |
| 271 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(BrotliBitReadercxx . . $ BrotliBitReader#* const br, |
| 272 | brotli_reg_tcxx . . $ uint64_t# n_bits, |
| 273 | brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* val) { |
| 274 | *val = BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br) & BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(n_bits); |
| 275 | BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[BrotliTakeBits] %d %d %d val: %6x\n", |
| 276 | (int)BrotliBitReaderGetAvailIn(br), (int)br->bit_pos_, |
| 277 | (int)n_bits, (int)*val)); |
| 278 | BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, n_bits); |
| 279 | } |
| 280 | |
| 281 | /* Reads the specified number of bits from |br| and advances the bit pos. |
| 282 | Assumes that there is enough input to perform BrotliFillBitWindow. |
| 283 | Up to 24 bits are allowed to be requested from this method. */ |
| 284 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! BrotliReadBits24cxx . . $ BrotliReadBits24(b970e0c403979745).( |
| 285 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n_bits) { |
| 286 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(n_bits <= 24); |
| 287 | if (BROTLI_64_BITScxx . . $ `c/common/platform.h:233:9`! || (n_bits <= 16)) { |
| 288 | brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! val; |
| 289 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, n_bits); |
| 290 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, n_bits, &val); |
| 291 | return val; |
| 292 | } else { |
| 293 | brotli_reg_tcxx . . $ uint64_t# low_val; |
| 294 | brotli_reg_tcxx . . $ uint64_t# high_val; |
| 295 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, 16); |
| 296 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, 16, &low_val); |
| 297 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, 8); |
| 298 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, n_bits - 16, &high_val); |
| 299 | return low_val | (high_val << 16); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /* Same as BrotliReadBits24, but allows reading up to 32 bits. */ |
| 304 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ uint64_t# BrotliReadBits32cxx . . $ BrotliReadBits32(b970e0c403979745).( |
| 305 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n_bits) { |
| 306 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(n_bits <= 32); |
| 307 | if (BROTLI_64_BITScxx . . $ `c/common/platform.h:233:9`! || (n_bits <= 16)) { |
| 308 | brotli_reg_tcxx . . $ uint64_t# val; |
| 309 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, n_bits); |
| 310 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, n_bits, &val); |
| 311 | return val; |
| 312 | } else { |
| 313 | brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! low_val; |
| 314 | brotli_reg_tcxx . . $ uint64_t# high_val; |
| 315 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, 16); |
| 316 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, 16, &low_val); |
| 317 | BrotliFillBitWindowcxx . . $ BrotliFillBitWindow(aea9ea103d4b1d3f).(br, 16); |
| 318 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, n_bits - 16, &high_val); |
| 319 | return low_val | (high_val << 16); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /* Tries to read the specified amount of bits. Returns BROTLI_FALSE, if there |
| 324 | is not enough input. |n_bits| MUST be positive. |
| 325 | Up to 24 bits are allowed to be requested from this method. */ |
| 326 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).( |
| 327 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ uint64_t# n_bits, brotli_reg_tcxx . . $ uint64_t#* val) { |
| 328 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(n_bits <= 24); |
| 329 | while (BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) < n_bits) { |
| 330 | if (!BrotliPullBytecxx . . $ BrotliPullByte(4966df8ab2ee854a).(br)) { |
| 331 | return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 332 | } |
| 333 | } |
| 334 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, n_bits, val); |
| 335 | return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 336 | } |
| 337 | |
| 338 | /* Same as BrotliSafeReadBits, but allows reading up to 32 bits. */ |
| 339 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliSafeReadBits32cxx . . $ BrotliSafeReadBits32(d859fb483c1e4a60).( |
| 340 | BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ uint64_t# n_bits, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* val) { |
| 341 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(n_bits <= 32); |
| 342 | if (BROTLI_64_BITScxx . . $ `c/common/platform.h:233:9`! || (n_bits <= 24)) { |
| 343 | while (BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) < n_bits) { |
| 344 | if (!BrotliPullBytecxx . . $ BrotliPullByte(4966df8ab2ee854a).(br)) { |
| 345 | return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 346 | } |
| 347 | } |
| 348 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, n_bits, val); |
| 349 | return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 350 | } else { |
| 351 | return BrotliSafeReadBits32Slowcxx . . $ BrotliSafeReadBits32Slow(d859fb483c1e4a60).(br, n_bits, val); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /* Advances the bit reader position to the next byte boundary and verifies |
| 356 | that any skipped bits are set to zero. */ |
| 357 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliJumpToByteBoundarycxx . . $ BrotliJumpToByteBoundary(4966df8ab2ee854a).(BrotliBitReadercxx . . $ BrotliBitReader#* br) { |
| 358 | brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! pad_bits_count = BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) & 0x7; |
| 359 | brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! pad_bits = 0; |
| 360 | if (pad_bits_count != 0) { |
| 361 | BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, pad_bits_count, &pad_bits); |
| 362 | } |
| 363 | BrotliBitReaderNormalizecxx . . $ BrotliBitReaderNormalize(165eb0102fa4fad4).(br); |
| 364 | return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(pad_bits == 0); |
| 365 | } |
| 366 | |
| 367 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliDropBytescxx . . $ BrotliDropBytes(aea9ea103d4b1d3f).(BrotliBitReadercxx . . $ BrotliBitReader#* br, size_tcxx . . $ size_t# num) { |
| 368 | /* Check detour is legal: accumulator must to be empty. */ |
| 369 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(br->bit_pos_ == 0); |
| 370 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(br->val_ == 0); |
| 371 | br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. += num; |
| 372 | } |
| 373 | |
| 374 | /* Copies remaining input bytes stored in the bit reader to the output. Value |
| 375 | |num| may not be larger than BrotliGetRemainingBytes. The bit reader must be |
| 376 | warmed up again after this. */ |
| 377 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void BrotliCopyBytescxx . . $ BrotliCopyBytes(d008cefe4a22b384).(uint8_tcxx . . $ uint8_t#* dest, |
| 378 | BrotliBitReadercxx . . $ BrotliBitReader#* br, size_tcxx . . $ size_t# num) { |
| 379 | while (BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) >= 8 && num > 0) { |
| 380 | *dest = (uint8_tcxx . . $ uint8_t#)BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br); |
| 381 | BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, 8); |
| 382 | ++dest; |
| 383 | --num; |
| 384 | } |
| 385 | BrotliBitReaderNormalizecxx . . $ BrotliBitReaderNormalize(165eb0102fa4fad4).(br); |
| 386 | if (num > 0) { |
| 387 | memcpycxx . . $ memcpy(cc817cb175f282d).(dest, br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in., num); |
| 388 | BrotliDropBytescxx . . $ BrotliDropBytes(aea9ea103d4b1d3f).(br, num); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | BROTLI_UNUSED_FUNCTIONcxx . . $ `c/common/platform.h:154:9`! void BrotliBitReaderSuppressUnusedFunctionscxx . . $ BrotliBitReaderSuppressUnusedFunctions(49f6e7a06ebc5aa8).(void) { |
| 393 | BROTLI_UNUSEDcxx . . $ BrotliBitReaderSuppressUnusedFunctions(49f6e7a06ebc5aa8).(&BrotliBitReaderSuppressUnusedFunctions); |
| 394 | |
| 395 | BROTLI_UNUSEDcxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(&BrotliBitReaderGetAvailIn); |
| 396 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliBitReaderLoadBits); |
| 397 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliBitReaderRestoreState); |
| 398 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliBitReaderSaveState); |
| 399 | BROTLI_UNUSEDcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).(&BrotliBitReaderSetInput); |
| 400 | BROTLI_UNUSEDcxx . . $ BrotliBitReaderUnload(165eb0102fa4fad4).(&BrotliBitReaderUnload); |
| 401 | BROTLI_UNUSEDcxx . . $ BrotliCheckInputAmount(4966df8ab2ee854a).(&BrotliCheckInputAmount); |
| 402 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliCopyBytes); |
| 403 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliFillBitWindow16); |
| 404 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliGet16BitsUnmasked); |
| 405 | BROTLI_UNUSEDcxx . . $ BrotliGetBits(b970e0c403979745).(&BrotliGetBits); |
| 406 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliGetRemainingBytes); |
| 407 | BROTLI_UNUSEDcxx . . $ BrotliJumpToByteBoundary(4966df8ab2ee854a).(&BrotliJumpToByteBoundary); |
| 408 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliReadBits24); |
| 409 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliReadBits32); |
| 410 | BROTLI_UNUSEDcxx . . $ BrotliSafeGetBits(d859fb483c1e4a60).(&BrotliSafeGetBits); |
| 411 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliSafeReadBits); |
| 412 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(&BrotliSafeReadBits32); |
| 413 | } |
| 414 | |
| 415 | #if defined(__cplusplus) || defined(c_plusplus) |
| 416 | } /* extern "C" */ |
| 417 | #endif |
| 418 | |
| 419 | #endif /* BROTLI_DEC_BIT_READER_H_ */ |