std/jpeg: tweak decode_mcu up-front r.length check

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               236MB/s ± 0%  237MB/s ± 0%  +0.11%  (p=0.032 n=4+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  210MB/s ± 0%  213MB/s ± 0%  +1.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   385MB/s ± 0%  384MB/s ± 0%    ~     (p=0.095 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              338MB/s ± 0%  338MB/s ± 0%    ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         353MB/s ± 0%  353MB/s ± 0%    ~     (p=0.548 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         481MB/s ± 0%  481MB/s ± 0%    ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            360MB/s ± 0%  359MB/s ± 0%  -0.35%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 244MB/s ± 0%  245MB/s ± 0%  +0.44%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    251MB/s ± 0%  247MB/s ± 0%  -1.46%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     509MB/s ± 0%  510MB/s ± 0%  +0.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                431MB/s ± 0%  432MB/s ± 0%  +0.24%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           455MB/s ± 0%  456MB/s ± 0%  +0.26%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           481MB/s ± 0%  484MB/s ± 0%  +0.56%  (p=0.016 n=4+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              463MB/s ± 0%  465MB/s ± 0%  +0.36%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2023-06-22 11:37:40 +10:00
1 parent 255516bc21
commit a00150f62f
6 files changed
+85 -58

No files matched your search

@@ -52,6 +52,16 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
while.goto_done true {{
while.block true {
// Ensure that we have enough bits for this iteration of the
// while.block loop body. Worst case, there are 64 components and
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
// need (64 * 4) = 256 bytes available. 8 more bytes of slack means
// that we can always call peek_u64be.
if r.length() < 264 {
ret = 1 // Request another fill_bitstream call.
break.goto_done
}
while.goto_do_eob true {{
if this.eob_run > 0 {
break.goto_do_eob
@@ -62,22 +72,9 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
while.ac_components true,
inv ac_huff_table_fast <> nullptr,
{
// Load at least 47 bits, by keeping 56 .. 64 loaded (call it 8
// bytes). Just like the other decode_mcu_etc functions, this
// is enough for the Huffman-encoded ac_symbol (up to 16 bits)
// and processing the ac_value (up to 15 bits).
//
// After that, it's simpler for this "AC low bit" flavor if we
// never suspend for the rest of this iteration of the
// while.ac_components loop.
//
// Specifically, we want to have enough bits in the bitstream
// so that we don't suspend inside the while.refine_non_zeroes
// loop. In the worst case, we need another 8 bytes for
// refining non-zero coefficients plus 8 bytes slack so that we
// can always call peek_u64be. 8 + 8 + 8 = 24 bytes in total.
if r.length() < 24 {
ret = 1 // Request another fill_bitstream call.
// Load at least 56 bits.
if r.length() < 8 {
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)
@@ -203,9 +200,9 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
unzig = UNZIG[1 + this.mcu_zig_index]
if this.mcu_blocks[0][unzig] <> 0 {
if n_bits == 0 {
// Load at least 1 bit, by keeping 56 .. 64 loaded.
// Load at least 56 bits.
if r.length() < 8 {
ret = 1 // Request another fill_bitstream call.
ret = 2 // Internal error.
break.goto_done
}
bits |= r.peek_u64be() >> (n_bits & 63)