diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 75841100..aefde454 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -2878,6 +2878,7 @@ struct wuffs_deflate__decoder__struct { uint32_t f_bits; uint32_t f_n_bits; uint32_t f_history_index; + uint32_t f_n_huffs_bits[2]; bool f_end_of_block; uint32_t p_decode_io_writer[1]; @@ -2889,7 +2890,6 @@ struct wuffs_deflate__decoder__struct { struct { uint32_t f_huffs[2][1024]; - uint32_t f_n_huffs_bits[2]; uint8_t f_history[32768]; uint8_t f_code_lengths[320]; @@ -6944,9 +6944,7 @@ wuffs_deflate__decoder__init_dynamic_huffman(wuffs_deflate__decoder* self, status = v_status; goto exit; } - v_mask = ((((uint32_t)(1)) << wuffs_base__u32__min( - self->private_data.f_n_huffs_bits[0], 9)) - - 1); + v_mask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1); v_i = 0; label_0_continue:; while (v_i < (v_n_lit + v_n_dist)) { @@ -7196,9 +7194,9 @@ label_0_break:; } label_1_break:; if (v_max_cl <= 9) { - self->private_data.f_n_huffs_bits[a_which] = v_max_cl; + self->private_impl.f_n_huffs_bits[a_which] = v_max_cl; } else { - self->private_data.f_n_huffs_bits[a_which] = 9; + self->private_impl.f_n_huffs_bits[a_which] = 9; } v_i = 0; if ((v_n_symbols != ((uint32_t)(v_offsets[v_max_cl]))) || @@ -7380,12 +7378,8 @@ wuffs_deflate__decoder__decode_huffman_fast(wuffs_deflate__decoder* self, } v_bits = self->private_impl.f_bits; v_n_bits = self->private_impl.f_n_bits; - v_lmask = ((((uint32_t)(1)) << wuffs_base__u32__min( - self->private_data.f_n_huffs_bits[0], 9)) - - 1); - v_dmask = ((((uint32_t)(1)) << wuffs_base__u32__min( - self->private_data.f_n_huffs_bits[1], 9)) - - 1); + v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1); + v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1); label_0_continue:; while ((((uint64_t)(io1_a_dst - iop_a_dst)) >= 258) && (((uint64_t)(io1_a_src - iop_a_src)) >= 12)) { @@ -7721,12 +7715,8 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self, } v_bits = self->private_impl.f_bits; v_n_bits = self->private_impl.f_n_bits; - v_lmask = ((((uint32_t)(1)) << wuffs_base__u32__min( - self->private_data.f_n_huffs_bits[0], 9)) - - 1); - v_dmask = ((((uint32_t)(1)) << wuffs_base__u32__min( - self->private_data.f_n_huffs_bits[1], 9)) - - 1); + v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1); + v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1); label_0_continue:; while (!(self->private_impl.p_decode_huffman_slow[0] != 0)) { while (true) { diff --git a/script/wuffs-deflate-decoder-decode-huffman.c b/script/wuffs-deflate-decoder-decode-huffman.c index 2d08d8f4..25cd0529 100644 --- a/script/wuffs-deflate-decoder-decode-huffman.c +++ b/script/wuffs-deflate-decoder-decode-huffman.c @@ -150,12 +150,12 @@ typedef struct wuffs_deflate__decoder__struct { uint32_t f_bits; uint32_t f_n_bits; uint32_t f_history_index; + uint32_t f_n_huffs_bits[2]; bool f_end_of_block; } private_impl; struct { // 1024 is huffs_table_size in std/deflate/decode_deflate.wuffs. uint32_t f_huffs[2][1024]; - uint32_t f_n_huffs_bits[2]; uint8_t f_history[32768]; uint8_t f_code_lengths[320]; } private_data; @@ -278,8 +278,8 @@ wuffs_base__status c_wuffs_deflate__decoder__decode_huffman_fast( // Initialize other local variables. uint8_t* pdst_mark = a_dst.private_impl.mark ? a_dst.private_impl.mark : pdst; - uint32_t lmask = MASK(self->private_data.f_n_huffs_bits[0]); - uint32_t dmask = MASK(self->private_data.f_n_huffs_bits[1]); + uint32_t lmask = MASK(self->private_impl.f_n_huffs_bits[0]); + uint32_t dmask = MASK(self->private_impl.f_n_huffs_bits[1]); outer_loop: while ((pdst <= qdst) && (psrc <= qsrc)) { diff --git a/std/deflate/decode_deflate.wuffs b/std/deflate/decode_deflate.wuffs index b84925cd..ce43f785 100644 --- a/std/deflate/decode_deflate.wuffs +++ b/std/deflate/decode_deflate.wuffs @@ -69,6 +69,9 @@ pub struct decoder?( // history_index indexes the history array, defined below. history_index base.u32, + // n_huffs_bits is discussed in the huffs field comment. + n_huffs_bits array[2] base.u32[..9], + // end_of_block is whether decode_huffman_xxx saw an end-of-block code. // // TODO: can decode_huffman_xxx signal this in band instead of out of band? @@ -106,8 +109,7 @@ pub struct decoder?( // - bits 3 .. 0 are the number of decoder.bits to consume. // // Exactly one of the eight bits 31-24 should be set. - huffs array[2] array[huffs_table_size] base.u32, - n_huffs_bits array[2] base.u32, + huffs array[2] array[huffs_table_size] base.u32, // history holds up to the last 32KiB of decoded output, if the decoding // was incomplete (e.g. due to a short read or write). RFC 1951 (DEFLATE) @@ -389,7 +391,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader) { } // Decode the code lengths for the next two Huffman tables. - mask = ((1 as base.u32) << (this.n_huffs_bits[0].min(x:9))) - 1 + mask = ((1 as base.u32) << (this.n_huffs_bits[0])) - 1 i = 0 while i < (n_lit + n_dist) { assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist) diff --git a/std/deflate/decode_huffman_fast.wuffs b/std/deflate/decode_huffman_fast.wuffs index 496a120f..53e46728 100644 --- a/std/deflate/decode_huffman_fast.wuffs +++ b/std/deflate/decode_huffman_fast.wuffs @@ -41,8 +41,8 @@ pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) ba bits = this.bits n_bits = this.n_bits - lmask = ((1 as base.u32) << this.n_huffs_bits[0].min(x:9)) - 1 - dmask = ((1 as base.u32) << this.n_huffs_bits[1].min(x:9)) - 1 + lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1 + dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1 // Check up front, on each iteration, that we have enough buffer space to // both read (12 bytes) and write (258 bytes) as much as we need to. Doing diff --git a/std/deflate/decode_huffman_slow.wuffs b/std/deflate/decode_huffman_slow.wuffs index 7f3ef081..c3a7137e 100644 --- a/std/deflate/decode_huffman_slow.wuffs +++ b/std/deflate/decode_huffman_slow.wuffs @@ -45,8 +45,8 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) { bits = this.bits n_bits = this.n_bits - lmask = ((1 as base.u32) << this.n_huffs_bits[0].min(x:9)) - 1 - dmask = ((1 as base.u32) << this.n_huffs_bits[1].min(x:9)) - 1 + lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1 + dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1 while:loop not coroutine_resumed { // Decode an lcode symbol from H-L.