Merge claude/project-thread-0izcgq (large window at qualities 3 to 9)

Put the q10/q11 variable region before the ring buffer (now the last
region), growing it (and moving the ring buffer) at the first
transform_io call to use a workbuf longer than workbuf_len's minimum.
Large window now also works at qualities 10 and 11.
This commit is contained in:
Claude committed 2026-10-27 04:46:52 +00:00
commit 7d58caf91c
11 files changed
+1664 -216

No files matched your search

+44 -1
View File
@@ -102,7 +102,7 @@ pri func encoder.fc_bank_bits() base.u32[..= 16] {
}
// Mirrors ChooseHasher in quality.h (with BROTLI_MAX_SIMD_QUALITY defined as
// 6), for qualities 2 to 9 and lgwin up to 24.
// 6), for qualities 2 to 9.
pri func encoder.choose_hasher!() {
var q : base.u32[..= 11]
@@ -149,6 +149,25 @@ pri func encoder.choose_hasher!() {
this.h_num_last_distances = 10
}
}
this.hr_jump = 0
if this.lgwin > 24 {
// Different hashers for large window brotli: not for qualities <= 2,
// these are too fast for large window. Not for qualities >= 10:
// their hasher already works well with large window. So the changes
// are:
// H3 --> H35: for quality 3.
// H54 --> H55: for quality 4 with size hint > 1MB
// H6/H68 --> H65: for qualities 5, 6, 7, 8, 9.
// See encode_hasher_composite.wuffs: the composite hasher's
// HASHER_A stays in this.hasher_type.
if (this.hasher_type == 3) or (this.hasher_type == 54) {
this.hr_jump = 4
} else if (this.hasher_type == 6) or (this.hasher_type == 68) {
this.hasher_type = 6
this.hr_jump = 1
}
}
}
// hasher_alloc_size mirrors FN(HashMemAllocInBytes) (alloc_size[i], for i in
@@ -226,6 +245,9 @@ pri func encoder.hasher_setup!(wb: slice base.u8, position: base.u64, input_size
htype: this.hasher_type, bucket_bits: this.h_bucket_bits, block_bits: this.h_block_bits, i: 0)
this.h_off2 = this.h_off1 ~mod+ this.hasher_alloc_size(
htype: this.hasher_type, bucket_bits: this.h_bucket_bits, block_bits: this.h_block_bits, i: 1)
// The composite hashers' HASHER_B memory follows HASHER_A's.
this.hr_off = this.h_off2
this.hr_fresh = true
this.h_is_prepared = false
this.h_is_setup = true
}
@@ -314,6 +336,18 @@ pri func encoder.hasher_prepare!(wb: slice base.u8, one_shot: base.bool, input_s
j ~mod+= 1
}
}
if this.hr_jump <> 0 {
// The composite hasher's FN(Prepare) (in hash_composite_inc.h), for
// HASHER_B. HASHER_B's FN(Initialize) is deferred to the first
// FN(Prepare). HASHER_A's FN(Initialize) does not touch the hasher
// memory, so doing it earlier (in hasher_setup) is equivalent.
if this.hr_fresh {
this.hr_fresh = false
this.hasher_rolling_initialize!(wb: args.wb)
}
this.hasher_rolling_prepare!(wb: args.wb, input_size: args.input_size, data_off: this.rb_buf_off)
}
}
// Mirrors FN(HashBytes) in hash_longest_match_quickly_inc.h.
@@ -449,6 +483,10 @@ pri func encoder.hasher_stitch_to_previous_block!(wb: slice base.u8, num_bytes:
this.hasher_store!(wb: args.wb, ix: args.position ~mod- 2)
this.hasher_store!(wb: args.wb, ix: args.position ~mod- 1)
}
if this.hr_jump <> 0 {
// The composite hasher's HASHER_B.
this.hasher_rolling_stitch_to_previous_block!(wb: args.wb, num_bytes: args.num_bytes, position: args.position)
}
}
// Mirrors PrepareDistanceCache in hash.h, via each hasher's
@@ -614,6 +652,11 @@ pri func encoder.find_longest_match!(wb: slice base.u8, cur_ix: base.u64, max_le
this.find_longest_match_forgetful!(wb: args.wb, cur_ix: args.cur_ix, max_length: args.max_length,
max_backward: args.max_backward, dictionary_distance: args.dictionary_distance, max_distance: args.max_distance)
}
if this.hr_jump <> 0 {
// The composite hasher's HASHER_B.
this.hasher_rolling_find_longest_match!(wb: args.wb, cur_ix: args.cur_ix, max_length: args.max_length,
max_backward: args.max_backward)
}
}
// Mirrors FN(FindLongestMatch) in hash_longest_match_quickly_inc.h.