Use the workbuf instead of lzw.decoder.suffixes

This commit will soon be followed by a rollback, but it is committed
anyway so that we can refer to these numbers in the git log.

name                                     old speed      new speed      delta

wuffs_lzw_decode_20k/clang5               255MB/s ± 0%   241MB/s ± 0%   -5.63%  (p=0.008 n=5+5)
wuffs_lzw_decode_100k/clang5              418MB/s ± 1%   401MB/s ± 1%   -4.02%  (p=0.008 n=5+5)

wuffs_lzw_decode_20k/gcc7                 255MB/s ± 1%   235MB/s ± 0%   -7.88%  (p=0.008 n=5+5)
wuffs_lzw_decode_100k/gcc7                444MB/s ± 1%   382MB/s ± 0%  -13.90%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/clang5             239MB/s ± 2%   235MB/s ± 1%   -1.89%  (p=0.016 n=5+5)
wuffs_gif_decode_1k_color/clang5          135MB/s ± 0%   132MB/s ± 0%   -1.86%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/clang5          692MB/s ± 1%   678MB/s ± 0%   -2.08%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_indexed/clang5       186MB/s ± 0%   181MB/s ± 0%   -2.58%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/clang5               237MB/s ± 1%   226MB/s ± 0%   -4.46%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/clang5   536MB/s ± 0%   506MB/s ± 0%   -5.53%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_realistic/clang5    219MB/s ± 0%   203MB/s ± 1%   -7.11%  (p=0.008 n=5+5)
wuffs_gif_decode_1000k/clang5             222MB/s ± 0%   206MB/s ± 0%   -7.25%  (p=0.008 n=5+5)
wuffs_gif_decode_anim_screencap/clang5   1.07GB/s ± 0%  1.04GB/s ± 1%   -3.11%  (p=0.008 n=5+5)

wuffs_gif_decode_1k_bw/gcc7               262MB/s ± 0%   255MB/s ± 1%   -2.63%  (p=0.008 n=5+5)
wuffs_gif_decode_1k_color/gcc7            142MB/s ± 1%   137MB/s ± 1%   -3.38%  (p=0.008 n=5+5)
wuffs_gif_decode_10k_bgra/gcc7            596MB/s ± 1%   593MB/s ± 0%     ~     (p=0.151 n=5+5)
wuffs_gif_decode_10k_indexed/gcc7         185MB/s ± 0%   182MB/s ± 2%   -1.63%  (p=0.008 n=5+5)
wuffs_gif_decode_20k/gcc7                 230MB/s ± 0%   226MB/s ± 0%   -1.78%  (p=0.008 n=5+5)
wuffs_gif_decode_100k_artificial/gcc7     490MB/s ± 1%   488MB/s ± 0%     ~     (p=0.095 n=5+5)
wuffs_gif_decode_100k_realistic/gcc7      203MB/s ± 1%   203MB/s ± 0%     ~     (p=0.421 n=5+5)
wuffs_gif_decode_1000k/gcc7               207MB/s ± 0%   207MB/s ± 0%     ~     (p=1.000 n=5+5)
wuffs_gif_decode_anim_screencap/gcc7     1.04GB/s ± 0%  1.03GB/s ± 0%   -0.83%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2019-02-03 14:57:34 +11:00
1 parent d1f1340d47
commit f877fb2c59
7 files changed
+109 -59

No files matched your search

