mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Have std/bzip2 read 4 (not 1) bytes per inner loop
name old speed new speed delta wuffs_bzip2_decode_10k/clang11 42.9MB/s ± 0% 46.5MB/s ± 0% +8.38% (p=0.008 n=5+5) wuffs_bzip2_decode_100k/clang11 36.9MB/s ± 0% 39.4MB/s ± 1% +6.75% (p=0.008 n=5+5) wuffs_bzip2_decode_10k/gcc10 36.5MB/s ± 0% 43.8MB/s ± 0% +19.73% (p=0.008 n=5+5) wuffs_bzip2_decode_100k/gcc10 30.8MB/s ± 0% 35.9MB/s ± 0% +16.37% (p=0.008 n=5+5)
This commit is contained in:
1 parent
94a2c704d4
commit
fdad12d59f
4 files changed
+395
-132
No files matched your search
@@ -6934,8 +6934,13 @@ struct wuffs_bzip2__decoder__struct {
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint32_t f_block_size;
|
||||
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;
|
||||
uint32_t f_final_checksum_have;
|
||||
uint32_t f_block_checksum_want;
|
||||
uint32_t f_original_pointer;
|
||||
@@ -6961,12 +6966,7 @@ struct wuffs_bzip2__decoder__struct {
|
||||
uint32_t f_bwt[1048576];
|
||||
|
||||
struct {
|
||||
uint8_t v_which;
|
||||
uint32_t v_ticks;
|
||||
uint32_t v_section;
|
||||
uint32_t v_bs;
|
||||
uint32_t v_node_index;
|
||||
uint32_t v_run_shift;
|
||||
} s_decode_block_slow[1];
|
||||
struct {
|
||||
uint32_t v_i;
|
||||
@@ -24864,6 +24864,7 @@ const char wuffs_bzip2__error__bad_number_of_huffman_codes[] = "#bzip2: bad numb
|
||||
const char wuffs_bzip2__error__bad_number_of_sections[] = "#bzip2: bad number of sections";
|
||||
const char wuffs_bzip2__error__unsupported_huffman_code[] = "#bzip2: unsupported Huffman code";
|
||||
const char wuffs_bzip2__error__unsupported_block_randomization[] = "#bzip2: unsupported block randomization";
|
||||
const char wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state[] = "#bzip2: internal error: inconsistent Huffman decoder state";
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
@@ -24912,6 +24913,11 @@ WUFFS_BZIP2__REV_CRC32_TABLE[256] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_block_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_block_slow(
|
||||
wuffs_bzip2__decoder* self,
|
||||
@@ -25026,6 +25032,128 @@ sizeof__wuffs_bzip2__decoder() {
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func bzip2.decoder.decode_block_fast
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_bzip2__decoder__decode_block_fast(
|
||||
wuffs_bzip2__decoder* self,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint32_t v_bits = 0;
|
||||
uint32_t v_n_bits = 0;
|
||||
uint32_t v_block_size = 0;
|
||||
uint8_t v_which = 0;
|
||||
uint32_t v_ticks = 0;
|
||||
uint32_t v_section = 0;
|
||||
uint32_t v_run_shift = 0;
|
||||
uint16_t v_child = 0;
|
||||
uint32_t v_child_ff = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_output = 0;
|
||||
uint32_t v_run = 0;
|
||||
uint32_t v_mtft0 = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
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;
|
||||
label__outer__continue:;
|
||||
while (((uint64_t)(io2_a_src - iop_a_src)) >= 4) {
|
||||
if (v_ticks > 0) {
|
||||
v_ticks -= 1;
|
||||
} else {
|
||||
v_ticks = 49;
|
||||
v_section += 1;
|
||||
v_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(v_section & 32767)] & 7)];
|
||||
}
|
||||
v_bits |= (wuffs_base__peek_u32be__no_bounds_check(iop_a_src) >> v_n_bits);
|
||||
iop_a_src += ((31 - v_n_bits) >> 3);
|
||||
v_n_bits |= 24;
|
||||
v_child = 0;
|
||||
while (v_child < 1024) {
|
||||
v_child = self->private_data.f_huffman_trees[v_which][v_child][(v_bits >> 31)];
|
||||
v_bits <<= 1;
|
||||
if (v_n_bits <= 0) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_n_bits -= 1;
|
||||
}
|
||||
if (v_child < 1280) {
|
||||
v_child_ff = ((uint32_t)((v_child & 255)));
|
||||
v_output = ((uint32_t)(self->private_data.f_mtft[v_child_ff]));
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_child_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_child_ff));
|
||||
self->private_data.f_mtft[0] = ((uint8_t)(v_output));
|
||||
self->private_data.f_letter_counts[v_output] += 1;
|
||||
self->private_data.f_bwt[v_block_size] = v_output;
|
||||
if (v_block_size >= self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_block_size += 1;
|
||||
v_run_shift = 0;
|
||||
goto label__outer__continue;
|
||||
} else if (v_child > 1281) {
|
||||
self->private_impl.f_decode_block_finished = true;
|
||||
goto label__outer__break;
|
||||
}
|
||||
if (v_run_shift >= 23) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_run = (((uint32_t)((v_child - 1279))) << v_run_shift);
|
||||
v_run_shift += 1;
|
||||
v_i = v_block_size;
|
||||
v_j = (v_run + v_block_size);
|
||||
if (v_j > self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_block_size = v_j;
|
||||
v_mtft0 = ((uint32_t)(self->private_data.f_mtft[0]));
|
||||
self->private_data.f_letter_counts[v_mtft0] += v_run;
|
||||
while (v_i < v_j) {
|
||||
self->private_data.f_bwt[v_i] = v_mtft0;
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
label__outer__break:;
|
||||
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;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func bzip2.decoder.decode_block_slow
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -25034,18 +25162,13 @@ wuffs_bzip2__decoder__decode_block_slow(
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint8_t v_which = 0;
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_node_index = 0;
|
||||
uint16_t v_child = 0;
|
||||
uint32_t v_child_ff = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_ticks = 0;
|
||||
uint32_t v_section = 0;
|
||||
uint32_t v_bs = 0;
|
||||
uint32_t v_output = 0;
|
||||
uint32_t v_node_index = 0;
|
||||
uint32_t v_run_shift = 0;
|
||||
uint32_t v_run = 0;
|
||||
uint32_t v_mtft0 = 0;
|
||||
|
||||
@@ -25062,40 +25185,18 @@ wuffs_bzip2__decoder__decode_block_slow(
|
||||
|
||||
uint32_t coro_susp_point = self->private_impl.p_decode_block_slow[0];
|
||||
if (coro_susp_point) {
|
||||
v_which = self->private_data.s_decode_block_slow[0].v_which;
|
||||
v_ticks = self->private_data.s_decode_block_slow[0].v_ticks;
|
||||
v_section = self->private_data.s_decode_block_slow[0].v_section;
|
||||
v_bs = self->private_data.s_decode_block_slow[0].v_bs;
|
||||
v_node_index = self->private_data.s_decode_block_slow[0].v_node_index;
|
||||
v_run_shift = self->private_data.s_decode_block_slow[0].v_run_shift;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[0] & 7)];
|
||||
v_section = 1;
|
||||
v_i = 0;
|
||||
v_j = 0;
|
||||
while (v_i < 256) {
|
||||
if (self->private_data.f_presence[v_i] != 0) {
|
||||
self->private_data.f_mtft[(v_j & 255)] = ((uint8_t)(v_i));
|
||||
v_j += 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_letter_counts[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
v_ticks = 50;
|
||||
while (true) {
|
||||
if (v_ticks > 0) {
|
||||
v_ticks -= 1;
|
||||
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;
|
||||
} else {
|
||||
v_ticks = 49;
|
||||
v_which = WUFFS_BZIP2__CLAMP_TO_5[(self->private_data.f_huffman_selectors[(v_section & 32767)] & 7)];
|
||||
v_section += 1;
|
||||
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)];
|
||||
}
|
||||
v_node_index = 0;
|
||||
label__0__continue:;
|
||||
@@ -25113,7 +25214,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[v_which][v_node_index][(self->private_impl.f_bits >> 31)];
|
||||
v_child = self->private_data.f_huffman_trees[self->private_impl.f_decode_block_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) {
|
||||
@@ -25125,30 +25226,31 @@ wuffs_bzip2__decoder__decode_block_slow(
|
||||
wuffs_base__slice_u8__copy_from_slice(wuffs_base__make_slice_u8_ij(self->private_data.f_mtft, 1, (1 + v_child_ff)), wuffs_base__make_slice_u8(self->private_data.f_mtft, v_child_ff));
|
||||
self->private_data.f_mtft[0] = ((uint8_t)(v_output));
|
||||
self->private_data.f_letter_counts[v_output] += 1;
|
||||
self->private_data.f_bwt[v_bs] = v_output;
|
||||
if (v_bs >= self->private_impl.f_max_incl_block_size) {
|
||||
self->private_data.f_bwt[self->private_impl.f_block_size] = v_output;
|
||||
if (self->private_impl.f_block_size >= self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_bs += 1;
|
||||
v_run_shift = 0;
|
||||
self->private_impl.f_block_size += 1;
|
||||
self->private_impl.f_decode_block_run_shift = 0;
|
||||
goto label__0__break;
|
||||
} else if (v_child > 1281) {
|
||||
self->private_impl.f_decode_block_finished = true;
|
||||
goto label__outer__break;
|
||||
}
|
||||
if (v_run_shift >= 23) {
|
||||
if (self->private_impl.f_decode_block_run_shift >= 23) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_run = (((uint32_t)((v_child - 1279))) << v_run_shift);
|
||||
v_run_shift += 1;
|
||||
v_i = v_bs;
|
||||
v_j = (v_run + v_bs);
|
||||
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_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) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
v_bs = v_j;
|
||||
self->private_impl.f_block_size = v_j;
|
||||
v_mtft0 = ((uint32_t)(self->private_data.f_mtft[0]));
|
||||
self->private_data.f_letter_counts[v_mtft0] += v_run;
|
||||
while (v_i < v_j) {
|
||||
@@ -25160,11 +25262,6 @@ wuffs_bzip2__decoder__decode_block_slow(
|
||||
label__0__break:;
|
||||
}
|
||||
label__outer__break:;
|
||||
if (v_bs > self->private_impl.f_max_incl_block_size) {
|
||||
status = wuffs_base__make_status(wuffs_bzip2__error__bad_block_length);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_block_size = v_bs;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
@@ -25175,12 +25272,7 @@ wuffs_bzip2__decoder__decode_block_slow(
|
||||
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_which = v_which;
|
||||
self->private_data.s_decode_block_slow[0].v_ticks = v_ticks;
|
||||
self->private_data.s_decode_block_slow[0].v_section = v_section;
|
||||
self->private_data.s_decode_block_slow[0].v_bs = v_bs;
|
||||
self->private_data.s_decode_block_slow[0].v_node_index = v_node_index;
|
||||
self->private_data.s_decode_block_slow[0].v_run_shift = v_run_shift;
|
||||
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -25249,6 +25341,7 @@ wuffs_bzip2__decoder__transform_io(
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint64_t v_tag = 0;
|
||||
wuffs_base__status v_status = wuffs_base__make_status(NULL);
|
||||
uint32_t v_final_checksum_want = 0;
|
||||
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
@@ -25364,17 +25457,39 @@ wuffs_bzip2__decoder__transform_io(
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
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);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
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) {
|
||||
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);
|
||||
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) {
|
||||
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);
|
||||
if (a_src) {
|
||||
iop_a_src = a_src->data.ptr + a_src->meta.ri;
|
||||
}
|
||||
if (status.repr) {
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
label__1__break:;
|
||||
wuffs_bzip2__decoder__invert_bwt(self);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
status = wuffs_bzip2__decoder__flush_block(self, a_dst);
|
||||
@@ -25446,6 +25561,7 @@ wuffs_bzip2__decoder__prepare_block(
|
||||
|
||||
uint8_t v_c = 0;
|
||||
uint32_t v_i = 0;
|
||||
uint32_t v_j = 0;
|
||||
uint32_t v_selector = 0;
|
||||
uint32_t v_sel_ff = 0;
|
||||
uint8_t v_movee = 0;
|
||||
@@ -25719,6 +25835,20 @@ wuffs_bzip2__decoder__prepare_block(
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
v_j = 0;
|
||||
while (v_i < 256) {
|
||||
if (self->private_data.f_presence[v_i] != 0) {
|
||||
self->private_data.f_mtft[(v_j & 255)] = ((uint8_t)(v_i));
|
||||
v_j += 1;
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
v_i = 0;
|
||||
while (v_i < 256) {
|
||||
self->private_data.f_letter_counts[v_i] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
|
||||
Reference in new issue
Block a user