* 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
This commit is contained in:
Eugene Kliuchnikov 2018-05-03 11:16:21 +02:00 committed by GitHub
parent f94cd51b5c
commit f5ed35d065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 372 additions and 144 deletions

View File

@ -5883,7 +5883,7 @@ static BrotliDictionary kBrotliDictionary = {
122784, 122784,
/* data */ /* data */
#ifdef BROTLI_EXTERNAL_DICTIONARY_DATA #if defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
NULL NULL
#else #else
kBrotliDictionaryData kBrotliDictionaryData

View File

@ -4,46 +4,6 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/ */
/* Macros for compiler / platform specific features and build options. */
#ifndef BROTLI_COMMON_PLATFORM_H_
#define BROTLI_COMMON_PLATFORM_H_
#include <string.h> /* memcpy */
#include <stdlib.h> /* malloc, free */
#include <brotli/port.h>
#include <brotli/types.h>
#if defined OS_LINUX || defined OS_CYGWIN
#include <endian.h>
#elif defined OS_FREEBSD
#include <machine/endian.h>
#elif defined OS_MACOSX
#include <machine/endian.h>
/* Let's try and follow the Linux convention */
#define BROTLI_X_BYTE_ORDER BYTE_ORDER
#define BROTLI_X_LITTLE_ENDIAN LITTLE_ENDIAN
#define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
#endif
#if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
#include <assert.h>
#include <stdio.h>
#endif
#if defined(__has_builtin)
#define BROTLI_HAS_BUILTIN(x) __has_builtin(x)
#else
#define BROTLI_HAS_BUILTIN(x) 0
#endif
#if defined(__has_attribute)
#define BROTLI_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
#define BROTLI_HAS_ATTRIBUTE(x) 0
#endif
/* Macros for compiler / platform specific features and build options. /* Macros for compiler / platform specific features and build options.
Build options are: Build options are:
@ -60,57 +20,370 @@
* BROTLI_ENABLE_LOG enables asserts and dumps various state information * BROTLI_ENABLE_LOG enables asserts and dumps various state information
*/ */
#if BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(always_inline) #ifndef BROTLI_COMMON_PLATFORM_H_
#define BROTLI_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) #define BROTLI_COMMON_PLATFORM_H_
#include <string.h> /* memcpy */
#include <stdlib.h> /* malloc, free */
#include <brotli/port.h>
#include <brotli/types.h>
#if defined(OS_LINUX) || defined(OS_CYGWIN)
#include <endian.h>
#elif defined(OS_FREEBSD)
#include <machine/endian.h>
#elif defined(OS_MACOSX)
#include <machine/endian.h>
/* Let's try and follow the Linux convention */
#define BROTLI_X_BYTE_ORDER BYTE_ORDER
#define BROTLI_X_LITTLE_ENDIAN LITTLE_ENDIAN
#define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
#endif
#if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
#include <assert.h>
#include <stdio.h>
#endif
/* 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 #else
#define BROTLI_ATTRIBUTE_ALWAYS_INLINE #define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) (0)
#endif #endif
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
#define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN #define BROTLI_MSVC_VERSION \
#elif BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(visibility) BROTLI_MAKE_VERSION((_MSC_FULL_VER / 10000000), \
#define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN \ (_MSC_FULL_VER % 10000000) / 100000, \
__attribute__ ((visibility ("hidden"))) (_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 #else
#define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
(_MSC_VER >= ((major * 100) + (minor)))
#endif #endif
#ifndef BROTLI_INTERNAL #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
#define BROTLI_INTERNAL BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN #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 #endif
#ifndef _MSC_VER #if defined(BROTLI_INTEL_VERSION)
#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \ #define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) (BROTLI_INTEL_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
#define BROTLI_INLINE inline BROTLI_ATTRIBUTE_ALWAYS_INLINE
#else #else
#define BROTLI_INLINE #define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) (0)
#endif #endif
#else /* _MSC_VER */
#define BROTLI_INLINE __forceinline
#endif /* _MSC_VER */
#if BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(unused) #if defined(__PGI) && \
#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused)) 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 #else
#define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE #define BROTLI_PGI_VERSION_CHECK(major, minor, patch) (0)
#endif #endif
#if !defined(__cplusplus) && !defined(c_plusplus) && \ #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) #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_SUNPRO_VERSION_CHECK(major, minor, patch) (0)
#endif
#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
#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_ARM_VERSION_CHECK(major, minor, patch) (0)
#endif
#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_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(__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 #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 #define BROTLI_RESTRICT __restrict
#elif BROTLI_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus)
#define BROTLI_RESTRICT _Restrict
#else #else
#define BROTLI_RESTRICT #define BROTLI_RESTRICT
#endif #endif
#if BROTLI_MODERN_COMPILER || BROTLI_HAS_ATTRIBUTE(noinline) #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
#define BROTLI_NOINLINE __attribute__((noinline)) (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 #else
#define BROTLI_NOINLINE #define BROTLI_NOINLINE
#endif #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)) || \ #if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
(defined(M_ARM) && (M_ARM == 7)) (defined(M_ARM) && (M_ARM == 7))
#define BROTLI_TARGET_ARMV7 #define BROTLI_TARGET_ARMV7
@ -179,13 +452,13 @@
#define BROTLI_BIG_ENDIAN 0 #define BROTLI_BIG_ENDIAN 0
#endif #endif
#ifdef BROTLI_X_BYTE_ORDER #if defined(BROTLI_X_BYTE_ORDER)
#undef BROTLI_X_BYTE_ORDER #undef BROTLI_X_BYTE_ORDER
#undef BROTLI_X_LITTLE_ENDIAN #undef BROTLI_X_LITTLE_ENDIAN
#undef BROTLI_X_BIG_ENDIAN #undef BROTLI_X_BIG_ENDIAN
#endif #endif
#ifdef BROTLI_BUILD_PORTABLE #if defined(BROTLI_BUILD_PORTABLE)
#define BROTLI_ALIGNED_READ (!!1) #define BROTLI_ALIGNED_READ (!!1)
#elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \ #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)
@ -318,34 +591,9 @@ static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) {
} }
#endif /* BROTLI_LITTLE_ENDIAN */ #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. */ /* 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)) #define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
#else #else
#define BROTLI_IS_CONSTANT(x) (!!0) #define BROTLI_IS_CONSTANT(x) (!!0)
@ -357,7 +605,7 @@ OR:
#define BROTLI_HAS_UBFX (!!0) #define BROTLI_HAS_UBFX (!!0)
#endif #endif
#ifdef BROTLI_ENABLE_LOG #if defined(BROTLI_ENABLE_LOG)
#define BROTLI_DCHECK(x) assert(x) #define BROTLI_DCHECK(x) assert(x)
#define BROTLI_LOG(x) printf x #define BROTLI_LOG(x) printf x
#else #else

