mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
std/jpeg: read Huffman look-up table earlier
This commit is the first of two. It just changes code, and is the minimal code change that leads to these performance improvements. The follow-up commit will add comments that will also include a reference to this one's commit hash. Even later commits may do some more refactoring. name old speed new speed delta wuffs_jpeg_decode_19k_8bpp/clang11 224MB/s ± 0% 236MB/s ± 0% +5.38% (p=0.016 n=5+4) wuffs_jpeg_decode_30k_24bpp_progressive/clang11 211MB/s ± 0% 210MB/s ± 0% -0.55% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/clang11 377MB/s ± 0% 385MB/s ± 0% +1.91% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/clang11 328MB/s ± 0% 338MB/s ± 0% +3.23% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/clang11 341MB/s ± 0% 353MB/s ± 0% +3.47% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/clang11 472MB/s ± 0% 481MB/s ± 0% +1.93% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/clang11 347MB/s ± 0% 360MB/s ± 0% +3.70% (p=0.008 n=5+5) wuffs_jpeg_decode_19k_8bpp/gcc10 225MB/s ± 0% 244MB/s ± 0% +8.27% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/gcc10 246MB/s ± 0% 251MB/s ± 0% +1.67% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/gcc10 498MB/s ± 0% 509MB/s ± 0% +2.18% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/gcc10 408MB/s ± 0% 431MB/s ± 0% +5.86% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/gcc10 428MB/s ± 0% 455MB/s ± 0% +6.38% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/gcc10 470MB/s ± 0% 481MB/s ± 0% +2.46% (p=0.016 n=5+4) wuffs_jpeg_decode_4002k_24bpp/gcc10 433MB/s ± 0% 463MB/s ± 0% +7.03% (p=0.008 n=5+5)
This commit is contained in:
1 parent
bedf2bd7c3
commit
d9c7740ea6
3 files changed
+20
-4
No files matched your search
@@ -42108,11 +42108,15 @@ wuffs_jpeg__decoder__decode_mcu__choosy_default(
|
||||
v_ret = 1u;
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
if (v_n_bits < 16u) {
|
||||
v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u));
|
||||
}
|
||||
v_z = 1u;
|
||||
self->private_impl.f_mcu_zig_index = 0u;
|
||||
v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[self->private_impl.f_mcu_current_block];
|
||||
v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u];
|
||||
while (v_z < 64u) {
|
||||
v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)]));
|
||||
if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) {
|
||||
v_ret = 2u;
|
||||
goto label__goto_done__break;
|
||||
@@ -42120,7 +42124,6 @@ wuffs_jpeg__decoder__decode_mcu__choosy_default(
|
||||
v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u));
|
||||
iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u);
|
||||
v_n_bits |= 56u;
|
||||
v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)]));
|
||||
v_ac_bl = (v_ac_ht_fast >> 8u);
|
||||
if (v_n_bits >= v_ac_bl) {
|
||||
v_ac_symbol = (255u & v_ac_ht_fast);
|
||||
@@ -42267,11 +42270,15 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits(
|
||||
v_ret = 1u;
|
||||
goto label__goto_done__break;
|
||||
}
|
||||
if (v_n_bits < 16u) {
|
||||
v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u));
|
||||
}
|
||||
v_z = self->private_impl.f_mcu_zig_index;
|
||||
self->private_impl.f_mcu_zig_index = 0u;
|
||||
v_ac_h = self->private_impl.f_mcu_blocks_ac_hselector[0u];
|
||||
v_ac_huff_table_fast = &self->private_impl.f_huff_tables_fast[v_ac_h][0u];
|
||||
while (v_z <= ((uint32_t)(self->private_impl.f_scan_se))) {
|
||||
v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)]));
|
||||
if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) {
|
||||
v_ret = 2u;
|
||||
goto label__goto_done__break;
|
||||
@@ -42279,7 +42286,6 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits(
|
||||
v_bits |= (wuffs_base__peek_u64be__no_bounds_check(iop_v_r) >> (v_n_bits & 63u));
|
||||
iop_v_r += ((63u - (v_n_bits & 63u)) >> 3u);
|
||||
v_n_bits |= 56u;
|
||||
v_ac_ht_fast = ((uint32_t)(v_ac_huff_table_fast[(v_bits >> 56u)]));
|
||||
v_ac_bl = (v_ac_ht_fast >> 8u);
|
||||
if (v_n_bits >= v_ac_bl) {
|
||||
v_ac_symbol = (255u & v_ac_ht_fast);
|
||||
|
||||
@@ -149,6 +149,10 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
break.goto_done
|
||||
}
|
||||
|
||||
if n_bits < 16 {
|
||||
bits |= r.peek_u64be() >> (n_bits & 63)
|
||||
}
|
||||
|
||||
z = 1
|
||||
this.mcu_zig_index = 0
|
||||
ac_h = this.mcu_blocks_ac_hselector[this.mcu_current_block]
|
||||
@@ -157,6 +161,8 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
inv this.mcu_current_block < 10,
|
||||
inv ac_huff_table_fast <> nullptr,
|
||||
{
|
||||
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
|
||||
|
||||
// Load at least 31 bits, by keeping 56 .. 64 loaded.
|
||||
//
|
||||
// TODO: eliminate this bounds check entirely.
|
||||
@@ -169,7 +175,6 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
|
||||
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
|
||||
ac_bl = ac_ht_fast >> 8
|
||||
if n_bits >= ac_bl {
|
||||
ac_symbol = 0xFF & ac_ht_fast
|
||||
|
||||
@@ -65,6 +65,10 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
break.goto_done
|
||||
}
|
||||
|
||||
if n_bits < 16 {
|
||||
bits |= r.peek_u64be() >> (n_bits & 63)
|
||||
}
|
||||
|
||||
z = this.mcu_zig_index
|
||||
this.mcu_zig_index = 0
|
||||
ac_h = this.mcu_blocks_ac_hselector[0]
|
||||
@@ -74,6 +78,8 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
{
|
||||
assert z < 64 via "a < b: a <= c; c < b"(c: (this.scan_se as base.u32))
|
||||
|
||||
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
|
||||
|
||||
// Load at least 31 bits, by keeping 56 .. 64 loaded.
|
||||
//
|
||||
// TODO: eliminate this bounds check entirely.
|
||||
@@ -86,7 +92,6 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
|
||||
n_bits |= 56
|
||||
|
||||
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
|
||||
ac_ht_fast = ac_huff_table_fast[bits >> 56] as base.u32
|
||||
ac_bl = ac_ht_fast >> 8
|
||||
if n_bits >= ac_bl {
|
||||
ac_symbol = 0xFF & ac_ht_fast
|
||||
|
||||
Reference in new issue
Block a user