From 7d8085f891e99857c9587fc90f3f549f461827d5 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 2 Nov 2017 16:35:15 +1100 Subject: [PATCH] Re-introduce reader1.use_limit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The std/flate benchmarks get better. The std/gif benchmarks get worse, but that's possibly because the PUFFS_USE_NO_OP_PERFORMANCE_HACKS hacks are fragile. name old speed new speed delta puffs_adler32_10k/clang 2.45GB/s ± 0% 2.45GB/s ± 0% ~ (p=0.310 n=5+5) puffs_adler32_100k/clang 2.46GB/s ± 0% 2.46GB/s ± 0% ~ (p=0.690 n=5+5) puffs_flate_decode_1k/clang 113MB/s ± 0% 113MB/s ± 0% ~ (p=0.690 n=5+5) puffs_flate_decode_10k/clang 140MB/s ± 0% 140MB/s ± 0% ~ (p=0.222 n=5+5) puffs_flate_decode_100k/clang 151MB/s ± 0% 151MB/s ± 0% ~ (p=0.095 n=5+5) puffs_zlib_decode_10k/clang 132MB/s ± 1% 132MB/s ± 0% ~ (p=0.548 n=5+5) puffs_zlib_decode_100k/clang 143MB/s ± 0% 143MB/s ± 0% ~ (p=0.730 n=5+4) puffs_adler32_10k/gcc 3.26GB/s ± 0% 3.26GB/s ± 0% ~ (p=0.548 n=5+5) puffs_adler32_100k/gcc 3.27GB/s ± 0% 3.27GB/s ± 0% ~ (p=0.841 n=5+5) puffs_flate_decode_1k/gcc 108MB/s ± 0% 125MB/s ± 0% +14.97% (p=0.008 n=5+5) puffs_flate_decode_10k/gcc 128MB/s ± 0% 148MB/s ± 0% +15.48% (p=0.016 n=4+5) puffs_flate_decode_100k/gcc 136MB/s ± 0% 158MB/s ± 0% +16.40% (p=0.008 n=5+5) puffs_zlib_decode_10k/gcc 123MB/s ± 0% 141MB/s ± 0% +14.70% (p=0.016 n=4+5) puffs_zlib_decode_100k/gcc 131MB/s ± 0% 151MB/s ± 0% +15.60% (p=0.016 n=5+4) puffs_gif_lzw_decode_20k/clang 131MB/s ± 1% 128MB/s ± 3% -2.04% (p=0.032 n=5+5) puffs_gif_lzw_decode_100k/clang 172MB/s ± 1% 173MB/s ± 1% ~ (p=0.151 n=5+5) puffs_gif_decode_1k/clang 351MB/s ± 3% 341MB/s ± 5% ~ (p=0.310 n=5+5) puffs_gif_decode_10k/clang 138MB/s ± 1% 134MB/s ± 3% -3.34% (p=0.008 n=5+5) puffs_gif_decode_100k/clang 122MB/s ± 2% 122MB/s ± 2% ~ (p=1.000 n=5+5) puffs_gif_decode_1000k/clang 126MB/s ± 1% 122MB/s ± 4% -3.07% (p=0.016 n=5+5) puffs_gif_lzw_decode_20k/gcc 140MB/s ± 3% 140MB/s ± 3% ~ (p=0.421 n=5+5) puffs_gif_lzw_decode_100k/gcc 187MB/s ± 2% 184MB/s ± 1% ~ (p=0.056 n=5+5) puffs_gif_decode_1k/gcc 401MB/s ± 1% 357MB/s ± 1% -10.88% (p=0.008 n=5+5) puffs_gif_decode_10k/gcc 154MB/s ± 1% 126MB/s ± 1% -18.42% (p=0.008 n=5+5) puffs_gif_decode_100k/gcc 131MB/s ± 2% 109MB/s ± 0% -17.37% (p=0.008 n=5+5) puffs_gif_decode_1000k/gcc 135MB/s ± 1% 111MB/s ± 1% -17.65% (p=0.008 n=5+5) --- cmd/puffs-c/internal/cgen/base-header.h | 8 ++++++++ cmd/puffs-c/internal/cgen/base-impl.h | 2 ++ cmd/puffs-c/internal/cgen/data.go | 10 +++++----- cmd/puffs-c/internal/cgen/templates.h | 3 ++- gen/c/std/flate.c | 20 +++++++++++++++----- gen/c/std/gif.c | 22 ++++++++++++++++------ gen/h/std/flate.h | 8 ++++++++ gen/h/std/gif.h | 8 ++++++++ 8 files changed, 64 insertions(+), 17 deletions(-) diff --git a/cmd/puffs-c/internal/cgen/base-header.h b/cmd/puffs-c/internal/cgen/base-header.h index ac976d7b..859a2c83 100644 --- a/cmd/puffs-c/internal/cgen/base-header.h +++ b/cmd/puffs-c/internal/cgen/base-header.h @@ -93,6 +93,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + bool use_limit; #ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS struct { puffs_base__paired_nulls* noph0; @@ -112,6 +116,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + // TODO: bool use_limit; } private_impl; } puffs_base__writer1; diff --git a/cmd/puffs-c/internal/cgen/base-impl.h b/cmd/puffs-c/internal/cgen/base-impl.h index 933c1e23..0fa942db 100644 --- a/cmd/puffs-c/internal/cgen/base-impl.h +++ b/cmd/puffs-c/internal/cgen/base-impl.h @@ -301,6 +301,7 @@ static inline puffs_base__empty_struct puffs_base__reader1__limit( o->private_impl.limit = ptr + limit; } } + o->private_impl.use_limit = true; return ((puffs_base__empty_struct){}); } @@ -326,6 +327,7 @@ static inline puffs_base__empty_struct puffs_base__writer1__limit( o->private_impl.limit = ptr + limit; } } + // TODO: o->private_impl.use_limit = true; return ((puffs_base__empty_struct){}); } diff --git a/cmd/puffs-c/internal/cgen/data.go b/cmd/puffs-c/internal/cgen/data.go index 58729948..bca4df1a 100644 --- a/cmd/puffs-c/internal/cgen/data.go +++ b/cmd/puffs-c/internal/cgen/data.go @@ -20,8 +20,8 @@ const baseHeader = "" + "#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Puffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include \n#include \n#include \n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n//\n// Si" + "milarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API / ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like\n// redundant no-ops, but for reasons to be investigated, can have dramatic\n// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks).\n//\n// TODO: investigate; delete these hacks (without regressing performance).\n// The order matters here. Clang als" + "o defines \"__GNUC__\".\n#if defined(__clang__)\n#elif defined(__GNUC__)\n#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1\n#endif\n\n// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base__slice_u8;\n\n// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base__buf1;\n\n#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS\ntypedef struct {\n void* always_null0;\n void* always_null1;\n} puffs_base__paired_nulls;\n#endif\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like u" + - "sers can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS\n struct {\n puffs_base__paired_nulls* noph0;\n uint32_t noph1;\n } * no_op_performance_hacks;\n#endif\n } private_impl;\n} puffs_base__reader1;\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HE" + - "ADER_H\n" + + "sers can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n // use_limit is redundant, in that it always equals (limit != NULL), but\n // having a separate bool can have a significant performance effect with\n // gcc 4.8.4 (e.g. 1.1x on some benchmarks).\n bool use_limit;\n#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS\n struct {\n puffs_base__paired_nulls* noph0;\n uint32_t noph1;\n } * no_op_performance_hacks;\n#endif\n } private_impl;\n} puffs_base__reader1;\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access th" + + "e private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n // use_limit is redundant, in that it always equals (limit != NULL), but\n // having a separate bool can have a significant performance effect with\n // gcc 4.8.4 (e.g. 1.1x on some benchmarks).\n // TODO: bool use_limit;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" + "" const baseImpl = "" + @@ -34,8 +34,8 @@ const baseImpl = "" + "alid, empty\n// slice) is valid 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 length = dst.len < src.len ? dst.len : src.len;\n if (length > 0) {\n memmove(dst.ptr, src.ptr, length);\n }\n return length;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start, // May be NULL, meaning an unmarked writer1.\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n if (!start) {\n return 0;\n }\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 n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: is manual unrolling actually helpful?\n for (; n >= 8; n -= 8) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *star" + "t++;\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 puffs_base__writer1__copy_from_reader32(\n 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 size_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t puffs_base__writer1__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base__slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n " + " puffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\n// Note that the *__limit and *__mark methods are private (in base-impl.h) not\n// public (in base-header.h). We assume that, at the boundary between user code\n// and Puffs code, the reader1 and writer1's private_impl fields (including\n// limit and mark) are NULL. Otherwise, some internal assumptions break down.\n// For example, the limit field is represented as a pointer, even though\n// conceptually it is a count, but that pointer-to-count correspondence becomes\n// invalid if a buffer is re-used (e.g. on resuming a coroutine).\n//\n// Admittedly, some of the Puffs test code calls these methods, but that test\n// code is still Puffs code, not user code. Other Puffs test code modifies\n// private_impl fields directly.\n\nstatic inline puffs_base__" + - "empty_struct puffs_base__reader1__limit(\n puffs_base__reader1* o,\n uint8_t* ptr,\n uint64_t limit) {\n if (!o->buf) {\n o->private_impl.limit = NULL;\n } else {\n uint64_t len = o->buf->wi - o->buf->ri;\n if (limit > len) {\n limit = len;\n }\n if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr))) {\n o->private_impl.limit = ptr + limit;\n }\n }\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__mark(\n puffs_base__reader1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__limit(\n puffs_base__writer1* o,\n uint8_t* ptr,\n uint64_t limit) {\n if (!o->buf) {\n o->private_impl.limit = NULL;\n } else {\n uint64_t len = o->buf->len - o->buf->wi;\n if (limit > len) {\n limit = len;\n }\n if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr))) {\n o->private_impl.limit = " + - "ptr + limit;\n }\n }\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" + + "empty_struct puffs_base__reader1__limit(\n puffs_base__reader1* o,\n uint8_t* ptr,\n uint64_t limit) {\n if (!o->buf) {\n o->private_impl.limit = NULL;\n } else {\n uint64_t len = o->buf->wi - o->buf->ri;\n if (limit > len) {\n limit = len;\n }\n if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr))) {\n o->private_impl.limit = ptr + limit;\n }\n }\n o->private_impl.use_limit = true;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__mark(\n puffs_base__reader1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__limit(\n puffs_base__writer1* o,\n uint8_t* ptr,\n uint64_t limit) {\n if (!o->buf) {\n o->private_impl.limit = NULL;\n } else {\n uint64_t len = o->buf->len - o->buf->wi;\n if (limit > len) {\n limit = len;\n }\n if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr" + + "))) {\n o->private_impl.limit = ptr + limit;\n }\n }\n // TODO: o->private_impl.use_limit = true;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" + "" type template_args_short_read struct { @@ -44,7 +44,7 @@ type template_args_short_read struct { } func template_short_read(b *buffer, args template_args_short_read) error { - b.printf("short_read_%s:\nif (a_%s.buf && a_%s.buf->closed && !a_%s.private_impl.limit) {\nstatus = %sERROR_UNEXPECTED_EOF;\ngoto exit;\n}\nstatus = %sSUSPENSION_SHORT_READ;\ngoto suspend;\n", + b.printf("short_read_%s:\nif (a_%s.buf && a_%s.buf->closed &&\n!a_%s.private_impl.use_limit) {\nstatus = %sERROR_UNEXPECTED_EOF;\ngoto exit;\n}\nstatus = %sSUSPENSION_SHORT_READ;\ngoto suspend;\n", args.name, args.name, args.name, diff --git a/cmd/puffs-c/internal/cgen/templates.h b/cmd/puffs-c/internal/cgen/templates.h index ae11fbb3..b756e291 100644 --- a/cmd/puffs-c/internal/cgen/templates.h +++ b/cmd/puffs-c/internal/cgen/templates.h @@ -23,7 +23,8 @@ template short_read(string qPKGPREFIXq, string qnameq) { short_read_qnameq: - if (a_qnameq.buf && a_qnameq.buf->closed && !a_qnameq.private_impl.limit) { + if (a_qnameq.buf && a_qnameq.buf->closed && + !a_qnameq.private_impl.use_limit) { status = qPKGPREFIXqERROR_UNEXPECTED_EOF; goto exit; } diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index bbfae029..f3c6453f 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -96,6 +96,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + bool use_limit; #ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS struct { puffs_base__paired_nulls* noph0; @@ -115,6 +119,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + // TODO: bool use_limit; } private_impl; } puffs_base__writer1; @@ -647,6 +655,7 @@ static inline puffs_base__empty_struct puffs_base__reader1__limit( o->private_impl.limit = ptr + limit; } } + o->private_impl.use_limit = true; return ((puffs_base__empty_struct){}); } @@ -672,6 +681,7 @@ static inline puffs_base__empty_struct puffs_base__writer1__limit( o->private_impl.limit = ptr + limit; } } + // TODO: o->private_impl.use_limit = true; return ((puffs_base__empty_struct){}); } @@ -1155,7 +1165,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1289,7 +1299,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1682,7 +1692,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1988,7 +1998,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF; goto exit; } @@ -2480,7 +2490,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF; goto exit; } diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index f4be3e75..4926a3e1 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -96,6 +96,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + bool use_limit; #ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS struct { puffs_base__paired_nulls* noph0; @@ -115,6 +119,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + // TODO: bool use_limit; } private_impl; } puffs_base__writer1; @@ -594,6 +602,7 @@ static inline puffs_base__empty_struct puffs_base__reader1__limit( o->private_impl.limit = ptr + limit; } } + o->private_impl.use_limit = true; return ((puffs_base__empty_struct){}); } @@ -619,6 +628,7 @@ static inline puffs_base__empty_struct puffs_base__writer1__limit( o->private_impl.limit = ptr + limit; } } + // TODO: o->private_impl.use_limit = true; return ((puffs_base__empty_struct){}); } @@ -880,7 +890,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_GIF__ERROR_UNEXPECTED_EOF; goto exit; } @@ -954,7 +964,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_GIF__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1055,7 +1065,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_GIF__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1152,7 +1162,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_GIF__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1326,7 +1336,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_GIF__ERROR_UNEXPECTED_EOF; goto exit; } @@ -1561,7 +1571,7 @@ exit: return status; short_read_src: - if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit) { + if (a_src.buf && a_src.buf->closed && !a_src.private_impl.use_limit) { status = PUFFS_GIF__ERROR_UNEXPECTED_EOF; goto exit; } diff --git a/gen/h/std/flate.h b/gen/h/std/flate.h index d7f47066..e825c854 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -96,6 +96,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + bool use_limit; #ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS struct { puffs_base__paired_nulls* noph0; @@ -115,6 +119,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + // TODO: bool use_limit; } private_impl; } puffs_base__writer1; diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index c490a514..2fc5d1eb 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -96,6 +96,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + bool use_limit; #ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS struct { puffs_base__paired_nulls* noph0; @@ -115,6 +119,10 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; + // use_limit is redundant, in that it always equals (limit != NULL), but + // having a separate bool can have a significant performance effect with + // gcc 4.8.4 (e.g. 1.1x on some benchmarks). + // TODO: bool use_limit; } private_impl; } puffs_base__writer1;