mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
base: add io_writer.limited_copy_etc_return_cusp
This commit is contained in:
1 parent
7fb80a047b
commit
e517ca4bee
6 files changed
+88
-5
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -579,6 +579,13 @@ var funcsOther = [...]string{
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_fast!(up_to: u32, distance: u32) u32",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - up_to <= this.length()
|
||||
// - distance >= 1
|
||||
// - distance <= this.history_length()
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_fast_return_cusp!(up_to: u32, distance: u32) u32[..= 0xFFFF]",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - (up_to + 8) <= this.length()
|
||||
// - distance >= 8
|
||||
|
||||
@@ -1211,7 +1211,8 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistoryFast {
|
||||
} else if (method == t.IDLimitedCopyU32FromHistoryFast) ||
|
||||
(method == t.IDLimitedCopyU32FromHistoryFastReturnCusp) {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), nil, one, nil); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
+5
-3
@@ -524,9 +524,10 @@ const (
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast = ID(0x172)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast = ID(0x173)
|
||||
IDLimitedCopyU32FromHistoryFast = ID(0x174)
|
||||
IDLimitedCopyU32FromReader = ID(0x175)
|
||||
IDLimitedCopyU32FromSlice = ID(0x176)
|
||||
IDLimitedCopyU32ToSlice = ID(0x177)
|
||||
IDLimitedCopyU32FromHistoryFastReturnCusp = ID(0x175)
|
||||
IDLimitedCopyU32FromReader = ID(0x176)
|
||||
IDLimitedCopyU32FromSlice = ID(0x177)
|
||||
IDLimitedCopyU32ToSlice = ID(0x178)
|
||||
|
||||
// -------- 0x180 block.
|
||||
|
||||
@@ -970,6 +971,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
||||
IDLimitedCopyU32FromHistoryFast: "limited_copy_u32_from_history_fast",
|
||||
IDLimitedCopyU32FromHistoryFastReturnCusp: "limited_copy_u32_from_history_fast_return_cusp",
|
||||
IDLimitedCopyU32FromReader: "limited_copy_u32_from_reader",
|
||||
IDLimitedCopyU32FromSlice: "limited_copy_u32_from_slice",
|
||||
IDLimitedCopyU32ToSlice: "limited_copy_u32_to_slice",
|
||||
|
||||
@@ -14783,6 +14783,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.
|
||||
|
||||
Reference in new issue
Block a user