Delete image_buffer linearization optimization

It helps at small image sizes, but it doesn't help at all for larger
images. The extra code is probably not worth it. Numbers below, old is
with the optimization, new is without.

name                             old speed      new speed      delta

wuffs_gif_decode_1k_bw/clang      307MB/s ± 2%   286MB/s ± 0%  -6.84%  (p=0.000 n=48+42)
wuffs_gif_decode_1k_color/clang   137MB/s ± 1%   134MB/s ± 0%  -2.36%  (p=0.000 n=46+44)
wuffs_gif_decode_10k/clang        125MB/s ± 2%   125MB/s ± 0%    ~     (p=0.617 n=46+45)
wuffs_gif_decode_100k/clang       119MB/s ± 1%   119MB/s ± 0%    ~     (p=0.827 n=47+43)
wuffs_gif_decode_1000k/clang      121MB/s ± 1%   121MB/s ± 1%  +0.31%  (p=0.022 n=49+46)

wuffs_gif_decode_1k_bw/gcc        320MB/s ± 1%   304MB/s ± 1%  -4.77%  (p=0.000 n=48+46)
wuffs_gif_decode_1k_color/gcc     156MB/s ± 1%   153MB/s ± 1%  -2.08%  (p=0.000 n=46+49)
wuffs_gif_decode_10k/gcc          141MB/s ± 1%   141MB/s ± 0%  -0.06%  (p=0.012 n=44+46)
wuffs_gif_decode_100k/gcc         126MB/s ± 1%   127MB/s ± 0%  +0.76%  (p=0.000 n=45+42)
wuffs_gif_decode_1000k/gcc        129MB/s ± 1%   130MB/s ± 1%  +0.89%  (p=0.000 n=46+44)
This commit is contained in:
Nigel Tao committed 2018-05-29 08:15:19 +10:00
1 parent 3c3e6fc2fa
commit c723329263
2 files changed
-116

No files matched your search