View File

@ -6,7 +6,7 @@
#include <brotli/decode.h> #include <brotli/decode.h>
#ifdef __ARM_NEON__ #if defined(__ARM_NEON__)
#include <arm_neon.h> #include <arm_neon.h>
#endif #endif

View File

@ -20,7 +20,7 @@ extern "C" {
#define BROTLI_REVERSE_BITS_MAX 8 #define BROTLI_REVERSE_BITS_MAX 8
#ifdef BROTLI_RBIT #if defined(BROTLI_RBIT)
#define BROTLI_REVERSE_BITS_BASE \ #define BROTLI_REVERSE_BITS_BASE \
((sizeof(brotli_reg_t) << 3) - BROTLI_REVERSE_BITS_MAX) ((sizeof(brotli_reg_t) << 3) - BROTLI_REVERSE_BITS_MAX)
#else #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 where reverse(value, len) is the bit-wise reversal of the len least
significant bits of value. */ significant bits of value. */
static BROTLI_INLINE brotli_reg_t BrotliReverseBits(brotli_reg_t num) { static BROTLI_INLINE brotli_reg_t BrotliReverseBits(brotli_reg_t num) {
#ifdef BROTLI_RBIT #if defined(BROTLI_RBIT)
return BROTLI_RBIT(num); return BROTLI_RBIT(num);
#else #else
return kReverseBits[num]; return kReverseBits[num];

View File

@ -73,8 +73,9 @@ BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
REQUIRES: length > 0 REQUIRES: length > 0
REQUIRES: length <= (1 << 24) */ REQUIRES: length <= (1 << 24) */
BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock( BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
BROTLI_BOOL is_final_block, const uint8_t* input, size_t position, BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input,
size_t mask, size_t len, size_t* storage_ix, uint8_t* storage); 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) #if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */ } /* extern "C" */

View File

@ -202,7 +202,7 @@ static BROTLI_INLINE void EmitInsertLen(size_t insertlen,
} else { } else {
BrotliWriteBits(depth[61], bits[61], storage_ix, storage); BrotliWriteBits(depth[61], bits[61], storage_ix, storage);
BrotliWriteBits(12, insertlen - 2114, 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) { if (insertlen < 22594) {
BrotliWriteBits(depth[62], bits[62], storage_ix, storage); BrotliWriteBits(depth[62], bits[62], storage_ix, storage);
BrotliWriteBits(14, insertlen - 6210, storage_ix, storage); BrotliWriteBits(14, insertlen - 6210, storage_ix, storage);
++histo[22]; ++histo[62];
} else { } else {
BrotliWriteBits(depth[63], bits[63], storage_ix, storage); BrotliWriteBits(depth[63], bits[63], storage_ix, storage);
BrotliWriteBits(24, insertlen - 22594, 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 { } else {
BrotliWriteBits(depth[39], bits[39], storage_ix, storage); BrotliWriteBits(depth[39], bits[39], storage_ix, storage);
BrotliWriteBits(24, copylen - 2118, 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(depth[39], bits[39], storage_ix, storage);
BrotliWriteBits(24, copylen - 2120, storage_ix, storage); BrotliWriteBits(24, copylen - 2120, storage_ix, storage);
BrotliWriteBits(depth[64], bits[64], storage_ix, storage); BrotliWriteBits(depth[64], bits[64], storage_ix, storage);
++histo[47]; ++histo[39];
++histo[64]; ++histo[64];
} }
} }

View File

@ -34,7 +34,6 @@ typedef struct BrotliEncoderDictionary {
BROTLI_INTERNAL void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict); BROTLI_INTERNAL void BrotliInitEncoderDictionary(BrotliEncoderDictionary* dict);
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */ } /* extern "C" */
#endif #endif

View File

@ -20,7 +20,8 @@ extern "C" {
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) { static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
/* TODO: generalize and move to platform.h */ /* 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); return 31u ^ (uint32_t)__builtin_clz((uint32_t)n);
#else #else
uint32_t result = 0; uint32_t result = 0;

View File

@ -36,8 +36,10 @@ extern "C" {
* * HasherCommon structure * * HasherCommon structure
* * private structured hasher data, depending on hasher type * * private structured hasher data, depending on hasher type
* * private dynamic hasher data, depending on hasher type and parameters * * 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 { typedef struct {
BrotliHasherParams params; BrotliHasherParams params;

View File

@ -37,7 +37,7 @@ static BROTLI_INLINE void BrotliWriteBits(size_t n_bits,
uint64_t bits, uint64_t bits,
size_t* BROTLI_RESTRICT pos, size_t* BROTLI_RESTRICT pos,
uint8_t* BROTLI_RESTRICT array) { 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, /* 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 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 1 bit is needed to initialize the bit-stream ahead (i.e. if 7

View File

@ -4,34 +4,18 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 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 API declarations. */
Build options are:
* BROTLI_BUILD_MODERN_COMPILER forces to use modern compilers built-ins,
features and attributes
*/
#ifndef BROTLI_COMMON_PORT_H_ #ifndef BROTLI_COMMON_PORT_H_
#define BROTLI_COMMON_PORT_H_ #define BROTLI_COMMON_PORT_H_
#if defined(__GNUC__) && defined(__GNUC_MINOR__) /* NB: borrowed from github.com.nemequ/hedley. */
#define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) #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 #else
#define BROTLI_GCC_VERSION 0 #define BROTLI_ARRAY_PARAM(name)
#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
#else
#define BROTLI_MODERN_COMPILER 0
#endif #endif
#if defined(BROTLI_SHARED_COMPILATION) && defined(_WIN32) #if defined(BROTLI_SHARED_COMPILATION) && defined(_WIN32)

View File

@ -80,11 +80,4 @@ typedef void* (*brotli_alloc_func)(void* opaque, size_t size);
*/ */
typedef void (*brotli_free_func)(void* opaque, void* address); 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_ */ #endif /* BROTLI_COMMON_TYPES_H_ */