Skip to content

Commit

Permalink
Update (#656)
Browse files Browse the repository at this point in the history
 * proper fix for the "fall through" warning"
 * automatic NDIRECT/NPOSTFIX tuning (better compression)
 * fix unaligned access for `aarch64`-cross-`armhf` build
 * fix `aarch64` detection (10% decoder speedup)
 * expose `large_window` CLI option
 * make default window size 16MiB
 * ramp up version to 1.0.4
  • Loading branch information
eustas authored Mar 27, 2018
1 parent 515fc62 commit 0f3c84e
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 100 deletions.
1 change: 0 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ STRICT_C_OPTIONS = [
"-Wmissing-declarations",
"-Wmissing-prototypes",
"-Wno-strict-aliasing",
"-Wno-implicit-fallthrough",
"-Wshadow",
"-Wsign-compare",
]
Expand Down
2 changes: 1 addition & 1 deletion c/common/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define BROTLI_MAX_NPOSTFIX 3
#define BROTLI_MAX_NDIRECT 120
#define BROTLI_MAX_DISTANCE_BITS 24U
#define BROTLI_DISTANCE_ALPHABET_SIZE(NDIRECT, NPOSTFIX, MAXNBITS) ( \
#define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \
BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) + \
((MAXNBITS) << ((NPOSTFIX) + 1)))
/* BROTLI_NUM_DISTANCE_SYMBOLS == 1128 */
Expand Down
25 changes: 18 additions & 7 deletions c/common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@
#define BROTLI_NOINLINE
#endif

#if defined(__arm__) || defined(__thumb__) || \
defined(_M_ARM) || defined(_M_ARMT) || defined(__ARM64_ARCH_8__)
#define BROTLI_TARGET_ARM
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
(defined(M_ARM) && (M_ARM == 7))
#define BROTLI_TARGET_ARMV7
#endif /* ARMv7 */
#if defined(__aarch64__) || defined(__ARM64_ARCH_8__)

#if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \
defined(__aarch64__) || defined(__ARM64_ARCH_8__)
#define BROTLI_TARGET_ARMV8
#endif /* ARMv8 */
#endif /* ARM */

#if defined(__i386) || defined(_M_IX86)
#define BROTLI_TARGET_X86
Expand Down Expand Up @@ -213,12 +211,25 @@ static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) {
static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
return *(const uint32_t*)p;
}
#if (BROTLI_64_BITS)
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
return *(const uint64_t*)p;
}
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
*(uint64_t*)p = v;
}
#else /* BROTLI_64_BITS */
/* Avoid emitting LDRD / STRD, which require properly aligned address. */
static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
const uint32_t* dwords = (const uint32_t*)p;
return dwords[0] | ((uint64_t)dwords[1] << 32);
}
static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) {
uint32_t* dwords = (uint32_t *)p;
dwords[0] = (uint32_t)v;
dwords[1] = (uint32_t)(v >> 32);
}
#endif /* BROTLI_64_BITS */
#endif /* BROTLI_ALIGNED_READ */

#if BROTLI_LITTLE_ENDIAN
Expand Down Expand Up @@ -328,7 +339,7 @@ To apply compiler hint, enclose the branching condition into macros, like this:
#define BROTLI_IS_CONSTANT(x) (!!0)
#endif

#if defined(BROTLI_TARGET_ARM)
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
#define BROTLI_HAS_UBFX (!!1)
#else
#define BROTLI_HAS_UBFX (!!0)
Expand Down Expand Up @@ -362,7 +373,7 @@ static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) {
return output;
}
#define BROTLI_RBIT(x) BrotliRBit(x)
#endif /* armv7 */
#endif /* armv7 / armv8 */
#endif /* gcc || clang */
#if !defined(BROTLI_RBIT)
static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ }
Expand Down
4 changes: 2 additions & 2 deletions c/common/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
BrotliEncoderVersion methods. */

/* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */
#define BROTLI_VERSION 0x1000003
#define BROTLI_VERSION 0x1000004

/* This macro is used by build system to produce Libtool-friendly soname. See
https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
*/

/* ABI version, calculated as (CURRENT << 24) | (REVISION << 12) | AGE */
#define BROTLI_ABI_VERSION 0x1003000
#define BROTLI_ABI_VERSION 0x1004000

