@@ -70,18 +70,6 @@ use a 64-bit target such as x64 or 64-bit ARM.")
70
70
#define STRINGIFY_IMPLEMENTATION_(a) #a
71
71
#define STRINGIFY(a) STRINGIFY_IMPLEMENTATION_(a)
72
72
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
-
85
73
// Our fast kernels require 64-bit systems.
86
74
//
87
75
// 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.")
91
79
//
92
80
// The simdjson users should still have the fallback kernel. It is
93
81
// 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
+ //
94
113
#if SIMDJSON_IS_X86_64
114
+
115
+ // Default Haswell to on: it could be selected at runtime.
95
116
#ifndef SIMDJSON_IMPLEMENTATION_HASWELL
96
117
#define SIMDJSON_IMPLEMENTATION_HASWELL 1
97
118
#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.
98
135
#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE
99
136
#define SIMDJSON_IMPLEMENTATION_WESTMERE 1
100
137
#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
102
152
#endif // SIMDJSON_IS_X86_64
103
153
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
+
104
169
// We are going to use runtime dispatch.
105
170
#ifdef SIMDJSON_IS_X86_64
106
171
#ifdef __clang__
0 commit comments