Bump decode_huffman_fast's src available hurdle.

We will need this later, to prove that the other read_u8 calls in
decode_huffman_fast will not suspend.

It's not obvious why the clang benchmarks don't change but the gcc ones
(including the adler numbers, which are superficially unrelated) look
worse. If the change from 6 to 12 bytes is a genuine performance
regression, then a future commit can tighten the bound back to 6,
although it would probably make the decode_huffman_fast assertions and
proof requirements considerably more complicated.

name                           old speed      new speed      delta

puffs_adler32_10k/clang        2.40GB/s ± 1%  2.41GB/s ± 0%    ~     (p=0.690 n=5+5)
puffs_adler32_100k/clang       2.39GB/s ± 2%  2.40GB/s ± 1%    ~     (p=1.000 n=5+5)
puffs_flate_decode_1k/clang     128MB/s ± 0%   128MB/s ± 0%    ~     (p=1.000 n=5+5)
puffs_flate_decode_10k/clang    167MB/s ± 2%   168MB/s ± 0%    ~     (p=0.548 n=5+5)
puffs_flate_decode_100k/clang   193MB/s ± 2%   194MB/s ± 0%    ~     (p=0.310 n=5+5)
puffs_zlib_decode_10k/clang     157MB/s ± 0%   155MB/s ± 4%    ~     (p=0.421 n=5+5)
puffs_zlib_decode_100k/clang    180MB/s ± 1%   177MB/s ± 3%    ~     (p=0.222 n=5+5)

puffs_adler32_10k/gcc          3.26GB/s ± 0%  3.20GB/s ± 1%  -1.81%  (p=0.008 n=5+5)
puffs_adler32_100k/gcc         3.26GB/s ± 0%  3.21GB/s ± 0%  -1.63%  (p=0.008 n=5+5)
puffs_flate_decode_1k/gcc       129MB/s ± 0%   126MB/s ± 1%  -2.30%  (p=0.008 n=5+5)
puffs_flate_decode_10k/gcc      164MB/s ± 0%   161MB/s ± 0%  -1.86%  (p=0.008 n=5+5)
puffs_flate_decode_100k/gcc     185MB/s ± 0%   180MB/s ± 3%  -2.81%  (p=0.016 n=4+5)
puffs_zlib_decode_10k/gcc       157MB/s ± 0%   151MB/s ± 2%  -3.49%  (p=0.008 n=5+5)
puffs_zlib_decode_100k/gcc      175MB/s ± 0%   170MB/s ± 2%  -2.97%  (p=0.016 n=4+5)
This commit is contained in:
Nigel Tao committed 2017-11-05 08:56:55 +11:00
1 parent 55e0bc513b
commit db57d8b707
2 files changed
+21 -4

No files matched your search

+1 -1
View File
@@ -2036,7 +2036,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
label_0_continue:;
while (((uint64_t)(b_rend_src - b_rptr_src)) >= 6) {
while (((uint64_t)(b_rend_src - b_rptr_src)) >= 12) {
if (v_n_bits < 15) {
{
uint8_t t_0 = *b_rptr_src++;
+20 -3
View File
@@ -30,7 +30,24 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
var lmask u32[..511] = ((1 as u32) << this.n_huffs_bits[0]) - 1
var dmask u32[..511] = ((1 as u32) << this.n_huffs_bits[1]) - 1
while:loop in.src.available() >= 6 {
// Strictly speaking, we only need 6 bytes (48 bits) of available input,
// because the H-L length/literal code is up to 15 bits plus up to 5 extra
// bits, the H-D distance code is up to 15 bits plus up to 13 extra bits
// and 15 + 5 + 15 + 13 == 48. However, in.src.available() assertions are
// made in terms of bytes, not bits.
//
// In theory, we could write assertions that mixed bytes and bits, such as:
//
// assert ((in.src.available() >= 6) and (n_bits >= 5)) or
// ((in.src.available() >= 4) and (n_bits >= 21))
//
// but that looks clumsy and makes the proofs more complicated. Instead, we
// are conservative and work in terms of bytes only. In bytes, each code
// requires either one (direct) or two (redirect) lookups, up to 2 bytes
// for each. There are also up to 13 extra bits, or 2 bytes. Thus, each
// code requires up to 2 + 2 + 2 == 6 bytes, and there are two codes (one
// from H-L and one from H-D). Therefore, we check for at least 12 bytes.
while:loop in.src.available() >= 12 {
// Ensure that we have at least 15 bits of input.
if n_bits < 15 {
assert n_bits >= 0 // TODO: this shouldn't be necessary.
@@ -40,13 +57,13 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
n_bits += 8
assert n_bits >= 15
} else {
assert in.src.available() >= 4
assert in.src.available() >= 10
}
// These assertions are redundant, but are listed explicitly for
// clarity. They must hold regardless of which branch was taken for the
// if statement above.
assert in.src.available() >= 4
assert in.src.available() >= 10
assert n_bits >= 15
// Decode an lcode symbol from H-L.