#endif /* BROTLI_COMMON_VERSION_H_ */
63 changes: 34 additions & 29 deletions c/dec/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static BROTLI_NOINLINE BrotliDecoderErrorCode DecodeVarLenUint8(
*value = 0;
return BROTLI_DECODER_SUCCESS;
}
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_DECODE_UINT8_SHORT:
if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, 3, &bits))) {
Expand All @@ -203,7 +203,7 @@ static BROTLI_NOINLINE BrotliDecoderErrorCode DecodeVarLenUint8(
}
/* Use output value as a temporary storage. It MUST be persisted. */
*value = bits;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_DECODE_UINT8_LONG:
if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, *value, &bits))) {
Expand Down Expand Up @@ -240,7 +240,7 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
break;
}
s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_EMPTY;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER_EMPTY:
if (!BrotliSafeReadBits(br, 1, &bits)) {
Expand All @@ -251,7 +251,7 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
return BROTLI_DECODER_SUCCESS;
}
s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER_NIBBLES:
if (!BrotliSafeReadBits(br, 2, &bits)) {
Expand All @@ -265,7 +265,7 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
break;
}
s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_SIZE;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER_SIZE:
i = s->loop_counter;
Expand All @@ -281,7 +281,7 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
}
s->substate_metablock_header =
BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED:
if (!s->is_last_metablock) {
Expand All @@ -302,7 +302,7 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_RESERVED);
}
s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_BYTES;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER_BYTES:
if (!BrotliSafeReadBits(br, 2, &bits)) {
Expand All @@ -314,7 +314,7 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE DecodeMetaBlockLength(
}
s->size_nibbles = (uint8_t)bits;
s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_METADATA;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER_METADATA:
i = s->loop_counter;
Expand Down Expand Up @@ -756,7 +756,7 @@ static BrotliDecoderErrorCode ReadHuffmanCode(uint32_t alphabet_size,
s->substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX;
continue;
}
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_HUFFMAN_SIMPLE_SIZE:
/* Read symbols, codes & code lengths directly. */
Expand All @@ -765,16 +765,16 @@ static BrotliDecoderErrorCode ReadHuffmanCode(uint32_t alphabet_size,
return BROTLI_DECODER_NEEDS_MORE_INPUT;
}
s->sub_loop_counter = 0;
/* No break, transit to the next state. */
/* Fall through. */

case BROTLI_STATE_HUFFMAN_SIMPLE_READ: {
BrotliDecoderErrorCode result =
ReadSimpleHuffmanSymbols(alphabet_size, max_symbol, s);
if (result != BROTLI_DECODER_SUCCESS) {
return result;
}
/* No break, transit to the next state. */
}
/* Fall through. */

case BROTLI_STATE_HUFFMAN_SIMPLE_BUILD: {
uint32_t table_size;
Expand Down Expand Up @@ -818,8 +818,8 @@ static BrotliDecoderErrorCode ReadHuffmanCode(uint32_t alphabet_size,
s->repeat_code_len = 0;
s->space = 32768;
s->substate_huffman = BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS;
/* No break, transit to the next state. */
}
/* Fall through. */

case BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS: {
uint32_t table_size;
Expand Down Expand Up @@ -996,7 +996,7 @@ static BrotliDecoderErrorCode DecodeContextMap(uint32_t context_map_size,
return BROTLI_DECODER_SUCCESS;
}
s->substate_context_map = BROTLI_STATE_CONTEXT_MAP_READ_PREFIX;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_CONTEXT_MAP_READ_PREFIX: {
uint32_t bits;
Expand All @@ -1014,8 +1014,8 @@ static BrotliDecoderErrorCode DecodeContextMap(uint32_t context_map_size,
}
BROTLI_LOG_UINT(s->max_run_length_prefix);
s->substate_context_map = BROTLI_STATE_CONTEXT_MAP_HUFFMAN;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_CONTEXT_MAP_HUFFMAN: {
uint32_t alphabet_size = *num_htrees + s->max_run_length_prefix;
Expand All @@ -1024,8 +1024,8 @@ static BrotliDecoderErrorCode DecodeContextMap(uint32_t context_map_size,
if (result != BROTLI_DECODER_SUCCESS) return result;
s->code = 0xFFFF;
s->substate_context_map = BROTLI_STATE_CONTEXT_MAP_DECODE;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_CONTEXT_MAP_DECODE: {
uint32_t context_index = s->context_index;
Expand Down Expand Up @@ -1073,8 +1073,8 @@ static BrotliDecoderErrorCode DecodeContextMap(uint32_t context_map_size,
} while (--reps);
}
}
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_CONTEXT_MAP_TRANSFORM: {
uint32_t bits;
Expand Down Expand Up @@ -1362,8 +1362,8 @@ static BrotliDecoderErrorCode BROTLI_NOINLINE CopyUncompressedBlockToOutput(
return BROTLI_DECODER_NEEDS_MORE_INPUT;
}
s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_WRITE;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_UNCOMPRESSED_WRITE: {
BrotliDecoderErrorCode result;
Expand Down Expand Up @@ -2102,7 +2102,7 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
break;
}
s->state = BROTLI_STATE_INITIALIZE;
/* No break, continue to next state */
/* Fall through. */

case BROTLI_STATE_INITIALIZE:
BROTLI_LOG_UINT(s->window_bits);
Expand All @@ -2121,13 +2121,13 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
s->block_type_trees + 3 * BROTLI_HUFFMAN_MAX_SIZE_258;

s->state = BROTLI_STATE_METABLOCK_BEGIN;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_BEGIN:
BrotliDecoderStateMetablockBegin(s);
BROTLI_LOG_UINT(s->pos);
s->state = BROTLI_STATE_METABLOCK_HEADER;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_METABLOCK_HEADER:
result = DecodeMetaBlockLength(s, br); /* Reads 2 - 31 bits. */
Expand Down Expand Up @@ -2202,7 +2202,7 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
break;
}
s->state = BROTLI_STATE_HUFFMAN_CODE_1;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_HUFFMAN_CODE_1: {
uint32_t alphabet_size = s->num_block_types[s->loop_counter] + 2;
Expand All @@ -2211,8 +2211,8 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
&s->block_type_trees[tree_offset], NULL, s);
if (result != BROTLI_DECODER_SUCCESS) break;
s->state = BROTLI_STATE_HUFFMAN_CODE_2;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_HUFFMAN_CODE_2: {
uint32_t alphabet_size = BROTLI_NUM_BLOCK_LEN_SYMBOLS;
Expand All @@ -2221,8 +2221,8 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
&s->block_len_trees[tree_offset], NULL, s);
if (result != BROTLI_DECODER_SUCCESS) break;
s->state = BROTLI_STATE_HUFFMAN_CODE_3;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_HUFFMAN_CODE_3: {
int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_26;
Expand Down Expand Up @@ -2258,16 +2258,16 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
}
s->loop_counter = 0;
s->state = BROTLI_STATE_CONTEXT_MODES;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_CONTEXT_MODES:
result = ReadContextModes(s);
if (result != BROTLI_DECODER_SUCCESS) {
break;
}
s->state = BROTLI_STATE_CONTEXT_MAP_1;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_CONTEXT_MAP_1:
result = DecodeContextMap(
Expand All @@ -2278,13 +2278,13 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
}
DetectTrivialLiteralBlockTypes(s);
s->state = BROTLI_STATE_CONTEXT_MAP_2;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_CONTEXT_MAP_2: {
uint32_t num_direct_codes =
s->num_direct_distance_codes - BROTLI_NUM_DISTANCE_SHORT_CODES;
uint32_t num_distance_codes = BROTLI_DISTANCE_ALPHABET_SIZE(
num_direct_codes, s->distance_postfix_bits,
s->distance_postfix_bits, num_direct_codes,
(s->large_window ? BROTLI_LARGE_MAX_DISTANCE_BITS :
BROTLI_MAX_DISTANCE_BITS));
uint32_t max_distance_symbol = (s->large_window ?
Expand Down Expand Up @@ -2313,8 +2313,8 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
}
s->loop_counter = 0;
s->state = BROTLI_STATE_TREE_GROUP;
/* No break, continue to next state. */
}
/* Fall through. */

case BROTLI_STATE_TREE_GROUP: {
HuffmanTreeGroup* hgroup = NULL;
Expand Down Expand Up @@ -2342,8 +2342,11 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
}

case BROTLI_STATE_COMMAND_BEGIN:
/* Fall through. */
case BROTLI_STATE_COMMAND_INNER:
/* Fall through. */
case BROTLI_STATE_COMMAND_POST_DECODE_LITERALS:
/* Fall through. */
case BROTLI_STATE_COMMAND_POST_WRAP_COPY:
result = ProcessCommands(s);
if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
Expand All @@ -2352,7 +2355,9 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
break;

case BROTLI_STATE_COMMAND_INNER_WRITE:
/* Fall through. */
case BROTLI_STATE_COMMAND_POST_WRITE_1:
/* Fall through. */
case BROTLI_STATE_COMMAND_POST_WRITE_2:
result = WriteRingBuffer(
s, available_out, next_out, total_out, BROTLI_FALSE);
Expand Down Expand Up @@ -2406,7 +2411,7 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
*next_in = br->next_in;
}
s->state = BROTLI_STATE_DONE;
/* No break, continue to next state. */
/* Fall through. */

case BROTLI_STATE_DONE:
if (s->ringbuffer != 0) {
Expand Down
Loading

0 comments on commit 0f3c84e

Please sign in to comment.