Rename std/bzip2 decode_block_* functions

This commit is contained in:
Nigel Tao committed 2022-05-24 11:24:57 +10:00
1 parent fc0c5e465b
commit ae1e075401
4 files changed
+86 -86

No files matched your search

+48 -48
View File
@@ -6936,11 +6936,11 @@ struct wuffs_bzip2__decoder__struct {
uint32_t f_n_bits;
uint32_t f_max_incl_block_size;
uint32_t f_block_size;
bool f_decode_block_finished;
uint8_t f_decode_block_which;
uint32_t f_decode_block_ticks;
uint32_t f_decode_block_section;
uint32_t f_decode_block_run_shift;
bool f_decode_huffman_finished;
uint8_t f_decode_huffman_which;
uint32_t f_decode_huffman_ticks;
uint32_t f_decode_huffman_section;
uint32_t f_decode_huffman_run_shift;
uint32_t f_final_checksum_have;
uint32_t f_block_checksum_want;
uint32_t f_original_pointer;
@@ -6953,7 +6953,7 @@ struct wuffs_bzip2__decoder__struct {
uint32_t p_prepare_block[1];
uint32_t p_read_code_lengths[1];
uint32_t p_flush_block[1];
uint32_t p_decode_block_slow[1];
uint32_t p_decode_huffman_slow[1];
} private_impl;
struct {
@@ -6990,7 +6990,7 @@ struct wuffs_bzip2__decoder__struct {
} s_flush_block[1];
struct {
uint32_t v_node_index;
} s_decode_block_slow[1];
} s_decode_huffman_slow[1];
} private_data;
#ifdef __cplusplus
@@ -24944,12 +24944,12 @@ wuffs_bzip2__decoder__flush_block(
wuffs_base__io_buffer* a_dst);
static wuffs_base__status
wuffs_bzip2__decoder__decode_block_fast(
wuffs_bzip2__decoder__decode_huffman_fast(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_src);
static wuffs_base__status
wuffs_bzip2__decoder__decode_block_slow(
wuffs_bzip2__decoder__decode_huffman_slow(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_src);
@@ -25213,30 +25213,30 @@ wuffs_bzip2__decoder__transform_io(
goto suspend;
}
self->private_impl.f_block_size = 0;
self->private_impl.f_decode_block_finished = false;
self->private_impl.f_decode_block_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[0] & 7)];
self->private_impl.f_decode_block_ticks = 50;
self->private_impl.f_decode_block_section = 0;
self->private_impl.f_decode_block_run_shift = 0;
while ( ! self->private_impl.f_decode_block_finished) {
self->private_impl.f_decode_huffman_finished = false;
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[0] & 7)];
self->private_impl.f_decode_huffman_ticks = 50;
self->private_impl.f_decode_huffman_section = 0;
self->private_impl.f_decode_huffman_run_shift = 0;
while ( ! self->private_impl.f_decode_huffman_finished) {
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
v_status = wuffs_bzip2__decoder__decode_block_fast(self, a_src);
v_status = wuffs_bzip2__decoder__decode_huffman_fast(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (wuffs_base__status__is_error(&v_status)) {
status = v_status;
goto exit;
} else if (self->private_impl.f_decode_block_finished) {
} else if (self->private_impl.f_decode_huffman_finished) {
goto label__1__break;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
status = wuffs_bzip2__decoder__decode_block_slow(self, a_src);
status = wuffs_bzip2__decoder__decode_huffman_slow(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
@@ -26026,10 +26026,10 @@ wuffs_bzip2__decoder__flush_block(
return status;
}
// -------- func bzip2.decoder.decode_block_fast
// -------- func bzip2.decoder.decode_huffman_fast
static wuffs_base__status
wuffs_bzip2__decoder__decode_block_fast(
wuffs_bzip2__decoder__decode_huffman_fast(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
@@ -26064,10 +26064,10 @@ wuffs_bzip2__decoder__decode_block_fast(
v_bits = self->private_impl.f_bits;
v_n_bits = self->private_impl.f_n_bits;
v_block_size = self->private_impl.f_block_size;
v_which = self->private_impl.f_decode_block_which;
v_ticks = self->private_impl.f_decode_block_ticks;
v_section = self->private_impl.f_decode_block_section;
v_run_shift = self->private_impl.f_decode_block_run_shift;
v_which = self->private_impl.f_decode_huffman_which;
v_ticks = self->private_impl.f_decode_huffman_ticks;
v_section = self->private_impl.f_decode_huffman_section;
v_run_shift = self->private_impl.f_decode_huffman_run_shift;
label__outer__continue:;
while (((uint64_t)(io2_a_src - iop_a_src)) >= 4) {
if (v_ticks > 0) {
@@ -26108,7 +26108,7 @@ wuffs_bzip2__decoder__decode_block_fast(
v_run_shift = 0;
goto label__outer__continue;
} else if (v_child > 1281) {
self->private_impl.f_decode_block_finished = true;
self->private_impl.f_decode_huffman_finished = true;
goto label__outer__break;
}
if (v_run_shift >= 23) {
@@ -26135,10 +26135,10 @@ wuffs_bzip2__decoder__decode_block_fast(
self->private_impl.f_bits = v_bits;
self->private_impl.f_n_bits = v_n_bits;
self->private_impl.f_block_size = v_block_size;
self->private_impl.f_decode_block_which = v_which;
self->private_impl.f_decode_block_ticks = v_ticks;
self->private_impl.f_decode_block_section = v_section;
self->private_impl.f_decode_block_run_shift = v_run_shift;
self->private_impl.f_decode_huffman_which = v_which;
self->private_impl.f_decode_huffman_ticks = v_ticks;
self->private_impl.f_decode_huffman_section = v_section;
self->private_impl.f_decode_huffman_run_shift = v_run_shift;
status = wuffs_base__make_status(NULL);
goto ok;
@@ -26152,10 +26152,10 @@ wuffs_bzip2__decoder__decode_block_fast(
return status;
}
// -------- func bzip2.decoder.decode_block_slow
// -------- func bzip2.decoder.decode_huffman_slow
static wuffs_base__status
wuffs_bzip2__decoder__decode_block_slow(
wuffs_bzip2__decoder__decode_huffman_slow(
wuffs_bzip2__decoder* self,
wuffs_base__io_buffer* a_src) {
wuffs_base__status status = wuffs_base__make_status(NULL);
@@ -26181,20 +26181,20 @@ wuffs_bzip2__decoder__decode_block_slow(
io2_a_src = io0_a_src + a_src->meta.wi;
}
uint32_t coro_susp_point = self->private_impl.p_decode_block_slow[0];
uint32_t coro_susp_point = self->private_impl.p_decode_huffman_slow[0];
if (coro_susp_point) {
v_node_index = self->private_data.s_decode_block_slow[0].v_node_index;
v_node_index = self->private_data.s_decode_huffman_slow[0].v_node_index;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
while ( ! (self->private_impl.p_decode_block_slow[0] != 0)) {
if (self->private_impl.f_decode_block_ticks > 0) {
self->private_impl.f_decode_block_ticks -= 1;
while ( ! (self->private_impl.p_decode_huffman_slow[0] != 0)) {
if (self->private_impl.f_decode_huffman_ticks > 0) {
self->private_impl.f_decode_huffman_ticks -= 1;
} else {
self->private_impl.f_decode_block_ticks = 49;
self->private_impl.f_decode_block_section += 1;
self->private_impl.f_decode_block_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(self->private_impl.f_decode_block_section & 32767)] & 7)];
self->private_impl.f_decode_huffman_ticks = 49;
self->private_impl.f_decode_huffman_section += 1;
self->private_impl.f_decode_huffman_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(self->private_impl.f_decode_huffman_section & 32767)] & 7)];
}
v_node_index = 0;
label__0__continue:;
@@ -26212,7 +26212,7 @@ wuffs_bzip2__decoder__decode_block_slow(
self->private_impl.f_bits = (((uint32_t)(v_c)) << 24);
self->private_impl.f_n_bits = 8;
}
v_child = self->private_data.f_huffman_trees[self->private_impl.f_decode_block_which][v_node_index][(self->private_impl.f_bits >> 31)];
v_child = self->private_data.f_huffman_trees[self->private_impl.f_decode_huffman_which][v_node_index][(self->private_impl.f_bits >> 31)];
self->private_impl.f_bits <<= 1;
self->private_impl.f_n_bits -= 1;
if (v_child < 1024) {
@@ -26230,18 +26230,18 @@ wuffs_bzip2__decoder__decode_block_slow(
goto exit;
}
self->private_impl.f_block_size += 1;
self->private_impl.f_decode_block_run_shift = 0;
self->private_impl.f_decode_huffman_run_shift = 0;
goto label__0__break;
} else if (v_child > 1281) {
self->private_impl.f_decode_block_finished = true;
self->private_impl.f_decode_huffman_finished = true;
goto label__outer__break;
}
if (self->private_impl.f_decode_block_run_shift >= 23) {
if (self->private_impl.f_decode_huffman_run_shift >= 23) {
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
goto exit;
}
v_run = (((uint32_t)((v_child - 1279))) << self->private_impl.f_decode_block_run_shift);
self->private_impl.f_decode_block_run_shift += 1;
v_run = (((uint32_t)((v_child - 1279))) << self->private_impl.f_decode_huffman_run_shift);
self->private_impl.f_decode_huffman_run_shift += 1;
v_i = self->private_impl.f_block_size;
v_j = (v_run + self->private_impl.f_block_size);
if (v_j > self->private_impl.f_max_incl_block_size) {
@@ -26263,14 +26263,14 @@ wuffs_bzip2__decoder__decode_block_slow(
goto ok;
ok:
self->private_impl.p_decode_block_slow[0] = 0;
self->private_impl.p_decode_huffman_slow[0] = 0;
goto exit;
}
goto suspend;
suspend:
self->private_impl.p_decode_block_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_block_slow[0].v_node_index = v_node_index;
self->private_impl.p_decode_huffman_slow[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_data.s_decode_huffman_slow[0].v_node_index = v_node_index;
goto exit;
exit:
+16 -16
View File
@@ -36,12 +36,12 @@ pub struct decoder? implements base.io_transformer(
// Block size is measured prior to the RLE1 step.
max_incl_block_size : base.u32[..= 900000],
block_size : base.u32[..= 900000],
decode_block_finished : base.bool,
decode_block_which : base.u8[..= 5],
decode_block_ticks : base.u32[..= 50],
decode_block_section : base.u32,
decode_block_run_shift : base.u32[..= 23],
block_size : base.u32[..= 900000],
decode_huffman_finished : base.bool,
decode_huffman_which : base.u8[..= 5],
decode_huffman_ticks : base.u32[..= 50],
decode_huffman_section : base.u32,
decode_huffman_run_shift : base.u32[..= 23],
final_checksum_have : base.u32,
block_checksum_want : base.u32,
@@ -158,19 +158,19 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
this.prepare_block?(src: args.src)
this.block_size = 0
this.decode_block_finished = false
this.decode_block_which = CLAMP_TO_5[this.huffman_selectors[0] & 7]
this.decode_block_ticks = 50
this.decode_block_section = 0
this.decode_block_run_shift = 0
while not this.decode_block_finished {
status = this.decode_block_fast!(src: args.src)
this.decode_huffman_finished = false
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[0] & 7]
this.decode_huffman_ticks = 50
this.decode_huffman_section = 0
this.decode_huffman_run_shift = 0
while not this.decode_huffman_finished {
status = this.decode_huffman_fast!(src: args.src)
if status.is_error() {
return status
} else if this.decode_block_finished {
} else if this.decode_huffman_finished {
break
}
this.decode_block_slow?(src: args.src)
this.decode_huffman_slow?(src: args.src)
} endwhile
this.invert_bwt!()
@@ -668,7 +668,7 @@ pri func decoder.build_huffman_table!(which: base.u32[..= 5]) {
// invert_bwt performs "two passes over the data, and one pass over the
// alphabet", per the BWT technical report, except that the first data pass
// (accumulating this.letter_counts) is integrated into the decode_block_etc
// (accumulating this.letter_counts) is integrated into the decode_huffman_etc
// methods.
pri func decoder.invert_bwt!() {
var i : base.u32
+10 -10
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
pri func decoder.decode_huffman_fast!(src: base.io_reader) base.status {
var bits : base.u32
var n_bits : base.u32[..= 31]
var block_size : base.u32[..= 900000]
@@ -33,10 +33,10 @@ pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
bits = this.bits
n_bits = this.n_bits
block_size = this.block_size
which = this.decode_block_which
ticks = this.decode_block_ticks
section = this.decode_block_section
run_shift = this.decode_block_run_shift
which = this.decode_huffman_which
ticks = this.decode_huffman_ticks
section = this.decode_huffman_section
run_shift = this.decode_huffman_run_shift
// Apply the Huffman trees.
while.outer args.src.length() >= 4 {
@@ -83,7 +83,7 @@ pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
run_shift = 0
continue.outer
} else if child > 1281 { // EOB symbol.
this.decode_block_finished = true
this.decode_huffman_finished = true
break.outer
}
@@ -115,10 +115,10 @@ pri func decoder.decode_block_fast!(src: base.io_reader) base.status {
this.bits = bits
this.n_bits = n_bits
this.block_size = block_size
this.decode_block_which = which
this.decode_block_ticks = ticks
this.decode_block_section = section
this.decode_block_run_shift = run_shift
this.decode_huffman_which = which
this.decode_huffman_ticks = ticks
this.decode_huffman_section = section
this.decode_huffman_run_shift = run_shift
return ok
}
+12 -12
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pri func decoder.decode_block_slow?(src: base.io_reader) {
pri func decoder.decode_huffman_slow?(src: base.io_reader) {
var c : base.u8
var node_index : base.u32[..= 1023]
@@ -26,12 +26,12 @@ pri func decoder.decode_block_slow?(src: base.io_reader) {
// Apply the Huffman trees.
while.outer not coroutine_resumed {
if this.decode_block_ticks > 0 {
this.decode_block_ticks -= 1
if this.decode_huffman_ticks > 0 {
this.decode_huffman_ticks -= 1
} else {
this.decode_block_ticks = 49
this.decode_block_section ~mod+= 1
this.decode_block_which = CLAMP_TO_5[this.huffman_selectors[this.decode_block_section & 32767] & 7]
this.decode_huffman_ticks = 49
this.decode_huffman_section ~mod+= 1
this.decode_huffman_which = CLAMP_TO_5[this.huffman_selectors[this.decode_huffman_section & 32767] & 7]
}
node_index = 0
@@ -42,7 +42,7 @@ pri func decoder.decode_block_slow?(src: base.io_reader) {
this.n_bits = 8
assert this.n_bits > 0
}
child = this.huffman_trees[this.decode_block_which][node_index][this.bits >> 31]
child = this.huffman_trees[this.decode_huffman_which][node_index][this.bits >> 31]
this.bits ~mod<<= 1
this.n_bits -= 1
@@ -65,20 +65,20 @@ pri func decoder.decode_block_slow?(src: base.io_reader) {
}
assert this.block_size < 900000 via "a < b: a < c; c <= b"(c: this.max_incl_block_size)
this.block_size += 1
this.decode_block_run_shift = 0
this.decode_huffman_run_shift = 0
break
} else if child > 1281 { // EOB symbol.
this.decode_block_finished = true
this.decode_huffman_finished = true
break.outer
}
// RUNA or RUNB symbol.
if this.decode_block_run_shift >= 23 {
if this.decode_huffman_run_shift >= 23 {
return "#bad block length"
}
run = ((child - 1279) as base.u32) << this.decode_block_run_shift
this.decode_block_run_shift += 1
run = ((child - 1279) as base.u32) << this.decode_huffman_run_shift
this.decode_huffman_run_shift += 1
i = this.block_size
j = run + this.block_size
if j > this.max_incl_block_size {