aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2018-05-03 11:16:21 +0200
committerGitHub <noreply@github.com>2018-05-03 11:16:21 +0200
commitf5ed35d0658eed11787aeea1262d4370f2e9a5de (patch)
tree8d0ee2b7a8413602a5886f4bb53eaf51f237ed0b
parentf94cd51b5c91eb8cf1204859b1c784b14d6a647a (diff)
downloadbrotli-f5ed35d0658eed11787aeea1262d4370f2e9a5de.zip
brotli-f5ed35d0658eed11787aeea1262d4370f2e9a5de.tar.gz
brotli-f5ed35d0658eed11787aeea1262d4370f2e9a5de.tar.bz2
Update (#664)
* Update * fix ifdef style * get back to fine-compiler-version-based-macros (use Hedley) * fix q=0 histogram collection for very long copy/insert commands
-rw-r--r--c/common/dictionary.c2
-rwxr-xr-xc/common/platform.h412
-rw-r--r--c/dec/decode.c2
-rw-r--r--c/dec/huffman.c4
-rw-r--r--c/enc/brotli_bit_stream.h5
-rw-r--r--c/enc/compress_fragment.c10
-rwxr-xr-xc/enc/encoder_dict.h1
-rw-r--r--c/enc/fast_log.h3
-rw-r--r--c/enc/hash.h6
-rw-r--r--c/enc/write_bits.h2
-rw-r--r--c/include/brotli/port.h30
-rw-r--r--c/include/brotli/types.h7
12 files changed, 356 insertions, 128 deletions
diff --git a/c/common/dictionary.c b/c/common/dictionary.c
index d0872bd..64822a3 100644
--- a/c/common/dictionary.c
+++ b/c/common/dictionary.c
@@ -5883,7 +5883,7 @@ static BrotliDictionary kBrotliDictionary = {
122784,
/* data */
-#ifdef BROTLI_EXTERNAL_DICTIONARY_DATA
+#if defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
NULL
#else
kBrotliDictionaryData
diff --git a/c/common/platform.h b/c/common/platform.h
index b4e435a..37b9d21 100755
--- a/c/common/platform.h
+++ b/c/common/platform.h
@@ -4,7 +4,21 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
-/* Macros for compiler / platform specific features and build options. */
+/* Macros for compiler / platform specific features and build options.
+
+ Build options are:
+ * BROTLI_BUILD_32_BIT disables 64-bit optimizations
+ * BROTLI_BUILD_64_BIT forces to use 64-bit optimizations
+ * BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations
+ * BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations
+ * BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations
+ * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
+ read and overlapping memcpy; this reduces decompression speed by 5%
+ * BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
+ * BROTLI_DEBUG dumps file name and line number when decoder detects stream
+ or memory error
+ * BROTLI_ENABLE_LOG enables asserts and dumps various state information
+*/
#ifndef BROTLI_COMMON_PLATFORM_H_
#define BROTLI_COMMON_PLATFORM_H_
@@ -15,11 +29,11 @@
#include <brotli/port.h>
#include <brotli/types.h>
-#if defined OS_LINUX || defined OS_CYGWIN
+#if defined(OS_LINUX) || defined(OS_CYGWIN)
#include <endian.h>
-#elif defined OS_FREEBSD
+#elif defined(OS_FREEBSD)
#include <machine/endian.h>
-#elif defined OS_MACOSX
+#elif defined(OS_MACOSX)
#include <machine/endian.h>
/* Let's try and follow the Linux convention */
#define BROTLI_X_BYTE_ORDER BYTE_ORDER
@@ -32,85 +46,344 @@
#include <stdio.h>
#endif
-#if defined(__has_builtin)
-#define BROTLI_HAS_BUILTIN(x) __has_builtin(x)
+/* The following macros were borrowed from https://github.com/nemequ/hedley
+ * with permission of original author - Evan Nemerson <evan@nemerson.com> */
+
+/* >>> >>> >>> hedley macros */
+
+#define BROTLI_MAKE_VERSION(major, minor, revision) \
+ (((major) * 1000000) + ((minor) * 1000) + (revision))
+
+#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
+#define BROTLI_GNUC_VERSION \
+ BROTLI_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
+#elif defined(__GNUC__)
+#define BROTLI_GNUC_VERSION BROTLI_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, 0)
+#endif
+
+#if defined(BROTLI_GNUC_VERSION)
+#define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_GNUC_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
#else
-#define BROTLI_HAS_BUILTIN(x) 0
+#define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) (0)
#endif
-#if defined(__has_attribute)
-#define BROTLI_HAS_ATTRIBUTE(x) __has_attribute(x)
+#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
+#define BROTLI_MSVC_VERSION \
+ BROTLI_MAKE_VERSION((_MSC_FULL_VER / 10000000), \
+ (_MSC_FULL_VER % 10000000) / 100000, \
+ (_MSC_FULL_VER % 100000) / 100)
+#elif defined(_MSC_FULL_VER)
+#define BROTLI_MSVC_VERSION \
+ BROTLI_MAKE_VERSION((_MSC_FULL_VER / 1000000), \
+ (_MSC_FULL_VER % 1000000) / 10000, \
+ (_MSC_FULL_VER % 10000) / 10)
+#elif defined(_MSC_VER)
+#define BROTLI_MSVC_VERSION \
+ BROTLI_MAKE_VERSION(_MSC_VER / 100, _MSC_VER % 100, 0)
+#endif
+
+#if !defined(_MSC_VER)
+#define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) (0)
+#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
+#define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
+ (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
+#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
+#define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
+ (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
#else
-#define BROTLI_HAS_ATTRIBUTE(x) 0
+#define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
+ (_MSC_VER >= ((major * 100) + (minor)))
#endif
-/* Macros for compiler / platform specific features and build options.
+#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
+#define BROTLI_INTEL_VERSION \
+ BROTLI_MAKE_VERSION(__INTEL_COMPILER / 100, \
+ __INTEL_COMPILER % 100, \
+ __INTEL_COMPILER_UPDATE)
+#elif defined(__INTEL_COMPILER)
+#define BROTLI_INTEL_VERSION \
+ BROTLI_MAKE_VERSION(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
+#endif
- Build options are:
- * BROTLI_BUILD_32_BIT disables 64-bit optimizations
- * BROTLI_BUILD_64_BIT forces to use 64-bit optimizations
- * BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations
- * BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations
- * BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations
- * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
- read and overlapping memcpy; this reduces decompression speed by 5%
- * BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
- * BROTLI_DEBUG dumps file name and line number when decoder detects stream
- or memory error
- * BROTLI_ENABLE_LOG enables asserts and dumps various state information
-*/
+#if defined(BROTLI_INTEL_VERSION)
+#define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_INTEL_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
+#else
+#define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) (0)
+#endif
-#if BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(always_inline)
-#define BROTLI_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
+#if defined(__PGI) && \
+ defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
+#define BROTLI_PGI_VERSION \
+ BROTLI_MAKE_VERSION(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
+#endif
+
+#if defined(BROTLI_PGI_VERSION)
+#define BROTLI_PGI_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_PGI_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
#else
-#define BROTLI_ATTRIBUTE_ALWAYS_INLINE
+#define BROTLI_PGI_VERSION_CHECK(major, minor, patch) (0)
#endif
-#if defined(_WIN32) || defined(__CYGWIN__)
-#define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN
-#elif BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(visibility)
-#define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN \
- __attribute__ ((visibility ("hidden")))
+#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
+#define BROTLI_SUNPRO_VERSION \
+ BROTLI_MAKE_VERSION( \
+ (((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), \
+ (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), \
+ (__SUNPRO_C & 0xf) * 10)
+#elif defined(__SUNPRO_C)
+#define BROTLI_SUNPRO_VERSION \
+ BROTLI_MAKE_VERSION((__SUNPRO_C >> 8) & 0xf, \
+ (__SUNPRO_C >> 4) & 0xf, \
+ (__SUNPRO_C) & 0xf)
+#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
+#define BROTLI_SUNPRO_VERSION \
+ BROTLI_MAKE_VERSION( \
+ (((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), \
+ (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), \
+ (__SUNPRO_CC & 0xf) * 10)
+#elif defined(__SUNPRO_CC)
+#define BROTLI_SUNPRO_VERSION \
+ BROTLI_MAKE_VERSION((__SUNPRO_CC >> 8) & 0xf, \
+ (__SUNPRO_CC >> 4) & 0xf, \
+ (__SUNPRO_CC) & 0xf)
+#endif
+
+#if defined(BROTLI_SUNPRO_VERSION)
+#define BROTLI_SUNPRO_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_SUNPRO_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
#else
-#define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN
+#define BROTLI_SUNPRO_VERSION_CHECK(major, minor, patch) (0)
#endif
-#ifndef BROTLI_INTERNAL
-#define BROTLI_INTERNAL BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN
+#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
+#define BROTLI_ARM_VERSION \
+ BROTLI_MAKE_VERSION((__ARMCOMPILER_VERSION / 1000000), \
+ (__ARMCOMPILER_VERSION % 1000000) / 10000, \
+ (__ARMCOMPILER_VERSION % 10000) / 100)
+#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
+#define BROTLI_ARM_VERSION \
+ BROTLI_MAKE_VERSION((__ARMCC_VERSION / 1000000), \
+ (__ARMCC_VERSION % 1000000) / 10000, \
+ (__ARMCC_VERSION % 10000) / 100)
#endif
-#ifndef _MSC_VER
-#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
- (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
-#define BROTLI_INLINE inline BROTLI_ATTRIBUTE_ALWAYS_INLINE
+#if defined(BROTLI_ARM_VERSION)
+#define BROTLI_ARM_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_ARM_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
#else
-#define BROTLI_INLINE
+#define BROTLI_ARM_VERSION_CHECK(major, minor, patch) (0)
#endif
-#else /* _MSC_VER */
-#define BROTLI_INLINE __forceinline
-#endif /* _MSC_VER */
-#if BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(unused)
-#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused))
+#if defined(__ibmxl__)
+#define BROTLI_IBM_VERSION \
+ BROTLI_MAKE_VERSION(__ibmxl_version__, \
+ __ibmxl_release__, \
+ __ibmxl_modification__)
+#elif defined(__xlC__) && defined(__xlC_ver__)
+#define BROTLI_IBM_VERSION \
+ BROTLI_MAKE_VERSION(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
+#elif defined(__xlC__)
+#define BROTLI_IBM_VERSION BROTLI_MAKE_VERSION(__xlC__ >> 8, __xlC__ & 0xff, 0)
+#endif
+
+#if defined(BROTLI_IBM_VERSION)
+#define BROTLI_IBM_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_IBM_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
#else
-#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE
+#define BROTLI_IBM_VERSION_CHECK(major, minor, patch) (0)
+#endif
+
+#if defined(__TI_COMPILER_VERSION__)
+#define BROTLI_TI_VERSION \
+ BROTLI_MAKE_VERSION((__TI_COMPILER_VERSION__ / 1000000), \
+ (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
+ (__TI_COMPILER_VERSION__ % 1000))
+#endif
+
+#if defined(BROTLI_TI_VERSION)
+#define BROTLI_TI_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_TI_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
+#else
+#define BROTLI_TI_VERSION_CHECK(major, minor, patch) (0)
+#endif
+
+#if defined(__IAR_SYSTEMS_ICC__)
+#if __VER__ > 1000
+#define BROTLI_IAR_VERSION \
+ BROTLI_MAKE_VERSION((__VER__ / 1000000), \
+ (__VER__ / 1000) % 1000, \
+ (__VER__ % 1000))
+#else
+#define BROTLI_IAR_VERSION BROTLI_MAKE_VERSION(VER / 100, __VER__ % 100, 0)
+#endif
+#endif
+
+#if defined(BROTLI_IAR_VERSION)
+#define BROTLI_IAR_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_IAR_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
+#else
+#define BROTLI_IAR_VERSION_CHECK(major, minor, patch) (0)
+#endif
+
+#if defined(__TINYC__)
+#define BROTLI_TINYC_VERSION \
+ BROTLI_MAKE_VERSION(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
+#endif
+
+#if defined(BROTLI_TINYC_VERSION)
+#define BROTLI_TINYC_VERSION_CHECK(major, minor, patch) \
+ (BROTLI_TINYC_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
+#else
+#define BROTLI_TINYC_VERSION_CHECK(major, minor, patch) (0)
+#endif
+
+#if defined(__has_attribute)
+#define BROTLI_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
+ __has_attribute(attribute)
+#else
+#define BROTLI_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
+ BROTLI_GNUC_VERSION_CHECK(major, minor, patch)
#endif
-#if !defined(__cplusplus) && !defined(c_plusplus) && \
- (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
+#if defined(__has_builtin)
+#define BROTLI_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \
+ __has_builtin(builtin)
+#else
+#define BROTLI_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \
+ BROTLI_GNUC_VERSION_CHECK(major, minor, patch)
+#endif
+
+/* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable
+ compilers.
+
+To apply compiler hint, enclose the branching condition into macros, like this:
+
+ if (BROTLI_PREDICT_TRUE(zero == 0)) {
+ // main execution path
+ } else {
+ // compiler should place this code outside of main execution path
+ }
+
+OR:
+
+ if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) {
+ // compiler should place this code outside of main execution path
+ }
+
+*/
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_expect, 3, 0, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
+ BROTLI_SUNPRO_VERSION_CHECK(5, 12, 0) || \
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
+ BROTLI_TI_VERSION_CHECK(7, 3, 0) || \
+ BROTLI_TINYC_VERSION_CHECK(0, 9, 27)
+#define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
+#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
+#else
+#define BROTLI_PREDICT_FALSE(x) (x)
+#define BROTLI_PREDICT_TRUE(x) (x)
+#endif
+
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
+ !defined(__cplusplus)
#define BROTLI_RESTRICT restrict
-#elif BROTLI_GCC_VERSION > 295 || defined(__llvm__)
+#elif BROTLI_GNUC_VERSION_CHECK(3, 1, 0) || \
+ BROTLI_MSVC_VERSION_CHECK(14, 0, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
+ BROTLI_PGI_VERSION_CHECK(17, 10, 0) || \
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
+ BROTLI_IAR_VERSION_CHECK(8, 0, 0) || \
+ (BROTLI_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus))
#define BROTLI_RESTRICT __restrict
+#elif BROTLI_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus)
+#define BROTLI_RESTRICT _Restrict
#else
#define BROTLI_RESTRICT
#endif
-#if BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(noinline)
-#define BROTLI_NOINLINE __attribute__((noinline))
+#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
+ (defined(__cplusplus) && (__cplusplus >= 199711L))
+#define BROTLI_MAYBE_INLINE inline
+#elif defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__) || \
+ BROTLI_ARM_VERSION_CHECK(6, 2, 0)
+#define BROTLI_MAYBE_INLINE __inline__
+#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0) || \
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || BROTLI_TI_VERSION_CHECK(8, 0, 0)
+#define BROTLI_MAYBE_INLINE __inline
+#else
+#define BROTLI_MAYBE_INLINE
+#endif
+
+#if BROTLI_GNUC_HAS_ATTRIBUTE(always_inline, 4, 0, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
+#define BROTLI_INLINE BROTLI_MAYBE_INLINE __attribute__((__always_inline__))
+#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+#define BROTLI_INLINE BROTLI_MAYBE_INLINE __forceinline
+#elif BROTLI_TI_VERSION_CHECK(7, 0, 0) && defined(__cplusplus)
+#define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
+#elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
+#define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("inline=forced")
+#else
+#define BROTLI_INLINE BROTLI_MAYBE_INLINE
+#endif
+
+#if BROTLI_GNUC_HAS_ATTRIBUTE(noinline, 4, 0, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
+ BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__))
+#define BROTLI_NOINLINE __attribute__((__noinline__))
+#elif BROTLI_MSVC_VERSION_CHECK(13, 10, 0)
+#define BROTLI_NOINLINE __declspec(noinline)
+#elif BROTLI_PGI_VERSION_CHECK(10, 2, 0)
+#define BROTLI_NOINLINE _Pragma("noinline")
+#elif BROTLI_TI_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
+#define BROTLI_NOINLINE _Pragma("FUNC_CANNOT_INLINE;")
+#elif BROTLI_IAR_VERSION_CHECK(8, 0, 0)
+#define BROTLI_NOINLINE _Pragma("inline=never")
#else
#define BROTLI_NOINLINE
#endif
+/* BROTLI_INTERNAL could be defined to override visibility, e.g. for tests. */
+#if !defined(BROTLI_INTERNAL)
+#if defined(_WIN32) || defined(__CYGWIN__)
+#define BROTLI_INTERNAL
+#elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
+ BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
+ BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
+ BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
+ BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
+ (BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
+ defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
+#define BROTLI_INTERNAL __attribute__ ((visibility ("hidden")))
+#else
+#define BROTLI_INTERNAL
+#endif
+#endif
+
+/* <<< <<< <<< end of headley macros. */
+
+#if BROTLI_GNUC_HAS_ATTRIBUTE(unused, 2, 7, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
+#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused))
+#else
+#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE
+#endif
+
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
(defined(M_ARM) && (M_ARM == 7))
#define BROTLI_TARGET_ARMV7
@@ -179,16 +452,16 @@
#define BROTLI_BIG_ENDIAN 0
#endif
-#ifdef BROTLI_X_BYTE_ORDER
+#if defined(BROTLI_X_BYTE_ORDER)
#undef BROTLI_X_BYTE_ORDER
#undef BROTLI_X_LITTLE_ENDIAN
#undef BROTLI_X_BIG_ENDIAN
#endif
-#ifdef BROTLI_BUILD_PORTABLE
+#if defined(BROTLI_BUILD_PORTABLE)
#define BROTLI_ALIGNED_READ (!!1)
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
- defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
+ defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
/* Allow unaligned read only for white-listed CPUs. */
#define BROTLI_ALIGNED_READ (!!0)
#else
@@ -318,34 +591,9 @@ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
}
#endif /* BROTLI_LITTLE_ENDIAN */
-/* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable
- compilers.
-
-To apply compiler hint, enclose the branching condition into macros, like this:
-
- if (BROTLI_PREDICT_TRUE(zero == 0)) {
- // main execution path
- } else {
- // compiler should place this code outside of main execution path
- }
-
-OR:
-
- if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) {
- // compiler should place this code outside of main execution path
- }
-
-*/
-#if BROTLI_MODERN_COMPILER || BROTLI_HAS_BUILTIN(__builtin_expect)
-#define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
-#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
-#else
-#define BROTLI_PREDICT_FALSE(x) (x)
-#define BROTLI_PREDICT_TRUE(x) (x)
-#endif
-
/* BROTLI_IS_CONSTANT macros returns true for compile-time constants. */
-#if BROTLI_MODERN_COMPILER || BROTLI_HAS_BUILTIN(__builtin_constant_p)
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_constant_p, 3, 0, 1) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
#else
#define BROTLI_IS_CONSTANT(x) (!!0)
@@ -357,7 +605,7 @@ OR:
#define BROTLI_HAS_UBFX (!!0)
#endif
-#ifdef BROTLI_ENABLE_LOG
+#if defined(BROTLI_ENABLE_LOG)
#define BROTLI_DCHECK(x) assert(x)
#define BROTLI_LOG(x) printf x
#else
diff --git a/c/dec/decode.c b/c/dec/decode.c
index 86dcd5f..278b622 100644
--- a/c/dec/decode.c
+++ b/c/dec/decode.c
@@ -6,7 +6,7 @@
#include <brotli/decode.h>
-#ifdef __ARM_NEON__
+#if defined(__ARM_NEON__)
#include <arm_neon.h>
#endif
diff --git a/c/dec/huffman.c b/c/dec/huffman.c
index f142442..c5eafad 100644
--- a/c/dec/huffman.c
+++ b/c/dec/huffman.c
@@ -20,7 +20,7 @@ extern "C" {
#define BROTLI_REVERSE_BITS_MAX 8
-#ifdef BROTLI_RBIT
+#if defined(BROTLI_RBIT)
#define BROTLI_REVERSE_BITS_BASE \
((sizeof(brotli_reg_t) << 3) - BROTLI_REVERSE_BITS_MAX)
#else
@@ -68,7 +68,7 @@ static uint8_t kReverseBits[1 << BROTLI_REVERSE_BITS_MAX] = {
where reverse(value, len) is the bit-wise reversal of the len least
significant bits of value. */
static BROTLI_INLINE brotli_reg_t BrotliReverseBits(brotli_reg_t num) {
-#ifdef BROTLI_RBIT
+#if defined(BROTLI_RBIT)
return BROTLI_RBIT(num);
#else
return kReverseBits[num];
diff --git a/c/enc/brotli_bit_stream.h b/c/enc/brotli_bit_stream.h
index 9089b1d..2ed703b 100644
--- a/c/enc/brotli_bit_stream.h
+++ b/c/enc/brotli_bit_stream.h
@@ -73,8 +73,9 @@ BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
REQUIRES: length > 0
REQUIRES: length <= (1 << 24) */
BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
- BROTLI_BOOL is_final_block, const uint8_t* input, size_t position,
- size_t mask, size_t len, size_t* storage_ix, uint8_t* storage);
+ BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input,
+ size_t position, size_t mask, size_t len,
+ size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage);
#if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */
diff --git a/c/enc/compress_fragment.c b/c/enc/compress_fragment.c
index f75069b..9e50b20 100644
--- a/c/enc/compress_fragment.c
+++ b/c/enc/compress_fragment.c
@@ -202,7 +202,7 @@ static BROTLI_INLINE void EmitInsertLen(size_t insertlen,
} else {
BrotliWriteBits(depth[61], bits[61], storage_ix, storage);
BrotliWriteBits(12, insertlen - 2114, storage_ix, storage);
- ++histo[21];
+ ++histo[61];
}
}
@@ -215,11 +215,11 @@ static BROTLI_INLINE void EmitLongInsertLen(size_t insertlen,
if (insertlen < 22594) {
BrotliWriteBits(depth[62], bits[62], storage_ix, storage);
BrotliWriteBits(14, insertlen - 6210, storage_ix, storage);
- ++histo[22];
+ ++histo[62];
} else {
BrotliWriteBits(depth[63], bits[63], storage_ix, storage);
BrotliWriteBits(24, insertlen - 22594, storage_ix, storage);
- ++histo[23];
+ ++histo[63];
}
}
@@ -251,7 +251,7 @@ static BROTLI_INLINE void EmitCopyLen(size_t copylen,
} else {
BrotliWriteBits(depth[39], bits[39], storage_ix, storage);
BrotliWriteBits(24, copylen - 2118, storage_ix, storage);
- ++histo[47];
+ ++histo[39];
}
}
@@ -293,7 +293,7 @@ static BROTLI_INLINE void EmitCopyLenLastDistance(size_t copylen,
BrotliWriteBits(depth[39], bits[39], storage_ix, storage);
BrotliWriteBits(24, copylen - 2120, storage_ix, storage);
BrotliWriteBits(depth[64], bits[64], storage_ix, storage);
- ++histo[47];
+ ++histo[39];
++histo[64];
}
}
diff --git a/c/enc/encoder_dict.h b/c/enc/encoder_dict.h
index 9ac8b4a..3cb6b0a 100755
--- a/c/enc/encoder_dict.h
+++ b/c/enc/encoder_dict.h
@@ -34,7 +34,6 @@ typedef struct BrotliEncoderDictionary {
BROTLI_INTERNAL void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict);
-
#if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */
#endif
diff --git a/c/enc/fast_log.h b/c/enc/fast_log.h
index 1472cce..cade123 100644
--- a/c/enc/fast_log.h
+++ b/c/enc/fast_log.h
@@ -20,7 +20,8 @@ extern "C" {
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
/* TODO: generalize and move to platform.h */
-#if BROTLI_MODERN_COMPILER || BROTLI_HAS_BUILTIN(__builtin_clz)
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
return 31u ^ (uint32_t)__builtin_clz((uint32_t)n);
#else
uint32_t result = 0;
diff --git a/c/enc/hash.h b/c/enc/hash.h
index 1827ce6..fc7356b 100644
--- a/c/enc/hash.h
+++ b/c/enc/hash.h
@@ -36,8 +36,10 @@ extern "C" {
* * HasherCommon structure
* * private structured hasher data, depending on hasher type
* * private dynamic hasher data, depending on hasher type and parameters
- */
-typedef uint8_t* HasherHandle;
+ *
+ * Using "define" instead of "typedef", because on MSVC __restrict does not work
+ * on typedef pointer types. */
+#define HasherHandle uint8_t*
typedef struct {
BrotliHasherParams params;
diff --git a/c/enc/write_bits.h b/c/enc/write_bits.h
index ddfebeb..36515a6 100644
--- a/c/enc/write_bits.h
+++ b/c/enc/write_bits.h
@@ -37,7 +37,7 @@ static BROTLI_INLINE void BrotliWriteBits(size_t n_bits,
uint64_t bits,
size_t* BROTLI_RESTRICT pos,
uint8_t* BROTLI_RESTRICT array) {
-#ifdef BROTLI_LITTLE_ENDIAN
+#if defined(BROTLI_LITTLE_ENDIAN)
/* This branch of the code can write up to 56 bits at a time,
7 bits are lost by being perhaps already in *p and at least
1 bit is needed to initialize the bit-stream ahead (i.e. if 7
diff --git a/c/include/brotli/port.h b/c/include/brotli/port.h
index d49fa6a..e5ac4ba 100644
--- a/c/include/brotli/port.h
+++ b/c/include/brotli/port.h
@@ -4,34 +4,18 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
-/* Macros for compiler / platform specific features and build options.
-
- Build options are:
- * BROTLI_BUILD_MODERN_COMPILER forces to use modern compilers built-ins,
- features and attributes
- */
+/* Macros for compiler / platform specific API declarations. */
#ifndef BROTLI_COMMON_PORT_H_
#define BROTLI_COMMON_PORT_H_
-#if defined(__GNUC__) && defined(__GNUC_MINOR__)
-#define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
-#else
-#define BROTLI_GCC_VERSION 0
-#endif
-
-#if defined(__ICC)
-#define BROTLI_ICC_VERSION __ICC
-#else
-#define BROTLI_ICC_VERSION 0
-#endif
-
-#if defined(BROTLI_BUILD_MODERN_COMPILER)
-#define BROTLI_MODERN_COMPILER 1
-#elif BROTLI_GCC_VERSION >= 304 || BROTLI_ICC_VERSION >= 1600
-#define BROTLI_MODERN_COMPILER 1
+/* NB: borrowed from github.com.nemequ/hedley. */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
+ !defined(__STDC_NO_VLA__) && !defined(__cplusplus) && \
+ !defined(__PGI) && !defined(__PGIC__) && !defined(__TINYC__)
+#define BROTLI_ARRAY_PARAM(name) (name)
#else
-#define BROTLI_MODERN_COMPILER 0
+#define BROTLI_ARRAY_PARAM(name)
#endif
#if defined(BROTLI_SHARED_COMPILATION) && defined(_WIN32)
diff --git a/c/include/brotli/types.h b/c/include/brotli/types.h
index fcb2710..eff1a3c 100644
--- a/c/include/brotli/types.h
+++ b/c/include/brotli/types.h
@@ -80,11 +80,4 @@ typedef void* (*brotli_alloc_func)(void* opaque, size_t size);
*/
typedef void (*brotli_free_func)(void* opaque, void* address);
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
- !defined(__cplusplus) && !defined(__PGI)
-#define BROTLI_ARRAY_PARAM(L) L
-#else
-#define BROTLI_ARRAY_PARAM(L)
-#endif
-
#endif /* BROTLI_COMMON_TYPES_H_ */