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

+12 -6
View File
@@ -41585,6 +41585,7 @@ wuffs_jpeg__decoder__decode_mcu__choosy_default(
uint32_t v_dc_blm1 = 0;
uint32_t v_dc_ht_slow = 0;
uint32_t v_dc_value = 0;
const uint16_t(* v_ac_huff_table_fast) = NULL;
uint8_t v_ac_h = 0;
uint32_t v_ac_symbol = 0;
uint32_t v_ac_ht_fast = 0;
@@ -41674,6 +41675,8 @@ wuffs_jpeg__decoder__decode_mcu__choosy_default(
goto label__dc_component__break;
}
label__dc_component__break:;
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 (true) {
if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) {
v_ret = 1u;
@@ -41682,8 +41685,7 @@ 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_h = self->private_impl.f_mcu_blocks_ac_hselector[self->private_impl.f_mcu_current_block];
v_ac_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_ac_h][(v_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);
@@ -41787,6 +41789,7 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits(
const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint32_t v_pos = 0;
const uint16_t(* v_ac_huff_table_fast) = NULL;
uint8_t v_ac_h = 0;
uint32_t v_ac_symbol = 0;
uint32_t v_ac_ht_fast = 0;
@@ -41833,6 +41836,8 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_high_bits(
((uint64_t)(self->private_impl.f_bitstream_ri)));
while (true) {
while (true) {
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 (true) {
if (((uint64_t)(io2_v_r - iop_v_r)) < 8u) {
v_ret = 1u;
@@ -41841,8 +41846,7 @@ 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_h = self->private_impl.f_mcu_blocks_ac_hselector[0u];
v_ac_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_ac_h][(v_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);
@@ -41943,6 +41947,7 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit(
const uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
const uint8_t* io2_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
uint32_t v_pos = 0;
const uint16_t(* v_ac_huff_table_fast) = NULL;
uint8_t v_ac_h = 0;
uint32_t v_ac_symbol = 0;
uint32_t v_ac_ht_fast = 0;
@@ -41984,6 +41989,8 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit(
if (self->private_impl.f_eob_run > 0u) {
goto label__goto_do_eob__break;
}
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 (true) {
if (((uint64_t)(io2_v_r - iop_v_r)) < 24u) {
v_ret = 1u;
@@ -41992,8 +41999,7 @@ wuffs_jpeg__decoder__decode_mcu_progressive_ac_low_bit(
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_h = self->private_impl.f_mcu_blocks_ac_hselector[0u];
v_ac_ht_fast = ((uint32_t)(self->private_impl.f_huff_tables_fast[v_ac_h][(v_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);
+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 {