From ed6ce6fd54d0feab28c3c2fa7cfef8b0cbab81b3 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 2 Nov 2017 13:44:05 +1100 Subject: [PATCH] Add PUFFS_USE_NO_OP_PERFORMANCE_HACKS. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old speed new speed delta puffs_adler32_10k/gcc 3.26GB/s ± 0% 3.26GB/s ± 0% ~ (p=0.222 n=5+5) puffs_adler32_100k/gcc 3.27GB/s ± 0% 3.27GB/s ± 0% -0.12% (p=0.032 n=5+5) puffs_flate_decode_1k/gcc 108MB/s ± 0% 108MB/s ± 0% ~ (p=0.841 n=5+5) puffs_flate_decode_10k/gcc 128MB/s ± 0% 128MB/s ± 0% ~ (p=0.057 n=4+4) puffs_flate_decode_100k/gcc 136MB/s ± 0% 136MB/s ± 0% ~ (p=0.222 n=5+5) puffs_zlib_decode_10k/gcc 123MB/s ± 0% 123MB/s ± 0% ~ (p=0.730 n=5+4) puffs_zlib_decode_100k/gcc 130MB/s ± 0% 131MB/s ± 0% ~ (p=1.000 n=5+5) puffs_gif_lzw_decode_20k/gcc 137MB/s ± 4% 140MB/s ± 3% ~ (p=0.095 n=5+5) puffs_gif_lzw_decode_100k/gcc 177MB/s ± 3% 187MB/s ± 2% +5.75% (p=0.008 n=5+5) puffs_gif_decode_1k/gcc 348MB/s ± 0% 401MB/s ± 1% +15.34% (p=0.016 n=4+5) puffs_gif_decode_10k/gcc 121MB/s ± 5% 154MB/s ± 1% +27.90% (p=0.008 n=5+5) puffs_gif_decode_100k/gcc 106MB/s ± 4% 131MB/s ± 2% +24.35% (p=0.008 n=5+5) puffs_gif_decode_1000k/gcc 109MB/s ± 2% 135MB/s ± 1% +24.03% (p=0.008 n=5+5) --- cmd/puffs-c/internal/cgen/base-header.h | 24 ++++++++++ cmd/puffs-c/internal/cgen/data.go | 7 +-- cmd/puffs-c/internal/cgen/func.go | 17 ++++--- cmd/puffs-c/internal/cgen/noph.go | 62 +++++++++++++++++++++++++ cmd/puffs-c/internal/cgen/var.go | 17 +++++++ gen/c/std/flate.c | 24 ++++++++++ gen/c/std/gif.c | 42 +++++++++++++++++ gen/h/std/flate.h | 24 ++++++++++ gen/h/std/gif.h | 24 ++++++++++ 9 files changed, 232 insertions(+), 9 deletions(-) create mode 100644 cmd/puffs-c/internal/cgen/noph.go diff --git a/cmd/puffs-c/internal/cgen/base-header.h b/cmd/puffs-c/internal/cgen/base-header.h index 282a796a..ac976d7b 100644 --- a/cmd/puffs-c/internal/cgen/base-header.h +++ b/cmd/puffs-c/internal/cgen/base-header.h @@ -45,6 +45,17 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) +// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like +// redundant no-ops, but for reasons to be investigated, can have dramatic +// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks). +// +// TODO: investigate; delete these hacks (without regressing performance). +// The order matters here. Clang also defines "__GNUC__". +#if defined(__clang__) +#elif defined(__GNUC__) +#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1 +#endif + // puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length). // // A value with all fields NULL or zero is a valid, empty slice. @@ -65,6 +76,13 @@ typedef struct { bool closed; // No further writes are expected. } puffs_base__buf1; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +typedef struct { + void* always_null0; + void* always_null1; +} puffs_base__paired_nulls; +#endif + typedef struct { // TODO: move buf into private_impl? As it is, it looks like users can modify // the buf field to point to a different buffer, which can turn the limit and @@ -75,6 +93,12 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + struct { + puffs_base__paired_nulls* noph0; + uint32_t noph1; + } * no_op_performance_hacks; +#endif } private_impl; } puffs_base__reader1; diff --git a/cmd/puffs-c/internal/cgen/data.go b/cmd/puffs-c/internal/cgen/data.go index f93ddb95..58729948 100644 --- a/cmd/puffs-c/internal/cgen/data.go +++ b/cmd/puffs-c/internal/cgen/data.go @@ -18,9 +18,10 @@ package cgen 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_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, p" + - "lus 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\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__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_HEADER_H\n" + + "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" + "" const baseImpl = "" + diff --git a/cmd/puffs-c/internal/cgen/func.go b/cmd/puffs-c/internal/cgen/func.go index ac14ec3d..294e43a7 100644 --- a/cmd/puffs-c/internal/cgen/func.go +++ b/cmd/puffs-c/internal/cgen/func.go @@ -30,6 +30,7 @@ type funk struct { bFooter buffer astFunc *a.Func + cName string derivedVars map[t.ID]struct{} jumpTargets map[a.Loop]uint32 coroSuspPoint uint32 @@ -56,6 +57,13 @@ func (k *funk) jumpTarget(n a.Loop) (uint32, error) { return jt, nil } +func (g *gen) funcCName(n *a.Func) string { + if r := n.Receiver(); r != 0 { + return g.pkgPrefix + r.String(g.tm) + "__" + n.Name().String(g.tm) + } + return g.pkgPrefix + n.Name().String(g.tm) +} + func (g *gen) writeFuncSignature(b *buffer, n *a.Func) error { // TODO: write n's return values. if n.Suspendible() { @@ -71,12 +79,8 @@ func (g *gen) writeFuncSignature(b *buffer, n *a.Func) error { return fmt.Errorf("TODO: multiple return values") } - b.writes(g.pkgPrefix) - if r := n.Receiver(); r != 0 { - b.writes(r.String(g.tm)) - b.writes("__") - } - b.printf("%s(", n.Name().String(g.tm)) + b.writes(g.funcCName(n)) + b.writeb('(') comma := false if r := n.Receiver(); r != 0 { @@ -129,6 +133,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error { func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error { g.currFunk = funk{ astFunc: n, + cName: g.funcCName(n), public: n.Public(), suspendible: n.Suspendible(), } diff --git a/cmd/puffs-c/internal/cgen/noph.go b/cmd/puffs-c/internal/cgen/noph.go new file mode 100644 index 00000000..cf311a37 --- /dev/null +++ b/cmd/puffs-c/internal/cgen/noph.go @@ -0,0 +1,62 @@ +// Copyright 2017 The Puffs Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cgen + +// This file hard-codes PUFFS_USE_NO_OP_PERFORMANCE_HACKS code fragments that +// look like redundant no-ops, but for reasons to be investigated, can have +// dramatic performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks). +// +// TODO: investigate; delete these hacks (without regressing performance). + +type nophKey struct { + gCurrFunkCName string + genMethod string + headerFooter bool +} + +var noOpPerformanceHacks = map[nophKey]string{ + { + gCurrFunkCName: "puffs_gif__decoder__decode_id", + genMethod: "writeSaveDerivedVar", + headerFooter: false, + }: ` +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +if (a_src.private_impl.no_op_performance_hacks) { + puffs_base__paired_nulls* pn = + a_src.private_impl.no_op_performance_hacks->noph0; + while (pn && pn->always_null0) { + *((int*)(pn->always_null0)) = 0; + pn = (puffs_base__paired_nulls*)(pn->always_null1); + } +} +#endif +`, + { + gCurrFunkCName: "puffs_gif__lzw_decoder__decode", + genMethod: "writeLoadDerivedVar", + headerFooter: true, + }: ` +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +if (a_src.private_impl.no_op_performance_hacks) { + if (a_src.private_impl.no_op_performance_hacks->noph1 && + (len > a_src.private_impl.no_op_performance_hacks->noph1)) { + len = a_src.private_impl.no_op_performance_hacks->noph1; + } +} +#endif +`, +} + +// puffs_gif__decoder__decode_id diff --git a/cmd/puffs-c/internal/cgen/var.go b/cmd/puffs-c/internal/cgen/var.go index 6fec9d63..c681eb84 100644 --- a/cmd/puffs-c/internal/cgen/var.go +++ b/cmd/puffs-c/internal/cgen/var.go @@ -101,6 +101,15 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header b.printf("%srptr_%s = %s%s.buf->ptr + %s%s.buf->ri;", bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr) b.printf("uint64_t len = %s%s.buf->wi - %s%s.buf->ri;", aPrefix, nameStr, aPrefix, nameStr) + + if s := noOpPerformanceHacks[nophKey{ + gCurrFunkCName: g.currFunk.cName, + genMethod: "writeLoadDerivedVar", + headerFooter: header, + }]; s != "" { + b.writes(s) + } + b.printf("%srend_%s = %srptr_%s + len;", bPrefix, nameStr, bPrefix, nameStr) b.printf("if (%s%s.private_impl.limit && (%srend_%s > %s%s.private_impl.limit)) {"+ " %srend_%s = %s%s.private_impl.limit; }", @@ -153,6 +162,14 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr) b.printf("%s%s.buf->ri += n;", aPrefix, nameStr) + if s := noOpPerformanceHacks[nophKey{ + gCurrFunkCName: g.currFunk.cName, + genMethod: "writeSaveDerivedVar", + headerFooter: footer, + }]; s != "" { + b.writes(s) + } + if footer { b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srend_%s);", bPrefix, nameStr) } diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 36ec7a6d..bbfae029 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -48,6 +48,17 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) +// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like +// redundant no-ops, but for reasons to be investigated, can have dramatic +// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks). +// +// TODO: investigate; delete these hacks (without regressing performance). +// The order matters here. Clang also defines "__GNUC__". +#if defined(__clang__) +#elif defined(__GNUC__) +#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1 +#endif + // puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length). // // A value with all fields NULL or zero is a valid, empty slice. @@ -68,6 +79,13 @@ typedef struct { bool closed; // No further writes are expected. } puffs_base__buf1; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +typedef struct { + void* always_null0; + void* always_null1; +} puffs_base__paired_nulls; +#endif + typedef struct { // TODO: move buf into private_impl? As it is, it looks like users can modify // the buf field to point to a different buffer, which can turn the limit and @@ -78,6 +96,12 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + struct { + puffs_base__paired_nulls* noph0; + uint32_t noph1; + } * no_op_performance_hacks; +#endif } private_impl; } puffs_base__reader1; diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 2e9fd0c9..f4be3e75 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -48,6 +48,17 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) +// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like +// redundant no-ops, but for reasons to be investigated, can have dramatic +// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks). +// +// TODO: investigate; delete these hacks (without regressing performance). +// The order matters here. Clang also defines "__GNUC__". +#if defined(__clang__) +#elif defined(__GNUC__) +#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1 +#endif + // puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length). // // A value with all fields NULL or zero is a valid, empty slice. @@ -68,6 +79,13 @@ typedef struct { bool closed; // No further writes are expected. } puffs_base__buf1; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +typedef struct { + void* always_null0; + void* always_null1; +} puffs_base__paired_nulls; +#endif + typedef struct { // TODO: move buf into private_impl? As it is, it looks like users can modify // the buf field to point to a different buffer, which can turn the limit and @@ -78,6 +96,12 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + struct { + puffs_base__paired_nulls* noph0; + uint32_t noph1; + } * no_op_performance_hacks; +#endif } private_impl; } puffs_base__reader1; @@ -1221,6 +1245,16 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self, if (a_src.buf) { size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri); a_src.buf->ri += n; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + if (a_src.private_impl.no_op_performance_hacks) { + puffs_base__paired_nulls* pn = + a_src.private_impl.no_op_performance_hacks->noph0; + while (pn && pn->always_null0) { + *((int*)(pn->always_null0)) = 0; + pn = (puffs_base__paired_nulls*)(pn->always_null1); + } + } +#endif } puffs_gif__status t_3 = puffs_gif__lzw_decoder__decode( &self->private_impl.f_lzw, a_dst, v_r); @@ -1364,6 +1398,14 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self, if (a_src.buf) { b_rptr_src = a_src.buf->ptr + a_src.buf->ri; uint64_t len = a_src.buf->wi - a_src.buf->ri; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + if (a_src.private_impl.no_op_performance_hacks) { + if (a_src.private_impl.no_op_performance_hacks->noph1 && + (len > a_src.private_impl.no_op_performance_hacks->noph1)) { + len = a_src.private_impl.no_op_performance_hacks->noph1; + } + } +#endif b_rend_src = b_rptr_src + len; if (a_src.private_impl.limit && (b_rend_src > a_src.private_impl.limit)) { b_rend_src = a_src.private_impl.limit; diff --git a/gen/h/std/flate.h b/gen/h/std/flate.h index 09b717cb..d7f47066 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -48,6 +48,17 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) +// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like +// redundant no-ops, but for reasons to be investigated, can have dramatic +// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks). +// +// TODO: investigate; delete these hacks (without regressing performance). +// The order matters here. Clang also defines "__GNUC__". +#if defined(__clang__) +#elif defined(__GNUC__) +#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1 +#endif + // puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length). // // A value with all fields NULL or zero is a valid, empty slice. @@ -68,6 +79,13 @@ typedef struct { bool closed; // No further writes are expected. } puffs_base__buf1; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +typedef struct { + void* always_null0; + void* always_null1; +} puffs_base__paired_nulls; +#endif + typedef struct { // TODO: move buf into private_impl? As it is, it looks like users can modify // the buf field to point to a different buffer, which can turn the limit and @@ -78,6 +96,12 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + struct { + puffs_base__paired_nulls* noph0; + uint32_t noph1; + } * no_op_performance_hacks; +#endif } private_impl; } puffs_base__reader1; diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index c9dfcfcf..c490a514 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -48,6 +48,17 @@ // TODO: don't hard code this in base-header.h. #define PUFFS_VERSION (0x00001) +// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like +// redundant no-ops, but for reasons to be investigated, can have dramatic +// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks). +// +// TODO: investigate; delete these hacks (without regressing performance). +// The order matters here. Clang also defines "__GNUC__". +#if defined(__clang__) +#elif defined(__GNUC__) +#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1 +#endif + // puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length). // // A value with all fields NULL or zero is a valid, empty slice. @@ -68,6 +79,13 @@ typedef struct { bool closed; // No further writes are expected. } puffs_base__buf1; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS +typedef struct { + void* always_null0; + void* always_null1; +} puffs_base__paired_nulls; +#endif + typedef struct { // TODO: move buf into private_impl? As it is, it looks like users can modify // the buf field to point to a different buffer, which can turn the limit and @@ -78,6 +96,12 @@ typedef struct { struct { uint8_t* limit; uint8_t* mark; +#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS + struct { + puffs_base__paired_nulls* noph0; + uint32_t noph1; + } * no_op_performance_hacks; +#endif } private_impl; } puffs_base__reader1;