From 308d1fc0841b890fc0b1870dd31ad1a2c9056923 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 16 Dec 2013 16:21:54 +0100 Subject: [PATCH] Checks for Intel CRC32 instruction for the assembler. In OpenBSD 5.4, AS is old 2.15 and it's not supported. --- configure.ac | 17 +++++++++++++++++ mingw.h | 7 +++++++ murmur3.c | 24 ++++++++++++------------ speed.c | 2 +- spooky2.c | 12 ++++++------ util.c | 13 ++++++------- 6 files changed, 49 insertions(+), 26 deletions(-) diff --git a/configure.ac b/configure.ac index 2060c82a..da308c15 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,23 @@ dnl Checks for compiler AC_CHECK_CC_OPT([-Wall], CFLAGS="$CFLAGS -Wall", []) AC_CHECK_CC_OPT([-Wextra], CFLAGS="$CFLAGS -Wextra", []) +dnl Checks for AS supporting the CRC instruction. In OpenBSD 5.4 it's not. +AC_MSG_CHECKING([for crc32b]) +asmcrc=no +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#if defined(__i386__) || defined(__x86_64__) + unsigned f(unsigned crc, unsigned char b) + { + asm volatile ("crc32b %1, %0\n" : "+r" (crc) : "rm" (b)); + return crc; + } +#else +#error not x86 +#endif +]])], +[AC_DEFINE([HAVE_CRC32B], [1], [Define if statvfs exists.]) asmcrc=yes]) +AC_MSG_RESULT([$asmcrc]) + dnl Checks for test environment AS_CASE([$host], [*-*-mingw*], [TESTENV="$WINE"], diff --git a/mingw.h b/mingw.h index 0bc79246..3ff246c8 100644 --- a/mingw.h +++ b/mingw.h @@ -22,6 +22,13 @@ #include +/** + * Assume to always have CRC32B if running in x86 + */ +#if defined(__i386__) || defined(__x86_64__) +#define HAVE_CRC32B 1 +#endif + /** * Redefines PATH_MAX to allow very long paths. */ diff --git a/murmur3.c b/murmur3.c index 58bfccb9..6bbc03d2 100644 --- a/murmur3.c +++ b/murmur3.c @@ -88,10 +88,10 @@ void MurmurHash3_x86_128(const void* key, unsigned len, const uint8_t* seed, voi uint32_t h4 = ((uint32_t*)seed)[3]; #if WORDS_BIGENDIAN - h1 = swap32(h1); - h2 = swap32(h2); - h3 = swap32(h3); - h4 = swap32(h4); + h1 = util_swap32(h1); + h2 = util_swap32(h2); + h3 = util_swap32(h3); + h4 = util_swap32(h4); #endif blocks = (const uint32_t*)data; @@ -105,10 +105,10 @@ void MurmurHash3_x86_128(const void* key, unsigned len, const uint8_t* seed, voi uint32_t k4 = blocks[3]; #if WORDS_BIGENDIAN - k1 = swap32(k1); - k2 = swap32(k2); - k3 = swap32(k3); - k4 = swap32(k4); + k1 = util_swap32(k1); + k2 = util_swap32(k2); + k3 = util_swap32(k3); + k4 = util_swap32(k4); #endif k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1; @@ -178,10 +178,10 @@ void MurmurHash3_x86_128(const void* key, unsigned len, const uint8_t* seed, voi h2 += h1; h3 += h1; h4 += h1; #if WORDS_BIGENDIAN - h1 = swap32(h1); - h2 = swap32(h2); - h3 = swap32(h3); - h4 = swap32(h4); + h1 = util_swap32(h1); + h2 = util_swap32(h2); + h3 = util_swap32(h3); + h4 = util_swap32(h4); #endif ((uint32_t*)out)[0] = h1; diff --git a/speed.c b/speed.c index 5f42dcee..290bc7d9 100644 --- a/speed.c +++ b/speed.c @@ -178,7 +178,7 @@ void speed(void) printf("%8s", "intel"); fflush(stdout); -#if defined(__i386__) || defined(__x86_64__) +#if HAVE_CRC32B if (cpu_has_sse42()) { SPEED_START { for(j=0;j -#define swap32(x) bswap_32(x) -#define swap64(x) bswap_64(x) +#define util_swap32(x) bswap_32(x) +#define util_swap64(x) bswap_64(x) #else -static inline uint32_t swap32(uint32_t v) +static inline uint32_t util_swap32(uint32_t v) { return (rotl32(v, 8) & 0x00ff00ff) | (rotl32(v, 24) & 0xff00ff00); } -static inline uint64_t swap64(uint64_t v) +static inline uint64_t util_swap64(uint64_t v) { return (rotl64(v, 8) & 0x000000ff000000ffLLU) | (rotl64(v, 24) & 0x0000ff000000ff00LLU)