Use C-style comments in the brotli decoder.

This commit is contained in:
Zoltan Szabadka
2013-12-16 14:45:57 +01:00
parent 931479d735
commit 30625ba238
13 changed files with 491 additions and 476 deletions
+49 -47
View File
@@ -1,18 +1,19 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Bit reading helpers
/* Copyright 2013 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Bit reading helpers
*/
#ifndef BROTLI_DEC_BIT_READER_H_
#define BROTLI_DEC_BIT_READER_H_
@@ -38,26 +39,26 @@ static const uint32_t kBitMask[BROTLI_MAX_NUM_BIT_READ] = {
};
typedef struct {
// Input byte buffer, consist of a ringbuffer and a "slack" region where
// bytes from the start of the ringbuffer are copied.
/* Input byte buffer, consist of a ringbuffer and a "slack" region where */
/* bytes from the start of the ringbuffer are copied. */
uint8_t buf_[BROTLI_IBUF_SIZE];
BrotliInput input_; // input callback
uint64_t val_; // pre-fetched bits
size_t pos_; // byte position in stream
int bit_pos_; // current bit-reading position in val_
size_t end_pos_; // current end position in stream
int eos_; // input stream is finished
BrotliInput input_; /* input callback */
uint64_t val_; /* pre-fetched bits */
size_t pos_; /* byte position in stream */
int bit_pos_; /* current bit-reading position in val_ */
size_t end_pos_; /* current end position in stream */
int eos_; /* input stream is finished */
} BrotliBitReader;
int BrotliInitBitReader(BrotliBitReader* const br, BrotliInput input);
// Return the prefetched bits, so they can be looked up.
/* Return the prefetched bits, so they can be looked up. */
static BROTLI_INLINE uint32_t BrotliPrefetchBits(BrotliBitReader* const br) {
return (uint32_t)(br->val_ >> br->bit_pos_);
}
// For jumping over a number of bits in the bit stream when accessed with
// BrotliPrefetchBits and BrotliFillBitWindow.
/* For jumping over a number of bits in the bit stream when accessed with */
/* BrotliPrefetchBits and BrotliFillBitWindow. */
static BROTLI_INLINE void BrotliSetBitPos(BrotliBitReader* const br, int val) {
#ifdef BROTLI_DECODE_DEBUG
int n_bits = val - br->bit_pos_;
@@ -68,7 +69,7 @@ static BROTLI_INLINE void BrotliSetBitPos(BrotliBitReader* const br, int val) {
br->bit_pos_ = val;
}
// Reload up to 64 bits byte-by-byte
/* Reload up to 64 bits byte-by-byte */
static BROTLI_INLINE void ShiftBytes(BrotliBitReader* const br) {
while (br->bit_pos_ >= 8) {
br->val_ >>= 8;
@@ -78,17 +79,18 @@ static BROTLI_INLINE void ShiftBytes(BrotliBitReader* const br) {
}
}
// Fills up the input ringbuffer by calling the input callback.
//
// Does nothing if there are at least 32 bytes present after current position.
//
// Returns 0 if either:
// - the input callback returned an error, or
// - there is no more input and the position is past the end of the stream.
//
// After encountering the end of the input stream, 32 additional zero bytes are
// copied to the ringbuffer, therefore it is safe to call this function after
// every 32 bytes of input is read.
/* Fills up the input ringbuffer by calling the input callback.
Does nothing if there are at least 32 bytes present after current position.
Returns 0 if either:
- the input callback returned an error, or
- there is no more input and the position is past the end of the stream.
After encountering the end of the input stream, 32 additional zero bytes are
copied to the ringbuffer, therefore it is safe to call this function after
every 32 bytes of input is read.
*/
static BROTLI_INLINE int BrotliReadMoreInput(BrotliBitReader* const br) {
if (br->pos_ + 32 < br->end_pos_) {
return 1;
@@ -102,7 +104,7 @@ static BROTLI_INLINE int BrotliReadMoreInput(BrotliBitReader* const br) {
}
if (bytes_read < BROTLI_READ_SIZE) {
br->eos_ = 1;
// Store 32 bytes of zero after the stream end.
/* Store 32 bytes of zero after the stream end. */
#if (defined(__x86_64__) || defined(_M_X64))
*(uint64_t*)(dst + bytes_read) = 0;
*(uint64_t*)(dst + bytes_read + 8) = 0;
@@ -113,7 +115,7 @@ static BROTLI_INLINE int BrotliReadMoreInput(BrotliBitReader* const br) {
#endif
}
if (dst == br->buf_) {
// Copy the head of the ringbuffer to the slack region.
/* Copy the head of the ringbuffer to the slack region. */
#if (defined(__x86_64__) || defined(_M_X64))
UNALIGNED_COPY64(br->buf_ + BROTLI_IBUF_SIZE - 32, br->buf_);
UNALIGNED_COPY64(br->buf_ + BROTLI_IBUF_SIZE - 24, br->buf_ + 8);
@@ -128,14 +130,14 @@ static BROTLI_INLINE int BrotliReadMoreInput(BrotliBitReader* const br) {
}
}
// Advances the Read buffer by 5 bytes to make room for reading next 24 bits.
/* Advances the Read buffer by 5 bytes to make room for reading next 24 bits. */
static BROTLI_INLINE void BrotliFillBitWindow(BrotliBitReader* const br) {
if (br->bit_pos_ >= 40) {
#if (defined(__x86_64__) || defined(_M_X64))
br->val_ >>= 40;
br->bit_pos_ -= 40;
// The expression below needs a little-endian arch to work correctly.
// This gives a large speedup for decoding speed.
/* The expression below needs a little-endian arch to work correctly. */
/* This gives a large speedup for decoding speed. */
br->val_ |= *(const uint64_t*)(
br->buf_ + (br->pos_ & BROTLI_IBUF_MASK)) << 24;
br->pos_ += 5;
@@ -145,8 +147,8 @@ static BROTLI_INLINE void BrotliFillBitWindow(BrotliBitReader* const br) {
}
}
// Reads the specified number of bits from Read Buffer.
// Requires that n_bits is positive.
/* Reads the specified number of bits from Read Buffer. */
/* Requires that n_bits is positive. */
static BROTLI_INLINE uint32_t BrotliReadBits(
BrotliBitReader* const br, int n_bits) {
uint32_t val;
@@ -161,7 +163,7 @@ static BROTLI_INLINE uint32_t BrotliReadBits(
}
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
} /* extern "C" */
#endif
#endif // BROTLI_DEC_BIT_READER_H_
#endif /* BROTLI_DEC_BIT_READER_H_ */