mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 16:32:11 +01:00
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:
1 parent
0181537d0d
commit
34049e52d8
4 files changed
+35
-5
No files matched your search
@@ -138,6 +138,18 @@ var reasons = [...]struct {
|
||||
return nil
|
||||
}},
|
||||
|
||||
{`"a > b: b < a"`, func(q *checker, n *a.Assert) error {
|
||||
op, xa, xb := parseBinaryOp(n.Condition())
|
||||
if op != t.IDXBinaryGreaterThan {
|
||||
return errFailed
|
||||
}
|
||||
// b < a
|
||||
if err := proveReasonRequirement(q, t.IDXBinaryLessThan, xb, xa); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
|
||||
{`"a <= b: b >= a"`, func(q *checker, n *a.Assert) error {
|
||||
op, xa, xb := parseBinaryOp(n.Condition())
|
||||
if op != t.IDXBinaryLessEq {
|
||||
@@ -210,6 +222,18 @@ var reasons = [...]struct {
|
||||
return nil
|
||||
}},
|
||||
|
||||
{`"a >= b: b <= a"`, func(q *checker, n *a.Assert) error {
|
||||
op, xa, xb := parseBinaryOp(n.Condition())
|
||||
if op != t.IDXBinaryGreaterEq {
|
||||
return errFailed
|
||||
}
|
||||
// b <= a
|
||||
if err := proveReasonRequirement(q, t.IDXBinaryLessEq, xb, xa); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
|
||||
{`"a < (b + c): a < c; 0 <= b"`, func(q *checker, n *a.Assert) error {
|
||||
op, xa, t0 := parseBinaryOp(n.Condition())
|
||||
if op != t.IDXBinaryLessThan {
|
||||
|
||||
@@ -37,11 +37,15 @@ var reasons = [...]string{
|
||||
"a < b: a < c; c <= b",
|
||||
"a < b: a <= c; c < b",
|
||||
|
||||
"a > b: b < a",
|
||||
|
||||
"a <= b: b >= a",
|
||||
"a <= b: a <= c; c <= b",
|
||||
"a <= b: a <= c; c == b",
|
||||
"a <= b: a == c; c <= b",
|
||||
|
||||
"a >= b: b <= a",
|
||||
|
||||
"a < (b + c): a < c; 0 <= b",
|
||||
"a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c",
|
||||
|
||||
|
||||
@@ -5958,7 +5958,7 @@ label_0_continue:;
|
||||
}
|
||||
v_dist_minus_1 = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
if (v_n_bits < 15) {
|
||||
if (v_n_bits < v_table_entry_n_bits) {
|
||||
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
|
||||
(iop_a_src += 1, wuffs_base__return_empty_struct());
|
||||
v_n_bits += 8;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user