mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Use a table, not a formula, to get low bits mask
It's not an optimization per se. It addresses the fact that, in the C programming language, if u is an uint32_t value, then (u<<32) is undefined behavior, so ((1<<32)-1) isn't necessarily 0xFFFFFFFF: https://stackoverflow.com/questions/7401888/why-doesnt-left-bit-shift-for-32-bit-integers-work-as-expected-when-used name old speed new speed delta wuffs_deflate_decode_1k/clang 147MB/s ± 1% 147MB/s ± 0% ~ (p=0.206 n=49+5) wuffs_deflate_decode_10k/clang 234MB/s ± 1% 239MB/s ± 0% +2.24% (p=0.000 n=49+5) wuffs_deflate_decode_100k/clang 261MB/s ± 0% 270MB/s ± 0% +3.38% (p=0.000 n=48+5) wuffs_deflate_decode_1k/gcc 160MB/s ± 1% 160MB/s ± 0% ~ (p=0.322 n=43+5) wuffs_deflate_decode_10k/gcc 270MB/s ± 1% 272MB/s ± 0% +0.93% (p=0.000 n=46+5) wuffs_deflate_decode_100k/gcc 313MB/s ± 1% 322MB/s ± 0% +2.97% (p=0.000 n=42+5) wuffs_gif_decode_1k_bw/clang 253MB/s ± 1% 259MB/s ± 1% +2.28% (p=0.000 n=45+5) wuffs_gif_decode_1k_color/clang 116MB/s ± 1% 128MB/s ± 0% +11.20% (p=0.000 n=45+5) wuffs_gif_decode_10k/clang 135MB/s ± 1% 154MB/s ± 1% +14.39% (p=0.000 n=44+5) wuffs_gif_decode_100k_artificial/clang 429MB/s ± 1% 426MB/s ± 0% -0.70% (p=0.000 n=48+5) wuffs_gif_decode_100k_realistic/clang 162MB/s ± 0% 171MB/s ± 0% +6.13% (p=0.000 n=43+5) wuffs_gif_decode_1000k/clang 163MB/s ± 1% 172MB/s ± 0% +6.04% (p=0.000 n=50+5) wuffs_gif_decode_anim_screencap/clang 900MB/s ± 0% 909MB/s ± 0% +1.06% (p=0.000 n=45+5) wuffs_gif_decode_1k_bw/gcc 268MB/s ± 1% 269MB/s ± 0% +0.63% (p=0.000 n=49+5) wuffs_gif_decode_1k_color/gcc 133MB/s ± 1% 135MB/s ± 1% +1.45% (p=0.000 n=50+5) wuffs_gif_decode_10k/gcc 160MB/s ± 1% 158MB/s ± 0% -1.24% (p=0.000 n=48+5) wuffs_gif_decode_100k_artificial/gcc 448MB/s ± 1% 446MB/s ± 0% -0.40% (p=0.039 n=50+5) wuffs_gif_decode_100k_realistic/gcc 180MB/s ± 1% 177MB/s ± 0% -1.48% (p=0.000 n=50+5) wuffs_gif_decode_1000k/gcc 182MB/s ± 1% 179MB/s ± 0% -1.39% (p=0.000 n=48+5) wuffs_gif_decode_anim_screencap/gcc 963MB/s ± 1% 960MB/s ± 0% -0.33% (p=0.022 n=47+5) wuffs_gzip_decode_10k/clang 215MB/s ± 1% 221MB/s ± 0% +2.46% (p=0.000 n=49+5) wuffs_gzip_decode_100k/clang 239MB/s ± 1% 246MB/s ± 0% +3.03% (p=0.000 n=47+5) wuffs_gzip_decode_10k/gcc 248MB/s ± 0% 248MB/s ± 0% ~ (p=0.469 n=45+5) wuffs_gzip_decode_100k/gcc 290MB/s ± 1% 291MB/s ± 0% +0.34% (p=0.007 n=49+5) wuffs_lzw_decode_20k/clang 187MB/s ± 0% 199MB/s ± 2% +6.45% (p=0.000 n=49+5) wuffs_lzw_decode_100k/clang 304MB/s ± 1% 329MB/s ± 1% +8.44% (p=0.000 n=46+5) wuffs_lzw_decode_20k/gcc 223MB/s ± 1% 208MB/s ± 2% -6.78% (p=0.000 n=46+5) wuffs_lzw_decode_100k/gcc 364MB/s ± 1% 352MB/s ± 0% -3.39% (p=0.000 n=49+5) wuffs_zlib_decode_10k/clang 214MB/s ± 0% 216MB/s ± 1% +0.69% (p=0.026 n=49+5) wuffs_zlib_decode_100k/clang 237MB/s ± 0% 242MB/s ± 0% +2.37% (p=0.000 n=48+5) wuffs_zlib_decode_10k/gcc 247MB/s ± 1% 245MB/s ± 1% -0.69% (p=0.001 n=44+5) wuffs_zlib_decode_100k/gcc 288MB/s ± 1% 288MB/s ± 1% ~ (p=0.629 n=47+5)
This commit is contained in:
1 parent
717d98441e
commit
92ecd0a901
4 files changed
+106
-18
No files matched your search
@@ -3357,15 +3357,15 @@ wuffs_base__store_u64le(uint8_t* p, uint64_t x) {
|
||||
|
||||
// --------
|
||||
|
||||
// TODO: do we need to care about (1 << 32) being re-interpreted as (1 << 0)
|
||||
// on some architectures??
|
||||
//
|
||||
// Should the first "1" be "(uint32_t)1"?
|
||||
extern const uint8_t wuffs_base__low_bits_mask__u8[9];
|
||||
extern const uint16_t wuffs_base__low_bits_mask__u16[17];
|
||||
extern const uint32_t wuffs_base__low_bits_mask__u32[33];
|
||||
extern const uint64_t wuffs_base__low_bits_mask__u64[65];
|
||||
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U8(n) ((1 << (n)) - 1)
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U16(n) ((1 << (n)) - 1)
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U32(n) ((1 << (n)) - 1)
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U64(n) ((1 << (n)) - 1)
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U8(n) (wuffs_base__low_bits_mask__u8[n])
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U16(n) (wuffs_base__low_bits_mask__u16[n])
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U32(n) (wuffs_base__low_bits_mask__u32[n])
|
||||
#define WUFFS_BASE__LOW_BITS_MASK__U64(n) (wuffs_base__low_bits_mask__u64[n])
|
||||
|
||||
// --------
|
||||
|
||||
@@ -3751,6 +3751,49 @@ wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)
|
||||
|
||||
const uint8_t wuffs_base__low_bits_mask__u8[9] = {
|
||||
0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF,
|
||||
};
|
||||
|
||||
const uint16_t wuffs_base__low_bits_mask__u16[17] = {
|
||||
0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,
|
||||
0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,
|
||||
};
|
||||
|
||||
const uint32_t wuffs_base__low_bits_mask__u32[33] = {
|
||||
0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F,
|
||||
0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
|
||||
0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF,
|
||||
0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
|
||||
0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF,
|
||||
0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
const uint64_t wuffs_base__low_bits_mask__u64[65] = {
|
||||
0x0000000000000000, 0x0000000000000001, 0x0000000000000003,
|
||||
0x0000000000000007, 0x000000000000000F, 0x000000000000001F,
|
||||
0x000000000000003F, 0x000000000000007F, 0x00000000000000FF,
|
||||
0x00000000000001FF, 0x00000000000003FF, 0x00000000000007FF,
|
||||
0x0000000000000FFF, 0x0000000000001FFF, 0x0000000000003FFF,
|
||||
0x0000000000007FFF, 0x000000000000FFFF, 0x000000000001FFFF,
|
||||
0x000000000003FFFF, 0x000000000007FFFF, 0x00000000000FFFFF,
|
||||
0x00000000001FFFFF, 0x00000000003FFFFF, 0x00000000007FFFFF,
|
||||
0x0000000000FFFFFF, 0x0000000001FFFFFF, 0x0000000003FFFFFF,
|
||||
0x0000000007FFFFFF, 0x000000000FFFFFFF, 0x000000001FFFFFFF,
|
||||
0x000000003FFFFFFF, 0x000000007FFFFFFF, 0x00000000FFFFFFFF,
|
||||
0x00000001FFFFFFFF, 0x00000003FFFFFFFF, 0x00000007FFFFFFFF,
|
||||
0x0000000FFFFFFFFF, 0x0000001FFFFFFFFF, 0x0000003FFFFFFFFF,
|
||||
0x0000007FFFFFFFFF, 0x000000FFFFFFFFFF, 0x000001FFFFFFFFFF,
|
||||
0x000003FFFFFFFFFF, 0x000007FFFFFFFFFF, 0x00000FFFFFFFFFFF,
|
||||
0x00001FFFFFFFFFFF, 0x00003FFFFFFFFFFF, 0x00007FFFFFFFFFFF,
|
||||
0x0000FFFFFFFFFFFF, 0x0001FFFFFFFFFFFF, 0x0003FFFFFFFFFFFF,
|
||||
0x0007FFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x001FFFFFFFFFFFFF,
|
||||
0x003FFFFFFFFFFFFF, 0x007FFFFFFFFFFFFF, 0x00FFFFFFFFFFFFFF,
|
||||
0x01FFFFFFFFFFFFFF, 0x03FFFFFFFFFFFFFF, 0x07FFFFFFFFFFFFFF,
|
||||
0x0FFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF,
|
||||
0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
|
||||
};
|
||||
|
||||
const char* wuffs_base__warning__end_of_data = "~base: end of data";
|
||||
const char* wuffs_base__suspension__short_read = "$base: short read";
|
||||
const char* wuffs_base__suspension__short_write = "$base: short write";
|
||||
|
||||
Reference in new issue
Block a user