mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Remove some if's from deflate.decode_huffman_fast
name old speed new speed delta wuffs_deflate_decode_1k/clang 145MB/s ± 0% 151MB/s ± 1% +4.54% (p=0.008 n=5+5) wuffs_deflate_decode_10k/clang 234MB/s ± 0% 230MB/s ± 0% -1.75% (p=0.008 n=5+5) wuffs_deflate_decode_100k/clang 263MB/s ± 0% 276MB/s ± 1% +5.17% (p=0.008 n=5+5) wuffs_deflate_decode_1k/gcc 157MB/s ± 1% 157MB/s ± 0% ~ (p=0.421 n=5+5) wuffs_deflate_decode_10k/gcc 265MB/s ± 0% 259MB/s ± 0% -2.16% (p=0.008 n=5+5) wuffs_deflate_decode_100k/gcc 313MB/s ± 0% 315MB/s ± 0% +0.39% (p=0.016 n=5+5) wuffs_gzip_decode_10k/clang 216MB/s ± 0% 212MB/s ± 0% -1.69% (p=0.016 n=5+4) wuffs_gzip_decode_100k/clang 241MB/s ± 0% 252MB/s ± 0% +4.67% (p=0.016 n=5+4) wuffs_gzip_decode_10k/gcc 251MB/s ± 1% 248MB/s ± 1% -1.05% (p=0.008 n=5+5) wuffs_gzip_decode_100k/gcc 285MB/s ± 1% 291MB/s ± 0% +2.16% (p=0.008 n=5+5) wuffs_zlib_decode_10k/clang 213MB/s ± 0% 210MB/s ± 0% -1.18% (p=0.008 n=5+5) wuffs_zlib_decode_100k/clang 239MB/s ± 0% 247MB/s ± 0% +3.08% (p=0.008 n=5+5) wuffs_zlib_decode_10k/gcc 244MB/s ± 0% 247MB/s ± 0% +1.15% (p=0.008 n=5+5) wuffs_zlib_decode_100k/gcc 282MB/s ± 0% 291MB/s ± 0% +2.90% (p=0.008 n=5+5)
This commit is contained in:
1 parent
776e82d542
commit
3e70383c6c
6 files changed
+52
-55
No files matched your search
@@ -153,8 +153,11 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// length = base_number + extra_bits.
|
||||
var length base.u32[..0x7FFF] = (table_entry >> 8) & 0x7FFF
|
||||
// length = base_number_minus_3 + 3 + extra_bits.
|
||||
//
|
||||
// The -3 is from the bias in script/print-deflate-magic-numbers.go.
|
||||
// That bias makes the "& 0xFF" 1 and 15-ish lines below correct.
|
||||
var length base.u32[..258] = ((table_entry >> 8) & 0xFF) + 3
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
if table_entry_n_bits > 0 {
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
@@ -174,16 +177,15 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
assert args.src.available() >= 6
|
||||
assert n_bits >= 15
|
||||
|
||||
length = (length + bits.low_bits(n:table_entry_n_bits)) & 0x7FFF
|
||||
// The "+ 253" is the same as "- 3", after the "& 0xFF", but the
|
||||
// plus form won't require an underflow check.
|
||||
length = ((length + 253 + bits.low_bits(n:table_entry_n_bits)) & 0xFF) + 3
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
|
||||
} else {
|
||||
assert args.src.available() >= 6
|
||||
}
|
||||
if length > 258 {
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
@@ -252,7 +254,7 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
// distance = dist_minus_1 + 1.
|
||||
//
|
||||
// The -1 is from the bias in script/print-deflate-magic-numbers.go.
|
||||
// That bias makes the "& 0x7FFF" 15-ish lines below correct and
|
||||
// That bias makes the "& 0x7FFF" 2 and 15-ish lines below correct and
|
||||
// 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
|
||||
@@ -281,7 +283,6 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
// its presence minimizes the diff between decode_huffman_fast and
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre length <= 258,
|
||||
pre args.dst.available() >= 258,
|
||||
{
|
||||
// Copy from this.history.
|
||||
@@ -297,14 +298,9 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c:length)
|
||||
length -= hdist
|
||||
hlen = hdist
|
||||
// TODO: this if check should be redundant.
|
||||
if length > 258 {
|
||||
return "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
} else {
|
||||
hlen = length
|
||||
length = 0
|
||||
assert length <= 258
|
||||
}
|
||||
if this.history_index < hdist {
|
||||
return "?bad distance"
|
||||
@@ -324,7 +320,6 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
// "etc", but its presence minimizes the diff between
|
||||
// decode_huffman_fast and decode_huffman_slow.
|
||||
while true,
|
||||
inv length <= 258,
|
||||
inv args.dst.available() >= 258,
|
||||
{
|
||||
// TODO: copy_from_slice32 should probably update the
|
||||
@@ -350,7 +345,6 @@ pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert length <= 258
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= args.dst.since_mark().length()
|
||||
assert args.dst.available() >= 258
|
||||
|
||||
|
||||
Reference in new issue
Block a user