Rename some copy_from_xxx methods

This commit is contained in:
Nigel Tao committed 2018-07-08 13:56:49 +10:00
1 parent 732365b80d
commit 26eba56f57
17 files changed
+217 -218

No files matched your search

+17 -17
View File
@@ -513,12 +513,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -536,12 +536,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -555,18 +555,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -582,12 +582,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -621,11 +621,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+12 -9
View File
@@ -161,12 +161,12 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, rp replacementPolicy, depth uint32, bcoHack bool) error {
// TODO: don't hard-code the recv being a_dst.
switch method {
case t.IDCopyFromHistory32:
case t.IDCopyNFromHistory:
bco := ""
if bcoHack {
bco = "__bco"
}
b.printf("wuffs_base__io_writer__copy_from_history32%s("+
b.printf("wuffs_base__io_writer__copy_n_from_history%s("+
"&ioptr_dst, %sdst.private_impl.bounds[0], iobounds1_dst",
bco, aPrefix)
for _, o := range args {
@@ -178,18 +178,21 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
b.writeb(')')
return nil
case t.IDCopyFromReader32:
b.printf("wuffs_base__io_writer__copy_from_reader32(&ioptr_dst, iobounds1_dst,")
// TODO: don't assume that the first argument is "in.src".
b.printf("&ioptr_src, iobounds1_src,")
return g.writeArgs(b, args[1:], rp, depth)
case t.IDCopyNFromReader:
b.printf("wuffs_base__io_writer__copy_n_from_reader(&ioptr_dst, iobounds1_dst,")
if err := g.writeExpr(b, args[0].AsArg().Value(), rp, depth); err != nil {
return err
}
// TODO: don't assume that the last argument is "in.src".
b.printf(", &ioptr_src, iobounds1_src)")
return nil
case t.IDCopyFromSlice:
b.printf("wuffs_base__io_writer__copy_from_slice(&ioptr_dst, iobounds1_dst,")
return g.writeArgs(b, args, rp, depth)
case t.IDCopyFromSlice32:
b.printf("wuffs_base__io_writer__copy_from_slice32(&ioptr_dst, iobounds1_dst,")
case t.IDCopyNFromSlice:
b.printf("wuffs_base__io_writer__copy_n_from_slice(&ioptr_dst, iobounds1_dst,")
return g.writeArgs(b, args, rp, depth)
case t.IDSetMark:
+4 -4
View File
@@ -132,10 +132,10 @@ const basePrivateH = "" +
" .min_incl = min_incl,\n .max_excl = max_excl,\n });\n}\n\nstatic inline wuffs_base__rect_ii_u32 wuffs_base__utility__make_rect_ii_u32(\n wuffs_base__utility* ignored,\n uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_incl_x,\n uint32_t max_incl_y) {\n return ((wuffs_base__rect_ii_u32){\n .min_incl_x = min_incl_x,\n .min_incl_y = min_incl_y,\n .max_incl_x = max_incl_x,\n .max_incl_y = max_incl_y,\n });\n}\n\nstatic inline wuffs_base__rect_ie_u32 wuffs_base__utility__make_rect_ie_u32(\n wuffs_base__utility* ignored,\n uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_excl_x,\n uint32_t max_excl_y) {\n return ((wuffs_base__rect_ie_u32){\n .min_incl_x = min_incl_x,\n .min_incl_y = min_incl_y,\n .max_excl_x = max_excl_x,\n .max_excl_y = max_excl_y,\n });\n}\n\n" +
"" +
"// ---------------- I/O\n\nstatic inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {\n return (buf.ptr || (buf.len == 0)) && (buf.len >= buf.wi) &&\n (buf.wi >= buf.ri);\n}\n\nstatic inline bool wuffs_base__io_reader__is_eof(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf && buf->closed && (buf->ptr + buf->wi == o.private_impl.bounds[1]);\n}\n\nstatic inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) bounds.\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline bool wuf" +
"fs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) bounds.\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n if (!distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = 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_from_history32 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_from_history32__bco below.\n //\n // Alternatively, or additionally, have a sloppy_copy_from_history32 method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized\n// version of the wuffs_base__io_writer__copy_from_history32 function above.\n// The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_pt" +
"r - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_reader32(\n uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r,\n uint32_t length) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_iop" +
"tr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t wuffs_base__io_writer__copy_from_slice(\n uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_slice32(\n uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n wuffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__set_limit(\n wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n uint64_t limit) {\n if (o && (((size_t)(o->pri" +
"fs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) bounds.\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_n_from_history(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = 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__bco 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 *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized\n// version of the wuffs_base__io_writer__copy_n_from_history function above.\n// The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_pt" +
"r - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_n_from_reader(\n uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_iop" +
"tr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t wuffs_base__io_writer__copy_from_slice(\n uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_n_from_slice(\n uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__set_limit(\n wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n uint64_t limit) {\n if (o && (((size_t)(o->pri" +
"vate_impl.bounds[1] - ioptr_r)) > limit)) {\n o->private_impl.bounds[1] = ioptr_r + limit;\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__set_mark(\n wuffs_base__io_reader* o,\n uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_writer__set(\n wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ioptr1_ptr,\n uint8_t** ioptr2_ptr,\n wuffs_base__slice_u8 s) {\n b->ptr = s.ptr;\n b->len = s.len;\n b->wi = 0;\n b->ri = 0;\n b->closed = false;\n o->private_impl.buf = b;\n o->private_impl.bounds[0] = s.ptr;\n o->private_impl.bounds[1] = s.ptr + s.len;\n *ioptr1_ptr = s.ptr;\n *ioptr2_ptr = s.ptr + s.len;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_writer__set_mark(\n wuffs_base__io_writer* o,\n uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base_" +
"_empty_struct){});\n}\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // WUFFS_INCLUDE_GUARD__BASE_PRIVATE\n" +
""
+17 -17
View File
@@ -2266,12 +2266,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2289,12 +2289,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2308,18 +2308,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2335,12 +2335,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2374,11 +2374,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+17 -17
View File
@@ -2334,12 +2334,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2357,12 +2357,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2376,18 +2376,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2403,12 +2403,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2442,11 +2442,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+17 -17
View File
@@ -2335,12 +2335,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2358,12 +2358,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2377,18 +2377,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2404,12 +2404,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2443,11 +2443,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+37 -41
View File
@@ -2426,12 +2426,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2449,12 +2449,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2468,18 +2468,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2495,12 +2495,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2534,11 +2534,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
@@ -3212,8 +3212,8 @@ static wuffs_base__status wuffs_deflate__decoder__decode_uncompressed(
}
v_length = ((v_length) & ((1 << (16)) - 1));
while (true) {
v_n_copied = wuffs_base__io_writer__copy_from_reader32(
&ioptr_dst, iobounds1_dst, &ioptr_src, iobounds1_src, v_length);
v_n_copied = wuffs_base__io_writer__copy_n_from_reader(
&ioptr_dst, iobounds1_dst, v_length, &ioptr_src, iobounds1_src);
if (v_length <= v_n_copied) {
status = WUFFS_BASE__STATUS_OK;
goto ok;
@@ -4152,22 +4152,20 @@ label_0_continue:;
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
while (true) {
v_n_copied = wuffs_base__io_writer__copy_from_slice32(
&ioptr_dst, iobounds1_dst,
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&ioptr_dst, iobounds1_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
.len = 32768}),
(v_hdist & 32767)),
v_hlen);
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
goto label_1_break;
}
v_hlen -= v_n_copied;
wuffs_base__io_writer__copy_from_slice32(
&ioptr_dst, iobounds1_dst,
wuffs_base__io_writer__copy_n_from_slice(
&ioptr_dst, iobounds1_dst, v_hlen,
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
.len = 32768}),
v_hlen);
.len = 32768}));
goto label_1_break;
}
label_1_break:;
@@ -4185,9 +4183,9 @@ label_0_continue:;
goto exit;
}
}
wuffs_base__io_writer__copy_from_history32__bco(
&ioptr_dst, a_dst.private_impl.bounds[0], iobounds1_dst,
(v_dist_minus_1 + 1), v_length);
wuffs_base__io_writer__copy_n_from_history__bco(
&ioptr_dst, a_dst.private_impl.bounds[0], iobounds1_dst, v_length,
(v_dist_minus_1 + 1));
goto label_2_break;
}
label_2_break:;
@@ -4532,13 +4530,12 @@ static wuffs_base__status wuffs_deflate__decoder__decode_huffman_slow(
}
v_hdist = (self->private_impl.f_history_index - v_hdist);
while (true) {
v_n_copied = wuffs_base__io_writer__copy_from_slice32(
&ioptr_dst, iobounds1_dst,
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&ioptr_dst, iobounds1_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
.len = 32768}),
(v_hdist & 32767)),
v_hlen);
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label_5_break;
@@ -4556,13 +4553,12 @@ static wuffs_base__status wuffs_deflate__decoder__decode_huffman_slow(
label_5_break:;
if (v_hlen > 0) {
while (true) {
v_n_copied = wuffs_base__io_writer__copy_from_slice32(
&ioptr_dst, iobounds1_dst,
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&ioptr_dst, iobounds1_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
((wuffs_base__slice_u8){
.ptr = self->private_impl.f_history, .len = 32768}),
(v_hdist & 32767)),
v_hlen);
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
goto label_6_break;
@@ -4578,9 +4574,9 @@ static wuffs_base__status wuffs_deflate__decoder__decode_huffman_slow(
goto label_0_continue;
}
}
v_n_copied = wuffs_base__io_writer__copy_from_history32(
&ioptr_dst, a_dst.private_impl.bounds[0], iobounds1_dst,
(v_dist_minus_1 + 1), v_length);
v_n_copied = wuffs_base__io_writer__copy_n_from_history(
&ioptr_dst, a_dst.private_impl.bounds[0], iobounds1_dst, v_length,
(v_dist_minus_1 + 1));
if (v_length <= v_n_copied) {
v_length = 0;
goto label_7_break;
+17 -17
View File
@@ -2590,12 +2590,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2613,12 +2613,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2632,18 +2632,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2659,12 +2659,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2698,11 +2698,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+17 -17
View File
@@ -2633,12 +2633,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2656,12 +2656,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2675,18 +2675,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2702,12 +2702,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2741,11 +2741,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+17 -17
View File
@@ -2366,12 +2366,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2389,12 +2389,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2408,18 +2408,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2435,12 +2435,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2474,11 +2474,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+17 -17
View File
@@ -2630,12 +2630,12 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
(o.private_impl.bounds[1] == NULL));
}
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
if (!distance) {
return 0;
}
@@ -2653,12 +2653,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
// 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_from_history32 Wuffs method should also take an unroll hint argument,
// 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'.
//
// See also wuffs_base__io_writer__copy_from_history32__bco below.
// See also wuffs_base__io_writer__copy_n_from_history__bco below.
//
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
// Alternatively, or additionally, have a sloppy_copy_n_from_history method
// that copies 8 bytes at a time, possibly writing more than length bytes?
for (; n >= 3; n -= 3) {
*ptr++ = *start++;
@@ -2672,18 +2672,18 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32(
return length;
}
// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_from_history32 function above.
// wuffs_base__io_writer__copy_n_from_history__bco is a Bounds Check Optimized
// version of the wuffs_base__io_writer__copy_n_from_history function above.
// The caller needs to prove that:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
static inline uint32_t wuffs_base__io_writer__copy_n_from_history__bco(
uint8_t** ptr_ptr,
uint8_t* start,
uint8_t* end,
uint32_t distance,
uint32_t length) {
uint32_t length,
uint32_t distance) {
uint8_t* ptr = *ptr_ptr;
start = ptr - distance;
uint32_t n = length;
@@ -2699,12 +2699,12 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
return length;
}
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_reader(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
uint32_t length,
uint8_t** ptr_ioptr_r,
uint8_t* iobounds1_r,
uint32_t length) {
uint8_t* iobounds1_r) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = length;
if (n > ((size_t)(iobounds1_w - ioptr_w))) {
@@ -2738,11 +2738,11 @@ static inline uint64_t wuffs_base__io_writer__copy_from_slice(
return n;
}
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
static inline uint32_t wuffs_base__io_writer__copy_n_from_slice(
uint8_t** ptr_ioptr_w,
uint8_t* iobounds1_w,
wuffs_base__slice_u8 src,
uint32_t length) {
uint32_t length,
wuffs_base__slice_u8 src) {
uint8_t* ioptr_w = *ptr_ioptr_w;
size_t n = src.len;
if (n > length) {
+3 -3
View File
@@ -239,10 +239,10 @@ var Funcs = []string{
"io_writer.set_mark!()()",
"io_writer.since_mark()(ret slice u8)",
"io_writer.copy_from_history32!(distance u32, length u32)(ret u32)",
"io_writer.copy_from_reader32!(r io_reader, length u32)(ret u32)",
"io_writer.copy_from_slice!(s slice u8)(ret u64)",
"io_writer.copy_from_slice32!(s slice u8, length u32)(ret u32)",
"io_writer.copy_n_from_history!(n u32, distance u32)(ret u32)",
"io_writer.copy_n_from_reader!(n u32, r io_reader)(ret u32)",
"io_writer.copy_n_from_slice!(n u32, s slice u8)(ret u32)",
// ---- status
+7 -7
View File
@@ -63,27 +63,27 @@ func (q *checker) optimizeNonSuspendible(n *a.Expr) error {
// TODO: check that nReceiver's type is actually a io_reader or io_writer.
switch nMethod {
case t.IDCopyFromHistory32:
return q.optimizeCopyFromHistory32(n)
case t.IDCopyNFromHistory:
return q.optimizeCopyNFromHistory(n)
}
return nil
}
// optimizeCopyFromHistory32 checks if the code generator can call the Bounds
// Check Optimized version of CopyFromHistory32. As per cgen's base-private.h,
// optimizeCopyNFromHistory checks if the code generator can call the Bounds
// Check Optimized version of CopyFromHistory. As per cgen's base-private.h,
// the conditions are:
// - distance > 0
// - distance <= (*ptr_ptr - start)
// - length <= (end - *ptr_ptr)
func (q *checker) optimizeCopyFromHistory32(n *a.Expr) error {
func (q *checker) optimizeCopyNFromHistory(n *a.Expr) error {
// The arguments are (distance, length).
nReceiver, _, args := splitReceiverMethodArgs(n)
if len(args) != 2 {
return nil
}
d := args[0].AsArg().Value()
l := args[1].AsArg().Value()
l := args[0].AsArg().Value()
d := args[1].AsArg().Value()
// Check "distance > 0".
check0:
+8 -8
View File
@@ -517,10 +517,10 @@ const (
IDSkip32Fast = ID(0x184)
IDSkip64 = ID(0x185)
IDCopyFromHistory32 = ID(0x190)
IDCopyFromReader32 = ID(0x191)
IDCopyFromSlice = ID(0x192)
IDCopyFromSlice32 = ID(0x193)
IDCopyFromSlice = ID(0x190)
IDCopyNFromHistory = ID(0x191)
IDCopyNFromReader = ID(0x192)
IDCopyNFromSlice = ID(0x193)
// -------- 0x200 block.
@@ -794,10 +794,10 @@ var builtInsByID = [nBuiltInIDs]string{
IDSkip32Fast: "skip32_fast",
IDSkip64: "skip64",
IDCopyFromHistory32: "copy_from_history32",
IDCopyFromReader32: "copy_from_reader32",
IDCopyFromSlice: "copy_from_slice",
IDCopyFromSlice32: "copy_from_slice32",
IDCopyFromSlice: "copy_from_slice",
IDCopyNFromHistory: "copy_n_from_history",
IDCopyNFromReader: "copy_n_from_reader",
IDCopyNFromSlice: "copy_n_from_slice",
// -------- 0x200 block.
+1 -1
View File
@@ -229,7 +229,7 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader)()
}
length = length.low_bits(n:16)
while true {
var n_copied base.u32 = in.dst.copy_from_reader32!(r:in.src, length:length)
var n_copied base.u32 = in.dst.copy_n_from_reader!(n:length, r:in.src)
if length <= n_copied {
return
}
+4 -4
View File
@@ -318,13 +318,13 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader)()
// TODO: copy_from_slice32 should probably update the
// "in.dst.available() >= 258" fact. It should certainly
// invalidate any fact that was "<=" instead of ">=".
n_copied = in.dst.copy_from_slice32!(
s:this.history[hdist & 0x7FFF:], length:hlen)
n_copied = in.dst.copy_n_from_slice!(
n:hlen, s:this.history[hdist & 0x7FFF:])
if hlen <= n_copied {
break
}
hlen -= n_copied
in.dst.copy_from_slice32!(s:this.history[:], length:hlen)
in.dst.copy_n_from_slice!(n:hlen, s:this.history[:])
break
}
@@ -348,7 +348,7 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader)()
assert (length as base.u64) <= in.dst.available() via "a <= b: a <= c; c <= b"(c:258)
// Copy from in.dst.
in.dst.copy_from_history32!(distance:(dist_minus_1 + 1), length:length)
in.dst.copy_n_from_history!(n:length, distance:(dist_minus_1 + 1))
break
}
}
+5 -5
View File
@@ -206,8 +206,8 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader)()
// Copy from hdist to the end of this.history.
while true {
n_copied = in.dst.copy_from_slice32!(
s:this.history[hdist & 0x7FFF:], length:hlen)
n_copied = in.dst.copy_n_from_slice!(
n:hlen, s:this.history[hdist & 0x7FFF:])
if hlen <= n_copied {
hlen = 0
break
@@ -226,8 +226,8 @@ 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.
if hlen > 0 {
while true {
n_copied = in.dst.copy_from_slice32!(
s:this.history[hdist & 0x7FFF:], length:hlen)
n_copied = in.dst.copy_n_from_slice!(
n:hlen, s:this.history[hdist & 0x7FFF:])
if hlen <= n_copied {
hlen = 0
break
@@ -246,7 +246,7 @@ pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader)()
}
// Copy from in.dst.
n_copied = in.dst.copy_from_history32!(distance:(dist_minus_1 + 1), length:length)
n_copied = in.dst.copy_n_from_history!(n:length, distance:(dist_minus_1 + 1))
if length <= n_copied {
length = 0
break