From 779a49bfd67793f64b43015a85bc5965fba2063f Mon Sep 17 00:00:00 2001 From: Evgenii Kliuchnikov Date: Thu, 20 Jul 2023 04:18:18 -0700 Subject: [PATCH] bake in runtime constant PiperOrigin-RevId: 549590409 --- c/enc/hash_longest_match64_inc.h | 14 ++++---------- c/enc/params.h | 1 - c/enc/quality.h | 1 - 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/c/enc/hash_longest_match64_inc.h b/c/enc/hash_longest_match64_inc.h index d02435e76..da75949ea 100644 --- a/c/enc/hash_longest_match64_inc.h +++ b/c/enc/hash_longest_match64_inc.h @@ -21,8 +21,8 @@ static BROTLI_INLINE size_t FN(StoreLookahead)(void) { return 8; } /* HashBytes is the function that chooses the bucket to place the address in. */ static BROTLI_INLINE uint32_t FN(HashBytes)(const uint8_t* BROTLI_RESTRICT data, - const uint64_t mask, const int shift) { + const uint64_t mask = (~((uint64_t)0U)) >> 24; /* Use only 5 bytes. */ const uint64_t h = (BROTLI_UNALIGNED_LOAD64LE(data) & mask) * kHashMul64Long; /* The higher bits contain more mixture from the multiplication, so we take our results from there. */ @@ -37,8 +37,6 @@ typedef struct HashLongestMatch { size_t block_size_; /* Left-shift for computing hash bucket index from hash value. */ int hash_shift_; - /* Mask for selecting the next 4-8 bytes of input */ - uint64_t hash_mask_; /* Mask for accessing entries in a block (in a ring-buffer manner). */ uint32_t block_mask_; @@ -64,7 +62,6 @@ static void FN(Initialize)( BROTLI_UNUSED(params); self->hash_shift_ = 64 - common->params.bucket_bits; - self->hash_mask_ = (~((uint64_t)0U)) >> (64 - 8 * common->params.hash_len); self->bucket_size_ = (size_t)1 << common->params.bucket_bits; self->block_bits_ = common->params.block_bits; self->block_size_ = (size_t)1 << common->params.block_bits; @@ -84,8 +81,7 @@ static void FN(Prepare)( if (one_shot && input_size <= partial_prepare_threshold) { size_t i; for (i = 0; i < input_size; ++i) { - const uint32_t key = FN(HashBytes)(&data[i], self->hash_mask_, - self->hash_shift_); + const uint32_t key = FN(HashBytes)(&data[i], self->hash_shift_); num[key] = 0; } } else { @@ -111,8 +107,7 @@ static BROTLI_INLINE void FN(Store)( const size_t mask, const size_t ix) { uint16_t* BROTLI_RESTRICT num = self->num_; uint32_t* BROTLI_RESTRICT buckets = self->buckets_; - const uint32_t key = FN(HashBytes)(&data[ix & mask], self->hash_mask_, - self->hash_shift_); + const uint32_t key = FN(HashBytes)(&data[ix & mask], self->hash_shift_); const size_t minor_ix = num[key] & self->block_mask_; const size_t offset = minor_ix + (key << self->block_bits_); ++num[key]; @@ -217,8 +212,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)( } } { - const uint32_t key = FN(HashBytes)( - &data[cur_ix_masked], self->hash_mask_, self->hash_shift_); + const uint32_t key = FN(HashBytes)(&data[cur_ix_masked], self->hash_shift_); uint32_t* BROTLI_RESTRICT bucket = &buckets[key << self->block_bits_]; const size_t down = (num[key] > self->block_size_) ? diff --git a/c/enc/params.h b/c/enc/params.h index baeb31967..78b2ab608 100644 --- a/c/enc/params.h +++ b/c/enc/params.h @@ -17,7 +17,6 @@ typedef struct BrotliHasherParams { int type; int bucket_bits; int block_bits; - int hash_len; int num_last_distances_to_check; } BrotliHasherParams; diff --git a/c/enc/quality.h b/c/enc/quality.h index 99891b479..4415a54ff 100644 --- a/c/enc/quality.h +++ b/c/enc/quality.h @@ -133,7 +133,6 @@ static BROTLI_INLINE void ChooseHasher(const BrotliEncoderParams* params, hparams->type = 6; hparams->block_bits = params->quality - 1; hparams->bucket_bits = 15; - hparams->hash_len = 5; hparams->num_last_distances_to_check = params->quality < 7 ? 4 : params->quality < 9 ? 10 : 16; } else {