Skip to content

Commit b0687f5

Browse files
committed
Set SIMDJSON_BUILTIN_IMPLEMENTATION to minimum supported
1 parent f5c8aa3 commit b0687f5

File tree

2 files changed

+97
-13
lines changed

2 files changed

+97
-13
lines changed

cmake/simdjson-flags.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,42 @@ else()
9494
target_compile_options(simdjson-internal-flags INTERFACE -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion)
9595
endif()
9696

97+
#
9798
# Optional flags
99+
#
100+
101+
# Implementation selection
98102
option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON)
99103
if(NOT SIMDJSON_IMPLEMENTATION_HASWELL)
104+
message(DEPRECATION "SIMDJSON_IMPLEMENTATION_HASWELL is deprecated. Use SIMDJSON_IMPLEMENTATION=haswell or SIMDJSON_IMPLEMENTATION=-haswell instead.")
100105
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_IMPLEMENTATION_HASWELL=0)
101106
endif()
102107
option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON)
103108
if(NOT SIMDJSON_IMPLEMENTATION_WESTMERE)
109+
message(DEPRECATION "SIMDJSON_IMPLEMENTATION_WESTMERE is deprecated. SIMDJSON_IMPLEMENTATION=-westmere instead.")
104110
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_IMPLEMENTATION_WESTMERE=0)
105111
endif()
106112
option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON)
107113
if(NOT SIMDJSON_IMPLEMENTATION_ARM64)
114+
message(DEPRECATION "SIMDJSON_IMPLEMENTATION_ARM64 is deprecated. Use SIMDJSON_IMPLEMENTATION=-arm64 instead.")
108115
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_IMPLEMENTATION_ARM64=0)
109116
endif()
110117
option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON)
111118
if(NOT SIMDJSON_IMPLEMENTATION_FALLBACK)
119+
message(DEPRECATION "SIMDJSON_IMPLEMENTATION_FALLBACK is deprecated. Use SIMDJSON_IMPLEMENTATION=-fallback instead.")
112120
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_IMPLEMENTATION_FALLBACK=0)
113121
endif()
122+
# e.g. SIMDJSON_IMPLEMENTATION="haswell westmere -fallback"
123+
set(SIMDJSON_IMPLEMENTATION "" CACHE STRING "Implementations to include/exclude: space separated list of architectures (haswell/westmere/arm64/fallback). Prepend with - to force an implementation off (e.g. -haswell). Defaults to compile-time detection.")
124+
foreach(implementation ${SIMDJSON_IMPLEMENTATION})
125+
string(TOUPPER ${implementation} implementation_upper)
126+
if(string(REGEX MATCH "^-(.*)" actual_implementation ${implementation_upper}))
127+
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_IMPLEMENTATION_${actual_implementation} 0)
128+
else()
129+
target_compile_definitions(simdjson-internal-flags INTERFACE SIMDJSON_IMPLEMENTATION_${implementation_upper} 1)
130+
endif()
131+
endforeach(implementation)
132+
114133

115134
option(SIMDJSON_BASH "Allow usage of bash within CMake" ON)
116135

