aboutsummaryrefslogtreecommitdiff
path: root/c/common
diff options
context:
space:
mode:
authorClinton Ingram <clinton.ingram@outlook.com>2020-03-19 03:57:56 -0700
committerGitHub <noreply@github.com>2020-03-19 11:57:56 +0100
commit924b2b2b9dc54005edbcd85a1b872330948cdd9e (patch)
treebe1ecf9203013101199ed44de74f38ee36f2153a /c/common
parent0503d8b7668cdf38092a249684ba5dc13f02a359 (diff)
downloadbrotli-924b2b2b9dc54005edbcd85a1b872330948cdd9e.zip
brotli-924b2b2b9dc54005edbcd85a1b872330948cdd9e.tar.gz
brotli-924b2b2b9dc54005edbcd85a1b872330948cdd9e.tar.bz2
Move TZCNT and BSR intrinsics to platform.h, add MSVC versions (#636)
Diffstat (limited to 'c/common')
-rwxr-xr-xc/common/platform.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/c/common/platform.h b/c/common/platform.h
index 2633e04..ca79359 100755
--- a/c/common/platform.h
+++ b/c/common/platform.h
@@ -41,6 +41,10 @@
#define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
#endif
+#if BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+#include <intrin.h>
+#endif
+
#if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
#include <assert.h>
#include <stdio.h>
@@ -522,6 +526,36 @@ BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t)
(A)[(J)] = __brotli_swap_tmp; \
}
+#if BROTLI_64_BITS
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_ctzll, 3, 4, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
+#define BROTLI_TZCNT64 __builtin_ctzll
+#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+#if defined(BROTLI_TARGET_X64)
+#define BROTLI_TZCNT64 _tzcnt_u64
+#else /* BROTLI_TARGET_X64 */
+static BROTLI_INLINE uint32_t BrotliBsf64Msvc(uint64_t x) {
+ uint32_t lsb;
+ _BitScanForward64(&lsb, x);
+ return lsb;
+}
+#define BROTLI_TZCNT64 BrotliBsf64Msvc
+#endif /* BROTLI_TARGET_X64 */
+#endif /* __builtin_ctzll */
+#endif /* BROTLI_64_BITS */
+
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
+#define BROTLI_BSR32(x) (31u ^ (uint32_t)__builtin_clz(x))
+#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+static BROTLI_INLINE uint32_t BrotliBsr32Msvc(uint32_t x) {
+ uint32_t msb;
+ _BitScanReverse(&msb, x);
+ return msb;
+}
+#define BROTLI_BSR32 BrotliBsr32Msvc
+#endif /* __builtin_clz */
+
/* Default brotli_alloc_func */
static void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
BROTLI_UNUSED(opaque);