From f107ec155dacd7f340ea6e45638e6dbf258c258c Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 22 Sep 2017 16:36:05 +1000 Subject: [PATCH] Rename puffs_u16be to puffs_base_load_u16be. --- cmd/puffs-c/internal/cgen/base-impl.h | 14 +++++++------- cmd/puffs-c/internal/cgen/data.go | 6 +++--- cmd/puffs-c/internal/cgen/statement.go | 2 +- gen/c/std/flate.c | 20 ++++++++++---------- gen/c/std/gif.c | 14 +++++++------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cmd/puffs-c/internal/cgen/base-impl.h b/cmd/puffs-c/internal/cgen/base-impl.h index 279b880e..9d26aba1 100644 --- a/cmd/puffs-c/internal/cgen/base-impl.h +++ b/cmd/puffs-c/internal/cgen/base-impl.h @@ -47,24 +47,24 @@ extern int printf(const char* __restrict __format, ...); // inline attribute to guide optimizations such as inlining, to avoid the // -Wunused-function warning, and we like to compile with -Wall -Werror. -// TODO: for puffs_u16be and similar functions, look for (ifdef) the x86 -// architecture and cast the pointer? Only do so if a benchmark justifies the -// additional code path. Modern compilers might already generate good code. +// TODO: for puffs_base_load_u16be etc, look for (ifdef) the x86 architecture +// and cast the pointer? Only do so if a benchmark justifies the additional code +// path. Modern compilers might already generate good code. -static inline uint16_t puffs_u16be(uint8_t* p) { +static inline uint16_t puffs_base_load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } -static inline uint16_t puffs_u16le(uint8_t* p) { +static inline uint16_t puffs_base_load_u16le(uint8_t* p) { return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8); } -static inline uint32_t puffs_u32be(uint8_t* p) { +static inline uint32_t puffs_base_load_u32be(uint8_t* p) { return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) | ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0); } -static inline uint32_t puffs_u32le(uint8_t* p) { +static inline uint32_t puffs_base_load_u32le(uint8_t* p) { return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24); } diff --git a/cmd/puffs-c/internal/cgen/data.go b/cmd/puffs-c/internal/cgen/data.go index a0ffb6a8..d307d03c 100644 --- a/cmd/puffs-c/internal/cgen/data.go +++ b/cmd/puffs-c/internal/cgen/data.go @@ -13,9 +13,9 @@ const baseHeader = "" + const baseImpl = "" + "#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\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#de" + - "fine 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\n// TODO: for puffs_u16be and similar functions, look for (ifdef) the x86\n// architecture and cast the pointer" + - "? Only do so if a benchmark justifies the\n// additional code path. Modern compilers might already generate good code.\n\nstatic inline uint16_t puffs_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t puffs_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t puffs_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_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\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.\nstatic inline void puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n memmove(dst.ptr, src.ptr, dst.len < src.len ? dst.len : src.len);\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" + + "fine 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\n// TODO: for puffs_base_load_u16be etc, look for (ifdef) the x86 architecture\n// and cast the pointer? Only d" + + "o so if a benchmark justifies the additional code\n// path. Modern compilers might already generate good code.\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 puffs_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\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 byte" + + "s 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.\nstatic inline void puffs_base_slice_u8_copy_from(puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n memmove(dst.ptr, src.ptr, dst.len < src.len ? dst.len : src.len);\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" + "" type template_args_short_read struct { diff --git a/cmd/puffs-c/internal/cgen/statement.go b/cmd/puffs-c/internal/cgen/statement.go index 1c4d716e..ab158d6d 100644 --- a/cmd/puffs-c/internal/cgen/statement.go +++ b/cmd/puffs-c/internal/cgen/statement.go @@ -659,7 +659,7 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia cPrefix, g.currFunk.astFunc.Name().String(g.tm)) b.printf("if (PUFFS_LIKELY(%srend_src - %srptr_src >= %d)) {", bPrefix, bPrefix, size/8) - b.printf("%s%d = puffs_u%d%s(%srptr_src);\n", tPrefix, temp1, size, endianness, bPrefix) + b.printf("%s%d = puffs_base_load_u%d%s(%srptr_src);\n", tPrefix, temp1, size, endianness, bPrefix) b.printf("%srptr_src += %d;\n", bPrefix, size/8) b.printf("} else {") b.printf("%s = 0;\n", scratchName) diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index ab1047dd..b034d46f 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -333,24 +333,24 @@ extern int printf(const char* __restrict __format, ...); // inline attribute to guide optimizations such as inlining, to avoid the // -Wunused-function warning, and we like to compile with -Wall -Werror. -// TODO: for puffs_u16be and similar functions, look for (ifdef) the x86 -// architecture and cast the pointer? Only do so if a benchmark justifies the -// additional code path. Modern compilers might already generate good code. +// TODO: for puffs_base_load_u16be etc, look for (ifdef) the x86 architecture +// and cast the pointer? Only do so if a benchmark justifies the additional code +// path. Modern compilers might already generate good code. -static inline uint16_t puffs_u16be(uint8_t* p) { +static inline uint16_t puffs_base_load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } -static inline uint16_t puffs_u16le(uint8_t* p) { +static inline uint16_t puffs_base_load_u16le(uint8_t* p) { return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8); } -static inline uint32_t puffs_u32be(uint8_t* p) { +static inline uint32_t puffs_base_load_u32be(uint8_t* p) { return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) | ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0); } -static inline uint32_t puffs_u32le(uint8_t* p) { +static inline uint32_t puffs_base_load_u32le(uint8_t* p) { return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24); } @@ -913,7 +913,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed( PUFFS_COROUTINE_SUSPENSION_POINT(1); uint32_t t_1; if (PUFFS_LIKELY(b_rend_src - b_rptr_src >= 4)) { - t_1 = puffs_u32le(b_rptr_src); + t_1 = puffs_base_load_u32le(b_rptr_src); b_rptr_src += 4; } else { self->private_impl.c_decode_uncompressed[0].scratch = 0; @@ -1978,7 +1978,7 @@ puffs_flate_status puffs_flate_zlib_decoder_decode( PUFFS_COROUTINE_SUSPENSION_POINT(1); uint16_t t_1; if (PUFFS_LIKELY(b_rend_src - b_rptr_src >= 2)) { - t_1 = puffs_u16be(b_rptr_src); + t_1 = puffs_base_load_u16be(b_rptr_src); b_rptr_src += 2; } else { self->private_impl.c_decode[0].scratch = 0; @@ -2047,7 +2047,7 @@ puffs_flate_status puffs_flate_zlib_decoder_decode( PUFFS_COROUTINE_SUSPENSION_POINT(4); uint32_t t_3; if (PUFFS_LIKELY(b_rend_src - b_rptr_src >= 4)) { - t_3 = puffs_u32be(b_rptr_src); + t_3 = puffs_base_load_u32be(b_rptr_src); b_rptr_src += 4; } else { self->private_impl.c_decode[0].scratch = 0; diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 2fd86477..b10b73f8 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -304,24 +304,24 @@ extern int printf(const char* __restrict __format, ...); // inline attribute to guide optimizations such as inlining, to avoid the // -Wunused-function warning, and we like to compile with -Wall -Werror. -// TODO: for puffs_u16be and similar functions, look for (ifdef) the x86 -// architecture and cast the pointer? Only do so if a benchmark justifies the -// additional code path. Modern compilers might already generate good code. +// TODO: for puffs_base_load_u16be etc, look for (ifdef) the x86 architecture +// and cast the pointer? Only do so if a benchmark justifies the additional code +// path. Modern compilers might already generate good code. -static inline uint16_t puffs_u16be(uint8_t* p) { +static inline uint16_t puffs_base_load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } -static inline uint16_t puffs_u16le(uint8_t* p) { +static inline uint16_t puffs_base_load_u16le(uint8_t* p) { return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8); } -static inline uint32_t puffs_u32be(uint8_t* p) { +static inline uint32_t puffs_base_load_u32be(uint8_t* p) { return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) | ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0); } -static inline uint32_t puffs_u32le(uint8_t* p) { +static inline uint32_t puffs_base_load_u32le(uint8_t* p) { return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24); }