Re-order some decode_huffman checks.

name                           old speed     new speed     delta
puffs_flate_decode_1k/clang    112MB/s ± 1%  123MB/s ± 0%  +10.03%  (p=0.008 n=5+5)
puffs_flate_decode_10k/clang   135MB/s ± 0%  146MB/s ± 0%   +7.81%  (p=0.008 n=5+5)
puffs_flate_decode_100k/clang  154MB/s ± 0%  166MB/s ± 0%   +7.61%  (p=0.016 n=5+4)
puffs_zlib_decode_10k/clang    128MB/s ± 0%  138MB/s ± 0%   +7.79%  (p=0.008 n=5+5)
puffs_zlib_decode_100k/clang   145MB/s ± 0%  156MB/s ± 0%   +7.33%  (p=0.016 n=5+4)
puffs_flate_decode_1k/gcc      119MB/s ± 0%  128MB/s ± 0%   +7.49%  (p=0.029 n=4+4)
puffs_flate_decode_10k/gcc     138MB/s ± 1%  146MB/s ± 0%   +6.18%  (p=0.016 n=5+4)
puffs_flate_decode_100k/gcc    153MB/s ± 0%  164MB/s ± 0%   +6.92%  (p=0.029 n=4+4)
puffs_zlib_decode_10k/gcc      132MB/s ± 0%  140MB/s ± 0%   +6.13%  (p=0.016 n=5+4)
puffs_zlib_decode_100k/gcc     147MB/s ± 0%  156MB/s ± 0%   +6.48%  (p=0.016 n=5+4)
This commit is contained in:
Nigel Tao committed 2017-10-21 17:19:43 +11:00
1 parent b3c7360907
commit 76f7621221
2 files changed
+68 -37

No files matched your search

+40 -23
View File
@@ -1375,7 +1375,18 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_n_bits += 8;
}
label_1_break:;
if ((v_table_entry >> 28) == 1) {
if ((v_table_entry >> 31) != 0) {
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
if (b_wptr_dst == b_wend_dst) {
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
goto suspend;
}
*b_wptr_dst++ = ((v_table_entry >> 8) & 255);
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
goto label_0_break;
} else if ((v_table_entry >> 28) != 0) {
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
while (true) {
@@ -1393,7 +1404,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_n_bits -= v_table_entry_n_bits;
goto label_2_break;
}
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
@@ -1402,24 +1413,30 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_n_bits += 8;
}
label_2_break:;
if ((v_table_entry >> 28) == 1) {
if ((v_table_entry >> 31) != 0) {
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
if (b_wptr_dst == b_wend_dst) {
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
goto suspend;
}
*b_wptr_dst++ = ((v_table_entry >> 8) & 255);
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
goto label_0_break;
} else if ((v_table_entry >> 28) != 0) {
status =
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
goto exit;
} else if ((v_table_entry >> 27) != 0) {
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
goto exit;
} else {
status =
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
goto exit;
}
}
if ((v_table_entry >> 31) != 0) {
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (b_wptr_dst == b_wend_dst) {
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
goto suspend;
}
*b_wptr_dst++ = ((v_table_entry >> 8) & 255);
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
goto label_0_break;
} else if ((v_table_entry >> 24) == 8) {
} else if ((v_table_entry >> 27) != 0) {
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
goto exit;
} else {
@@ -1430,7 +1447,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_length = ((v_table_entry >> 8) & 32767);
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
while (v_n_bits < v_table_entry_n_bits) {
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
@@ -1451,7 +1468,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_n_bits -= v_table_entry_n_bits;
goto label_3_break;
}
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
@@ -1478,7 +1495,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_n_bits -= v_table_entry_n_bits;
goto label_4_break;
}
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
@@ -1505,7 +1522,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_distance = ((v_table_entry >> 8) & 32767);
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
while (v_n_bits < v_table_entry_n_bits) {
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
@@ -1557,7 +1574,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
}
}
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
}
label_5_break:;
if (v_hlen > 0) {
@@ -1576,7 +1593,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
v_hlen -= v_n_copied;
v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767);
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
}
label_6_break:;
}
@@ -1592,7 +1609,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
}
v_length -= v_n_copied;
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
}
label_7_break:;
}
+28 -14
View File
@@ -248,8 +248,18 @@ pri func flate_decoder.decode_huffman?(dst writer1, src reader1)() {
bits |= (in.src.read_u8?() as u32) << n_bits
n_bits += 8
}
// Check for a redirect.
if (table_entry >> 28) == 1 {
if (table_entry >> 31) != 0 {
// Literal.
in.dst.write_u8?(x:(table_entry >> 8) & 0xFF)
continue
} else if (table_entry >> 30) != 0 {
// No-op; code continues past the if-else chain.
} else if (table_entry >> 29) != 0 {
// End of block.
break
} else if (table_entry >> 28) != 0 {
// Redirect.
var redir_top u32[..0xFFFF] = (table_entry >> 8) & 0xFFFF
var redir_mask u32[..0x7FFF] = ((1 as u32) << ((table_entry >> 4) & 0x0F)) - 1
while true {
@@ -267,21 +277,25 @@ pri func flate_decoder.decode_huffman?(dst writer1, src reader1)() {
bits |= (in.src.read_u8?() as u32) << n_bits
n_bits += 8
}
if (table_entry >> 28) == 1 {
if (table_entry >> 31) != 0 {
// Literal.
in.dst.write_u8?(x:(table_entry >> 8) & 0xFF)
continue
} else if (table_entry >> 30) != 0 {
// No-op; code continues past the if-else chain.
} else if (table_entry >> 29) != 0 {
// End of block.
break
} else if (table_entry >> 28) != 0 {
return error "internal error: inconsistent Huffman decoder state"
} else if (table_entry >> 27) != 0 {
return error "bad Huffman code"
} else {
return error "internal error: inconsistent Huffman decoder state"
}
}
if (table_entry >> 31) != 0 {
// Literal.
in.dst.write_u8?(x:(table_entry >> 8) & 0xFF)
continue
} else if (table_entry >> 30) != 0 {
// No-op; code continues past the if-else chain.
} else if (table_entry >> 29) != 0 {
// End of block.
break
} else if (table_entry >> 24) == 0x08 {
} else if (table_entry >> 27) != 0 {
return error "bad Huffman code"
} else {
return error "internal error: inconsistent Huffman decoder state"