std/jpeg: memoize ac_huff_table_fast

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               215MB/s ± 0%  226MB/s ± 0%  +5.17%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  209MB/s ± 0%  210MB/s ± 0%  +0.50%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   368MB/s ± 0%  380MB/s ± 1%  +3.11%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              313MB/s ± 0%  327MB/s ± 0%  +4.27%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         326MB/s ± 0%  338MB/s ± 0%  +3.50%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         462MB/s ± 0%  468MB/s ± 0%  +1.14%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            329MB/s ± 1%  346MB/s ± 0%  +5.39%  (p=0.008 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 174MB/s ± 0%  175MB/s ± 0%  +0.55%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    228MB/s ± 0%  248MB/s ± 0%  +8.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     472MB/s ± 0%  478MB/s ± 0%  +1.20%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                327MB/s ± 0%  328MB/s ± 0%  +0.47%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           344MB/s ± 0%  346MB/s ± 0%  +0.46%  (p=0.016 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           422MB/s ± 0%  424MB/s ± 0%  +0.49%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              349MB/s ± 0%  348MB/s ± 0%  -0.24%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2023-06-13 22:38:29 +10:00
1 parent 19f56ebfd2
commit dd6a5d5435
4 files changed
+44 -17

No files matched your search

+7 -2
View File
@@ -37,6 +37,8 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
var dc_ht_slow : base.u32
var dc_value : base.u32
var ac_huff_table_fast : nptr roarray[256] base.u16
var ac_h : base.u8[..= 7]
var ac_symbol : base.u32[..= 0xFF]
var ac_ht_fast : base.u32
@@ -131,8 +133,11 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
break.dc_component
} endwhile.dc_component
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,
inv this.mcu_current_block < 10,
inv ac_huff_table_fast <> nullptr,
{
// Load at least 31 bits, by keeping 56 .. 64 loaded.
if r.length() < 8 {
@@ -144,8 +149,7 @@ 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_h = this.mcu_blocks_ac_hselector[this.mcu_current_block]
ac_ht_fast = this.huff_tables_fast[ac_h][bits >> 56] as base.u32
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
@@ -158,6 +162,7 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
n_bits ~mod-= 9
while true,
inv this.mcu_current_block < 10,
inv ac_huff_table_fast <> nullptr,
{
ac_ht_slow = this.huff_tables_slow[ac_h][ac_blm1]
if ac_code < (ac_ht_slow >> 8) {
@@ -21,6 +21,8 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
var r : base.io_reader
var pos : base.u32
var ac_huff_table_fast : nptr roarray[256] base.u16
var ac_h : base.u8[..= 7]
var ac_symbol : base.u32[..= 0xFF]
var ac_ht_fast : base.u32
@@ -50,7 +52,11 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
while.goto_done true {{
while.block true {
while.ac_components true {
ac_h = this.mcu_blocks_ac_hselector[0]
ac_huff_table_fast = this.huff_tables_fast[ac_h][..] as ptr array[256] base.u16
while.ac_components true,
inv ac_huff_table_fast <> nullptr,
{
// Load at least 31 bits, by keeping 56 .. 64 loaded.
if r.length() < 8 {
ret = 1 // Request another fill_bitstream call.
@@ -61,8 +67,7 @@ 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_h = this.mcu_blocks_ac_hselector[0]
ac_ht_fast = this.huff_tables_fast[ac_h][bits >> 56] as base.u32
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
@@ -73,7 +78,9 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
ac_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true {
while true,
inv ac_huff_table_fast <> nullptr,
{
ac_ht_slow = this.huff_tables_slow[ac_h][ac_blm1]
if ac_code < (ac_ht_slow >> 8) {
ac_symbol = this.huff_tables_symbols[ac_h][0xFF & (ac_code ~mod+ ac_ht_slow)] as base.u32
@@ -23,6 +23,8 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
var r : base.io_reader
var pos : base.u32
var ac_huff_table_fast : nptr roarray[256] base.u16
var ac_h : base.u8[..= 7]
var ac_symbol : base.u32[..= 0xFF]
var ac_ht_fast : base.u32
@@ -55,7 +57,11 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
break.goto_do_eob
}
while.ac_components true {
ac_h = this.mcu_blocks_ac_hselector[0]
ac_huff_table_fast = this.huff_tables_fast[ac_h][..] as ptr array[256] base.u16
while.ac_components true,
inv ac_huff_table_fast <> nullptr,
{
// Load at least 31 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)
@@ -77,8 +83,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
n_bits |= 56
// Read the Huffman-encoded ac_symbol, up to 16 bits long.
ac_h = this.mcu_blocks_ac_hselector[0]
ac_ht_fast = this.huff_tables_fast[ac_h][bits >> 56] as base.u32
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
@@ -89,7 +94,9 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
ac_blm1 = 8
bits ~mod<<= 9
n_bits ~mod-= 9
while true {
while true,
inv ac_huff_table_fast <> nullptr,
{
ac_ht_slow = this.huff_tables_slow[ac_h][ac_blm1]
if ac_code < (ac_ht_slow >> 8) {
ac_symbol = this.huff_tables_symbols[ac_h][0xFF & (ac_code ~mod+ ac_ht_slow)] as base.u32
@@ -132,7 +139,9 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
}
// Consume 1 bit per non-zero AC coefficient, up to 63 bits.
while.refine_non_zeroes true {
while.refine_non_zeroes true,
inv ac_huff_table_fast <> nullptr,
{
unzig = UNZIG[this.mcu_zig_index]
if this.mcu_blocks[0][unzig] <> 0 {
if n_bits == 0 {