From 732365b80d85dd3b034d5613e2294372d799c908 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 8 Jul 2018 13:12:50 +1000 Subject: [PATCH] Add write_fast_uxx methods --- cmd/wuffs-c/internal/cgen/base/base-private.h | 122 ++++++++++++++++++ cmd/wuffs-c/internal/cgen/builtin.go | 81 +++++++++--- cmd/wuffs-c/internal/cgen/data.go | 12 +- gen/c/base.c | 122 ++++++++++++++++++ gen/c/std/adler32.c | 122 ++++++++++++++++++ gen/c/std/crc32.c | 122 ++++++++++++++++++ gen/c/std/deflate.c | 122 ++++++++++++++++++ gen/c/std/gif.c | 122 ++++++++++++++++++ gen/c/std/gzip.c | 122 ++++++++++++++++++ gen/c/std/lzw.c | 122 ++++++++++++++++++ gen/c/std/zlib.c | 122 ++++++++++++++++++ lang/builtin/builtin.go | 25 ++++ lang/check/bounds.go | 54 +++++--- lang/token/list.go | 32 +++++ 14 files changed, 1260 insertions(+), 42 deletions(-) diff --git a/cmd/wuffs-c/internal/cgen/base/base-private.h b/cmd/wuffs-c/internal/cgen/base/base-private.h index ab629835..73be45c1 100644 --- a/cmd/wuffs-c/internal/cgen/base/base-private.h +++ b/cmd/wuffs-c/internal/cgen/base/base-private.h @@ -87,6 +87,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -169,6 +173,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/cmd/wuffs-c/internal/cgen/builtin.go b/cmd/wuffs-c/internal/cgen/builtin.go index 97e01ab9..652a68c9 100644 --- a/cmd/wuffs-c/internal/cgen/builtin.go +++ b/cmd/wuffs-c/internal/cgen/builtin.go @@ -116,10 +116,6 @@ func (g *gen) writeBuiltinIO(b *buffer, recv *a.Expr, method t.ID, args []*a.Nod func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, rp replacementPolicy, depth uint32) error { // TODO: don't hard-code the recv being a_src. switch method { - case t.IDPeekU8: - b.writes("(*ioptr_src)") - return nil - case t.IDSetLimit: b.printf("wuffs_base__io_reader__set_limit(&%ssrc, ioptr_src,", aPrefix) // TODO: update the ioptr variables? @@ -149,8 +145,8 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args [] return nil } - if method >= t.IDPeekU8 { - if m := method - t.IDPeekU8; m < t.ID(len(peekMethods)) { + if method >= peekMethodsBase { + if m := method - peekMethodsBase; m < t.ID(len(peekMethods)) { if p := peekMethods[m]; p.n != 0 { b.printf("wuffs_base__load_u%d%ce(ioptr_src)", p.n, p.endianness) return nil @@ -212,6 +208,24 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args [] return nil } + if method >= writeFastMethodsBase { + if m := method - writeFastMethodsBase; m < t.ID(len(writeFastMethods)) { + if p := writeFastMethods[m]; p.n != 0 { + // Generate a three part expression using the comma operator: + // "(store, pointer increment, return_empty_struct call)". The + // final part is a function call (to a static inline function) + // instead of a struct literal, to avoid a "expression result + // unused" compiler error. + b.printf("(wuffs_base__store_u%d%ce(ioptr_dst,", p.n, p.endianness) + if err := g.writeExpr(b, args[0].AsArg().Value(), rp, depth); err != nil { + return err + } + b.printf("), ioptr_dst += %d, wuffs_base__return_empty_struct())", p.n/8) + return nil + } + } + } + return g.writeBuiltinIO(b, recv, method, args, rp, depth) } @@ -499,23 +513,48 @@ func (g *gen) writeBuiltinCallSuspendibles(b *buffer, n *a.Expr, depth uint32) e return errNoSuchBuiltin } +const peekMethodsBase = t.IDPeekU8 + var peekMethods = [...]struct { n uint8 endianness uint8 }{ - // t.IDPeekU8 is a special case, neither big nor little endian. - t.IDPeekU16BE - t.IDPeekU8: {16, 'b'}, - t.IDPeekU16LE - t.IDPeekU8: {16, 'l'}, - t.IDPeekU24BE - t.IDPeekU8: {24, 'b'}, - t.IDPeekU24LE - t.IDPeekU8: {24, 'l'}, - t.IDPeekU32BE - t.IDPeekU8: {32, 'b'}, - t.IDPeekU32LE - t.IDPeekU8: {32, 'l'}, - t.IDPeekU40BE - t.IDPeekU8: {40, 'b'}, - t.IDPeekU40LE - t.IDPeekU8: {40, 'l'}, - t.IDPeekU48BE - t.IDPeekU8: {48, 'b'}, - t.IDPeekU48LE - t.IDPeekU8: {48, 'l'}, - t.IDPeekU56BE - t.IDPeekU8: {56, 'b'}, - t.IDPeekU56LE - t.IDPeekU8: {56, 'l'}, - t.IDPeekU64BE - t.IDPeekU8: {64, 'b'}, - t.IDPeekU64LE - t.IDPeekU8: {64, 'l'}, + t.IDPeekU8 - peekMethodsBase: {8, 'b'}, + t.IDPeekU16BE - peekMethodsBase: {16, 'b'}, + t.IDPeekU16LE - peekMethodsBase: {16, 'l'}, + t.IDPeekU24BE - peekMethodsBase: {24, 'b'}, + t.IDPeekU24LE - peekMethodsBase: {24, 'l'}, + t.IDPeekU32BE - peekMethodsBase: {32, 'b'}, + t.IDPeekU32LE - peekMethodsBase: {32, 'l'}, + t.IDPeekU40BE - peekMethodsBase: {40, 'b'}, + t.IDPeekU40LE - peekMethodsBase: {40, 'l'}, + t.IDPeekU48BE - peekMethodsBase: {48, 'b'}, + t.IDPeekU48LE - peekMethodsBase: {48, 'l'}, + t.IDPeekU56BE - peekMethodsBase: {56, 'b'}, + t.IDPeekU56LE - peekMethodsBase: {56, 'l'}, + t.IDPeekU64BE - peekMethodsBase: {64, 'b'}, + t.IDPeekU64LE - peekMethodsBase: {64, 'l'}, +} + +const writeFastMethodsBase = t.IDWriteFastU8 + +var writeFastMethods = [...]struct { + n uint8 + endianness uint8 +}{ + t.IDWriteFastU8 - writeFastMethodsBase: {8, 'b'}, + t.IDWriteFastU16BE - writeFastMethodsBase: {16, 'b'}, + t.IDWriteFastU16LE - writeFastMethodsBase: {16, 'l'}, + t.IDWriteFastU24BE - writeFastMethodsBase: {24, 'b'}, + t.IDWriteFastU24LE - writeFastMethodsBase: {24, 'l'}, + t.IDWriteFastU32BE - writeFastMethodsBase: {32, 'b'}, + t.IDWriteFastU32LE - writeFastMethodsBase: {32, 'l'}, + t.IDWriteFastU40BE - writeFastMethodsBase: {40, 'b'}, + t.IDWriteFastU40LE - writeFastMethodsBase: {40, 'l'}, + t.IDWriteFastU48BE - writeFastMethodsBase: {48, 'b'}, + t.IDWriteFastU48LE - writeFastMethodsBase: {48, 'l'}, + t.IDWriteFastU56BE - writeFastMethodsBase: {56, 'b'}, + t.IDWriteFastU56LE - writeFastMethodsBase: {56, 'l'}, + t.IDWriteFastU64BE - writeFastMethodsBase: {64, 'b'}, + t.IDWriteFastU64LE - writeFastMethodsBase: {64, 'l'}, } diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index d03141ba..f4954747 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -112,10 +112,14 @@ const basePrivateH = "" + "UTINE_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 WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\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 static, so that linking multiple wuffs .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 wuffs_base__empty_struct wuffs_base__return_empty_struct() {\n return ((wuffs_base__empty_struct){});\n}\n\n" + "" + - "// ---------------- Numeric Types\n\nstatic inline uint16_t wuffs_base__load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t wuffs_base__load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t wuffs_base__load_u24be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 16) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 0);\n}\n\nstatic inline uint32_t wuffs_base__load_u24le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16);\n}\n\nstatic inline uint32_t wuffs_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 wuffs_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 uint64_t wuffs_base__load_u40be(uint8_t" + - "* p) {\n return ((uint64_t)(p[0]) << 32) | ((uint64_t)(p[1]) << 24) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 8) |\n ((uint64_t)(p[4]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u40le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32);\n}\n\nstatic inline uint64_t wuffs_base__load_u48be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 40) | ((uint64_t)(p[1]) << 32) |\n ((uint64_t)(p[2]) << 24) | ((uint64_t)(p[3]) << 16) |\n ((uint64_t)(p[4]) << 8) | ((uint64_t)(p[5]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u48le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40);\n}\n\nstatic inline uint64_t wuffs_base__load_u56be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 48) | ((uint64_t)(p[1]) << 40) |\n ((u" + - "int64_t)(p[2]) << 32) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 16) | ((uint64_t)(p[5]) << 8) |\n ((uint64_t)(p[6]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u56le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48);\n}\n\nstatic inline uint64_t wuffs_base__load_u64be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |\n ((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |\n ((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |\n ((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u64le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << " + - "48) | ((uint64_t)(p[7]) << 56);\n}\n\n" + + "// ---------------- Numeric Types\n\nstatic inline uint8_t wuffs_base__load_u8be(uint8_t* p) {\n return p[0];\n}\n\nstatic inline uint16_t wuffs_base__load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t wuffs_base__load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t wuffs_base__load_u24be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 16) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 0);\n}\n\nstatic inline uint32_t wuffs_base__load_u24le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16);\n}\n\nstatic inline uint32_t wuffs_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 wuffs_base__load_u32le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint" + + "32_t)(p[3]) << 24);\n}\n\nstatic inline uint64_t wuffs_base__load_u40be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 32) | ((uint64_t)(p[1]) << 24) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 8) |\n ((uint64_t)(p[4]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u40le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32);\n}\n\nstatic inline uint64_t wuffs_base__load_u48be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 40) | ((uint64_t)(p[1]) << 32) |\n ((uint64_t)(p[2]) << 24) | ((uint64_t)(p[3]) << 16) |\n ((uint64_t)(p[4]) << 8) | ((uint64_t)(p[5]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u48le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40);\n}\n\nstatic inline uint64_t wuffs_base__load_u56be(uint8_t* p) {" + + "\n return ((uint64_t)(p[0]) << 48) | ((uint64_t)(p[1]) << 40) |\n ((uint64_t)(p[2]) << 32) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 16) | ((uint64_t)(p[5]) << 8) |\n ((uint64_t)(p[6]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u56le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48);\n}\n\nstatic inline uint64_t wuffs_base__load_u64be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |\n ((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |\n ((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |\n ((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);\n}\n\nstatic inline uint64_t wuffs_base__load_u64le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64" + + "_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);\n}\n\n" + + "" + + "// --------\n\nstatic inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) {\n p[0] = x;\n}\n\nstatic inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) {\n p[0] = x >> 8;\n p[1] = x >> 0;\n}\n\nstatic inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n}\n\nstatic inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) {\n p[0] = x >> 16;\n p[1] = x >> 8;\n p[2] = x >> 0;\n}\n\nstatic inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n}\n\nstatic inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) {\n p[0] = x >> 24;\n p[1] = x >> 16;\n p[2] = x >> 8;\n p[3] = x >> 0;\n}\n\nstatic inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n}\n\nstatic inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) {\n p[0] = x >> 32;\n p[1] = x >> 24;\n p[2] = x >> 16;\n p[3] = x >> 8;\n p[4] = x >> 0;\n}\n\nstatic inline void wuffs_" + + "base__store_u40le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n}\n\nstatic inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) {\n p[0] = x >> 40;\n p[1] = x >> 32;\n p[2] = x >> 24;\n p[3] = x >> 16;\n p[4] = x >> 8;\n p[5] = x >> 0;\n}\n\nstatic inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n p[5] = x >> 40;\n}\n\nstatic inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) {\n p[0] = x >> 48;\n p[1] = x >> 40;\n p[2] = x >> 32;\n p[3] = x >> 24;\n p[4] = x >> 16;\n p[5] = x >> 8;\n p[6] = x >> 0;\n}\n\nstatic inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n p[5] = x >> 40;\n p[6] = x >> 48;\n}\n\nstatic inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) {\n p[0] = x >> 56;\n p[1] = x >> 48;\n p[2] = x >> 40;\n p[3] = x >> 32;\n" + + " p[4] = x >> 24;\n p[5] = x >> 16;\n p[6] = x >> 8;\n p[7] = x >> 0;\n}\n\nstatic inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n p[5] = x >> 40;\n p[6] = x >> 48;\n p[7] = x >> 56;\n}\n\n" + "" + "// --------\n\nstatic inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_sub(*x, y);\n}\n\nstatic inline void wuffs_base__u16__sat_add_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_sub(*x, y);\n}\n\nstatic inline void wuffs_base__u32__sat_add_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_sub(*x, y);\n}\n\nstatic inline void wuffs_base__u64__sat_add_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_sub(*x, y);\n}\n\n" + "" + diff --git a/gen/c/base.c b/gen/c/base.c index fd714588..866ceaf1 100644 --- a/gen/c/base.c +++ b/gen/c/base.c @@ -1840,6 +1840,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -1922,6 +1926,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/adler32.c b/gen/c/std/adler32.c index da9ead63..5c2cc217 100644 --- a/gen/c/std/adler32.c +++ b/gen/c/std/adler32.c @@ -1908,6 +1908,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -1990,6 +1994,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/crc32.c b/gen/c/std/crc32.c index d3aa763d..d19f8bdb 100644 --- a/gen/c/std/crc32.c +++ b/gen/c/std/crc32.c @@ -1909,6 +1909,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -1991,6 +1995,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 0751129b..4d70b90e 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -2000,6 +2000,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -2082,6 +2086,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index f9ff8704..70e31760 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -2164,6 +2164,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -2246,6 +2250,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index 361ea182..2df80719 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -2207,6 +2207,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -2289,6 +2293,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/lzw.c b/gen/c/std/lzw.c index 953f42c8..915ccad6 100644 --- a/gen/c/std/lzw.c +++ b/gen/c/std/lzw.c @@ -1940,6 +1940,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -2022,6 +2026,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index 6f20e8ff..5c71a0cd 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -2204,6 +2204,10 @@ static inline wuffs_base__empty_struct wuffs_base__return_empty_struct() { // ---------------- Numeric Types +static inline uint8_t wuffs_base__load_u8be(uint8_t* p) { + return p[0]; +} + static inline uint16_t wuffs_base__load_u16be(uint8_t* p) { return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0); } @@ -2286,6 +2290,124 @@ static inline uint64_t wuffs_base__load_u64le(uint8_t* p) { // -------- +static inline void wuffs_base__store_u8be(uint8_t* p, uint8_t x) { + p[0] = x; +} + +static inline void wuffs_base__store_u16be(uint8_t* p, uint16_t x) { + p[0] = x >> 8; + p[1] = x >> 0; +} + +static inline void wuffs_base__store_u16le(uint8_t* p, uint16_t x) { + p[0] = x >> 0; + p[1] = x >> 8; +} + +static inline void wuffs_base__store_u24be(uint8_t* p, uint32_t x) { + p[0] = x >> 16; + p[1] = x >> 8; + p[2] = x >> 0; +} + +static inline void wuffs_base__store_u24le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; +} + +static inline void wuffs_base__store_u32be(uint8_t* p, uint32_t x) { + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x >> 0; +} + +static inline void wuffs_base__store_u32le(uint8_t* p, uint32_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; +} + +static inline void wuffs_base__store_u40be(uint8_t* p, uint64_t x) { + p[0] = x >> 32; + p[1] = x >> 24; + p[2] = x >> 16; + p[3] = x >> 8; + p[4] = x >> 0; +} + +static inline void wuffs_base__store_u40le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; +} + +static inline void wuffs_base__store_u48be(uint8_t* p, uint64_t x) { + p[0] = x >> 40; + p[1] = x >> 32; + p[2] = x >> 24; + p[3] = x >> 16; + p[4] = x >> 8; + p[5] = x >> 0; +} + +static inline void wuffs_base__store_u48le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; +} + +static inline void wuffs_base__store_u56be(uint8_t* p, uint64_t x) { + p[0] = x >> 48; + p[1] = x >> 40; + p[2] = x >> 32; + p[3] = x >> 24; + p[4] = x >> 16; + p[5] = x >> 8; + p[6] = x >> 0; +} + +static inline void wuffs_base__store_u56le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; +} + +static inline void wuffs_base__store_u64be(uint8_t* p, uint64_t x) { + p[0] = x >> 56; + p[1] = x >> 48; + p[2] = x >> 40; + p[3] = x >> 32; + p[4] = x >> 24; + p[5] = x >> 16; + p[6] = x >> 8; + p[7] = x >> 0; +} + +static inline void wuffs_base__store_u64le(uint8_t* p, uint64_t x) { + p[0] = x >> 0; + p[1] = x >> 8; + p[2] = x >> 16; + p[3] = x >> 24; + p[4] = x >> 32; + p[5] = x >> 40; + p[6] = x >> 48; + p[7] = x >> 56; +} + +// -------- + static inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) { *x = wuffs_base__u8__sat_add(*x, y); } diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index 23ff6295..4c294262 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -159,6 +159,10 @@ var Funcs = []string{ // TODO: these should have an explicit precondition "available() >= N". For // now, that's implicitly checked (i.e. hard coded). + // + // The io_reader has peek_etc methods and skip_fast32, not read_etc_fast, + // because we sometimes advance the pointer by less than what's read. See + // https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/ "io_reader.peek_u8()(ret u8)", "io_reader.peek_u16be()(ret u16)", "io_reader.peek_u16le()(ret u16)", @@ -208,6 +212,27 @@ var Funcs = []string{ "io_writer.write_u64be?(x u64)()", "io_writer.write_u64le?(x u64)()", + // TODO: these should have an explicit precondition "available() >= N". For + // now, that's implicitly checked (i.e. hard coded). + // + // The io_writer has write_fast_etc methods, not poke_etc and skip_fast32, + // because skip32_fast could leave uninitialized bytes in the io_buffer. + "io_writer.write_fast_u8!(x u8)()", + "io_writer.write_fast_u16be!(x u16)()", + "io_writer.write_fast_u16le!(x u16)()", + "io_writer.write_fast_u24be!(x u32[..0xFFFFFF])()", + "io_writer.write_fast_u24le!(x u32[..0xFFFFFF])()", + "io_writer.write_fast_u32be!(x u32)()", + "io_writer.write_fast_u32le!(x u32)()", + "io_writer.write_fast_u40be!(x u64[..0xFFFFFFFFFF])()", + "io_writer.write_fast_u40le!(x u64[..0xFFFFFFFFFF])()", + "io_writer.write_fast_u48be!(x u64[..0xFFFFFFFFFFFF])()", + "io_writer.write_fast_u48le!(x u64[..0xFFFFFFFFFFFF])()", + "io_writer.write_fast_u56be!(x u64[..0xFFFFFFFFFFFFFF])()", + "io_writer.write_fast_u56le!(x u64[..0xFFFFFFFFFFFFFF])()", + "io_writer.write_fast_u64be!(x u64)()", + "io_writer.write_fast_u64le!(x u64)()", + "io_writer.available()(ret u64)", "io_writer.set!(s slice u8)()", "io_writer.set_limit!(l u64)()", diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 265e5d7f..a0c1d110 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -1005,7 +1005,8 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (a.Bounds, } else if method >= t.IDPeekU8 { if m := method - t.IDPeekU8; m < t.ID(len(ioMethodAdvances)) { - advance, update = ioMethodAdvances[m], false + au := ioMethodAdvances[m] + advance, update = au.advance, au.update } } @@ -1022,22 +1023,41 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (a.Bounds, return a.Bounds{}, errNotASpecialCase } -var ioMethodAdvances = [...]*big.Int{ - t.IDPeekU8 - t.IDPeekU8: one, - t.IDPeekU16BE - t.IDPeekU8: two, - t.IDPeekU16LE - t.IDPeekU8: two, - t.IDPeekU24BE - t.IDPeekU8: three, - t.IDPeekU24LE - t.IDPeekU8: three, - t.IDPeekU32BE - t.IDPeekU8: four, - t.IDPeekU32LE - t.IDPeekU8: four, - t.IDPeekU40BE - t.IDPeekU8: five, - t.IDPeekU40LE - t.IDPeekU8: five, - t.IDPeekU48BE - t.IDPeekU8: six, - t.IDPeekU48LE - t.IDPeekU8: six, - t.IDPeekU56BE - t.IDPeekU8: seven, - t.IDPeekU56LE - t.IDPeekU8: seven, - t.IDPeekU64BE - t.IDPeekU8: eight, - t.IDPeekU64LE - t.IDPeekU8: eight, +var ioMethodAdvances = [...]struct { + advance *big.Int + update bool +}{ + t.IDPeekU8 - t.IDPeekU8: {one, false}, + t.IDPeekU16BE - t.IDPeekU8: {two, false}, + t.IDPeekU16LE - t.IDPeekU8: {two, false}, + t.IDPeekU24BE - t.IDPeekU8: {three, false}, + t.IDPeekU24LE - t.IDPeekU8: {three, false}, + t.IDPeekU32BE - t.IDPeekU8: {four, false}, + t.IDPeekU32LE - t.IDPeekU8: {four, false}, + t.IDPeekU40BE - t.IDPeekU8: {five, false}, + t.IDPeekU40LE - t.IDPeekU8: {five, false}, + t.IDPeekU48BE - t.IDPeekU8: {six, false}, + t.IDPeekU48LE - t.IDPeekU8: {six, false}, + t.IDPeekU56BE - t.IDPeekU8: {seven, false}, + t.IDPeekU56LE - t.IDPeekU8: {seven, false}, + t.IDPeekU64BE - t.IDPeekU8: {eight, false}, + t.IDPeekU64LE - t.IDPeekU8: {eight, false}, + + t.IDWriteFastU8 - t.IDPeekU8: {one, true}, + t.IDWriteFastU16BE - t.IDPeekU8: {two, true}, + t.IDWriteFastU16LE - t.IDPeekU8: {two, true}, + t.IDWriteFastU24BE - t.IDPeekU8: {three, true}, + t.IDWriteFastU24LE - t.IDPeekU8: {three, true}, + t.IDWriteFastU32BE - t.IDPeekU8: {four, true}, + t.IDWriteFastU32LE - t.IDPeekU8: {four, true}, + t.IDWriteFastU40BE - t.IDPeekU8: {five, true}, + t.IDWriteFastU40LE - t.IDPeekU8: {five, true}, + t.IDWriteFastU48BE - t.IDPeekU8: {six, true}, + t.IDWriteFastU48LE - t.IDPeekU8: {six, true}, + t.IDWriteFastU56BE - t.IDPeekU8: {seven, true}, + t.IDWriteFastU56LE - t.IDPeekU8: {seven, true}, + t.IDWriteFastU64BE - t.IDPeekU8: {eight, true}, + t.IDWriteFastU64LE - t.IDPeekU8: {eight, true}, } // makeSliceLength returns "x.length()". diff --git a/lang/token/list.go b/lang/token/list.go index 34cbd6b4..3fa19ec0 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -494,6 +494,22 @@ const ( IDWriteU64BE = ID(0x16E) IDWriteU64LE = ID(0x16F) + IDWriteFastU8 = ID(0x171) + IDWriteFastU16BE = ID(0x172) + IDWriteFastU16LE = ID(0x173) + IDWriteFastU24BE = ID(0x174) + IDWriteFastU24LE = ID(0x175) + IDWriteFastU32BE = ID(0x176) + IDWriteFastU32LE = ID(0x177) + IDWriteFastU40BE = ID(0x178) + IDWriteFastU40LE = ID(0x179) + IDWriteFastU48BE = ID(0x17A) + IDWriteFastU48LE = ID(0x17B) + IDWriteFastU56BE = ID(0x17C) + IDWriteFastU56LE = ID(0x17D) + IDWriteFastU64BE = ID(0x17E) + IDWriteFastU64LE = ID(0x17F) + IDSetLimit = ID(0x180) IDSetMark = ID(0x181) IDSinceMark = ID(0x182) @@ -755,6 +771,22 @@ var builtInsByID = [nBuiltInIDs]string{ IDWriteU64BE: "write_u64be", IDWriteU64LE: "write_u64le", + IDWriteFastU8: "write_fast_u8", + IDWriteFastU16BE: "write_fast_u16be", + IDWriteFastU16LE: "write_fast_u16le", + IDWriteFastU24BE: "write_fast_u24be", + IDWriteFastU24LE: "write_fast_u24le", + IDWriteFastU32BE: "write_fast_u32be", + IDWriteFastU32LE: "write_fast_u32le", + IDWriteFastU40BE: "write_fast_u40be", + IDWriteFastU40LE: "write_fast_u40le", + IDWriteFastU48BE: "write_fast_u48be", + IDWriteFastU48LE: "write_fast_u48le", + IDWriteFastU56BE: "write_fast_u56be", + IDWriteFastU56LE: "write_fast_u56le", + IDWriteFastU64BE: "write_fast_u64be", + IDWriteFastU64LE: "write_fast_u64le", + IDSetLimit: "set_limit", IDSetMark: "set_mark", IDSinceMark: "since_mark",