aboutsummaryrefslogtreecommitdiff
path: root/c/common/platform.h
diff options
context:
space:
mode:
authorBrotli <no-reply@google.com>2024-05-30 09:50:58 -0700
committerCopybara-Service <copybara-worker@google.com>2024-05-30 09:51:43 -0700
commitfe754f3459f4fd60d41aae7e87b5053b2ab3a7a3 (patch)
tree6fb83737ed90ccb3e93425075364aa2dc6686e85 /c/common/platform.h
parent8a626fd486b5fbad245aec29e4e436eeb16041b3 (diff)
downloadbrotli-fe754f3459f4fd60d41aae7e87b5053b2ab3a7a3.zip
brotli-fe754f3459f4fd60d41aae7e87b5053b2ab3a7a3.tar.gz
brotli-fe754f3459f4fd60d41aae7e87b5053b2ab3a7a3.tar.bz2
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: 638686412
Diffstat (limited to 'c/common/platform.h')
-rw-r--r--c/common/platform.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/c/common/platform.h b/c/common/platform.h
index c18ff02..713119e 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,11 +494,29 @@ 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);
BROTLI_UNUSED(&BrotliUnalignedRead32);
BROTLI_UNUSED(&BrotliUnalignedRead64);
+ BROTLI_UNUSED(&BrotliUnalignedReadSizeT);
BROTLI_UNUSED(&BrotliUnalignedWrite64);
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE);
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
@@ -516,6 +539,9 @@ BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
BROTLI_UNUSED(&brotli_max_uint8_t);
BROTLI_UNUSED(&BrotliDefaultAllocFunc);
BROTLI_UNUSED(&BrotliDefaultFreeFunc);
+ BROTLI_UNUSED(&BrotliRotateRight16);
+ BROTLI_UNUSED(&BrotliRotateRight32);
+ BROTLI_UNUSED(&BrotliRotateRight64);
#if BROTLI_ENABLE_DUMP
BROTLI_UNUSED(&BrotliDump);
#endif
@@ -534,6 +560,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_ */