mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Rename cgen/base-impl.h methods for consistency.
This commit is contained in:
1 parent
0384c5e4a8
commit
2335024d43
5 files changed
+57
-54
No files matched your search
@@ -139,13 +139,14 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is
|
||||
// the minimum of dst.len and src.len.
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, n) where
|
||||
// n is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
size_t n = dst.len < src.len ? dst.len : src.len;
|
||||
if (n > 0) {
|
||||
memmove(dst.ptr, src.ptr, n);
|
||||
@@ -153,11 +154,11 @@ static inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
if (length > (wend - wptr)) {
|
||||
length = wend - wptr;
|
||||
@@ -174,11 +175,11 @@ static inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
uint8_t* ptr = *ptr_ptr;
|
||||
size_t d = ptr - start;
|
||||
if ((d == 0) || (d < (size_t)(distance))) {
|
||||
|
||||
@@ -28,9 +28,9 @@ const baseImpl = "" +
|
||||
"ROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:;\n\n#define PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (status < 0) { \\\n goto exit; \\\n } else if (status == 0) { \\\n goto ok; \\\n } \\\n coro_susp_point = n; \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n// Declare the printf prototype. The generated code shouldn't need this at all,\n// but it's useful for manual printf debugging.\nextern int printf(const char* __restrict __format, ...);\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n" +
|
||||
"\n// ---------------- Static Inline Functions\n//\n// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They are in base-impl.h and hence copy/pasted into every generated C file,\n// instead of being in some \"base.c\" file, since a design goal is that users of\n// the generated C code can often just #include a single .c file, such as\n// \"gif.c\", without having to additionally include or otherwise build and link\n// a \"base.c\" file.\n//\n// They are static, so that linking multiple puffs .o files won't complain about\n// duplicate function definitions.\n//\n// They are explicitly marked inline, even if modern compilers don't use the\n// inline attribute to guide optimizations such as inlining, to avoid the\n// -Wunused-function warning, and we like to compile with -Wall -Werror.\n\nstatic inline uint16_t puffs_base_load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t puff" +
|
||||
"s_base_load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t puffs_base_load_u32be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);\n}\n\nstatic inline uint32_t puffs_base_load_u32le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_i(\n puffs_base_slice_u8 s,\n uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = s.len - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_j(\n puffs_base_slice_u8 s,\n uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline " +
|
||||
"puffs_base_slice_u8\npuffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\n// puffs_base_slice_u8_prefix returns up to the first n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_suffix returns up to the last n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.ptr += (uint64_t)(s.len) - n;\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is\n// the minimum of dst.len and src.len.\n//\n// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and" +
|
||||
" results in a no-op.\nstatic inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n size_t n = dst.len < src.len ? dst.len : src.len;\n if (n > 0) {\n memmove(dst.ptr, src.ptr, n);\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n if (length > (wend - wptr)) {\n length = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (length > (rend - rptr)) {\n length = rend - rptr;\n }\n if (length > 0) {\n memmove(wptr, rptr, length);\n *ptr_wptr += length;\n *ptr_rptr += length;\n }\n return length;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_history32(" +
|
||||
"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 size_t d = ptr - start;\n if ((d == 0) || (d < (size_t)(distance))) {\n return 0;\n }\n start = ptr - distance;\n size_t l = end - ptr;\n if ((size_t)(length) > l) {\n length = l;\n } else {\n l = length;\n }\n // TODO: is manual unrolling actually helpful?\n for (; l >= 8; l -= 8) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; l; l--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
"puffs_base_slice_u8\npuffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\n// puffs_base_slice_u8_prefix returns up to the first n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_suffix returns up to the last n bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(\n puffs_base_slice_u8 s,\n uint64_t n) {\n if ((uint64_t)(s.len) > n) {\n s.ptr += (uint64_t)(s.len) - n;\n s.len = n;\n }\n return s;\n}\n\n// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, n) where\n// n is the minimum of dst.len and src.len.\n//\n// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is val" +
|
||||
"id and results in a no-op.\nstatic inline uint64_t puffs_base_slice_u8_copy_from_slice(\n puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n size_t n = dst.len < src.len ? dst.len : src.len;\n if (n > 0) {\n memmove(dst.ptr, src.ptr, n);\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n if (length > (wend - wptr)) {\n length = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (length > (rend - rptr)) {\n length = rend - rptr;\n }\n if (length > 0) {\n memmove(wptr, rptr, length);\n *ptr_wptr += length;\n *ptr_rptr += length;\n }\n return length;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_from_hi" +
|
||||
"story32(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 size_t d = ptr - start;\n if ((d == 0) || (d < (size_t)(distance))) {\n return 0;\n }\n start = ptr - distance;\n size_t l = end - ptr;\n if ((size_t)(length) > l) {\n length = l;\n } else {\n l = length;\n }\n // TODO: is manual unrolling actually helpful?\n for (; l >= 8; l -= 8) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; l; l--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
""
|
||||
|
||||
type template_args_short_read struct {
|
||||
|
||||
@@ -160,7 +160,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) {
|
||||
b.printf("puffs_base_writer1_copy_from32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
b.printf("puffs_base_writer1_copy_from_reader32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
// TODO: don't assume that the first argument is "in.src".
|
||||
b.printf(", &%srptr_src, %srend_src,", bPrefix, bPrefix)
|
||||
a := n.Args()[1].Arg().Value()
|
||||
@@ -171,7 +171,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromHistory32, 2) {
|
||||
b.printf("puffs_base_writer1_copy_history32(&%swptr_dst, %swstart_dst, %swend_dst",
|
||||
b.printf("puffs_base_writer1_copy_from_history32(&%swptr_dst, %swstart_dst, %swend_dst",
|
||||
bPrefix, bPrefix, bPrefix)
|
||||
for _, o := range n.Args() {
|
||||
b.writeb(',')
|
||||
@@ -188,7 +188,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyCopyFromSlice, 1) {
|
||||
b.writes("puffs_base_slice_u8_copy_from(")
|
||||
b.writes("puffs_base_slice_u8_copy_from_slice(")
|
||||
receiver := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, receiver, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
|
||||
+21
-20
@@ -434,13 +434,14 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is
|
||||
// the minimum of dst.len and src.len.
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, n) where
|
||||
// n is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
size_t n = dst.len < src.len ? dst.len : src.len;
|
||||
if (n > 0) {
|
||||
memmove(dst.ptr, src.ptr, n);
|
||||
@@ -448,11 +449,11 @@ static inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
if (length > (wend - wptr)) {
|
||||
length = wend - wptr;
|
||||
@@ -469,11 +470,11 @@ static inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
uint8_t* ptr = *ptr_ptr;
|
||||
size_t d = ptr - start;
|
||||
if ((d == 0) || (d < (size_t)(distance))) {
|
||||
@@ -769,13 +770,13 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
});
|
||||
if (((uint64_t)(v_written.len)) >= 32768) {
|
||||
v_written = puffs_base_slice_u8_suffix(v_written, 32768);
|
||||
puffs_base_slice_u8_copy_from(
|
||||
puffs_base_slice_u8_copy_from_slice(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written);
|
||||
self->private_impl.f_history_index = 32768;
|
||||
} else {
|
||||
v_n = puffs_base_slice_u8_copy_from(
|
||||
v_n = puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8_subslice_i(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
@@ -783,7 +784,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
v_written);
|
||||
if (v_n < ((uint64_t)(v_written.len))) {
|
||||
v_written = puffs_base_slice_u8_subslice_i(v_written, v_n);
|
||||
v_n = puffs_base_slice_u8_copy_from(
|
||||
v_n = puffs_base_slice_u8_copy_from_slice(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written);
|
||||
@@ -1103,8 +1104,8 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
|
||||
}
|
||||
v_length = ((v_length) & ((1 << (16)) - 1));
|
||||
while (true) {
|
||||
v_n = puffs_base_writer1_copy_from32(&b_wptr_dst, b_wend_dst, &b_rptr_src,
|
||||
b_rend_src, v_length);
|
||||
v_n = puffs_base_writer1_copy_from_reader32(
|
||||
&b_wptr_dst, b_wend_dst, &b_rptr_src, b_rend_src, v_length);
|
||||
if (v_length == v_n) {
|
||||
goto label_0_break;
|
||||
} else if (v_length < v_n) {
|
||||
@@ -1443,7 +1444,7 @@ puffs_flate_status puffs_flate_decoder_decode_huffman(
|
||||
goto label_5_continue;
|
||||
}
|
||||
}
|
||||
v_n = puffs_base_writer1_copy_history32(
|
||||
v_n = puffs_base_writer1_copy_from_history32(
|
||||
&b_wptr_dst, b_wstart_dst, b_wend_dst, v_distance, v_length);
|
||||
if (v_length == v_n) {
|
||||
goto label_5_break;
|
||||
|
||||
+15
-14
@@ -401,13 +401,14 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from calls memmove(dst.ptr, src.ptr, n) where n is
|
||||
// the minimum of dst.len and src.len.
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, n) where
|
||||
// n is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
size_t n = dst.len < src.len ? dst.len : src.len;
|
||||
if (n > 0) {
|
||||
memmove(dst.ptr, src.ptr, n);
|
||||
@@ -415,11 +416,11 @@ static inline uint64_t puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
if (length > (wend - wptr)) {
|
||||
length = wend - wptr;
|
||||
@@ -436,11 +437,11 @@ static inline uint32_t puffs_base_writer1_copy_from32(uint8_t** ptr_wptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
uint8_t* ptr = *ptr_ptr;
|
||||
size_t d = ptr - start;
|
||||
if ((d == 0) || (d < (size_t)(distance))) {
|
||||
|
||||
Reference in new issue
Block a user