diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d6389b..c0ac8c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.5) project(STREAMVBYTE VERSION "2.0.0") set(STREAMVBYTE_LIB_VERSION "2.0.0" CACHE STRING "streamvbyte library version") @@ -97,11 +97,6 @@ if(MSVC) add_definitions("-D__restrict__=__restrict") endif() -# test for arm -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") - set(BASE_FLAGS ${BASE_FLAGS} "-D__ARM_NEON__") -endif() - set(STREAMVBYTE_SRCS ${PROJECT_SOURCE_DIR}/src/streamvbyte_encode.c ${PROJECT_SOURCE_DIR}/src/streamvbyte_decode.c diff --git a/Makefile b/Makefile index 2f312c9..fcade13 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,8 @@ PROCESSOR:=$(shell uname -m) -ifeq ($(PROCESSOR), aarch64) -# for 64-bit ARM processors (e.g., Linux), they may fail to defined __ARM_NEON__ -CFLAGS = -fPIC -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow -D__ARM_NEON__ -else + CFLAGS = -fPIC -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow -endif LDFLAGS = -shared LIBNAME=libstreamvbyte.so.0.0.1 LNLIBNAME=libstreamvbyte.so diff --git a/src/streamvbyte_decode.c b/src/streamvbyte_decode.c index b99c7e3..1f8c1aa 100644 --- a/src/streamvbyte_decode.c +++ b/src/streamvbyte_decode.c @@ -7,7 +7,7 @@ #pragma clang diagnostic ignored "-Wdeclaration-after-statement" #endif -#ifdef __ARM_NEON__ +#ifdef STREAMVBYTE_IS_ARM64 #include "streamvbyte_arm_decode.c" #endif @@ -76,7 +76,7 @@ size_t streamvbyte_decode(const uint8_t *in, uint32_t *out, uint32_t count) { keyPtr += (count/4) & ~ 7U; count &= 31; } -#elif defined(__ARM_NEON__) +#elif defined(STREAMVBYTE_IS_ARM64) dataPtr = svb_decode_vector(out, keyPtr, dataPtr, count); out += count - (count & 3); keyPtr += count/4; @@ -105,7 +105,7 @@ bool streamvbyte_validate_stream(const uint8_t *in, size_t inCount, const uint8_t *keyPtr = in; uint64_t encodedSize = 0; -#if defined(__ARM_NEON__) +#if defined(STREAMVBYTE_IS_ARM64) encodedSize = svb_validate_vector(&keyPtr, &outCount); #endif diff --git a/src/streamvbyte_encode.c b/src/streamvbyte_encode.c index f1602bd..6e4f8c7 100644 --- a/src/streamvbyte_encode.c +++ b/src/streamvbyte_encode.c @@ -62,7 +62,7 @@ static uint8_t *svb_encode_scalar(const uint32_t *in, } -#ifdef __ARM_NEON__ +#ifdef STREAMVBYTE_IS_ARM64 #include "streamvbyte_arm_encode.c" #endif @@ -120,7 +120,7 @@ size_t streamvbyte_encode(const uint32_t *in, uint32_t count, uint8_t *out) { uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys -#if defined(__ARM_NEON__) +#if defined(STREAMVBYTE_IS_ARM64) uint32_t count_quads = count / 4; count -= 4 * count_quads; diff --git a/src/streamvbyte_isadetection.h b/src/streamvbyte_isadetection.h index aee4c7c..0684df0 100644 --- a/src/streamvbyte_isadetection.h +++ b/src/streamvbyte_isadetection.h @@ -43,7 +43,9 @@ POSSIBILITY OF SUCH DAMAGE. #include #include - +#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) +#define STREAMVBYTE_IS_ARM64 1 +#endif // defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) #if defined(_MSC_VER) /* Microsoft C/C++-compatible compiler */ #include @@ -52,7 +54,7 @@ POSSIBILITY OF SUCH DAMAGE. #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) /* GCC-compatible compiler, targeting x86/x86-64 */ #include -#elif defined(__GNUC__) && defined(__ARM_NEON__) +#elif defined(__GNUC__) && defined(STREAMVBYTE_IS_ARM64) /* GCC-compatible compiler, targeting ARM with NEON */ #include #elif defined(__GNUC__) && defined(__IWMMXT__) @@ -263,9 +265,9 @@ static inline uint32_t streamvbyte_detect_supported_architectures(void) { } #endif -#ifdef __ARM_NEON__ +#ifdef STREAMVBYTE_IS_ARM64 #define STREAMVBYTE_ARM -#endif +#endif // STREAMVBYTE_IS_ARM64 #ifdef STREAMVBYTE_X64 // this is almost standard? diff --git a/tests/unit.c b/tests/unit.c index 30e5f2e..d642c58 100644 --- a/tests/unit.c +++ b/tests/unit.c @@ -2827,7 +2827,7 @@ int main(void) { } else { printf("Code was not vectorized (x64).\n"); } -#elif defined(__ARM_NEON__) +#elif defined(STREAMVBYTE_IS_ARM64) printf("Code was vectorized (ARM NEON).\n"); #else printf("Warning: you tested non-vectorized code.\n");