Skip to content

Commit 48a216d

Browse files
authored
simpler ARM detection (#75)
1 parent 383c00d commit 48a216d

File tree

6 files changed

+14
-21
lines changed

6 files changed

+14
-21
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.3)
1+
cmake_minimum_required(VERSION 3.5)
22
project(STREAMVBYTE VERSION "2.0.0")
33

44
set(STREAMVBYTE_LIB_VERSION "2.0.0" CACHE STRING "streamvbyte library version")
@@ -97,11 +97,6 @@ if(MSVC)
9797
add_definitions("-D__restrict__=__restrict")
9898
endif()
9999

100-
# test for arm
101-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
102-
set(BASE_FLAGS ${BASE_FLAGS} "-D__ARM_NEON__")
103-
endif()
104-
105100
set(STREAMVBYTE_SRCS
106101
${PROJECT_SOURCE_DIR}/src/streamvbyte_encode.c
107102
${PROJECT_SOURCE_DIR}/src/streamvbyte_decode.c

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55

66
PROCESSOR:=$(shell uname -m)
77

8-
ifeq ($(PROCESSOR), aarch64)
9-
# for 64-bit ARM processors (e.g., Linux), they may fail to defined __ARM_NEON__
10-
CFLAGS = -fPIC -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow -D__ARM_NEON__
11-
else
8+
129
CFLAGS = -fPIC -std=c99 -O3 -Wall -Wextra -pedantic -Wshadow
13-
endif
1410
LDFLAGS = -shared
1511
LIBNAME=libstreamvbyte.so.0.0.1
1612
LNLIBNAME=libstreamvbyte.so

src/streamvbyte_decode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#pragma clang diagnostic ignored "-Wdeclaration-after-statement"
88
#endif
99

10-
#ifdef __ARM_NEON__
10+
#ifdef STREAMVBYTE_IS_ARM64
1111
#include "streamvbyte_arm_decode.c"
1212
#endif
1313

@@ -76,7 +76,7 @@ size_t streamvbyte_decode(const uint8_t *in, uint32_t *out, uint32_t count) {
7676
keyPtr += (count/4) & ~ 7U;
7777
count &= 31;
7878
}
79-
#elif defined(__ARM_NEON__)
79+
#elif defined(STREAMVBYTE_IS_ARM64)
8080
dataPtr = svb_decode_vector(out, keyPtr, dataPtr, count);
8181
out += count - (count & 3);
8282
keyPtr += count/4;
@@ -105,7 +105,7 @@ bool streamvbyte_validate_stream(const uint8_t *in, size_t inCount,
105105
const uint8_t *keyPtr = in;
106106
uint64_t encodedSize = 0;
107107

108-
#if defined(__ARM_NEON__)
108+
#if defined(STREAMVBYTE_IS_ARM64)
109109
encodedSize = svb_validate_vector(&keyPtr, &outCount);
110110
#endif
111111

src/streamvbyte_encode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static uint8_t *svb_encode_scalar(const uint32_t *in,
6262
}
6363

6464

65-
#ifdef __ARM_NEON__
65+
#ifdef STREAMVBYTE_IS_ARM64
6666
#include "streamvbyte_arm_encode.c"
6767
#endif
6868

@@ -120,7 +120,7 @@ size_t streamvbyte_encode(const uint32_t *in, uint32_t count, uint8_t *out) {
120120
uint32_t keyLen = (count + 3) / 4; // 2-bits rounded to full byte
121121
uint8_t *dataPtr = keyPtr + keyLen; // variable byte data after all keys
122122

123-
#if defined(__ARM_NEON__)
123+
#if defined(STREAMVBYTE_IS_ARM64)
124124

125125
uint32_t count_quads = count / 4;
126126
count -= 4 * count_quads;

src/streamvbyte_isadetection.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ POSSIBILITY OF SUCH DAMAGE.
4343
#include <stdbool.h>
4444
#include <stdlib.h>
4545

46-
46+
#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
47+
#define STREAMVBYTE_IS_ARM64 1
48+
#endif // defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
4749
#if defined(_MSC_VER)
4850
/* Microsoft C/C++-compatible compiler */
4951
#include <intrin.h>
@@ -52,7 +54,7 @@ POSSIBILITY OF SUCH DAMAGE.
5254
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
5355
/* GCC-compatible compiler, targeting x86/x86-64 */
5456
#include <x86intrin.h>
55-
#elif defined(__GNUC__) && defined(__ARM_NEON__)
57+
#elif defined(__GNUC__) && defined(STREAMVBYTE_IS_ARM64)
5658
/* GCC-compatible compiler, targeting ARM with NEON */
5759
#include <arm_neon.h>
5860
#elif defined(__GNUC__) && defined(__IWMMXT__)
@@ -263,9 +265,9 @@ static inline uint32_t streamvbyte_detect_supported_architectures(void) {
263265
}
264266
#endif
265267

266-
#ifdef __ARM_NEON__
268+
#ifdef STREAMVBYTE_IS_ARM64
267269
#define STREAMVBYTE_ARM
268-
#endif
270+
#endif // STREAMVBYTE_IS_ARM64
269271

270272
#ifdef STREAMVBYTE_X64
271273
// this is almost standard?

tests/unit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,7 @@ int main(void) {
28272827
} else {
28282828
printf("Code was not vectorized (x64).\n");
28292829
}
2830-
#elif defined(__ARM_NEON__)
2830+
#elif defined(STREAMVBYTE_IS_ARM64)
28312831
printf("Code was vectorized (ARM NEON).\n");
28322832
#else
28332833
printf("Warning: you tested non-vectorized code.\n");

0 commit comments

Comments
 (0)