mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Remove some suspensions from decode_huffman_fast.
name old speed new speed delta puffs_adler32_10k/clang 2.46GB/s ± 0% 2.46GB/s ± 0% ~ (p=0.243 n=10+9) puffs_adler32_100k/clang 2.46GB/s ± 0% 2.46GB/s ± 0% +0.07% (p=0.002 n=10+9) puffs_flate_decode_1k/clang 125MB/s ± 0% 124MB/s ± 0% -0.58% (p=0.000 n=10+8) puffs_flate_decode_10k/clang 168MB/s ± 0% 165MB/s ± 0% -2.07% (p=0.000 n=9+8) puffs_flate_decode_100k/clang 203MB/s ± 0% 195MB/s ± 0% -3.85% (p=0.000 n=9+9) puffs_zlib_decode_10k/clang 157MB/s ± 0% 154MB/s ± 1% -2.07% (p=0.000 n=9+9) puffs_zlib_decode_100k/clang 187MB/s ± 0% 181MB/s ± 0% -3.50% (p=0.000 n=10+10) puffs_adler32_10k/gcc 3.20GB/s ± 1% 3.26GB/s ± 0% +2.07% (p=0.000 n=10+9) puffs_adler32_100k/gcc 3.21GB/s ± 1% 3.27GB/s ± 0% +1.71% (p=0.000 n=9+9) puffs_flate_decode_1k/gcc 128MB/s ± 2% 112MB/s ± 0% -12.35% (p=0.000 n=10+10) puffs_flate_decode_10k/gcc 181MB/s ± 1% 155MB/s ± 0% -14.07% (p=0.000 n=10+10) puffs_flate_decode_100k/gcc 208MB/s ± 0% 176MB/s ± 0% -15.23% (p=0.000 n=9+9) puffs_zlib_decode_10k/gcc 172MB/s ± 1% 137MB/s ± 0% -20.14% (p=0.000 n=10+9) puffs_zlib_decode_100k/gcc 195MB/s ± 1% 158MB/s ± 0% -18.97% (p=0.000 n=10+9)
This commit is contained in:
1 parent
44323f95ad
commit
934705a6e1
3 files changed
+61
-50
No files matched your search
+34
-36
@@ -2188,39 +2188,37 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 28) == 1) {
|
||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
while (true) {
|
||||
if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry =
|
||||
self->private_impl
|
||||
.f_huffs[1][v_redir_top + (v_bits & v_redir_mask)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
if (v_n_bits >= v_table_entry_n_bits) {
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
goto label_1_break;
|
||||
}
|
||||
if (v_n_bits < 15) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_8 = *b_rptr_src++;
|
||||
v_bits |= (((uint32_t)(t_8)) << v_n_bits);
|
||||
}
|
||||
v_n_bits += 8;
|
||||
{
|
||||
uint8_t t_9 = *b_rptr_src++;
|
||||
v_bits |= (((uint32_t)(t_9)) << v_n_bits);
|
||||
}
|
||||
v_n_bits += 8;
|
||||
} else {
|
||||
}
|
||||
label_1_break:;
|
||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry = self->private_impl
|
||||
.f_huffs[1][v_redir_top + (v_bits & v_redir_mask)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if ((v_table_entry >> 24) != 64) {
|
||||
if ((v_table_entry >> 24) == 8) {
|
||||
@@ -2235,12 +2233,12 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
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(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_9 = *b_rptr_src++;
|
||||
v_bits |= (((uint32_t)(t_9)) << v_n_bits);
|
||||
uint8_t t_10 = *b_rptr_src++;
|
||||
v_bits |= (((uint32_t)(t_10)) << v_n_bits);
|
||||
}
|
||||
v_n_bits += 8;
|
||||
}
|
||||
@@ -2293,19 +2291,19 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
v_hlen);
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label_2_break;
|
||||
goto label_1_break;
|
||||
}
|
||||
if (v_n_copied > 0) {
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = ((v_hdist + v_n_copied) & 32767);
|
||||
if (v_hdist == 0) {
|
||||
goto label_2_break;
|
||||
goto label_1_break;
|
||||
}
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
label_2_break:;
|
||||
label_1_break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
v_n_copied = puffs_base__writer1__copy_from_slice32(
|
||||
@@ -2317,14 +2315,14 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
v_hlen);
|
||||
if (v_hlen <= v_n_copied) {
|
||||
v_hlen = 0;
|
||||
goto label_3_break;
|
||||
goto label_2_break;
|
||||
}
|
||||
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(6);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
label_3_break:;
|
||||
label_2_break:;
|
||||
}
|
||||
if (v_length == 0) {
|
||||
goto label_0_continue;
|
||||
@@ -2335,18 +2333,18 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
v_length);
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
goto label_4_break;
|
||||
goto label_3_break;
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
}
|
||||
label_4_break:;
|
||||
label_3_break:;
|
||||
}
|
||||
label_0_break:;
|
||||
while (v_n_bits >= 8) {
|
||||
v_n_bits -= 8;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (b_rptr_src == b_rstart_src) {
|
||||
status = PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION;
|
||||
goto exit;
|
||||
|
||||
@@ -194,26 +194,37 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
|
||||
|
||||
// Check for a redirect.
|
||||
if (table_entry >> 28) == 1 {
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
while true {
|
||||
if (redir_top + (bits & redir_mask)) >= 1234 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
if n_bits >= table_entry_n_bits {
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
break
|
||||
}
|
||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c:table_entry_n_bits)
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
if n_bits < 15 {
|
||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||
bits |= (in.src.read_u8?() as u32) << n_bits
|
||||
n_bits += 8
|
||||
bits |= (in.src.read_u8?() as u32) << n_bits
|
||||
n_bits += 8
|
||||
assert n_bits >= 15
|
||||
} else {
|
||||
assert in.src.available() >= 2
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert in.src.available() >= 2
|
||||
assert n_bits >= 15
|
||||
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
if (redir_top + (bits & redir_mask)) >= 1234 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits -= table_entry_n_bits
|
||||
|
||||
// TODO: redundant?
|
||||
if (table_entry >> 31) != 0 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
} else {
|
||||
assert in.src.available() >= 2
|
||||
}
|
||||
|
||||
// For H-D, all symbols should be base number + extra bits.
|
||||
|
||||
@@ -145,6 +145,8 @@ pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
||||
bits |= (in.src.read_u8?() as u32) << n_bits
|
||||
n_bits += 8
|
||||
}
|
||||
|
||||
// TODO: redundant?
|
||||
if (table_entry >> 31) != 0 {
|
||||
return error "internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user