Skip to content

Commit

Permalink
bake in runtime constant
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 549590409
  • Loading branch information
eustas authored and Copybara-Service committed Jul 20, 2023
1 parent acc2656 commit 779a49b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
14 changes: 4 additions & 10 deletions c/enc/hash_longest_match64_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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_;

Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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];
Expand Down Expand Up @@ -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_) ?
Expand Down
1 change: 0 additions & 1 deletion c/enc/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion c/enc/quality.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 779a49b

Please sign in to comment.