+6
View File
@@ -443,6 +443,9 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
if err := g.writeExpr(b, foo, depth); err != nil { if err := g.writeExpr(b, foo, depth); err != nil {
return err return err
} }
if foo.MType().IsSliceType() {
b.writes(".ptr")
}
if fIndex != nil { if fIndex != nil {
b.writes(")+(") b.writes(")+(")
if err := g.writeExpr(b, fIndex, depth); err != nil { if err := g.writeExpr(b, fIndex, depth); err != nil {
@@ -453,6 +456,9 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
if err := g.writeExpr(b, bar, depth); err != nil { if err := g.writeExpr(b, bar, depth); err != nil {
return err return err
} }
if bar.MType().IsSliceType() {
b.writes(".ptr")
}
if bIndex != nil { if bIndex != nil {
b.writes(")+(") b.writes(")+(")
if err := g.writeExpr(b, bIndex, depth); err != nil { if err := g.writeExpr(b, bIndex, depth); err != nil {
+19
View File
@@ -348,3 +348,22 @@ func proveReasonRequirement(q *checker, op t.ID, lhs *a.Expr, rhs *a.Expr) error
} }
return nil return nil
} }
func proveReasonRequirementForRHSLength(q *checker, op t.ID, lhs *a.Expr, rhs *a.Expr) error {
if err := proveReasonRequirement(q, op, lhs, rhs); err != nil {
if (op == t.IDXBinaryLessThan) || (op == t.IDXBinaryLessEq) {
for _, x := range q.facts {
// Try to prove "lhs op rhs" by proving "lhs op const", given a
// fact x of the form "rhs >= const".
if (x.Operator() == t.IDXBinaryGreaterEq) && x.LHS().AsExpr().Eq(rhs) &&
(x.RHS().AsExpr().ConstValue() != nil) &&
(proveReasonRequirement(q, op, lhs, x.RHS().AsExpr()) == nil) {
return nil
}
}
}
return err
}
return nil
}
+2 -2
View File
@@ -866,7 +866,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (bounds, error) {
if err := proveReasonRequirement(q, t.IDXBinaryLessEq, zeroExpr, rhs); err != nil { if err := proveReasonRequirement(q, t.IDXBinaryLessEq, zeroExpr, rhs); err != nil {
return bounds{}, err return bounds{}, err
} }
if err := proveReasonRequirement(q, t.IDXBinaryLessThan, rhs, lengthExpr); err != nil { if err := proveReasonRequirementForRHSLength(q, t.IDXBinaryLessThan, rhs, lengthExpr); err != nil {
return bounds{}, err return bounds{}, err
} }
@@ -915,7 +915,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (bounds, error) {
return bounds{}, err return bounds{}, err
} }
if rhs != lengthExpr { if rhs != lengthExpr {
if err := proveReasonRequirement(q, t.IDXBinaryLessEq, rhs, lengthExpr); err != nil { if err := proveReasonRequirementForRHSLength(q, t.IDXBinaryLessEq, rhs, lengthExpr); err != nil {
return bounds{}, err return bounds{}, err
} }
} }
+37 -29
View File
@@ -2820,11 +2820,11 @@ extern const char* wuffs_lzw__error__bad_code;
// ---------------- Public Consts // ---------------- Public Consts
#define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL 0 #define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL 32768
static const uint64_t // static const uint64_t //
wuffs_lzw__decoder_workbuf_len_max_incl // wuffs_lzw__decoder_workbuf_len_max_incl //
WUFFS_BASE__POTENTIALLY_UNUSED = 0; WUFFS_BASE__POTENTIALLY_UNUSED = 32768;
// ---------------- Struct Declarations // ---------------- Struct Declarations
@@ -2994,11 +2994,11 @@ extern const char* wuffs_gif__error__too_much_pixel_data;
// ---------------- Public Consts // ---------------- Public Consts
#define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL 65535 #define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL 98303
static const uint64_t // static const uint64_t //
wuffs_gif__decoder_workbuf_len_max_incl // wuffs_gif__decoder_workbuf_len_max_incl //
WUFFS_BASE__POTENTIALLY_UNUSED = 65535; WUFFS_BASE__POTENTIALLY_UNUSED = 98303;
// ---------------- Struct Declarations // ---------------- Struct Declarations
@@ -7738,7 +7738,8 @@ const char* wuffs_lzw__error__internal_error_inconsistent_i_o =
static wuffs_base__empty_struct // static wuffs_base__empty_struct //
wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self, wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
wuffs_base__io_reader a_src); wuffs_base__io_reader a_src,
wuffs_base__slice_u8 a_workbuf);
static wuffs_base__status // static wuffs_base__status //
wuffs_lzw__decoder__write_to(wuffs_lzw__decoder* self, wuffs_lzw__decoder__write_to(wuffs_lzw__decoder* self,
@@ -7853,15 +7854,23 @@ wuffs_lzw__decoder__decode_io_writer(wuffs_lzw__decoder* self,
self->private_impl.f_n_bits = 0; self->private_impl.f_n_bits = 0;
self->private_impl.f_output_ri = 0; self->private_impl.f_output_ri = 0;
self->private_impl.f_output_wi = 0; self->private_impl.f_output_wi = 0;
if (((uint64_t)(a_workbuf.len)) < 32768) {
status = wuffs_base__error__bad_workbuf_length;
goto exit;
}
v_i = 0; v_i = 0;
while (v_i < self->private_impl.f_clear_code) { while (v_i < self->private_impl.f_clear_code) {
self->private_impl.f_lm1s[v_i] = 0; self->private_impl.f_lm1s[v_i] = 0;
self->private_impl.f_suffixes[((8 * v_i) + 0)] = ((uint8_t)(v_i)); a_workbuf.ptr[((uint64_t)(((8 * v_i) + 0)))] = ((uint8_t)(v_i));
v_i += 1; v_i += 1;
} }
label_0_continue:; label_0_continue:;
while (true) { while (true) {
wuffs_lzw__decoder__read_from(self, a_src); if (((uint64_t)(a_workbuf.len)) < 32768) {
status = wuffs_base__error__bad_workbuf_length;
goto exit;
}
wuffs_lzw__decoder__read_from(self, a_src, a_workbuf);
if (self->private_impl.f_output_wi > 0) { if (self->private_impl.f_output_wi > 0) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_lzw__decoder__write_to(self, a_dst); status = wuffs_lzw__decoder__write_to(self, a_dst);
@@ -7909,7 +7918,8 @@ exit:
static wuffs_base__empty_struct // static wuffs_base__empty_struct //
wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self, wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
wuffs_base__io_reader a_src) { wuffs_base__io_reader a_src,
wuffs_base__slice_u8 a_workbuf) {
uint32_t v_clear_code = 0; uint32_t v_clear_code = 0;
uint32_t v_end_code = 0; uint32_t v_end_code = 0;
uint32_t v_save_code = 0; uint32_t v_save_code = 0;
@@ -7941,6 +7951,9 @@ wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
io1_a_src = a_src.private_impl.limit; io1_a_src = a_src.private_impl.limit;
} }
if (((uint64_t)(a_workbuf.len)) < 32768) {
return ((wuffs_base__empty_struct){});
}
v_clear_code = self->private_impl.f_clear_code; v_clear_code = self->private_impl.f_clear_code;
v_end_code = self->private_impl.f_end_code; v_end_code = self->private_impl.f_end_code;
v_save_code = self->private_impl.f_save_code; v_save_code = self->private_impl.f_save_code;
@@ -7991,16 +8004,14 @@ wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
if ((v_lm1_a % 8) != 0) { if ((v_lm1_a % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] = self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code]; self->private_impl.f_prefixes[v_prev_code];
memcpy((self->private_impl.f_suffixes) + ((8 * v_save_code)), memcpy((a_workbuf.ptr) + ((8 * v_save_code)),
(self->private_impl.f_suffixes) + ((8 * v_prev_code)), 8); (a_workbuf.ptr) + ((8 * v_prev_code)), 8);
self->private_impl a_workbuf.ptr[((8 * v_save_code) + ((uint32_t)((v_lm1_a % 8))))] =
.f_suffixes[((8 * v_save_code) + ((uint32_t)((v_lm1_a % 8))))] =
((uint8_t)(v_code)); ((uint8_t)(v_code));
} else { } else {
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));
self->private_impl.f_suffixes[((8 * v_save_code) + 0)] = a_workbuf.ptr[((8 * v_save_code) + 0)] = ((uint8_t)(v_code));
((uint8_t)(v_code));
} }
v_save_code += 1; v_save_code += 1;
if (v_width < 12) { if (v_width < 12) {
@@ -8030,7 +8041,7 @@ wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3); v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
while (true) { while (true) {
memcpy((self->private_impl.f_output) + (v_o), memcpy((self->private_impl.f_output) + (v_o),
(self->private_impl.f_suffixes) + ((8 * v_c)), 8); (a_workbuf.ptr) + ((8 * v_c)), 8);
if (v_steps <= 0) { if (v_steps <= 0) {
goto label_1_break; goto label_1_break;
} }
@@ -8039,7 +8050,7 @@ wuffs_lzw__decoder__read_from(wuffs_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]));
} }
label_1_break:; label_1_break:;
v_first_byte = self->private_impl.f_suffixes[((8 * v_c) + 0)]; v_first_byte = a_workbuf.ptr[((8 * v_c) + 0)];
if (v_code == v_save_code) { if (v_code == v_save_code) {
self->private_impl.f_output[v_output_wi] = v_first_byte; self->private_impl.f_output[v_output_wi] = v_first_byte;
v_output_wi = ((v_output_wi + 1) & 8191); v_output_wi = ((v_output_wi + 1) & 8191);
@@ -8050,16 +8061,14 @@ wuffs_lzw__decoder__read_from(wuffs_lzw__decoder* self,
if ((v_lm1_b % 8) != 0) { if ((v_lm1_b % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] = self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code]; self->private_impl.f_prefixes[v_prev_code];
memcpy((self->private_impl.f_suffixes) + ((8 * v_save_code)), memcpy((a_workbuf.ptr) + ((8 * v_save_code)),
(self->private_impl.f_suffixes) + ((8 * v_prev_code)), 8); (a_workbuf.ptr) + ((8 * v_prev_code)), 8);
self->private_impl a_workbuf.ptr[((8 * v_save_code) + ((uint32_t)((v_lm1_b % 8))))] =
.f_suffixes[((8 * v_save_code) + ((uint32_t)((v_lm1_b % 8))))] =
v_first_byte; v_first_byte;
} else { } else {
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));
self->private_impl.f_suffixes[((8 * v_save_code) + 0)] = a_workbuf.ptr[((8 * v_save_code) + 0)] = ((uint8_t)(v_first_byte));
((uint8_t)(v_first_byte));
} }
v_save_code += 1; v_save_code += 1;
if (v_width < 12) { if (v_width < 12) {
@@ -8509,8 +8518,8 @@ wuffs_gif__decoder__workbuf_len(const wuffs_gif__decoder* self) {
} }
return wuffs_base__utility__make_range_ii_u64( return wuffs_base__utility__make_range_ii_u64(
((uint64_t)(self->private_impl.f_width)), (32768 + ((uint64_t)(self->private_impl.f_width))),
((uint64_t)(self->private_impl.f_width))); (32768 + ((uint64_t)(self->private_impl.f_width))));
} }
// -------- func gif.decoder.restart_frame // -------- func gif.decoder.restart_frame
@@ -10215,11 +10224,11 @@ wuffs_gif__decoder__decode_id_part2(wuffs_gif__decoder* self,
(iop_a_src += 1, wuffs_base__return_empty_struct()); (iop_a_src += 1, wuffs_base__return_empty_struct());
} }
label_1_break:; label_1_break:;
if (((uint64_t)(self->private_impl.f_width)) < if ((32768 + ((uint64_t)(self->private_impl.f_width))) <
((uint64_t)(a_workbuf.len))) { ((uint64_t)(a_workbuf.len))) {
a_workbuf = wuffs_base__slice_u8__subslice_j( a_workbuf = wuffs_base__slice_u8__subslice_j(
a_workbuf, ((uint64_t)(self->private_impl.f_width))); a_workbuf, (32768 + ((uint64_t)(self->private_impl.f_width))));
} else if (((uint64_t)(self->private_impl.f_width)) > } else if ((32768 + ((uint64_t)(self->private_impl.f_width))) >
((uint64_t)(a_workbuf.len))) { ((uint64_t)(a_workbuf.len))) {
status = wuffs_base__error__bad_workbuf_length; status = wuffs_base__error__bad_workbuf_length;
goto exit; goto exit;
@@ -10249,8 +10258,7 @@ wuffs_gif__decoder__decode_id_part2(wuffs_gif__decoder* self,
u_r.meta.ri = iop_v_r - u_r.data.ptr; u_r.meta.ri = iop_v_r - u_r.data.ptr;
wuffs_base__status t_1 = wuffs_lzw__decoder__decode_io_writer( wuffs_base__status t_1 = wuffs_lzw__decoder__decode_io_writer(
&self->private_impl.f_lzw, &self->private_impl.f_lzw,
wuffs_base__utility__null_io_writer(), v_r, wuffs_base__utility__null_io_writer(), v_r, a_workbuf);
wuffs_base__utility__null_slice_u8());
iop_v_r = u_r.data.ptr + u_r.meta.ri; iop_v_r = u_r.data.ptr + u_r.meta.ri;
v_lzw_status = t_1; v_lzw_status = t_1;
} }
+7 -7
View File
@@ -25,7 +25,7 @@ pub status "?too much pixel data"
pri status "?internal error: inconsistent ri/wi" pri status "?internal error: inconsistent ri/wi"
// TODO: reference lzw.decoder_workbuf_len_max_incl. // TODO: reference lzw.decoder_workbuf_len_max_incl.
pub const decoder_workbuf_len_max_incl base.u64 = 0xFFFF pub const decoder_workbuf_len_max_incl base.u64 = 32768 + 0xFFFF
// See the spec appendix E "Interlaced Images" on page 29. The first element // See the spec appendix E "Interlaced Images" on page 29. The first element
// represents either that the frame was non-interlaced, or that all interlace // represents either that the frame was non-interlaced, or that all interlace
@@ -184,8 +184,8 @@ pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
pub func decoder.workbuf_len() base.range_ii_u64 { pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64( return this.util.make_range_ii_u64(
min_incl:this.width as base.u64, min_incl:32768 + (this.width as base.u64),
max_incl:this.width as base.u64) max_incl:32768 + (this.width as base.u64))
} }
pub func decoder.restart_frame!(index base.u64, io_position base.u64) base.status { pub func decoder.restart_frame!(index base.u64, io_position base.u64) base.status {
@@ -707,9 +707,9 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
args.src.skip_fast!(actual:1, worst_case:1) args.src.skip_fast!(actual:1, worst_case:1)
} }
if (this.width as base.u64) < args.workbuf.length() { if (32768 + (this.width as base.u64)) < args.workbuf.length() {
args.workbuf = args.workbuf[:this.width as base.u64] args.workbuf = args.workbuf[:32768 + (this.width as base.u64)]
} else if (this.width as base.u64) > args.workbuf.length() { } else if (32768 + (this.width as base.u64)) > args.workbuf.length() {
return base."?bad workbuf length" return base."?bad workbuf length"
} }
@@ -719,7 +719,7 @@ pri func decoder.decode_id_part2?(dst ptr base.pixel_buffer, src base.io_reader,
} }
io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) { io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) {
lzw_status =? this.lzw.decode_io_writer?( lzw_status =? this.lzw.decode_io_writer?(
dst:this.util.null_io_writer(), src:r, workbuf:this.util.null_slice_u8()) dst:this.util.null_io_writer(), src:r, workbuf:args.workbuf)
this.compressed_ri ~sat+= r.since_mark().length() this.compressed_ri ~sat+= r.since_mark().length()
} }
+36 -19
View File
@@ -16,9 +16,8 @@ pub status "?bad code"
pri status "?internal error: inconsistent I/O" pri status "?internal error: inconsistent I/O"
// TODO: move bulk data buffers like decoder.suffixes or decoder.output into // The suffixes table is 8 bytes per code, so 4096 * 8 = 32768 bytes.
// the workbuf? pub const decoder_workbuf_len_max_incl base.u64 = 32768
pub const decoder_workbuf_len_max_incl base.u64 = 0
pub struct decoder?( pub struct decoder?(
// The value passed to set_literal_width. This lw field is copied to the // The value passed to set_literal_width. This lw field is copied to the
@@ -85,16 +84,25 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
this.n_bits = 0 this.n_bits = 0
this.output_ri = 0 this.output_ri = 0
this.output_wi = 0 this.output_wi = 0
if args.workbuf.length() < 32768 {
return base."?bad workbuf length"
}
i = 0 i = 0
while i < this.clear_code { while i < this.clear_code,
inv args.workbuf.length() >= 32768,
{
assert i < 256 via "a < b: a < c; c <= b"(c:this.clear_code) assert i < 256 via "a < b: a < c; c <= b"(c:this.clear_code)
this.lm1s[i] = 0 this.lm1s[i] = 0
this.suffixes[(8 * i) + 0] = i as base.u8 args.workbuf[((8 * i) + 0) as base.u64] = i as base.u8
i += 1 i += 1
} }
while true { while true {
this.read_from!(src:args.src) if args.workbuf.length() < 32768 {
return base."?bad workbuf length"
}
this.read_from!(src:args.src, workbuf:args.workbuf)
if this.output_wi > 0 { if this.output_wi > 0 {
this.write_to?(dst:args.dst) this.write_to?(dst:args.dst)
@@ -114,7 +122,7 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
} }
} }
pri func decoder.read_from!(src base.io_reader) { pri func decoder.read_from!(src base.io_reader, workbuf slice base.u8) {
var clear_code base.u32[..256] var clear_code base.u32[..256]
var end_code base.u32[..257] var end_code base.u32[..257]
@@ -133,6 +141,10 @@ pri func decoder.read_from!(src base.io_reader) {
var lm1_b base.u16[..4095] var lm1_b base.u16[..4095]
var lm1_a base.u16[..4095] var lm1_a base.u16[..4095]
if args.workbuf.length() < 32768 {
return nothing
}
clear_code = this.clear_code clear_code = this.clear_code
end_code = this.end_code end_code = this.end_code
@@ -143,7 +155,9 @@ pri func decoder.read_from!(src base.io_reader) {
n_bits = this.n_bits n_bits = this.n_bits
output_wi = this.output_wi output_wi = this.output_wi
while true { while true,
inv args.workbuf.length() >= 32768,
{
if n_bits < width { if n_bits < width {
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width) assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
if args.src.available() >= 4 { if args.src.available() >= 4 {
@@ -199,12 +213,12 @@ pri func decoder.read_from!(src base.io_reader) {
assert (8 * save_code) <= ((8 * save_code) + 8) via "a <= (a + b): 0 <= b"(b:8) assert (8 * save_code) <= ((8 * save_code) + 8) via "a <= (a + b): 0 <= b"(b:8)
assert (8 * prev_code) <= ((8 * prev_code) + 8) via "a <= (a + b): 0 <= b"(b:8) assert (8 * prev_code) <= ((8 * prev_code) + 8) via "a <= (a + b): 0 <= b"(b:8)
this.prefixes[save_code] = this.prefixes[prev_code] this.prefixes[save_code] = this.prefixes[prev_code]
this.suffixes[(8 * save_code):(8 * save_code) + 8].copy_from_slice!( args.workbuf[(8 * save_code):(8 * save_code) + 8].copy_from_slice!(
s:this.suffixes[(8 * prev_code):(8 * prev_code) + 8]) s:args.workbuf[(8 * prev_code):(8 * prev_code) + 8])
this.suffixes[(8 * save_code) + ((lm1_a % 8) as base.u32)] = code as base.u8 args.workbuf[(8 * save_code) + ((lm1_a % 8) as base.u32)] = code as base.u8
} else { } else {
this.prefixes[save_code] = prev_code as base.u16 this.prefixes[save_code] = prev_code as base.u16
this.suffixes[(8 * save_code) + 0] = code as base.u8 args.workbuf[(8 * save_code) + 0] = code as base.u8
} }
save_code += 1 save_code += 1
@@ -242,14 +256,17 @@ pri func decoder.read_from!(src base.io_reader) {
output_wi = (output_wi + 1 + (this.lm1s[c] as base.u32)) & 8191 output_wi = (output_wi + 1 + (this.lm1s[c] as base.u32)) & 8191
steps = (this.lm1s[c] as base.u32) >> 3 steps = (this.lm1s[c] as base.u32) >> 3
while true { while true,
inv args.workbuf.length() >= 32768,
{
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b:8) assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b:8)
assert (8 * c) <= ((8 * c) + 8) via "a <= (a + b): 0 <= b"(b:8) assert (8 * c) <= ((8 * c) + 8) via "a <= (a + b): 0 <= b"(b:8)
assert ((8 * c) + 8) <= 32768
// The final "8" is redundant semantically, but helps the // The final "8" is redundant semantically, but helps the
// wuffs-c code generator recognize that both slices have the // wuffs-c code generator recognize that both slices have the
// same constant length, and hence produce efficient C code. // same constant length, and hence produce efficient C code.
this.output[o:o + 8].copy_from_slice!(s:this.suffixes[(8 * c):(8 * c) + 8]) this.output[o:o + 8].copy_from_slice!(s:args.workbuf[(8 * c):(8 * c) + 8])
if steps <= 0 { if steps <= 0 {
break break
@@ -261,7 +278,7 @@ pri func decoder.read_from!(src base.io_reader) {
o = (o ~mod- 8) & 8191 o = (o ~mod- 8) & 8191
c = this.prefixes[c] as base.u32 c = this.prefixes[c] as base.u32
} }
first_byte = this.suffixes[(8 * c) + 0] first_byte = args.workbuf[(8 * c) + 0]
if code == save_code { if code == save_code {
this.output[output_wi] = first_byte this.output[output_wi] = first_byte
@@ -276,12 +293,12 @@ pri func decoder.read_from!(src base.io_reader) {
assert (8 * save_code) <= ((8 * save_code) + 8) via "a <= (a + b): 0 <= b"(b:8) assert (8 * save_code) <= ((8 * save_code) + 8) via "a <= (a + b): 0 <= b"(b:8)
assert (8 * prev_code) <= ((8 * prev_code) + 8) via "a <= (a + b): 0 <= b"(b:8) assert (8 * prev_code) <= ((8 * prev_code) + 8) via "a <= (a + b): 0 <= b"(b:8)
this.prefixes[save_code] = this.prefixes[prev_code] this.prefixes[save_code] = this.prefixes[prev_code]
this.suffixes[(8 * save_code):(8 * save_code) + 8].copy_from_slice!( args.workbuf[(8 * save_code):(8 * save_code) + 8].copy_from_slice!(
s:this.suffixes[(8 * prev_code):(8 * prev_code) + 8]) s:args.workbuf[(8 * prev_code):(8 * prev_code) + 8])
this.suffixes[(8 * save_code) + ((lm1_b % 8) as base.u32)] = first_byte args.workbuf[(8 * save_code) + ((lm1_b % 8) as base.u32)] = first_byte
} else { } else {
this.prefixes[save_code] = prev_code as base.u16 this.prefixes[save_code] = prev_code as base.u16
this.suffixes[(8 * save_code) + 0] = first_byte as base.u8 args.workbuf[(8 * save_code) + 0] = first_byte as base.u8
} }
save_code += 1 save_code += 1
+2 -2
View File
@@ -311,8 +311,8 @@ const char* do_test_wuffs_gif_decode(const char* filename,
} }
} }
if (wuffs_gif__decoder__workbuf_len(&dec).min_incl != 160) { if (wuffs_gif__decoder__workbuf_len(&dec).min_incl != 32768 + 160) {
RETURN_FAIL("workbuf_len: got %" PRIu64 ", want 160", RETURN_FAIL("workbuf_len: got %" PRIu64 ", want 32768 + 160",
wuffs_gif__decoder__workbuf_len(&dec).min_incl); wuffs_gif__decoder__workbuf_len(&dec).min_incl);
} }