std/lzma: use 8-byte-copy if applicable

name                            old speed      new speed      delta
wuffs_lzma_decode_100k/clang14  56.2MB/s ± 0%  60.7MB/s ± 0%  +7.96%  (p=0.008 n=5+5)
wuffs_lzma_decode_100k/gcc12    56.4MB/s ± 1%  61.7MB/s ± 1%  +9.44%  (p=0.008 n=5+5)

$ time example-mzcat < linux-6.8.2.tar.xz > /dev/null
Before: user 0m8.396s
After:  user 0m8.392s
This commit is contained in:
Nigel Tao committed 2024-03-31 16:02:06 +11:00
1 parent 7077c20cb6
commit b6b0f84187
7 files changed
+246 -27

No files matched your search

+89
View File
@@ -308,6 +308,52 @@ wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_dista
return length;
}
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp
// copies the previous byte (the one immediately before *ptr_iop_w), copying 8
// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.
// It also returns the cusp: a byte pair (as a u16le) being the last byte of
// and next byte after the copied history.
//
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
// As a special case, a zero length rounds up to 8 (even though 0 is already a
// multiple of 8), since there is always at least one 8 byte chunk copied.
//
// In terms of advancing *ptr_iop_w, length is not rounded up.
//
// The caller needs to prove that:
// - length >= 1
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance == 1
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp(
uint8_t** ptr_iop_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
uint8_t* p = *ptr_iop_w;
uint8_t* q = p - distance;
uint64_t x = p[-1];
x |= x << 8;
x |= x << 16;
x |= x << 32;
uint32_t n = length;
while (1) {
wuffs_base__poke_u64le__no_bounds_check(p, x);
if (n <= 8) {
p += n;
q += n;
break;
}
p += 8;
q += 8;
n -= 8;
}
*ptr_iop_w = p;
return (uint32_t)wuffs_base__peek_u16le__no_bounds_check(q - 1);
}
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast
// is like the
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast function
@@ -348,6 +394,49 @@ wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
return length;
}
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp
// is like the
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast function
// above, but copies 8 byte chunks at a time. It also returns the cusp: a byte
// pair (as a u16le) being the last byte of and next byte after the copied
// history.
//
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
// As a special case, a zero length rounds up to 8 (even though 0 is already a
// multiple of 8), since there is always at least one 8 byte chunk copied.
//
// In terms of advancing *ptr_iop_w, length is not rounded up.
//
// The caller needs to prove that:
// - length >= 1
// - (length + 8) <= (io2_w - *ptr_iop_w)
// - distance >= 8
// - distance <= (*ptr_iop_w - io0_w)
static inline uint32_t //
wuffs_private_impl__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast_return_cusp(
uint8_t** ptr_iop_w,
uint8_t* io0_w,
uint8_t* io2_w,
uint32_t length,
uint32_t distance) {
uint8_t* p = *ptr_iop_w;
uint8_t* q = p - distance;
uint32_t n = length;
while (1) {
memcpy(p, q, 8);
if (n <= 8) {
p += n;
q += n;
break;
}
p += 8;
q += 8;
n -= 8;
}
*ptr_iop_w = p;
return (uint32_t)wuffs_base__peek_u16le__no_bounds_check(q - 1);
}
static inline uint32_t //
wuffs_private_impl__io_writer__limited_copy_u32_from_reader(
uint8_t** ptr_iop_w,
+2
View File
@@ -321,7 +321,9 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
switch method {
case t.IDLimitedCopyU32FromHistory,
t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast,
t.IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp,
t.IDLimitedCopyU32FromHistory8ByteChunksFast,
t.IDLimitedCopyU32FromHistory8ByteChunksFastReturnCusp,
t.IDLimitedCopyU32FromHistoryFast,
t.IDLimitedCopyU32FromHistoryFastReturnCusp:
b.printf("wuffs_private_impl__io_writer__%s(\n&%s%s, %s%s, %s%s",