mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +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 //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_history(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io1_w,
|
uint8_t* io1_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint32_t distance) {
|
uint32_t distance) {
|
||||||
if (!distance) {
|
if (!distance) {
|
||||||
return 0;
|
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
|
// 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
|
// is mostly because 3 is the minimum length for the deflate format. This
|
||||||
// function implementation shouldn't overfit to that one format. Perhaps the
|
// function implementation shouldn't overfit to that one format. Perhaps the
|
||||||
// copy_n_from_history Wuffs method should also take an unroll hint argument,
|
// copy_n32_from_history Wuffs method should also take an unroll hint
|
||||||
// and the cgen can look if that argument is the constant expression '3'.
|
// 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?
|
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||||
for (; n >= 3; n -= 3) {
|
for (; n >= 3; n -= 3) {
|
||||||
*p++ = *q++;
|
*p++ = *q++;
|
||||||
@@ -74,18 +75,18 @@ wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wuffs_base__io_writer__copy_n_from_history_fast is like the
|
// wuffs_base__io_writer__copy_n32_from_history_fast is like the
|
||||||
// wuffs_base__io_writer__copy_n_from_history function above, but has stronger
|
// wuffs_base__io_writer__copy_n32_from_history function above, but has
|
||||||
// pre-conditions. The caller needs to prove that:
|
// stronger pre-conditions. The caller needs to prove that:
|
||||||
// - distance > 0
|
// - distance > 0
|
||||||
// - distance <= (*ptr_iop_w - io1_w)
|
// - distance <= (*ptr_iop_w - io1_w)
|
||||||
// - length <= (io2_w - *ptr_iop_w)
|
// - length <= (io2_w - *ptr_iop_w)
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_history_fast(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io1_w,
|
uint8_t* io1_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint32_t distance) {
|
uint32_t distance) {
|
||||||
uint8_t* p = *ptr_iop_w;
|
uint8_t* p = *ptr_iop_w;
|
||||||
uint8_t* q = p - distance;
|
uint8_t* q = p - distance;
|
||||||
uint32_t n = length;
|
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 //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_reader(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint8_t** ptr_iop_r,
|
uint8_t** ptr_iop_r,
|
||||||
uint8_t* io2_r) {
|
uint8_t* io2_r) {
|
||||||
uint8_t* iop_w = *ptr_iop_w;
|
uint8_t* iop_w = *ptr_iop_w;
|
||||||
size_t n = length;
|
size_t n = length;
|
||||||
if (n > ((size_t)(io2_w - iop_w))) {
|
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 //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
wuffs_base__slice_u8 src) {
|
wuffs_base__slice_u8 src) {
|
||||||
uint8_t* iop_w = *ptr_iop_w;
|
uint8_t* iop_w = *ptr_iop_w;
|
||||||
size_t n = src.len;
|
size_t n = src.len;
|
||||||
if (n > length) {
|
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)
|
iopPrefix, name, io0Prefix, name, io0Prefix, name)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case t.IDSkipFast:
|
case t.IDSkip32Fast:
|
||||||
// Generate a two part expression using the comma operator: "(pointer
|
// Generate a two part expression using the comma operator: "(pointer
|
||||||
// increment, return_empty_struct call)". The final part is a function
|
// increment, return_empty_struct call)". The final part is a function
|
||||||
// call (to a static inline function) instead of a struct literal, to
|
// 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 {
|
switch method {
|
||||||
case t.IDCopyNFromHistory, t.IDCopyNFromHistoryFast:
|
case t.IDCopyN32FromHistory, t.IDCopyN32FromHistoryFast:
|
||||||
suffix := ""
|
suffix := ""
|
||||||
if method == t.IDCopyNFromHistoryFast {
|
if method == t.IDCopyN32FromHistoryFast {
|
||||||
suffix = "_fast"
|
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)
|
suffix, iopPrefix, name, io0Prefix, name, io2Prefix, name)
|
||||||
for _, o := range args {
|
for _, o := range args {
|
||||||
b.writeb(',')
|
b.writeb(',')
|
||||||
@@ -234,13 +234,13 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
|||||||
b.writeb(')')
|
b.writeb(')')
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case t.IDCopyNFromReader:
|
case t.IDCopyN32FromReader:
|
||||||
readerName, err := g.ioRecvName(args[1].AsArg().Value())
|
readerName, err := g.ioRecvName(args[1].AsArg().Value())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
iopPrefix, name, io2Prefix, name)
|
||||||
if err := g.writeExpr(b, args[0].AsArg().Value(), depth); err != nil {
|
if err := g.writeExpr(b, args[0].AsArg().Value(), depth); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -253,8 +253,8 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
|||||||
iopPrefix, name, io2Prefix, name)
|
iopPrefix, name, io2Prefix, name)
|
||||||
return g.writeArgs(b, args, depth)
|
return g.writeArgs(b, args, depth)
|
||||||
|
|
||||||
case t.IDCopyNFromSlice:
|
case t.IDCopyN32FromSlice:
|
||||||
b.printf("wuffs_base__io_writer__copy_n_from_slice(&%s%s, %s%s,",
|
b.printf("wuffs_base__io_writer__copy_n32_from_slice(&%s%s, %s%s,",
|
||||||
iopPrefix, name, io2Prefix, name)
|
iopPrefix, name, io2Prefix, name)
|
||||||
return g.writeArgs(b, args, depth)
|
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")
|
b.printf(" = *iop_a_src++;\n")
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case t.IDSkip:
|
case t.IDSkip32:
|
||||||
x := n.Args()[0].AsArg().Value()
|
x := n.Args()[0].AsArg().Value()
|
||||||
if cv := x.ConstValue(); cv != nil && cv.Cmp(one) == 0 {
|
if cv := x.ConstValue(); cv != nil && cv.Cmp(one) == 0 {
|
||||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||||
|
|||||||
@@ -166,12 +166,12 @@ const baseImagePublicH = "" +
|
|||||||
""
|
""
|
||||||
|
|
||||||
const baseIOPrivateH = "" +
|
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" +
|
"// ---------------- 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 " +
|
||||||
" 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 > " +
|
" } 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" +
|
||||||
"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" +
|
" 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 " +
|
||||||
"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" +
|
" 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" +
|
||||||
"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" +
|
" 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" +
|
||||||
"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" +
|
"_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" +
|
"// ---------------- 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" +
|
||||||
""
|
""
|
||||||
|
|||||||
@@ -235,13 +235,13 @@ var Funcs = []string{
|
|||||||
"io_reader.since(mark: u64) slice u8",
|
"io_reader.since(mark: u64) slice u8",
|
||||||
"io_reader.take!(n: u64) slice u8",
|
"io_reader.take!(n: u64) slice u8",
|
||||||
|
|
||||||
"io_reader.skip?(n: u32)",
|
"io_reader.skip32?(n: u32)",
|
||||||
|
|
||||||
// TODO: this should have explicit pre-conditions "actual <= worst_case"
|
// TODO: this should have explicit pre-conditions "actual <= worst_case"
|
||||||
// and "worst_case <= available()". As an implementation restriction, we
|
// and "worst_case <= available()". As an implementation restriction, we
|
||||||
// also require that worst_case has a constant value. For now, that's all
|
// also require that worst_case has a constant value. For now, that's all
|
||||||
// implicitly checked (i.e. hard coded).
|
// implicitly checked (i.e. hard coded).
|
||||||
"io_reader.skip_fast!(actual: u32, worst_case: u32)",
|
"io_reader.skip32_fast!(actual: u32, worst_case: u32)",
|
||||||
|
|
||||||
// ---- io_writer
|
// ---- io_writer
|
||||||
|
|
||||||
@@ -290,16 +290,16 @@ var Funcs = []string{
|
|||||||
"io_writer.since(mark: u64) slice u8",
|
"io_writer.since(mark: u64) slice u8",
|
||||||
|
|
||||||
"io_writer.copy_from_slice!(s: slice u8) u64",
|
"io_writer.copy_from_slice!(s: slice u8) u64",
|
||||||
"io_writer.copy_n_from_history!(n: u32, distance: u32) u32",
|
"io_writer.copy_n32_from_history!(n: u32, distance: u32) u32",
|
||||||
"io_writer.copy_n_from_reader!(n: u32, r: io_reader) u32",
|
"io_writer.copy_n32_from_reader!(n: u32, r: io_reader) u32",
|
||||||
"io_writer.copy_n_from_slice!(n: u32, s: slice u8) u32",
|
"io_writer.copy_n32_from_slice!(n: u32, s: slice u8) u32",
|
||||||
|
|
||||||
// TODO: this should have explicit pre-conditions:
|
// TODO: this should have explicit pre-conditions:
|
||||||
// - n <= this.available()
|
// - n <= this.available()
|
||||||
// - distance > 0
|
// - distance > 0
|
||||||
// - distance <= this.since_mark().length()
|
// - distance <= this.since_mark().length()
|
||||||
// For now, that's all implicitly checked (i.e. hard coded).
|
// For now, that's all implicitly checked (i.e. hard coded).
|
||||||
"io_writer.copy_n_from_history_fast!(n: u32, distance: u32) u32",
|
"io_writer.copy_n32_from_history_fast!(n: u32, distance: u32) u32",
|
||||||
|
|
||||||
// ---- status
|
// ---- status
|
||||||
|
|
||||||
|
|||||||
@@ -1045,12 +1045,12 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
|||||||
return bounds{}, err
|
return bounds{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if method == t.IDCopyNFromHistoryFast {
|
} else if method == t.IDCopyN32FromHistoryFast {
|
||||||
if err := q.canCopyNFromHistoryFast(recv, n.Args()); err != nil {
|
if err := q.canCopyN32FromHistoryFast(recv, n.Args()); err != nil {
|
||||||
return bounds{}, err
|
return bounds{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if method == t.IDSkipFast {
|
} else if method == t.IDSkip32Fast {
|
||||||
args := n.Args()
|
args := n.Args()
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
return bounds{}, fmt.Errorf("check: internal error: bad skip_fast arguments")
|
return bounds{}, fmt.Errorf("check: internal error: bad skip_fast arguments")
|
||||||
@@ -1112,7 +1112,7 @@ func (q *checker) canUndoByte(recv *a.Expr) error {
|
|||||||
return fmt.Errorf("check: could not prove %s.can_undo_byte()", recv.Str(q.tm))
|
return fmt.Errorf("check: could not prove %s.can_undo_byte()", recv.Str(q.tm))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *checker) canCopyNFromHistoryFast(recv *a.Expr, args []*a.Node) error {
|
func (q *checker) canCopyN32FromHistoryFast(recv *a.Expr, args []*a.Node) error {
|
||||||
// As per cgen's io-private.h, there are three pre-conditions:
|
// As per cgen's io-private.h, there are three pre-conditions:
|
||||||
// - n <= this.available()
|
// - n <= this.available()
|
||||||
// - distance > 0
|
// - distance > 0
|
||||||
|
|||||||
+14
-14
@@ -492,15 +492,15 @@ const (
|
|||||||
IDMark = ID(0x163)
|
IDMark = ID(0x163)
|
||||||
IDPosition = ID(0x164)
|
IDPosition = ID(0x164)
|
||||||
IDSince = ID(0x165)
|
IDSince = ID(0x165)
|
||||||
IDSkip = ID(0x166)
|
IDSkip32 = ID(0x166)
|
||||||
IDSkipFast = ID(0x167)
|
IDSkip32Fast = ID(0x167)
|
||||||
IDTake = ID(0x168)
|
IDTake = ID(0x168)
|
||||||
|
|
||||||
IDCopyFromSlice = ID(0x170)
|
IDCopyFromSlice = ID(0x170)
|
||||||
IDCopyNFromHistory = ID(0x171)
|
IDCopyN32FromHistory = ID(0x171)
|
||||||
IDCopyNFromHistoryFast = ID(0x172)
|
IDCopyN32FromHistoryFast = ID(0x172)
|
||||||
IDCopyNFromReader = ID(0x173)
|
IDCopyN32FromReader = ID(0x173)
|
||||||
IDCopyNFromSlice = ID(0x174)
|
IDCopyN32FromSlice = ID(0x174)
|
||||||
|
|
||||||
// -------- 0x180 block.
|
// -------- 0x180 block.
|
||||||
|
|
||||||
@@ -834,15 +834,15 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDMark: "mark",
|
IDMark: "mark",
|
||||||
IDPosition: "position",
|
IDPosition: "position",
|
||||||
IDSince: "since",
|
IDSince: "since",
|
||||||
IDSkip: "skip",
|
IDSkip32: "skip32",
|
||||||
IDSkipFast: "skip_fast",
|
IDSkip32Fast: "skip32_fast",
|
||||||
IDTake: "take",
|
IDTake: "take",
|
||||||
|
|
||||||
IDCopyFromSlice: "copy_from_slice",
|
IDCopyFromSlice: "copy_from_slice",
|
||||||
IDCopyNFromHistory: "copy_n_from_history",
|
IDCopyN32FromHistory: "copy_n32_from_history",
|
||||||
IDCopyNFromHistoryFast: "copy_n_from_history_fast",
|
IDCopyN32FromHistoryFast: "copy_n32_from_history_fast",
|
||||||
IDCopyNFromReader: "copy_n_from_reader",
|
IDCopyN32FromReader: "copy_n32_from_reader",
|
||||||
IDCopyNFromSlice: "copy_n_from_slice",
|
IDCopyN32FromSlice: "copy_n32_from_slice",
|
||||||
|
|
||||||
// -------- 0x180 block.
|
// -------- 0x180 block.
|
||||||
|
|
||||||
|
|||||||
@@ -5069,11 +5069,11 @@ wuffs_base__io__since(uint64_t mark, uint64_t index, uint8_t* ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_history(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io1_w,
|
uint8_t* io1_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint32_t distance) {
|
uint32_t distance) {
|
||||||
if (!distance) {
|
if (!distance) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -5091,12 +5091,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
|
// 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
|
// is mostly because 3 is the minimum length for the deflate format. This
|
||||||
// function implementation shouldn't overfit to that one format. Perhaps the
|
// function implementation shouldn't overfit to that one format. Perhaps the
|
||||||
// copy_n_from_history Wuffs method should also take an unroll hint argument,
|
// copy_n32_from_history Wuffs method should also take an unroll hint
|
||||||
// and the cgen can look if that argument is the constant expression '3'.
|
// 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?
|
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||||
for (; n >= 3; n -= 3) {
|
for (; n >= 3; n -= 3) {
|
||||||
*p++ = *q++;
|
*p++ = *q++;
|
||||||
@@ -5110,18 +5111,18 @@ wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_iop_w,
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wuffs_base__io_writer__copy_n_from_history_fast is like the
|
// wuffs_base__io_writer__copy_n32_from_history_fast is like the
|
||||||
// wuffs_base__io_writer__copy_n_from_history function above, but has stronger
|
// wuffs_base__io_writer__copy_n32_from_history function above, but has
|
||||||
// pre-conditions. The caller needs to prove that:
|
// stronger pre-conditions. The caller needs to prove that:
|
||||||
// - distance > 0
|
// - distance > 0
|
||||||
// - distance <= (*ptr_iop_w - io1_w)
|
// - distance <= (*ptr_iop_w - io1_w)
|
||||||
// - length <= (io2_w - *ptr_iop_w)
|
// - length <= (io2_w - *ptr_iop_w)
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_history_fast(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io1_w,
|
uint8_t* io1_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint32_t distance) {
|
uint32_t distance) {
|
||||||
uint8_t* p = *ptr_iop_w;
|
uint8_t* p = *ptr_iop_w;
|
||||||
uint8_t* q = p - distance;
|
uint8_t* q = p - distance;
|
||||||
uint32_t n = length;
|
uint32_t n = length;
|
||||||
@@ -5138,11 +5139,11 @@ wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_reader(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
uint8_t** ptr_iop_r,
|
uint8_t** ptr_iop_r,
|
||||||
uint8_t* io2_r) {
|
uint8_t* io2_r) {
|
||||||
uint8_t* iop_w = *ptr_iop_w;
|
uint8_t* iop_w = *ptr_iop_w;
|
||||||
size_t n = length;
|
size_t n = length;
|
||||||
if (n > ((size_t)(io2_w - iop_w))) {
|
if (n > ((size_t)(io2_w - iop_w))) {
|
||||||
@@ -5177,10 +5178,10 @@ wuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t //
|
static inline uint32_t //
|
||||||
wuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_iop_w,
|
wuffs_base__io_writer__copy_n32_from_slice(uint8_t** ptr_iop_w,
|
||||||
uint8_t* io2_w,
|
uint8_t* io2_w,
|
||||||
uint32_t length,
|
uint32_t length,
|
||||||
wuffs_base__slice_u8 src) {
|
wuffs_base__slice_u8 src) {
|
||||||
uint8_t* iop_w = *ptr_iop_w;
|
uint8_t* iop_w = *ptr_iop_w;
|
||||||
size_t n = src.len;
|
size_t n = src.len;
|
||||||
if (n > length) {
|
if (n > length) {
|
||||||
@@ -7901,7 +7902,7 @@ wuffs_deflate__decoder__decode_uncompressed(wuffs_deflate__decoder* self,
|
|||||||
}
|
}
|
||||||
v_length = ((v_length)&0xFFFF);
|
v_length = ((v_length)&0xFFFF);
|
||||||
while (true) {
|
while (true) {
|
||||||
v_n_copied = wuffs_base__io_writer__copy_n_from_reader(
|
v_n_copied = wuffs_base__io_writer__copy_n32_from_reader(
|
||||||
&iop_a_dst, io2_a_dst, v_length, &iop_a_src, io2_a_src);
|
&iop_a_dst, io2_a_dst, v_length, &iop_a_src, io2_a_src);
|
||||||
if (v_length <= v_n_copied) {
|
if (v_length <= v_n_copied) {
|
||||||
status = wuffs_base__make_status(NULL);
|
status = wuffs_base__make_status(NULL);
|
||||||
@@ -8755,7 +8756,7 @@ label_0_continue:;
|
|||||||
}
|
}
|
||||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||||
while (true) {
|
while (true) {
|
||||||
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
|
v_n_copied = wuffs_base__io_writer__copy_n32_from_slice(
|
||||||
&iop_a_dst, io2_a_dst, v_hlen,
|
&iop_a_dst, io2_a_dst, v_hlen,
|
||||||
wuffs_base__slice_u8__subslice_i(
|
wuffs_base__slice_u8__subslice_i(
|
||||||
wuffs_base__make_slice_u8(self->private_data.f_history,
|
wuffs_base__make_slice_u8(self->private_data.f_history,
|
||||||
@@ -8765,7 +8766,7 @@ label_0_continue:;
|
|||||||
goto label_1_break;
|
goto label_1_break;
|
||||||
}
|
}
|
||||||
v_hlen -= v_n_copied;
|
v_hlen -= v_n_copied;
|
||||||
wuffs_base__io_writer__copy_n_from_slice(
|
wuffs_base__io_writer__copy_n32_from_slice(
|
||||||
&iop_a_dst, io2_a_dst, v_hlen,
|
&iop_a_dst, io2_a_dst, v_hlen,
|
||||||
wuffs_base__make_slice_u8(self->private_data.f_history, 32768));
|
wuffs_base__make_slice_u8(self->private_data.f_history, 32768));
|
||||||
goto label_1_break;
|
goto label_1_break;
|
||||||
@@ -8781,7 +8782,7 @@ label_0_continue:;
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wuffs_base__io_writer__copy_n_from_history_fast(
|
wuffs_base__io_writer__copy_n32_from_history_fast(
|
||||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||||
goto label_2_break;
|
goto label_2_break;
|
||||||
}
|
}
|
||||||
@@ -9126,7 +9127,7 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
|||||||
}
|
}
|
||||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||||
while (true) {
|
while (true) {
|
||||||
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
|
v_n_copied = wuffs_base__io_writer__copy_n32_from_slice(
|
||||||
&iop_a_dst, io2_a_dst, v_hlen,
|
&iop_a_dst, io2_a_dst, v_hlen,
|
||||||
wuffs_base__slice_u8__subslice_i(
|
wuffs_base__slice_u8__subslice_i(
|
||||||
wuffs_base__make_slice_u8(self->private_data.f_history,
|
wuffs_base__make_slice_u8(self->private_data.f_history,
|
||||||
@@ -9150,7 +9151,7 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
|||||||
label_5_break:;
|
label_5_break:;
|
||||||
if (v_hlen > 0) {
|
if (v_hlen > 0) {
|
||||||
while (true) {
|
while (true) {
|
||||||
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
|
v_n_copied = wuffs_base__io_writer__copy_n32_from_slice(
|
||||||
&iop_a_dst, io2_a_dst, v_hlen,
|
&iop_a_dst, io2_a_dst, v_hlen,
|
||||||
wuffs_base__slice_u8__subslice_i(
|
wuffs_base__slice_u8__subslice_i(
|
||||||
wuffs_base__make_slice_u8(self->private_data.f_history,
|
wuffs_base__make_slice_u8(self->private_data.f_history,
|
||||||
@@ -9172,7 +9173,7 @@ wuffs_deflate__decoder__decode_huffman_slow(wuffs_deflate__decoder* self,
|
|||||||
goto label_0_continue;
|
goto label_0_continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v_n_copied = wuffs_base__io_writer__copy_n_from_history(
|
v_n_copied = wuffs_base__io_writer__copy_n32_from_history(
|
||||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||||
if (v_length <= v_n_copied) {
|
if (v_length <= v_n_copied) {
|
||||||
v_length = 0;
|
v_length = 0;
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ pri func decoder.decode_uncompressed?(dst: base.io_writer, src: base.io_reader)
|
|||||||
}
|
}
|
||||||
length = length.low_bits(n: 16)
|
length = length.low_bits(n: 16)
|
||||||
while true {
|
while true {
|
||||||
n_copied = args.dst.copy_n_from_reader!(n: length, r: args.src)
|
n_copied = args.dst.copy_n32_from_reader!(n: length, r: args.src)
|
||||||
if length <= n_copied {
|
if length <= n_copied {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,10 +76,10 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
if n_bits < 15 {
|
if n_bits < 15 {
|
||||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert n_bits >= 15
|
assert n_bits >= 15
|
||||||
} else {
|
} else {
|
||||||
@@ -115,10 +115,10 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
if n_bits < 15 {
|
if n_bits < 15 {
|
||||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert n_bits >= 15
|
assert n_bits >= 15
|
||||||
} else {
|
} else {
|
||||||
@@ -173,10 +173,10 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
if n_bits < 15 {
|
if n_bits < 15 {
|
||||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert n_bits >= 15
|
assert n_bits >= 15
|
||||||
} else {
|
} else {
|
||||||
@@ -200,10 +200,10 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
if n_bits < 15 {
|
if n_bits < 15 {
|
||||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert n_bits >= 15
|
assert n_bits >= 15
|
||||||
} else {
|
} else {
|
||||||
@@ -225,10 +225,10 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
if n_bits < 15 {
|
if n_bits < 15 {
|
||||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert n_bits >= 15
|
assert n_bits >= 15
|
||||||
} else {
|
} else {
|
||||||
@@ -269,10 +269,10 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
|
assert n_bits < 15 via "a < b: a < c; c <= b"(c: table_entry_n_bits)
|
||||||
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
assert n_bits >= 0 // TODO: this shouldn't be necessary.
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert table_entry_n_bits <= n_bits via "a <= b: a <= c; c <= b"(c: 16)
|
assert table_entry_n_bits <= n_bits via "a <= b: a <= c; c <= b"(c: 16)
|
||||||
assert n_bits >= table_entry_n_bits via "a >= b: b <= a"()
|
assert n_bits >= table_entry_n_bits via "a >= b: b <= a"()
|
||||||
@@ -330,13 +330,13 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
// TODO: copy_from_slice32 should probably update the
|
// TODO: copy_from_slice32 should probably update the
|
||||||
// "args.dst.available() >= 258" fact. It should certainly
|
// "args.dst.available() >= 258" fact. It should certainly
|
||||||
// invalidate any fact that was "<=" instead of ">=".
|
// invalidate any fact that was "<=" instead of ">=".
|
||||||
n_copied = args.dst.copy_n_from_slice!(
|
n_copied = args.dst.copy_n32_from_slice!(
|
||||||
n: hlen, s: this.history[hdist & 0x7FFF ..])
|
n: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||||
if hlen <= n_copied {
|
if hlen <= n_copied {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
hlen -= n_copied
|
hlen -= n_copied
|
||||||
args.dst.copy_n_from_slice!(n: hlen, s: this.history[..])
|
args.dst.copy_n32_from_slice!(n: hlen, s: this.history[..])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ pri func decoder.decode_huffman_fast!(dst: base.io_writer, src: base.io_reader)
|
|||||||
assert (length as base.u64) <= args.dst.available() via "a <= b: a <= c; c <= b"(c: 258)
|
assert (length as base.u64) <= args.dst.available() via "a <= b: a <= c; c <= b"(c: 258)
|
||||||
|
|
||||||
// Copy from args.dst.
|
// Copy from args.dst.
|
||||||
args.dst.copy_n_from_history_fast!(n: length, distance: (dist_minus_1 + 1))
|
args.dst.copy_n32_from_history_fast!(n: length, distance: (dist_minus_1 + 1))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
|||||||
|
|
||||||
// Copy from hdist to the end of this.history.
|
// Copy from hdist to the end of this.history.
|
||||||
while true {
|
while true {
|
||||||
n_copied = args.dst.copy_n_from_slice!(
|
n_copied = args.dst.copy_n32_from_slice!(
|
||||||
n: hlen, s: this.history[hdist & 0x7FFF ..])
|
n: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||||
if hlen <= n_copied {
|
if hlen <= n_copied {
|
||||||
hlen = 0
|
hlen = 0
|
||||||
@@ -245,7 +245,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
|||||||
// Copy from the start of this.history, if we wrapped around.
|
// Copy from the start of this.history, if we wrapped around.
|
||||||
if hlen > 0 {
|
if hlen > 0 {
|
||||||
while true {
|
while true {
|
||||||
n_copied = args.dst.copy_n_from_slice!(
|
n_copied = args.dst.copy_n32_from_slice!(
|
||||||
n: hlen, s: this.history[hdist & 0x7FFF ..])
|
n: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||||
if hlen <= n_copied {
|
if hlen <= n_copied {
|
||||||
hlen = 0
|
hlen = 0
|
||||||
@@ -264,7 +264,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy from args.dst.
|
// Copy from args.dst.
|
||||||
n_copied = args.dst.copy_n_from_history!(n: length, distance: (dist_minus_1 + 1))
|
n_copied = args.dst.copy_n32_from_history!(n: length, distance: (dist_minus_1 + 1))
|
||||||
if length <= n_copied {
|
if length <= n_copied {
|
||||||
length = 0
|
length = 0
|
||||||
break
|
break
|
||||||
|
|||||||
+12
-12
@@ -253,7 +253,7 @@ pub func decoder.ack_metadata_chunk?(src: base.io_reader) {
|
|||||||
// metadata passed to the caller.
|
// metadata passed to the caller.
|
||||||
this.metadata_chunk_length_value += 1
|
this.metadata_chunk_length_value += 1
|
||||||
} else {
|
} else {
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
}
|
}
|
||||||
this.metadata_io_position =
|
this.metadata_io_position =
|
||||||
args.src.position() ~sat+ this.metadata_chunk_length_value
|
args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||||
@@ -261,7 +261,7 @@ pub func decoder.ack_metadata_chunk?(src: base.io_reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Consume the '\x00' that means a zero-length block.
|
// Consume the '\x00' that means a zero-length block.
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.call_sequence = 2
|
this.call_sequence = 2
|
||||||
@@ -399,7 +399,7 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
|||||||
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
|
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
|
||||||
flags = args.src.read_u8?()
|
flags = args.src.read_u8?()
|
||||||
if (flags & 0x80) <> 0 {
|
if (flags & 0x80) <> 0 {
|
||||||
args.src.skip?(n: (3 as base.u32) << (1 + (flags & 0x07)))
|
args.src.skip32?(n: (3 as base.u32) << (1 + (flags & 0x07)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the LZW literal width.
|
// Process the LZW literal width.
|
||||||
@@ -516,7 +516,7 @@ pri func decoder.decode_lsd?(src: base.io_reader) {
|
|||||||
flags = args.src.read_u8?()
|
flags = args.src.read_u8?()
|
||||||
background_color_index = args.src.read_u8?()
|
background_color_index = args.src.read_u8?()
|
||||||
// Ignore the Pixel Aspect Ratio byte.
|
// Ignore the Pixel Aspect Ratio byte.
|
||||||
args.src.skip?(n: 1)
|
args.src.skip32?(n: 1)
|
||||||
|
|
||||||
// Read the optional Global Color Table.
|
// Read the optional Global Color Table.
|
||||||
i = 0
|
i = 0
|
||||||
@@ -598,7 +598,7 @@ pri func decoder.skip_blocks?(src: base.io_reader) {
|
|||||||
if block_size == 0 {
|
if block_size == 0 {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
args.src.skip?(n: block_size as base.u32)
|
args.src.skip32?(n: block_size as base.u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,7 +646,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
|||||||
//
|
//
|
||||||
// Other extensions include XMP metadata.
|
// Other extensions include XMP metadata.
|
||||||
if block_size <> 11 {
|
if block_size <> 11 {
|
||||||
args.src.skip?(n: block_size as base.u32)
|
args.src.skip32?(n: block_size as base.u32)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
is_animexts = true
|
is_animexts = true
|
||||||
@@ -668,12 +668,12 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
|||||||
// count.
|
// count.
|
||||||
block_size = args.src.read_u8?()
|
block_size = args.src.read_u8?()
|
||||||
if block_size <> 3 {
|
if block_size <> 3 {
|
||||||
args.src.skip?(n: block_size as base.u32)
|
args.src.skip32?(n: block_size as base.u32)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c = args.src.read_u8?()
|
c = args.src.read_u8?()
|
||||||
if c <> 0x01 {
|
if c <> 0x01 {
|
||||||
args.src.skip?(n: 2)
|
args.src.skip32?(n: 2)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
this.num_loops = args.src.read_u16le_as_u32?()
|
this.num_loops = args.src.read_u16le_as_u32?()
|
||||||
@@ -703,7 +703,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
|||||||
yield? base."$short read"
|
yield? base."$short read"
|
||||||
}
|
}
|
||||||
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
|
this.metadata_chunk_length_value = args.src.peek_u8_as_u64()
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
this.metadata_fourcc_value = 0x49434350 // "ICCP"
|
this.metadata_fourcc_value = 0x49434350 // "ICCP"
|
||||||
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||||
this.call_sequence = 1
|
this.call_sequence = 1
|
||||||
@@ -722,7 +722,7 @@ pri func decoder.decode_ae?(src: base.io_reader) {
|
|||||||
// metadata passed to the caller.
|
// metadata passed to the caller.
|
||||||
this.metadata_chunk_length_value += 1
|
this.metadata_chunk_length_value += 1
|
||||||
} else {
|
} else {
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
}
|
}
|
||||||
this.metadata_fourcc_value = 0x584D5020 // "XMP "
|
this.metadata_fourcc_value = 0x584D5020 // "XMP "
|
||||||
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
this.metadata_io_position = args.src.position() ~sat+ this.metadata_chunk_length_value
|
||||||
@@ -962,7 +962,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
block_size = args.src.peek_u8_as_u64()
|
block_size = args.src.peek_u8_as_u64()
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if decoder_workbuf_len_max_incl_worst_case > args.workbuf.length() {
|
if decoder_workbuf_len_max_incl_worst_case > args.workbuf.length() {
|
||||||
@@ -993,7 +993,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
|||||||
|
|
||||||
// Skip any trailing blocks.
|
// Skip any trailing blocks.
|
||||||
if need_block_size or (block_size > 0) {
|
if need_block_size or (block_size > 0) {
|
||||||
args.src.skip?(n: block_size as base.u32)
|
args.src.skip32?(n: block_size as base.u32)
|
||||||
this.skip_blocks?(src: args.src)
|
this.skip_blocks?(src: args.src)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,12 +68,12 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
|||||||
}
|
}
|
||||||
flags = args.src.read_u8?()
|
flags = args.src.read_u8?()
|
||||||
// TODO: API for returning the header's MTIME field.
|
// TODO: API for returning the header's MTIME field.
|
||||||
args.src.skip?(n: 6)
|
args.src.skip32?(n: 6)
|
||||||
|
|
||||||
// Handle FEXTRA.
|
// Handle FEXTRA.
|
||||||
if (flags & 0x04) <> 0 {
|
if (flags & 0x04) <> 0 {
|
||||||
xlen = args.src.read_u16le?()
|
xlen = args.src.read_u16le?()
|
||||||
args.src.skip?(n: xlen as base.u32)
|
args.src.skip32?(n: xlen as base.u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle FNAME.
|
// Handle FNAME.
|
||||||
@@ -102,7 +102,7 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
|||||||
|
|
||||||
// Handle FHCRC.
|
// Handle FHCRC.
|
||||||
if (flags & 0x02) <> 0 {
|
if (flags & 0x02) <> 0 {
|
||||||
args.src.skip?(n: 2)
|
args.src.skip32?(n: 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserved flags bits must be zero.
|
// Reserved flags bits must be zero.
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
|||||||
// Read 4 bytes, using the "Variant 4" technique of
|
// Read 4 bytes, using the "Variant 4" technique of
|
||||||
// https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/
|
// https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/
|
||||||
bits |= args.src.peek_u32le() ~mod<< n_bits
|
bits |= args.src.peek_u32le() ~mod<< n_bits
|
||||||
args.src.skip_fast!(actual: (31 - n_bits) >> 3, worst_case: 3)
|
args.src.skip32_fast!(actual: (31 - n_bits) >> 3, worst_case: 3)
|
||||||
n_bits |= 24
|
n_bits |= 24
|
||||||
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
|
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
|
||||||
assert n_bits >= width via "a >= b: b <= a"()
|
assert n_bits >= width via "a >= b: b <= a"()
|
||||||
@@ -168,7 +168,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
if n_bits >= width {
|
if n_bits >= width {
|
||||||
// No-op.
|
// No-op.
|
||||||
@@ -177,7 +177,7 @@ pri func decoder.read_from!(src: base.io_reader) {
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
bits |= args.src.peek_u8_as_u32() << n_bits
|
bits |= args.src.peek_u8_as_u32() << n_bits
|
||||||
args.src.skip_fast!(actual: 1, worst_case: 1)
|
args.src.skip32_fast!(actual: 1, worst_case: 1)
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
|
assert width <= n_bits via "a <= b: a <= c; c <= b"(c: 12)
|
||||||
assert n_bits >= width via "a >= b: b <= a"()
|
assert n_bits >= width via "a >= b: b <= a"()
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ pri func decoder.skip_frame?(src: base.io_reader) {
|
|||||||
total_bytes = bytes_per_row * (this.height as base.u64)
|
total_bytes = bytes_per_row * (this.height as base.u64)
|
||||||
|
|
||||||
// TODO: total_bytes may be larger than UINT32_MAX.
|
// TODO: total_bytes may be larger than UINT32_MAX.
|
||||||
args.src.skip?(n: (total_bytes & 0xFFFFFFFF) as base.u32)
|
args.src.skip32?(n: (total_bytes & 0xFFFFFFFF) as base.u32)
|
||||||
|
|
||||||
this.seen_frame = true
|
this.seen_frame = true
|
||||||
this.call_sequence = 2
|
this.call_sequence = 2
|
||||||
|
|||||||
Reference in new issue
Block a user