mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
std/jpeg: check up-front for sufficient AC bits
The micro-benchmarks are mixed for now, but this sets us up to remove an inner-loop bounds check in a future commit. name old speed new speed delta wuffs_jpeg_decode_19k_8bpp/clang11 226MB/s ± 0% 224MB/s ± 1% -1.03% (p=0.029 n=4+4) wuffs_jpeg_decode_30k_24bpp_progressive/clang11 210MB/s ± 0% 206MB/s ± 0% -1.59% (p=0.029 n=4+4) wuffs_jpeg_decode_30k_24bpp_sequential/clang11 379MB/s ± 0% 374MB/s ± 0% -1.25% (p=0.016 n=4+5) wuffs_jpeg_decode_77k_24bpp/clang11 326MB/s ± 0% 319MB/s ± 0% -2.35% (p=0.029 n=4+4) wuffs_jpeg_decode_552k_24bpp_420/clang11 338MB/s ± 0% 329MB/s ± 0% -2.53% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/clang11 468MB/s ± 0% 465MB/s ± 0% -0.58% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/clang11 347MB/s ± 0% 332MB/s ± 0% -4.41% (p=0.016 n=4+5) wuffs_jpeg_decode_19k_8bpp/gcc10 174MB/s ± 0% 176MB/s ± 0% +1.18% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/gcc10 247MB/s ± 0% 246MB/s ± 0% -0.55% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/gcc10 477MB/s ± 0% 472MB/s ± 0% -0.90% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/gcc10 328MB/s ± 0% 334MB/s ± 0% +1.69% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/gcc10 346MB/s ± 0% 351MB/s ± 0% +1.57% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/gcc10 424MB/s ± 0% 425MB/s ± 0% +0.39% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/gcc10 350MB/s ± 0% 349MB/s ± 0% -0.23% (p=0.008 n=5+5)
This commit is contained in:
1 parent
2ca61b521f
commit
143991a301
5 files changed
+46
-8
No files matched your search
@@ -133,6 +133,18 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
break.dc_component
|
||||
} endwhile.dc_component
|
||||
|
||||
// Ensure that we have enough bits for the entire
|
||||
// while.ac_components loop.
|
||||
//
|
||||
// Worst case, there are 63 AC components (round that up to 64) and
|
||||
// each one needs (16 + 15) bits (round that up to 4 bytes), so we
|
||||
// need (64 * 4) = 256 bytes of buffer. Add 8 bytes slack so that
|
||||
// we can always call peek_u64be.
|
||||
if r.length() < 264 {
|
||||
ret = 1 // Request another fill_bitstream call.
|
||||
break.goto_done
|
||||
}
|
||||
|
||||
ac_h = this.mcu_blocks_ac_hselector[this.mcu_current_block]
|
||||
ac_huff_table_fast = this.huff_tables_fast[ac_h][..] as ptr array[256] base.u16
|
||||
while.ac_components true,
|
||||
@@ -140,8 +152,10 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
|
||||
inv ac_huff_table_fast <> nullptr,
|
||||
{
|
||||
// Load at least 31 bits, by keeping 56 .. 64 loaded.
|
||||
//
|
||||
// TODO: eliminate this bounds check entirely.
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user