include/simdjson/portability.h

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@ use a 64-bit target such as x64 or 64-bit ARM.")
7070
#define STRINGIFY_IMPLEMENTATION_(a) #a
7171
#define STRINGIFY(a) STRINGIFY_IMPLEMENTATION_(a)
7272
73-
#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK
74-
#define SIMDJSON_IMPLEMENTATION_FALLBACK 1
75-
#endif
76-
77-
#if SIMDJSON_IS_ARM64
78-
#ifndef SIMDJSON_IMPLEMENTATION_ARM64
79-
#define SIMDJSON_IMPLEMENTATION_ARM64 1
80-
#endif
81-
#define SIMDJSON_IMPLEMENTATION_HASWELL 0
82-
#define SIMDJSON_IMPLEMENTATION_WESTMERE 0
83-
#endif // SIMDJSON_IS_ARM64
84-
8573
// Our fast kernels require 64-bit systems.
8674
//
8775
// On 32-bit x86, we lack 64-bit popcnt, lzcnt, blsr instructions.
@@ -91,16 +79,93 @@ use a 64-bit target such as x64 or 64-bit ARM.")
9179
//
9280
// The simdjson users should still have the fallback kernel. It is
9381
// slower, but it should run everywhere.
82+
83+
//
84+
// Enable valid runtime implementations, and select SIMDJSON_BUILTIN_IMPLEMENTATION
85+
//
86+
87+
//
88+
// ARM 64-bit (NEON / Other)
89+
//
90+
#if SIMDJSON_IS_ARM64
91+
// Default ARM64 to on: it could be selected at runtime.
92+
#ifndef SIMDJSON_IMPLEMENTATION_ARM64
93+
#define SIMDJSON_IMPLEMENTATION_ARM64 1
94+
#endif
95+
#if __ARM_NEON
96+
//
97+
// NEON
98+
//
99+
// We're compiled natively for NEON, so arm64 will *always* work (the program is going
100+
// to fail in other ways if it's not run on a machine supporting NEON).
101+
//
102+
// Set builtin to arm64, and leave fallback defaulted to off.
103+
// It can still be enabled with SIMDJSON_IMPLEMENTATION_XXX flags, though it's unclear why one
104+
// would do so).
105+
//
106+
#define SIMDJSON_BUILTIN_IMPLEMENTATION arm64
107+
#endif
108+
#endif // SIMDJSON_IS_ARM64
109+
110+
//
111+
// Intel 64-bit (Haswell / Westmere / Other)
112+
//
94113
#if SIMDJSON_IS_X86_64
114+
115+
// Default Haswell to on: it could be selected at runtime.
95116
#ifndef SIMDJSON_IMPLEMENTATION_HASWELL
96117
#define SIMDJSON_IMPLEMENTATION_HASWELL 1
97118
#endif
119+
120+
#if __AVX2__ && __BMI__ && __PCLMUL__ && __LZCNT__ && SIMDJSON_IMPLEMENTATION_HASWELL
121+
//
122+
// Haswell
123+
//
124+
// We're compiled natively for Haswell, so Haswell will *always* work (more specifically, the
125+
// program is going to fail in other ways if it's not run on a machine supporting AVX2).
126+
//
127+
// Set builtin to haswell, and leave westmere and fallback defaulted to off.
128+
// They can still be enabled with SIMDJSON_IMPLEMENTATION_XXX flags, though it's unclear why one
129+
// would do so).
130+
//
131+
#define SIMDJSON_BUILTIN_IMPLEMENTATION haswell
132+
#else // Haswell
133+
134+
// We're not compiled natively for Haswell. Default Westmere to on: it could be selected at runtime.
98135
#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE
99136
#define SIMDJSON_IMPLEMENTATION_WESTMERE 1
100137
#endif
101-
#define SIMDJSON_IMPLEMENTATION_ARM64 0
138+
#if __SSE4_2__ && __PCLMUL__ && SIMDJSON_IMPLEMENTATION_WESTMERE
139+
//
140+
// Westmere
141+
//
142+
// We're compiled natively for Westmere, so Westmere will *always* work (the program is going
143+
// to fail in other ways if it's not run on a machine supporting SSE4.2).
144+
//
145+
// Set builtin to westmere, and leave fallback defaulted to off.
146+
// It can still be enabled with SIMDJSON_IMPLEMENTATION_XXX flags, though it's unclear why one
147+
// would do so).
148+
//
149+
#define SIMDJSON_BUILTIN_IMPLEMENTATION westmere
150+
#endif // Westmere
151+
#endif // Haswell
102152
#endif // SIMDJSON_IS_X86_64
103153
154+
//
155+
// If no specific builtin architecture was discovered, set builtin to fallback and make sure it's
156+
// enabled.
157+
//
158+
#ifndef SIMDJSON_BUILTIN_IMPLEMENTATION
159+
#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK
160+
#define SIMDJSON_IMPLEMENTATION_FALLBACK 1
161+
#endif
162+
#if SIMDJSON_IMPLEMENTATION_FALLBACK
163+
#define SIMDJSON_BUILTIN_IMPLEMENTATION fallback
164+
#else
165+
#error "fallback architecture is disabled, but is compiled with flags that allow it to run on machines that require fallback."
166+
#endif
167+
#endif // SIMDJSON_BUILTIN_IMPLEMENTATION
168+
104169
// We are going to use runtime dispatch.
105170
#ifdef SIMDJSON_IS_X86_64
106171
#ifdef __clang__

0 commit comments

Comments
 (0)