From bb809ac908a4b42772eaf4f5e9fb66ca7886a6c9 Mon Sep 17 00:00:00 2001 From: Brotli Date: Wed, 8 May 2024 17:59:09 -0700 Subject: Use a hash table header and SIMD to speed up hash table operations (similar to [Swiss Tables](https://abseil.io/about/design/swisstables)). PiperOrigin-RevId: 631982664 --- c/common/platform.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'c/common') diff --git a/c/common/platform.h b/c/common/platform.h index c18ff02..7965fea 100644 --- a/c/common/platform.h +++ b/c/common/platform.h @@ -282,6 +282,11 @@ static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) { memcpy(&t, p, sizeof t); return t; } +static BROTLI_INLINE size_t BrotliUnalignedReadSizeT(const void* p) { + size_t t; + memcpy(&t, p, sizeof t); + return t; +} static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { memcpy(p, &v, sizeof v); } @@ -489,6 +494,23 @@ BROTLI_COMMON_API void* BrotliDefaultAllocFunc(void* opaque, size_t size); /* Default brotli_free_func */ BROTLI_COMMON_API void BrotliDefaultFreeFunc(void* opaque, void* address); +/* Circular logical rotates. */ +static BROTLI_INLINE uint16_t BrotliRotateRight16(uint16_t const value, + size_t count) { + count &= 0x0F; /* for fickle pattern recognition */ + return (value >> count) | (uint16_t)(value << ((0U - count) & 0x0F)); +} +static BROTLI_INLINE uint32_t BrotliRotateRight32(uint32_t const value, + size_t count) { + count &= 0x1F; /* for fickle pattern recognition */ + return (value >> count) | (uint32_t)(value << ((0U - count) & 0x1F)); +} +static BROTLI_INLINE uint64_t BrotliRotateRight64(uint64_t const value, + size_t count) { + count &= 0x3F; /* for fickle pattern recognition */ + return (value >> count) | (uint64_t)(value << ((0U - count) & 0x3F)); +} + BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) { BROTLI_UNUSED(&BrotliSuppressUnusedFunctions); BROTLI_UNUSED(&BrotliUnalignedRead16); @@ -534,6 +556,13 @@ BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) { # define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */ # define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */ #endif + +/* The SIMD matchers are only faster at certain quality levels. */ +#if defined(_M_X64) && defined(BROTLI_TZCNT64) +#define BROTLI_MAX_SIMD_QUALITY 7 +#elif defined(BROTLI_TZCNT64) +#define BROTLI_MAX_SIMD_QUALITY 6 +#endif } #endif /* BROTLI_COMMON_PLATFORM_H_ */ -- cgit v1.1