std/jpeg: tighten EXTEND element type s/u32/u16/

I'm not sure of the underlying reason for the gcc benchmark anomaly (the
clang numbers don't change).

name                                             old speed     new speed     delta

wuffs_jpeg_decode_19k_8bpp/clang11               227MB/s ± 0%  227MB/s ± 0%     ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/clang11  209MB/s ± 0%  213MB/s ± 0%   +1.62%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/clang11   379MB/s ± 0%  380MB/s ± 0%   +0.13%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/clang11              329MB/s ± 0%  329MB/s ± 0%   +0.06%  (p=0.008 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/clang11         342MB/s ± 0%  342MB/s ± 0%     ~     (p=0.690 n=5+5)
wuffs_jpeg_decode_552k_24bpp_444/clang11         468MB/s ± 0%  469MB/s ± 0%   +0.10%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/clang11            348MB/s ± 0%  348MB/s ± 0%   +0.08%  (p=0.016 n=5+5)

wuffs_jpeg_decode_19k_8bpp/gcc10                 213MB/s ± 0%  213MB/s ± 0%     ~     (p=0.151 n=5+5)
wuffs_jpeg_decode_30k_24bpp_progressive/gcc10    221MB/s ± 0%  246MB/s ± 0%  +11.51%  (p=0.008 n=5+5)
wuffs_jpeg_decode_30k_24bpp_sequential/gcc10     487MB/s ± 0%  482MB/s ± 0%   -0.98%  (p=0.008 n=5+5)
wuffs_jpeg_decode_77k_24bpp/gcc10                392MB/s ± 0%  392MB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_jpeg_decode_552k_24bpp_420/gcc10           413MB/s ± 0%  412MB/s ± 0%     ~     (p=0.190 n=4+5)
wuffs_jpeg_decode_552k_24bpp_444/gcc10           459MB/s ± 0%  460MB/s ± 0%   +0.09%  (p=0.008 n=5+5)
wuffs_jpeg_decode_4002k_24bpp/gcc10              419MB/s ± 0%  419MB/s ± 0%   +0.04%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2023-06-18 21:35:49 +10:00
1 parent e4902dbd45
commit 36323abf87
6 files changed
+59 -59

No files matched your search

+9 -9
View File
@@ -123,18 +123,18 @@ pri const BIAS_AND_CLAMP : roarray[1024] base.u8 = [
// )
//
// func main() {
// for i := 0; i < 16; i++ {
// for t := 0; t < 16; t++ {
// // "V = (SLL –1 T) + 1" and SLL is "Shift Left Logical".
// v := (uint32(0xFFFF_FFFF) << t) + 1
// fmt.Printf("0x%08X,", v)
// if (i & 3) == 3 {
// v := (uint16(0xFFFF) << t) + 1
// fmt.Printf("0x%04X,", v)
// if (t & 3) == 3 {
// fmt.Println()
// }
// }
// }
pri const EXTEND : roarray[16] base.u32 = [
0x0000_0000, 0xFFFF_FFFF, 0xFFFF_FFFD, 0xFFFF_FFF9,
0xFFFF_FFF1, 0xFFFF_FFE1, 0xFFFF_FFC1, 0xFFFF_FF81,
0xFFFF_FF01, 0xFFFF_FE01, 0xFFFF_FC01, 0xFFFF_F801,
0xFFFF_F001, 0xFFFF_E001, 0xFFFF_C001, 0xFFFF_8001,
pri const EXTEND : roarray[16] base.u16 = [
0x0000, 0xFFFF, 0xFFFD, 0xFFF9,
0xFFF1, 0xFFE1, 0xFFC1, 0xFF81,
0xFF01, 0xFE01, 0xFC01, 0xF801,
0xF001, 0xE001, 0xC001, 0x8001,
]
+10 -10
View File
@@ -35,8 +35,8 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
var dc_code : base.u32
var dc_blm1 : base.u32[..= 15]
var dc_ht_slow : base.u32
var dc_value : base.u32
var dc_extend : base.u32
var dc_value : base.u16
var dc_extend : base.u16
var ac_huff_table_fast : nptr roarray[256] base.u16
@@ -47,8 +47,8 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
var ac_code : base.u32
var ac_blm1 : base.u32[..= 15]
var ac_ht_slow : base.u32
var ac_value : base.u32
var ac_extend : base.u32
var ac_value : base.u16
var ac_extend : base.u16
var ac_rrrr : base.u32[..= 15]
var ac_ssss : base.u32[..= 15]
@@ -123,13 +123,13 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
//
// The dc_value is shifted by (64 - dc_symbol) in two steps,
// because we want to shift by 64 (not 0) when dc_symbol is 0.
dc_value = (((bits >> 32) >> (32 - dc_symbol)) & 0xFFFF_FFFF) as base.u32
dc_value = (((bits >> 32) >> (32 - dc_symbol)) & 0xFFFF) as base.u16
dc_value ~mod+= dc_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF_FFFF) as base.u32) ^ 0xFFFF_FFFF)
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= dc_symbol
n_bits ~mod-= dc_symbol
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[this.mcu_current_block]]
this.mcu_previous_dc_values[csel] ~mod+= (dc_value & 0xFFFF) as base.u16
this.mcu_previous_dc_values[csel] ~mod+= dc_value
this.mcu_blocks[0][0] =
this.mcu_previous_dc_values[csel]
@@ -209,14 +209,14 @@ pri func decoder.decode_mcu!(workbuf: slice base.u8, mx: base.u32[..= 0x1FFF], m
// Process the ac_value in the next ac_ssss (up to 15) bits.
if ac_ssss > 0 {
ac_value = ((bits >> (64 - ac_ssss)) & 0xFFFF_FFFF) as base.u32
ac_value = ((bits >> (64 - ac_ssss)) & 0xFFFF) as base.u16
ac_value ~mod+= ac_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF_FFFF) as base.u32) ^ 0xFFFF_FFFF)
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= ac_ssss
n_bits ~mod-= ac_ssss
z += ac_rrrr + 1
this.mcu_blocks[0][UNZIG[z]] =
(ac_value & 0xFFFF) as base.u16
ac_value
} else if ac_rrrr < 15 {
break.ac_components
} else {
@@ -30,8 +30,8 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
var ac_code : base.u32
var ac_blm1 : base.u32[..= 15]
var ac_ht_slow : base.u32
var ac_value : base.u32
var ac_extend : base.u32
var ac_value : base.u16
var ac_extend : base.u16
var ac_rrrr : base.u32[..= 15]
var ac_ssss : base.u32[..= 15]
@@ -126,9 +126,9 @@ pri func decoder.decode_mcu_progressive_ac_high_bits!(workbuf: slice base.u8, mx
// Process the ac_value in the next ac_ssss (up to 15) bits or
// the eob_run in the next ac_rrrr (up to 15) bits.
if ac_ssss > 0 {
ac_value = ((bits >> (64 - ac_ssss)) & 0xFFFF_FFFF) as base.u32
ac_value = ((bits >> (64 - ac_ssss)) & 0xFFFF) as base.u16
ac_value ~mod+= ac_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF_FFFF) as base.u32) ^ 0xFFFF_FFFF)
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= ac_ssss
n_bits ~mod-= ac_ssss
z += ac_rrrr + 1
@@ -32,7 +32,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
var ac_code : base.u32
var ac_blm1 : base.u32[..= 15]
var ac_ht_slow : base.u32
var ac_value : base.u32
var ac_value : base.u16
var ac_rrrr : base.u32[..= 15]
var ac_ssss : base.u32[..= 15]
@@ -124,9 +124,9 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
// the eob_run in the next ac_rrrr (up to 15) bits.
ac_value = 0
if ac_ssss > 0 {
ac_value = (0x0000_0001 as base.u32) << this.scan_al
ac_value = (0x0001 as base.u16) << this.scan_al
if (bits >> 63) == 0 {
ac_value = (0xFFFF_FFFF as base.u32) ~mod<< this.scan_al
ac_value = (0xFFFF as base.u16) ~mod<< this.scan_al
}
bits ~mod<<= 1
n_bits ~mod-= 1
@@ -179,7 +179,7 @@ pri func decoder.decode_mcu_progressive_ac_low_bit!(workbuf: slice base.u8, mx:
} endwhile.refine_non_zeroes
if ac_value <> 0 {
this.mcu_blocks[0][UNZIG[1 + this.mcu_zig_index]] = (ac_value & 0xFFFF) as base.u16
this.mcu_blocks[0][UNZIG[1 + this.mcu_zig_index]] = ac_value
}
if this.mcu_zig_index >= (this.scan_se as base.u32) {
@@ -30,8 +30,8 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
var dc_code : base.u32
var dc_blm1 : base.u32[..= 15]
var dc_ht_slow : base.u32
var dc_value : base.u32
var dc_extend : base.u32
var dc_value : base.u16
var dc_extend : base.u16
bits = this.bitstream_bits
n_bits = this.bitstream_n_bits
@@ -95,13 +95,13 @@ pri func decoder.decode_mcu_progressive_dc_high_bits!(workbuf: slice base.u8, mx
//
// The dc_value is shifted by (64 - dc_symbol) in two steps,
// because we want to shift by 64 (not 0) when dc_symbol is 0.
dc_value = (((bits >> 32) >> (32 - dc_symbol)) & 0xFFFF_FFFF) as base.u32
dc_value = (((bits >> 32) >> (32 - dc_symbol)) & 0xFFFF) as base.u16
dc_value ~mod+= dc_extend &
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF_FFFF) as base.u32) ^ 0xFFFF_FFFF)
(((this.util.sign_extend_rshift_u64(a: bits, n: 63) & 0xFFFF) as base.u16) ^ 0xFFFF)
bits ~mod<<= dc_symbol
n_bits ~mod-= dc_symbol
csel = this.scan_comps_cselector[this.mcu_blocks_sselector[this.mcu_current_block]]
this.mcu_previous_dc_values[csel] ~mod+= (dc_value & 0xFFFF) as base.u16
this.mcu_previous_dc_values[csel] ~mod+= dc_value
this.mcu_blocks[this.mcu_current_block][0] =
this.mcu_previous_dc_values[csel] ~mod<< this.scan_al