-65
View File
@@ -3626,74 +3626,12 @@ static wuffs_gif__status wuffs_gif__decoder__copy_to_image_buffer(
uint32_t v_n;
uint32_t v_new_ri;
wuffs_base__table_u8 v_tab;
uint64_t v_i;
v_dst = ((wuffs_base__slice_u8){});
v_src = ((wuffs_base__slice_u8){});
v_n = 0;
v_new_ri = 0;
v_tab = wuffs_base__image_buffer__plane(a_ib, 0);
if (!self->private_impl.f_interlace &&
(((uint64_t)(v_tab.width)) == ((uint64_t)(v_tab.stride))) &&
(self->private_impl.f_dst_x0 == 0) &&
(((uint64_t)(self->private_impl.f_dst_x1)) ==
((uint64_t)(v_tab.width))) &&
(((uint64_t)(self->private_impl.f_dst_y1)) <=
((uint64_t)(v_tab.height)))) {
if (self->private_impl.f_uncompressed_ri >
self->private_impl.f_uncompressed_wi) {
status = WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_RI_WI;
goto exit;
}
v_src = wuffs_base__slice_u8__subslice_ij(
((wuffs_base__slice_u8){.ptr = self->private_impl.f_uncompressed,
.len = 4096}),
self->private_impl.f_uncompressed_ri,
self->private_impl.f_uncompressed_wi);
if (self->private_impl.f_dst_y >= self->private_impl.f_dst_y1) {
status = WUFFS_GIF__ERROR_TOO_MUCH_PIXEL_DATA;
goto exit;
}
v_i = 0;
v_dst = wuffs_base__table_u8__linearize(v_tab);
v_i = (((uint64_t)(self->private_impl.f_dst_y1)) *
((uint64_t)(self->private_impl.f_dst_x1)));
if (v_i < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_j(v_dst, v_i);
}
v_i = ((((uint64_t)(self->private_impl.f_dst_y)) *
((uint64_t)(self->private_impl.f_dst_x1))) +
((uint64_t)(self->private_impl.f_dst_x)));
if (v_i < ((uint64_t)(v_dst.len))) {
v_dst = wuffs_base__slice_u8__subslice_i(v_dst, v_i);
v_n = ((uint32_t)(
(wuffs_base__slice_u8__copy_from_slice(v_dst, v_src) & 4294967295)));
v_new_ri =
wuffs_base__u32__sat_add(self->private_impl.f_uncompressed_ri, v_n);
self->private_impl.f_uncompressed_ri =
wuffs_base__u32__min(v_new_ri, 4096);
wuffs_base__u64__sat_add_indirect(&v_i, ((uint64_t)(v_n)));
if (((uint64_t)(v_tab.width)) <= 0) {
status = WUFFS_GIF__ERROR_TOO_MUCH_PIXEL_DATA;
goto exit;
}
self->private_impl.f_dst_x =
((uint32_t)(((v_i % ((uint64_t)(v_tab.width))) & 4294967295)));
self->private_impl.f_dst_y =
((uint32_t)(((v_i / ((uint64_t)(v_tab.width))) & 4294967295)));
}
if (self->private_impl.f_uncompressed_ri ==
self->private_impl.f_uncompressed_wi) {
self->private_impl.f_uncompressed_ri = 0;
self->private_impl.f_uncompressed_wi = 0;
} else if (self->private_impl.f_uncompressed_ri >
self->private_impl.f_uncompressed_wi) {
status = WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_RI_WI;
goto exit;
}
status = WUFFS_GIF__STATUS_OK;
goto ok;
}
label_0_continue:;
while (self->private_impl.f_uncompressed_wi >
self->private_impl.f_uncompressed_ri) {
@@ -3767,9 +3705,6 @@ label_0_continue:;
label_0_break:;
self->private_impl.f_uncompressed_ri = 0;
self->private_impl.f_uncompressed_wi = 0;
goto ok;
ok:
goto exit;
exit:
return status;
-51
View File
@@ -525,57 +525,6 @@ pri func decoder.copy_to_image_buffer?(ib ptr base.image_buffer)() {
var tab table base.u8 = in.ib.plane(p:0)
// As an optimization, linearize tab's rows into one big slice, in order to
// make fewer copy_from_slice calls.
//
// TODO: measure this optimization and delete it if it doesn't help.
if (not this.interlace) and (tab.width() == tab.stride()) and (this.dst_x0 == 0) and
((this.dst_x1 as base.u64) == tab.width()) and
((this.dst_y1 as base.u64) <= tab.height()) {
if this.uncompressed_ri > this.uncompressed_wi {
return error "internal error: inconsistent ri/wi"
}
src = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi]
if this.dst_y >= this.dst_y1 {
return error "too much pixel data"
}
var i base.u64
dst = tab.linearize()
i = ((this.dst_y1 as base.u64) * (this.dst_x1 as base.u64))
if i < dst.length() {
dst = dst[:i]
}
i = ((this.dst_y as base.u64) * (this.dst_x1 as base.u64)) + (this.dst_x as base.u64)
if i < dst.length() {
dst = dst[i:]
n = (dst.copy_from_slice(s:src) & 0xFFFFFFFF) as base.u32
new_ri = this.uncompressed_ri ~sat+ n
this.uncompressed_ri = new_ri.min(x:4096)
i ~sat+= n as base.u64
if tab.width() <= 0 {
return error "too much pixel data"
}
this.dst_x = ((i % tab.width()) & 0xFFFFFFFF) as base.u32
this.dst_y = ((i / tab.width()) & 0xFFFFFFFF) as base.u32
}
if this.uncompressed_ri == this.uncompressed_wi {
this.uncompressed_ri = 0
this.uncompressed_wi = 0
} else if this.uncompressed_ri > this.uncompressed_wi {
return error "internal error: inconsistent ri/wi"
}
return
}
while this.uncompressed_wi > this.uncompressed_ri {
assert this.uncompressed_ri < this.uncompressed_wi via "a < b: b > a"()
src = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi]