base: add io_writer.limited_copy_etc_return_cusp

This commit is contained in:
Nigel Tao committed 2023-11-19 10:32:59 +11:00
1 parent 7fb80a047b
commit e517ca4bee
6 files changed
+88 -5

No files matched your search

+36
View File
@@ -229,6 +229,42 @@ wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast(
return length;
}
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast_return_cusp
// is like the
// wuffs_private_impl__io_writer__limited_copy_u32_from_history_fast function,
// but also returns the cusp: a byte pair (as a u16le) being the last byte of
// and next byte after the copied history.
//
// For example, if history was [10, 11, 12, 13, 14, 15, 16, 17, 18] then:
// - copying l=3, d=8 produces [11, 12, 13] and the cusp is (13, 14).
// - copying l=3, d=2 produces [17, 18, 17] and the cusp is (17, 18).
//
// The caller needs to prove that:
// - length <= (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_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;
for (; n >= 3; n -= 3) {
*p++ = *q++;
*p++ = *q++;
*p++ = *q++;
}
for (; n; n--) {
*p++ = *q++;
}
*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_distance_1_fast
// 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.
+2 -1
View File
@@ -306,7 +306,8 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
case t.IDLimitedCopyU32FromHistory,
t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast,
t.IDLimitedCopyU32FromHistory8ByteChunksFast,
t.IDLimitedCopyU32FromHistoryFast:
t.IDLimitedCopyU32FromHistoryFast,
t.IDLimitedCopyU32FromHistoryFastReturnCusp:
b.printf("wuffs_private_impl__io_writer__%s(\n&%s%s, %s%s, %s%s",
method.Str(g.tm), iopPrefix, recvName, io0Prefix, recvName, io2Prefix, recvName)
for _, o := range args {