diff --git a/cmd/puffs-c/internal/cgen/base-header.h b/cmd/puffs-c/internal/cgen/base-header.h index a14cd314..bf6c8b23 100644 --- a/cmd/puffs-c/internal/cgen/base-header.h +++ b/cmd/puffs-c/internal/cgen/base-header.h @@ -45,17 +45,6 @@ // 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. @@ -87,13 +76,6 @@ typedef struct puffs_base__limit1 { struct puffs_base__limit1* next; // Linked list of limits. } puffs_base__limit1; -#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 @@ -104,12 +86,6 @@ typedef struct { struct { puffs_base__limit1 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 8c3182bb..d92b77e7 100644 --- a/cmd/puffs-c/internal/cgen/data.go +++ b/cmd/puffs-c/internal/cgen/data.go @@ -18,10 +18,9 @@ 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_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// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are r" + - "ead from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base__limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base__limit1* next; // Linked list of limits.\n} puffs_base__limit1;\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 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 puffs_base__limit1 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 puffs_base__limit1 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_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\n// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base__limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base__limit1* next; // Linked list of limits.\n} puffs_base__limit1;\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 l" + + "imit 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 puffs_base__limit1 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 puffs_base__limit1 limit;\n uint8_t* mark;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" + "" const baseImpl = "" + diff --git a/cmd/puffs-c/internal/cgen/noph.go b/cmd/puffs-c/internal/cgen/noph.go deleted file mode 100644 index 9c3b5637..00000000 --- a/cmd/puffs-c/internal/cgen/noph.go +++ /dev/null @@ -1,62 +0,0 @@ -// 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). - -// TODO: delete this file. - -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 -`, -} diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index a27b9479..27e7cb26 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -48,17 +48,6 @@ // 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. @@ -90,13 +79,6 @@ typedef struct puffs_base__limit1 { struct puffs_base__limit1* next; // Linked list of limits. } puffs_base__limit1; -#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 @@ -107,12 +89,6 @@ typedef struct { struct { puffs_base__limit1 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 5322bcee..ab0c3ebe 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -48,17 +48,6 @@ // 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. @@ -90,13 +79,6 @@ typedef struct puffs_base__limit1 { struct puffs_base__limit1* next; // Linked list of limits. } puffs_base__limit1; -#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 @@ -107,12 +89,6 @@ typedef struct { struct { puffs_base__limit1 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/flate.h b/gen/h/std/flate.h index 3ef55b79..eee92284 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -48,17 +48,6 @@ // 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. @@ -90,13 +79,6 @@ typedef struct puffs_base__limit1 { struct puffs_base__limit1* next; // Linked list of limits. } puffs_base__limit1; -#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 @@ -107,12 +89,6 @@ typedef struct { struct { puffs_base__limit1 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 4c321215..ac407104 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -48,17 +48,6 @@ // 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. @@ -90,13 +79,6 @@ typedef struct puffs_base__limit1 { struct puffs_base__limit1* next; // Linked list of limits. } puffs_base__limit1; -#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 @@ -107,12 +89,6 @@ typedef struct { struct { puffs_base__limit1 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;