std/brotli: speed up the encoder at qualities 10 and 11, byte-exactly

- encode_float.wuffs: package-private fast paths for the f32/f64 add, sub,
  mul, compare and int conversion calls in the encoder's hot loops. Calling
  std/softfloat is a cross-package public call (a receiver check, never
  inlined). Each fast path returns exactly the softfloat result and falls
  back to it for the uncommon cases. script/manual-test-brotli-float.c
  cross-checks them against hardware float and double arithmetic.
- Zopfli update_nodes: compute a length's cost only when its copy code
  changes, hoist the distance cache values and the continuation byte, and
  use a table for small int to f32 conversions.
- FindBlocks: memoize (block_switch_bitcost + insert_cost) for capped costs
  and skip the subtraction for costs at or above a per-byte threshold
  (S(c) = c - min_cost is monotone, so such costs would be capped anyway).
- BrotliPopulationCost: per-call memo of each count's term and depth, and
  skip the zero terms of the entropy sums.
- std/softfloat: a 64-bit f32_add_mags.

Output is unchanged (mimic tests on gcc and clang, parity sweeps).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UZ978BikvkegL2JUkqoB1e
This commit is contained in:
Claude committed 2026-10-27 23:21:31 +00:00
1 parent 8ac9e2fd4c
commit 044437a8ec
16 files changed
+2650 -400

No files matched your search

+7 -7
View File
@@ -472,18 +472,18 @@ pri func encoder.should_compress_two_pass!(input: roslice base.u8, from: base.u6
var max_total_bit_cost : base.u64
var i : base.u64
corpus_size = this.sf.f64_from_u64(a: args.input_size)
corpus_size = this.bc.f64_from_u64(a: args.input_size)
// MIN_RATIO is 0.98 (0x3FEF_5C28_F5C2_8F5C).
if this.sf.f64_lt(
a: this.sf.f64_from_u64(a: args.num_literals),
b: this.sf.f64_mul(a: 0x3FEF_5C28_F5C2_8F5C, b: corpus_size)) <> 0 {
if this.bc.f64_lt(
a: this.bc.f64_from_u64(a: args.num_literals),
b: this.bc.f64_mul(a: 0x3FEF_5C28_F5C2_8F5C, b: corpus_size)) <> 0 {
return true
}
// max_total_bit_cost = corpus_size * 8 * MIN_RATIO / SAMPLE_RATE, where
// SAMPLE_RATE is 43 and 8.0 is 0x4020_0000_0000_0000.
max_total_bit_cost = this.sf.f64_div(
a: this.sf.f64_mul(
a: this.sf.f64_mul(a: corpus_size, b: 0x4020_0000_0000_0000),
a: this.bc.f64_mul(
a: this.bc.f64_mul(a: corpus_size, b: 0x4020_0000_0000_0000),
b: 0x3FEF_5C28_F5C2_8F5C),
b: 0x4045_8000_0000_0000)
this.histogram[.. 256].bulk_memset!(byte_value: 0)
@@ -494,7 +494,7 @@ pri func encoder.should_compress_two_pass!(input: roslice base.u8, from: base.u6
}
i ~mod+= 43
}
return this.sf.f64_lt(a: this.bits_entropy_of_histogram(), b: max_total_bit_cost) <> 0
return this.bc.f64_lt(a: this.bits_entropy_of_histogram(), b: max_total_bit_cost) <> 0
}
// Mirrors EmitUncompressedMetaBlock in compress_fragment_two_pass.c (which,