Optimize deflate Huffman; tighten an if

name                             old speed     new speed     delta
wuffs_deflate_decode_1k/clang    148MB/s ± 0%  149MB/s ± 0%  +0.61%  (p=0.008 n=5+5)
wuffs_deflate_decode_10k/clang   228MB/s ± 1%  235MB/s ± 0%  +3.45%  (p=0.016 n=5+4)
wuffs_deflate_decode_100k/clang  253MB/s ± 0%  262MB/s ± 0%  +3.42%  (p=0.008 n=5+5)
wuffs_deflate_decode_1k/gcc      158MB/s ± 1%  157MB/s ± 0%  -0.44%  (p=0.032 n=5+5)
wuffs_deflate_decode_10k/gcc     265MB/s ± 0%  274MB/s ± 0%  +3.31%  (p=0.008 n=5+5)
wuffs_deflate_decode_100k/gcc    300MB/s ± 0%  317MB/s ± 0%  +5.45%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2018-10-07 18:13:25 +11:00
1 parent 0181537d0d
commit 34049e52d8
4 files changed
+35 -5

No files matched your search

+6 -4
View File
@@ -256,8 +256,9 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
// undoing that bias makes proving (dist_minus_1 + 1) > 0 trivial.
var dist_minus_1 base.u32[..0x7FFF] = (table_entry >> 8) & 0x7FFF
table_entry_n_bits = (table_entry >> 4) & 0x0F
// Ensure that we have at least 15 bits of input.
if n_bits < 15 {
// Ensure that we have at least table_entry_n_bits bits of input.
if n_bits < table_entry_n_bits {
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
assert n_bits >= 0 // TODO: this shouldn't be necessary.
bits |= (args.src.peek_u8() as base.u32) << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
@@ -265,10 +266,11 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
bits |= (args.src.peek_u8() as base.u32) << n_bits
args.src.skip_fast!(actual:1, worst_case:1)
n_bits += 8
assert n_bits >= 15
assert table_entry_n_bits <= n_bits via "a <= b: a <= c; c <= b"(c:16)
assert n_bits >= table_entry_n_bits via "a >= b: b <= a"()
}
// Once again, redundant but explicit assertions.
assert n_bits >= 15
assert n_bits >= table_entry_n_bits
dist_minus_1 = (dist_minus_1 + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
bits >>= table_entry_n_bits