mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Rename skip / copy_n_etc to skip32 / copy_n32_etc
This commit is contained in:
1 parent
1dcb5a9283
commit
09ed091fe3
14 files changed
+138
-136
No files matched your search
@@ -33,11 +33,11 @@ wuffs_base__io__since(uint64_t mark, uint64_t index, uint8_t* ptr) {
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
wuffs_base__io_writer__copy_n32_from_history(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
if (!distance) {
|
||||
return 0;
|
||||
}
|
||||
@@ -55,12 +55,13 @@ wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
||||
// TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that
|
||||
// is mostly because 3 is the minimum length for the deflate format. This
|
||||
// function implementation shouldn't overfit to that one format. Perhaps the
|
||||
// copy_n_from_history Wuffs method should also take an unroll hint argument,
|
||||
// and the cgen can look if that argument is the constant expression '3'.
|
||||
// copy_n32_from_history Wuffs method should also take an unroll hint
|
||||
// argument, and the cgen can look if that argument is the constant
|
||||
// expression '3'.
|
||||
//
|
||||
// See also wuffs_base__io_writer__copy_n_from_history_fast below.
|
||||
// See also wuffs_base__io_writer__copy_n32_from_history_fast below.
|
||||
//
|
||||
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
|
||||
// Alternatively, or additionally, have a sloppy_copy_n32_from_history method
|
||||
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||
for (; n >= 3; n -= 3) {
|
||||
*p++ = *q++;
|
||||
@@ -74,18 +75,18 @@ wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__copy_n_from_history_fast is like the
|
||||
// wuffs_base__io_writer__copy_n_from_history function above, but has stronger
|
||||
// pre-conditions. The caller needs to prove that:
|
||||
// wuffs_base__io_writer__copy_n32_from_history_fast is like the
|
||||
// wuffs_base__io_writer__copy_n32_from_history function above, but has
|
||||
// stronger pre-conditions. The caller needs to prove that:
|
||||
// - distance > 0
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
// - length <= (io2_w - *ptr_iop_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
wuffs_base__io_writer__copy_n32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_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;
|
||||
@@ -102,11 +103,11 @@ wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint8_t** ptr_iop_r,
|
||||
uint8_t* io2_r) {
|
||||
wuffs_base__io_writer__copy_n32_from_reader(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint8_t** ptr_iop_r,
|
||||
uint8_t* io2_r) {
|
||||
uint8_t* iop_w = *ptr_iop_w;
|
||||
size_t n = length;
|
||||
if (n > ((size_t)(io2_w - iop_w))) {
|
||||
@@ -141,10 +142,10 @@ wuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
wuffs_base__slice_u8 src) {
|
||||
wuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
wuffs_base__slice_u8 src) {
|
||||
uint8_t* iop_w = *ptr_iop_w;
|
||||
size_t n = src.len;
|
||||
if (n > length) {
|
||||
|
||||
@@ -176,7 +176,7 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
iopPrefix, name, io0Prefix, name, io0Prefix, name)
|
||||
return nil
|
||||
|
||||
case t.IDSkipFast:
|
||||
case t.IDSkip32Fast:
|
||||
// Generate a two part expression using the comma operator: "(pointer
|
||||
// increment, return_empty_struct call)". The final part is a function
|
||||
// call (to a static inline function) instead of a struct literal, to
|
||||
@@ -218,12 +218,12 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
}
|
||||
|
||||
switch method {
|
||||
case t.IDCopyNFromHistory, t.IDCopyNFromHistoryFast:
|
||||
case t.IDCopyN32FromHistory, t.IDCopyN32FromHistoryFast:
|
||||
suffix := ""
|
||||
if method == t.IDCopyNFromHistoryFast {
|
||||
if method == t.IDCopyN32FromHistoryFast {
|
||||
suffix = "_fast"
|
||||
}
|
||||
b.printf("wuffs_base__io_writer__copy_n_from_history%s(&%s%s, %s%s, %s%s",
|
||||
b.printf("wuffs_base__io_writer__copy_n32_from_history%s(&%s%s, %s%s, %s%s",
|
||||
suffix, iopPrefix, name, io0Prefix, name, io2Prefix, name)
|
||||
for _, o := range args {
|
||||
b.writeb(',')
|
||||
@@ -234,13 +234,13 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
b.writeb(')')
|
||||
return nil
|
||||
|
||||
case t.IDCopyNFromReader:
|
||||
case t.IDCopyN32FromReader:
|
||||
readerName, err := g.ioRecvName(args[1].AsArg().Value())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.printf("wuffs_base__io_writer__copy_n_from_reader(&%s%s, %s%s,",
|
||||
b.printf("wuffs_base__io_writer__copy_n32_from_reader(&%s%s, %s%s,",
|
||||
iopPrefix, name, io2Prefix, name)
|
||||
if err := g.writeExpr(b, args[0].AsArg().Value(), depth); err != nil {
|
||||
return err
|
||||
@@ -253,8 +253,8 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
iopPrefix, name, io2Prefix, name)
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
case t.IDCopyNFromSlice:
|
||||
b.printf("wuffs_base__io_writer__copy_n_from_slice(&%s%s, %s%s,",
|
||||
case t.IDCopyN32FromSlice:
|
||||
b.printf("wuffs_base__io_writer__copy_n32_from_slice(&%s%s, %s%s,",
|
||||
iopPrefix, name, io2Prefix, name)
|
||||
return g.writeArgs(b, args, depth)
|
||||
|
||||
@@ -583,7 +583,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error
|
||||
b.printf(" = *iop_a_src++;\n")
|
||||
return nil
|
||||
|
||||
case t.IDSkip:
|
||||
case t.IDSkip32:
|
||||
x := n.Args()[0].AsArg().Value()
|
||||
if cv := x.ConstValue(); cv != nil && cv.Cmp(one) == 0 {
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
|
||||
@@ -166,12 +166,12 @@ const baseImagePublicH = "" +
|
||||
""
|
||||
|
||||
const baseIOPrivateH = "" +
|
||||
"// ---------------- I/O\n\nstatic inline uint64_t //\nwuffs_base__io__count_since(uint64_t mark, uint64_t index) {\n if (index >= mark) {\n return index - mark;\n }\n return 0;\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__io__since(uint64_t mark, uint64_t index, uint8_t* ptr) {\n if (index >= mark) {\n return wuffs_base__make_slice_u8(ptr + mark, index - mark);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* p = *ptr_iop_w;\n if ((size_t)(p - io1_w) < (size_t)(distance)) {\n return 0;\n }\n uint8_t* q = p - distance;\n size_t n = (size_t)(io2_w - p);\n if ((size_t)(length) > n) {\n length = (uint32_t)(n);\n } else {\n" +
|
||||
" n = (size_t)(length);\n }\n // TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // copy_n_from_history Wuffs method should also take an unroll hint argument,\n // and the cgen can look if that argument is the constant expression '3'.\n //\n // See also wuffs_base__io_writer__copy_n_from_history_fast below.\n //\n // Alternatively, or additionally, have a sloppy_copy_n_from_history method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n_from_history_fast is like the\n// wuffs_base__io_writer__copy_n_from_history function above, but has stronger\n// pre-conditions. The caller needs to prove that:\n// - distance > " +
|
||||
"0\n// - distance <= (*ptr_iop_w - io1_w)\n// - length <= (io2_w - *ptr_iop_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n uint8_t** ptr_iop_r,\n uint8_t* io2_r) {\n uint8_t* i" +
|
||||
"op_w = *ptr_iop_w;\n size_t n = length;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n uint8_t* iop_r = *ptr_iop_r;\n if (n > ((size_t)(io2_r - iop_r))) {\n n = (size_t)(io2_r - iop_r);\n }\n if (n > 0) {\n memmove(iop_w, iop_r, n);\n *ptr_iop_w += n;\n *ptr_iop_r += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint64_t)(n);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n w" +
|
||||
"uffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_reader__set(wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_r,\n uint8_t** ptr_io0_r,\n uint8_t** ptr_io1_r,\n uint8_t** ptr_io2_r,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = data.len;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n *ptr_iop_r = data.ptr;\n *ptr_io0_r = data.ptr;\n *ptr_io1_r = data.ptr;\n *ptr_io2_r = data.ptr + data.len;\n\n return b;\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__io_reader__take(uint8_t** ptr_iop_r, uint8_t* io2_r, uint64_t n) {\n if (n <= ((size_t)(io2_r - *ptr_i" +
|
||||
"op_r))) {\n uint8_t* p = *ptr_iop_r;\n *ptr_iop_r += n;\n return wuffs_base__make_slice_u8(p, n);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_writer__set(wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_w,\n uint8_t** ptr_io0_w,\n uint8_t** ptr_io1_w,\n uint8_t** ptr_io2_w,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = 0;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n *ptr_iop_w = data.ptr;\n *ptr_io0_w = data.ptr;\n *ptr_io1_w = data.ptr;\n *ptr_io2_w = data.ptr + data.len;\n\n return b;\n}\n\n" +
|
||||
"// ---------------- I/O\n\nstatic inline uint64_t //\nwuffs_base__io__count_since(uint64_t mark, uint64_t index) {\n if (index >= mark) {\n return index - mark;\n }\n return 0;\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__io__since(uint64_t mark, uint64_t index, uint8_t* ptr) {\n if (index >= mark) {\n return wuffs_base__make_slice_u8(ptr + mark, index - mark);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n32_from_history(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* p = *ptr_iop_w;\n if ((size_t)(p - io1_w) < (size_t)(distance)) {\n return 0;\n }\n uint8_t* q = p - distance;\n size_t n = (size_t)(io2_w - p);\n if ((size_t)(length) > n) {\n length = (uint32_t)(n);\n " +
|
||||
" } else {\n n = (size_t)(length);\n }\n // TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // copy_n32_from_history Wuffs method should also take an unroll hint\n // argument, and the cgen can look if that argument is the constant\n // expression '3'.\n //\n // See also wuffs_base__io_writer__copy_n32_from_history_fast below.\n //\n // Alternatively, or additionally, have a sloppy_copy_n32_from_history method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n32_from_history_fast is like the\n// wuffs_base__io_writer__copy_n32_from_history function above, but has\n// stronger pre-conditions. The caller needs to prove" +
|
||||
" that:\n// - distance > 0\n// - distance <= (*ptr_iop_w - io1_w)\n// - length <= (io2_w - *ptr_iop_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n32_from_history_fast(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n32_from_reader(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n uint8_t** ptr_iop_r,\n " +
|
||||
" uint8_t* io2_r) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = length;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n uint8_t* iop_r = *ptr_iop_r;\n if (n > ((size_t)(io2_r - iop_r))) {\n n = (size_t)(io2_r - iop_r);\n }\n if (n > 0) {\n memmove(iop_w, iop_r, n);\n *ptr_iop_w += n;\n *ptr_iop_r += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint64_t)(n);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t" +
|
||||
" length,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_reader__set(wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_r,\n uint8_t** ptr_io0_r,\n uint8_t** ptr_io1_r,\n uint8_t** ptr_io2_r,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = data.len;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n *ptr_iop_r = data.ptr;\n *ptr_io0_r = data.ptr;\n *ptr_io1_r = data.ptr;\n *ptr_io2_r = data.ptr + data.len;\n\n return b;\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__io_reader__take(uint8_t** ptr_iop_r, uint8_t* io2" +
|
||||
"_r, uint64_t n) {\n if (n <= ((size_t)(io2_r - *ptr_iop_r))) {\n uint8_t* p = *ptr_iop_r;\n *ptr_iop_r += n;\n return wuffs_base__make_slice_u8(p, n);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_writer__set(wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_w,\n uint8_t** ptr_io0_w,\n uint8_t** ptr_io1_w,\n uint8_t** ptr_io2_w,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = 0;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n *ptr_iop_w = data.ptr;\n *ptr_io0_w = data.ptr;\n *ptr_io1_w = data.ptr;\n *ptr_io2_w = data.ptr + data.len;\n\n return b;\n}\n\n" +
|
||||
"" +
|
||||
"// ---------------- I/O (Utility)\n\n#define wuffs_base__utility__empty_io_reader wuffs_base__empty_io_reader\n#define wuffs_base__utility__empty_io_writer wuffs_base__empty_io_writer\n" +
|
||||
""
|
||||
|
||||
Reference in new issue
Block a user