mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
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:
16 files changed
+2650
-400
No files matched your search
@@ -332,25 +332,25 @@ pri func encoder.should_merge_block!(input: roslice base.u8, from: base.u64, len
|
||||
|
||||
total = (args.len ~mod+ 42) / 43
|
||||
// r = (FastLog2(total) + 0.5) * (double)total + 200.
|
||||
r = this.sf.f64_add(
|
||||
a: this.sf.f64_mul(
|
||||
a: this.sf.f64_add(a: this.fast_log2(v: total), b: 0x3FE0_0000_0000_0000),
|
||||
b: this.sf.f64_from_u64(a: total)),
|
||||
r = this.bc.f64_add(
|
||||
a: this.bc.f64_mul(
|
||||
a: this.bc.f64_add(a: this.fast_log2(v: total), b: 0x3FE0_0000_0000_0000),
|
||||
b: this.bc.f64_from_u64(a: total)),
|
||||
b: 0x4069_0000_0000_0000)
|
||||
j = 0
|
||||
while j < 256 {
|
||||
// r -= (double)histo[i] * (depths[i] + FastLog2(histo[i])).
|
||||
h = this.histogram[j] as base.u64
|
||||
r = this.sf.f64_sub(
|
||||
r = this.bc.f64_sub(
|
||||
a: r,
|
||||
b: this.sf.f64_mul(
|
||||
a: this.sf.f64_from_u64(a: h),
|
||||
b: this.sf.f64_add(
|
||||
a: this.sf.f64_from_u32(a: this.lit_depth[j] as base.u32),
|
||||
b: this.bc.f64_mul(
|
||||
a: this.bc.f64_from_u64(a: h),
|
||||
b: this.bc.f64_add(
|
||||
a: this.bc.f64_from_u32(a: this.lit_depth[j] as base.u32),
|
||||
b: this.fast_log2(v: h))))
|
||||
j ~mod+= 1
|
||||
}
|
||||
return this.sf.f64_ge(a: r, b: 0) <> 0
|
||||
return this.bc.f64_ge(a: r, b: 0) <> 0
|
||||
}
|
||||
|
||||
// Mirrors ShouldUseUncompressedMode in compress_fragment.c.
|
||||
|
||||
Reference in new issue
Block a user