mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Optimize out unnecessary use_save_code variable.
I'm not sure why there's such a dramatic improvement, but I'll take it. name old speed new speed delta bench_lzw_decode_20k/clang 116MB/s ± 0% 125MB/s ± 0% +8.01% (p=0.029 n=4+4) bench_lzw_decode_100k/clang 154MB/s ± 0% 172MB/s ± 0% +11.86% (p=0.016 n=5+4) bench_gif_decode_1k/clang 285MB/s ± 1% 390MB/s ± 1% +36.86% (p=0.008 n=5+5) bench_gif_decode_10k/clang 122MB/s ± 0% 135MB/s ± 1% +10.44% (p=0.008 n=5+5) bench_gif_decode_100k/clang 110MB/s ± 0% 120MB/s ± 0% +9.27% (p=0.008 n=5+5) bench_gif_decode_1000k/clang 112MB/s ± 0% 122MB/s ± 5% +8.36% (p=0.016 n=4+5) bench_lzw_decode_20k/gcc 138MB/s ± 2% 155MB/s ± 0% +12.34% (p=0.008 n=5+5) bench_lzw_decode_100k/gcc 175MB/s ± 2% 200MB/s ± 0% +14.60% (p=0.008 n=5+5) bench_gif_decode_1k/gcc 389MB/s ± 3% 417MB/s ± 0% +7.29% (p=0.008 n=5+5) bench_gif_decode_10k/gcc 141MB/s ± 1% 146MB/s ± 0% +3.93% (p=0.008 n=5+5) bench_gif_decode_100k/gcc 128MB/s ± 2% 134MB/s ± 0% +4.88% (p=0.008 n=5+5) bench_gif_decode_1000k/gcc 130MB/s ± 2% 137MB/s ± 0% +5.94% (p=0.008 n=5+5)
This commit is contained in:
1 parent
94dcc14b44
commit
3a46d6ce36
3 files changed
+11
-22
No files matched your search
+5
-12
@@ -126,7 +126,6 @@ typedef struct {
|
|||||||
uint32_t coro_state;
|
uint32_t coro_state;
|
||||||
uint32_t v_clear_code;
|
uint32_t v_clear_code;
|
||||||
uint32_t v_end_code;
|
uint32_t v_end_code;
|
||||||
bool v_use_save_code;
|
|
||||||
uint32_t v_save_code;
|
uint32_t v_save_code;
|
||||||
uint32_t v_prev_code;
|
uint32_t v_prev_code;
|
||||||
uint32_t v_width;
|
uint32_t v_width;
|
||||||
@@ -1043,7 +1042,6 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
|
|
||||||
uint32_t v_clear_code;
|
uint32_t v_clear_code;
|
||||||
uint32_t v_end_code;
|
uint32_t v_end_code;
|
||||||
bool v_use_save_code;
|
|
||||||
uint32_t v_save_code;
|
uint32_t v_save_code;
|
||||||
uint32_t v_prev_code;
|
uint32_t v_prev_code;
|
||||||
uint32_t v_width;
|
uint32_t v_width;
|
||||||
@@ -1084,7 +1082,6 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
if (coro_state) {
|
if (coro_state) {
|
||||||
v_clear_code = self->private_impl.c_decode[0].v_clear_code;
|
v_clear_code = self->private_impl.c_decode[0].v_clear_code;
|
||||||
v_end_code = self->private_impl.c_decode[0].v_end_code;
|
v_end_code = self->private_impl.c_decode[0].v_end_code;
|
||||||
v_use_save_code = self->private_impl.c_decode[0].v_use_save_code;
|
|
||||||
v_save_code = self->private_impl.c_decode[0].v_save_code;
|
v_save_code = self->private_impl.c_decode[0].v_save_code;
|
||||||
v_prev_code = self->private_impl.c_decode[0].v_prev_code;
|
v_prev_code = self->private_impl.c_decode[0].v_prev_code;
|
||||||
v_width = self->private_impl.c_decode[0].v_width;
|
v_width = self->private_impl.c_decode[0].v_width;
|
||||||
@@ -1099,7 +1096,6 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
|
|
||||||
v_clear_code = (((uint32_t)(1)) << self->private_impl.f_literal_width);
|
v_clear_code = (((uint32_t)(1)) << self->private_impl.f_literal_width);
|
||||||
v_end_code = (v_clear_code + 1);
|
v_end_code = (v_clear_code + 1);
|
||||||
v_use_save_code = 0;
|
|
||||||
v_save_code = v_end_code;
|
v_save_code = v_end_code;
|
||||||
v_prev_code = 0;
|
v_prev_code = 0;
|
||||||
v_width = (self->private_impl.f_literal_width + 1);
|
v_width = (self->private_impl.f_literal_width + 1);
|
||||||
@@ -1129,13 +1125,12 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
*b_wptr_dst++ = ((uint8_t)(v_code));
|
*b_wptr_dst++ = ((uint8_t)(v_code));
|
||||||
if (v_use_save_code) {
|
if (v_save_code <= 4095) {
|
||||||
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_code));
|
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_code));
|
||||||
self->private_impl.f_prefixes[v_save_code] =
|
self->private_impl.f_prefixes[v_save_code] =
|
||||||
((uint16_t)(v_prev_code));
|
((uint16_t)(v_prev_code));
|
||||||
}
|
}
|
||||||
} else if (v_code == v_clear_code) {
|
} else if (v_code == v_clear_code) {
|
||||||
v_use_save_code = false;
|
|
||||||
v_save_code = v_end_code;
|
v_save_code = v_end_code;
|
||||||
v_prev_code = 0;
|
v_prev_code = 0;
|
||||||
v_width = (self->private_impl.f_literal_width + 1);
|
v_width = (self->private_impl.f_literal_width + 1);
|
||||||
@@ -1146,7 +1141,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
} else if (v_code <= v_save_code) {
|
} else if (v_code <= v_save_code) {
|
||||||
v_s = 4095;
|
v_s = 4095;
|
||||||
v_c = v_code;
|
v_c = v_code;
|
||||||
if ((v_code == v_save_code) && v_use_save_code) {
|
if (v_code == v_save_code) {
|
||||||
v_s -= 1;
|
v_s -= 1;
|
||||||
v_c = v_prev_code;
|
v_c = v_prev_code;
|
||||||
}
|
}
|
||||||
@@ -1160,7 +1155,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
|
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
|
||||||
}
|
}
|
||||||
self->private_impl.f_stack[v_s] = ((uint8_t)(v_c));
|
self->private_impl.f_stack[v_s] = ((uint8_t)(v_c));
|
||||||
if ((v_code == v_save_code) && v_use_save_code) {
|
if (v_code == v_save_code) {
|
||||||
self->private_impl.f_stack[4095] = ((uint8_t)(v_c));
|
self->private_impl.f_stack[4095] = ((uint8_t)(v_c));
|
||||||
}
|
}
|
||||||
PUFFS_COROUTINE_STATE(3);
|
PUFFS_COROUTINE_STATE(3);
|
||||||
@@ -1176,7 +1171,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
memmove(b_wptr_dst, self->private_impl.f_stack + v_s,
|
memmove(b_wptr_dst, self->private_impl.f_stack + v_s,
|
||||||
sizeof(self->private_impl.f_stack) - v_s);
|
sizeof(self->private_impl.f_stack) - v_s);
|
||||||
b_wptr_dst += sizeof(self->private_impl.f_stack) - v_s;
|
b_wptr_dst += sizeof(self->private_impl.f_stack) - v_s;
|
||||||
if (v_use_save_code) {
|
if (v_save_code <= 4095) {
|
||||||
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_c));
|
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_c));
|
||||||
self->private_impl.f_prefixes[v_save_code] =
|
self->private_impl.f_prefixes[v_save_code] =
|
||||||
((uint16_t)(v_prev_code));
|
((uint16_t)(v_prev_code));
|
||||||
@@ -1185,8 +1180,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
status = puffs_gif_error_lzw_code_is_out_of_range;
|
status = puffs_gif_error_lzw_code_is_out_of_range;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
v_use_save_code = (v_save_code < 4095);
|
if (v_save_code <= 4095) {
|
||||||
if (v_use_save_code) {
|
|
||||||
v_save_code += 1;
|
v_save_code += 1;
|
||||||
if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) {
|
if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) {
|
||||||
v_width += 1;
|
v_width += 1;
|
||||||
@@ -1202,7 +1196,6 @@ suspend:
|
|||||||
self->private_impl.c_decode[0].coro_state = coro_state;
|
self->private_impl.c_decode[0].coro_state = coro_state;
|
||||||
self->private_impl.c_decode[0].v_clear_code = v_clear_code;
|
self->private_impl.c_decode[0].v_clear_code = v_clear_code;
|
||||||
self->private_impl.c_decode[0].v_end_code = v_end_code;
|
self->private_impl.c_decode[0].v_end_code = v_end_code;
|
||||||
self->private_impl.c_decode[0].v_use_save_code = v_use_save_code;
|
|
||||||
self->private_impl.c_decode[0].v_save_code = v_save_code;
|
self->private_impl.c_decode[0].v_save_code = v_save_code;
|
||||||
self->private_impl.c_decode[0].v_prev_code = v_prev_code;
|
self->private_impl.c_decode[0].v_prev_code = v_prev_code;
|
||||||
self->private_impl.c_decode[0].v_width = v_width;
|
self->private_impl.c_decode[0].v_width = v_width;
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ typedef struct {
|
|||||||
uint32_t coro_state;
|
uint32_t coro_state;
|
||||||
uint32_t v_clear_code;
|
uint32_t v_clear_code;
|
||||||
uint32_t v_end_code;
|
uint32_t v_end_code;
|
||||||
bool v_use_save_code;
|
|
||||||
uint32_t v_save_code;
|
uint32_t v_save_code;
|
||||||
uint32_t v_prev_code;
|
uint32_t v_prev_code;
|
||||||
uint32_t v_width;
|
uint32_t v_width;
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
|||||||
var end_code u32[5..257] = clear_code + 1
|
var end_code u32[5..257] = clear_code + 1
|
||||||
|
|
||||||
// These variables do change.
|
// These variables do change.
|
||||||
var use_save_code bool
|
var save_code u32[..4096] = end_code // 4096 means do not save.
|
||||||
var save_code u32[..4095] = end_code
|
|
||||||
var prev_code u32[..4095]
|
var prev_code u32[..4095]
|
||||||
var width u32[..12] = this.literal_width + 1
|
var width u32[..12] = this.literal_width + 1
|
||||||
|
|
||||||
@@ -51,13 +50,12 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
|||||||
if code < clear_code {
|
if code < clear_code {
|
||||||
assert code < 256 via "a < b: a < c; c <= b"(c:clear_code)
|
assert code < 256 via "a < b: a < c; c <= b"(c:clear_code)
|
||||||
in.dst.write_u8?(x:code as u8)
|
in.dst.write_u8?(x:code as u8)
|
||||||
if use_save_code {
|
if save_code <= 4095 {
|
||||||
this.suffixes[save_code] = code as u8
|
this.suffixes[save_code] = code as u8
|
||||||
this.prefixes[save_code] = prev_code as u16
|
this.prefixes[save_code] = prev_code as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if code == clear_code {
|
} else if code == clear_code {
|
||||||
use_save_code = false
|
|
||||||
save_code = end_code
|
save_code = end_code
|
||||||
prev_code = 0
|
prev_code = 0
|
||||||
width = this.literal_width + 1
|
width = this.literal_width + 1
|
||||||
@@ -70,7 +68,7 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
|||||||
var s u32[..4095] = 4095
|
var s u32[..4095] = 4095
|
||||||
var c u32[..4095] = code
|
var c u32[..4095] = code
|
||||||
|
|
||||||
if (code == save_code) and use_save_code {
|
if code == save_code {
|
||||||
s -= 1
|
s -= 1
|
||||||
c = prev_code
|
c = prev_code
|
||||||
}
|
}
|
||||||
@@ -88,7 +86,7 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
|||||||
}
|
}
|
||||||
this.stack[s] = c as u8
|
this.stack[s] = c as u8
|
||||||
|
|
||||||
if (code == save_code) and use_save_code {
|
if code == save_code {
|
||||||
this.stack[4095] = c as u8
|
this.stack[4095] = c as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +95,7 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
|||||||
// type checking, bounds checking and code generation for it).
|
// type checking, bounds checking and code generation for it).
|
||||||
in.dst.write?(x:s)
|
in.dst.write?(x:s)
|
||||||
|
|
||||||
if use_save_code {
|
if save_code <= 4095 {
|
||||||
this.suffixes[save_code] = c as u8
|
this.suffixes[save_code] = c as u8
|
||||||
this.prefixes[save_code] = prev_code as u16
|
this.prefixes[save_code] = prev_code as u16
|
||||||
}
|
}
|
||||||
@@ -106,8 +104,7 @@ pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
|||||||
return error "LZW code is out of range"
|
return error "LZW code is out of range"
|
||||||
}
|
}
|
||||||
|
|
||||||
use_save_code = save_code < 4095
|
if save_code <= 4095 {
|
||||||
if use_save_code {
|
|
||||||
save_code += 1
|
save_code += 1
|
||||||
if (save_code == ((1 as u32) << width)) and (width < 12) {
|
if (save_code == ((1 as u32) << width)) and (width < 12) {
|
||||||
width += 1
|
width += 1
|
||||||
|
|||||||
Reference in new issue
Block a user