Re-organize flate Huffman decoder table bits.

Benchmarks are mixed, but it seems conceptually cleaner to arrange the
bits in the order that they're examined.

name                           old speed     new speed     delta
puffs_flate_decode_1k/clang    125MB/s ± 0%  123MB/s ± 1%  -1.91%  (p=0.008 n=5+5)
puffs_flate_decode_10k/clang   163MB/s ± 1%  157MB/s ± 0%  -3.55%  (p=0.008 n=5+5)
puffs_flate_decode_100k/clang  175MB/s ± 0%  173MB/s ± 0%  -0.75%  (p=0.016 n=4+5)
puffs_flate_decode_1k/gcc      127MB/s ± 0%  130MB/s ± 0%  +2.14%  (p=0.008 n=5+5)
puffs_flate_decode_10k/gcc     142MB/s ± 1%  149MB/s ± 0%  +4.99%  (p=0.016 n=5+4)
puffs_flate_decode_100k/gcc    162MB/s ± 2%  168MB/s ± 0%  +3.66%  (p=0.016 n=5+4)
This commit is contained in:
Nigel Tao committed 2017-10-06 13:07:49 +11:00
1 parent cec4e30245
commit cf6b1be5b5
5 files changed
+71 -68

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ func main1() error {
for j := 0; j < 32; j++ {
x := uint32(0x08000000)
if baseNumbers[i][j] != bad {
x = 0x20000000 | (baseNumbers[i][j] << 8) | (extraBits[i][j] << 4)
x = 0x40000000 | (baseNumbers[i][j] << 8) | (extraBits[i][j] << 4)
}
fmt.Printf("0x%08X,", x)
if j&7 == 7 {
+9 -8
View File
@@ -128,19 +128,20 @@ outer_loop:
uint32_t n = table_entry & 0x0F;
bits >>= n;
n_bits -= n;
if ((table_entry >> 30) == 1) {
if ((table_entry >> 31) != 0) {
// Literal.
*pdst++ = (uint8_t)(table_entry >> 8);
goto outer_loop;
}
if ((table_entry >> 29) == 1) {
// Back-reference.
if ((table_entry >> 30) != 0) {
// Back-reference; length = base number + extra bits.
break;
}
if ((table_entry >> 28) == 1) {
if ((table_entry >> 29) != 0) {
// End of block.
goto end;
}
if ((table_entry >> 24) != 0x80) {
if ((table_entry >> 24) != 0x10) {
status =
PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
goto end;
@@ -191,11 +192,11 @@ outer_loop:
uint32_t n = table_entry & 0x0F;
bits >>= n;
n_bits -= n;
if ((table_entry >> 29) == 1) {
// Back-reference.
if ((table_entry >> 30) != 0) {
// Back-reference; distance = base number + extra bits.
break;
}
if ((table_entry >> 24) != 0x80) {
if ((table_entry >> 24) != 0x10) {
status =
PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
goto end;