mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Optimize std/bzip2 flush_repeat_count checks
name old speed new speed delta wuffs_bzip2_decode_10k/clang11 60.5MB/s ± 0% 65.2MB/s ± 0% +7.85% (p=0.008 n=5+5) wuffs_bzip2_decode_100k/clang11 45.7MB/s ± 1% 52.4MB/s ± 0% +14.68% (p=0.008 n=5+5) wuffs_bzip2_decode_10k/gcc10 58.5MB/s ± 0% 60.6MB/s ± 0% +3.67% (p=0.008 n=5+5) wuffs_bzip2_decode_100k/gcc10 46.3MB/s ± 0% 49.2MB/s ± 0% +6.31% (p=0.008 n=5+5)
This commit is contained in:
1 parent
66f194f7e0
commit
bed155bd6f
3 files changed
+49
-57
No files matched your search
@@ -25970,7 +25970,15 @@ wuffs_bzip2__decoder__flush_fast(
|
|||||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||||
v_curr = ((uint8_t)((v_entry & 255)));
|
v_curr = ((uint8_t)((v_entry & 255)));
|
||||||
v_flush_pointer = (v_entry >> 12);
|
v_flush_pointer = (v_entry >> 12);
|
||||||
if (v_flush_repeat_count >= 4) {
|
if (v_flush_repeat_count < 4) {
|
||||||
|
if (v_curr == v_flush_prev) {
|
||||||
|
v_flush_repeat_count += 1;
|
||||||
|
} else {
|
||||||
|
v_flush_repeat_count = 1;
|
||||||
|
}
|
||||||
|
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||||
|
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_curr), iop_a_dst += 1);
|
||||||
|
} else {
|
||||||
v_flush_repeat_count = ((uint32_t)(v_curr));
|
v_flush_repeat_count = ((uint32_t)(v_curr));
|
||||||
while (v_flush_repeat_count > 0) {
|
while (v_flush_repeat_count > 0) {
|
||||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||||
@@ -25980,14 +25988,6 @@ wuffs_bzip2__decoder__flush_fast(
|
|||||||
v_flush_repeat_count -= 1;
|
v_flush_repeat_count -= 1;
|
||||||
}
|
}
|
||||||
v_flush_repeat_count = 0;
|
v_flush_repeat_count = 0;
|
||||||
} else if (v_curr != v_flush_prev) {
|
|
||||||
v_flush_repeat_count = 1;
|
|
||||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
|
||||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_curr), iop_a_dst += 1);
|
|
||||||
} else {
|
|
||||||
v_flush_repeat_count += 1;
|
|
||||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
|
||||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, v_curr), iop_a_dst += 1);
|
|
||||||
}
|
}
|
||||||
v_flush_prev = v_curr;
|
v_flush_prev = v_curr;
|
||||||
v_block_size -= 1;
|
v_block_size -= 1;
|
||||||
@@ -26057,12 +26057,26 @@ wuffs_bzip2__decoder__flush_slow(
|
|||||||
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
v_entry = self->private_data.f_bwt[v_flush_pointer];
|
||||||
v_curr = ((uint8_t)((v_entry & 255)));
|
v_curr = ((uint8_t)((v_entry & 255)));
|
||||||
v_flush_pointer = (v_entry >> 12);
|
v_flush_pointer = (v_entry >> 12);
|
||||||
if (v_flush_repeat_count >= 4) {
|
if (v_flush_repeat_count < 4) {
|
||||||
|
if (v_curr == v_flush_prev) {
|
||||||
|
v_flush_repeat_count += 1;
|
||||||
|
} else {
|
||||||
|
v_flush_repeat_count = 1;
|
||||||
|
}
|
||||||
|
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||||
|
self->private_data.s_flush_slow[0].scratch = v_curr;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||||
|
if (iop_a_dst == io2_a_dst) {
|
||||||
|
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
||||||
|
} else {
|
||||||
v_flush_repeat_count = ((uint32_t)(v_curr));
|
v_flush_repeat_count = ((uint32_t)(v_curr));
|
||||||
while (v_flush_repeat_count > 0) {
|
while (v_flush_repeat_count > 0) {
|
||||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_flush_prev)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
||||||
self->private_data.s_flush_slow[0].scratch = v_flush_prev;
|
self->private_data.s_flush_slow[0].scratch = v_flush_prev;
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||||
if (iop_a_dst == io2_a_dst) {
|
if (iop_a_dst == io2_a_dst) {
|
||||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
||||||
goto suspend;
|
goto suspend;
|
||||||
@@ -26071,26 +26085,6 @@ wuffs_bzip2__decoder__flush_slow(
|
|||||||
v_flush_repeat_count -= 1;
|
v_flush_repeat_count -= 1;
|
||||||
}
|
}
|
||||||
v_flush_repeat_count = 0;
|
v_flush_repeat_count = 0;
|
||||||
} else if (v_curr != v_flush_prev) {
|
|
||||||
v_flush_repeat_count = 1;
|
|
||||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
|
||||||
self->private_data.s_flush_slow[0].scratch = v_curr;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
|
||||||
if (iop_a_dst == io2_a_dst) {
|
|
||||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
|
||||||
goto suspend;
|
|
||||||
}
|
|
||||||
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
|
||||||
} else {
|
|
||||||
v_flush_repeat_count += 1;
|
|
||||||
v_block_checksum_have = (WUFFS_BZIP2__REV_CRC32_TABLE[(((uint8_t)((v_block_checksum_have >> 24))) ^ v_curr)] ^ ((uint32_t)(v_block_checksum_have << 8)));
|
|
||||||
self->private_data.s_flush_slow[0].scratch = v_curr;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
|
||||||
if (iop_a_dst == io2_a_dst) {
|
|
||||||
status = wuffs_base__make_status(wuffs_base__suspension__short_write);
|
|
||||||
goto suspend;
|
|
||||||
}
|
|
||||||
*iop_a_dst++ = ((uint8_t)(self->private_data.s_flush_slow[0].scratch));
|
|
||||||
}
|
}
|
||||||
v_flush_prev = v_curr;
|
v_flush_prev = v_curr;
|
||||||
v_block_size -= 1;
|
v_block_size -= 1;
|
||||||
|
|||||||
@@ -33,7 +33,18 @@ pri func decoder.flush_fast!(dst: base.io_writer) {
|
|||||||
curr = (entry & 0xFF) as base.u8
|
curr = (entry & 0xFF) as base.u8
|
||||||
flush_pointer = entry >> 12
|
flush_pointer = entry >> 12
|
||||||
|
|
||||||
if flush_repeat_count >= 4 {
|
if flush_repeat_count < 4 {
|
||||||
|
if curr == flush_prev {
|
||||||
|
flush_repeat_count += 1
|
||||||
|
} else {
|
||||||
|
flush_repeat_count = 1
|
||||||
|
}
|
||||||
|
block_checksum_have =
|
||||||
|
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||||
|
(block_checksum_have ~mod<< 8)
|
||||||
|
args.dst.write_u8_fast!(a: curr)
|
||||||
|
|
||||||
|
} else {
|
||||||
flush_repeat_count = curr as base.u32
|
flush_repeat_count = curr as base.u32
|
||||||
while flush_repeat_count > 0,
|
while flush_repeat_count > 0,
|
||||||
inv block_size > 0,
|
inv block_size > 0,
|
||||||
@@ -47,18 +58,6 @@ pri func decoder.flush_fast!(dst: base.io_writer) {
|
|||||||
flush_repeat_count -= 1
|
flush_repeat_count -= 1
|
||||||
} endwhile
|
} endwhile
|
||||||
flush_repeat_count = 0
|
flush_repeat_count = 0
|
||||||
} else if curr <> flush_prev {
|
|
||||||
flush_repeat_count = 1
|
|
||||||
block_checksum_have =
|
|
||||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
|
||||||
(block_checksum_have ~mod<< 8)
|
|
||||||
args.dst.write_u8_fast!(a: curr)
|
|
||||||
} else {
|
|
||||||
flush_repeat_count += 1
|
|
||||||
block_checksum_have =
|
|
||||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
|
||||||
(block_checksum_have ~mod<< 8)
|
|
||||||
args.dst.write_u8_fast!(a: curr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_prev = curr
|
flush_prev = curr
|
||||||
|
|||||||
@@ -33,7 +33,18 @@ pri func decoder.flush_slow?(dst: base.io_writer) {
|
|||||||
curr = (entry & 0xFF) as base.u8
|
curr = (entry & 0xFF) as base.u8
|
||||||
flush_pointer = entry >> 12
|
flush_pointer = entry >> 12
|
||||||
|
|
||||||
if flush_repeat_count >= 4 {
|
if flush_repeat_count < 4 {
|
||||||
|
if curr == flush_prev {
|
||||||
|
flush_repeat_count += 1
|
||||||
|
} else {
|
||||||
|
flush_repeat_count = 1
|
||||||
|
}
|
||||||
|
block_checksum_have =
|
||||||
|
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
||||||
|
(block_checksum_have ~mod<< 8)
|
||||||
|
args.dst.write_u8?(a: curr)
|
||||||
|
|
||||||
|
} else {
|
||||||
flush_repeat_count = curr as base.u32
|
flush_repeat_count = curr as base.u32
|
||||||
while flush_repeat_count > 0,
|
while flush_repeat_count > 0,
|
||||||
inv block_size > 0,
|
inv block_size > 0,
|
||||||
@@ -45,18 +56,6 @@ pri func decoder.flush_slow?(dst: base.io_writer) {
|
|||||||
flush_repeat_count -= 1
|
flush_repeat_count -= 1
|
||||||
} endwhile
|
} endwhile
|
||||||
flush_repeat_count = 0
|
flush_repeat_count = 0
|
||||||
} else if curr <> flush_prev {
|
|
||||||
flush_repeat_count = 1
|
|
||||||
block_checksum_have =
|
|
||||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
|
||||||
(block_checksum_have ~mod<< 8)
|
|
||||||
args.dst.write_u8?(a: curr)
|
|
||||||
} else {
|
|
||||||
flush_repeat_count += 1
|
|
||||||
block_checksum_have =
|
|
||||||
REV_CRC32_TABLE[((block_checksum_have >> 24) as base.u8) ^ curr] ^
|
|
||||||
(block_checksum_have ~mod<< 8)
|
|
||||||
args.dst.write_u8?(a: curr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_prev = curr
|
flush_prev = curr
|
||||||
|
|||||||
Reference in new issue
Block a user