Skip to content

Commit f92d002

Browse files
kouclaude
andauthored
Allow setting XSIMD_WITH_SSE3, SSSE3, SSE4_1 and SSE4_2 manually with MSVC (#1430)
MSVC doesn't define __SSE3__, __SSSE3__, __SSE4_1__ or __SSE4_2__ even with /arch:SSE4.2. So users need to define these reserved identifiers to enable these instruction sets with MSVC since #881. But defining them may break other libraries. For example, simdjson >= 5 uses GCC builtins such as __builtin_ctz when __SSE2__ is defined: apache/arrow#51690 This allows users to set XSIMD_WITH_SSE3, XSIMD_WITH_SSSE3, XSIMD_WITH_SSE4_1 and XSIMD_WITH_SSE4_2 manually only with MSVC. For example, users can enable SSE4.2 with MSVC by -DXSIMD_WITH_SSE4_2=1. Lower instruction sets are enabled automatically by the existing MSVC workaround. This also allows selecting SSE3 or SSSE3 with MSVC requested in #878. Other compilers including clang-cl define these macros based on compiler flags and require the corresponding compiler flags to use intrinsics. So setting them manually with other compilers is reported as an error. Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 514204f commit f92d002

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

‎include/xsimd/config/xsimd_config.hpp‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,15 @@
111111
* @ingroup xsimd_config_macro
112112
*
113113
* Set to 1 if SSE3 is available at compile-time, to 0 otherwise.
114+
*
115+
* It can be set manually only with MSVC because MSVC doesn't define
116+
* __SSE3__ even when SSE3 is enabled.
114117
*/
115-
#ifdef __SSE3__
118+
#ifdef XSIMD_WITH_SSE3
119+
#if !defined(_MSC_VER) || defined(__clang__)
120+
#error "XSIMD_WITH_SSE3 can be set manually only with MSVC"
121+
#endif
122+
#elif defined(__SSE3__)
116123
#define XSIMD_WITH_SSE3 1
117124
#else
118125
#define XSIMD_WITH_SSE3 0
@@ -122,8 +129,15 @@
122129
* @ingroup xsimd_config_macro
123130
*
124131
* Set to 1 if SSSE3 is available at compile-time, to 0 otherwise.
132+
*
133+
* It can be set manually only with MSVC because MSVC doesn't define
134+
* __SSSE3__ even when SSSE3 is enabled.
125135
*/
126-
#ifdef __SSSE3__
136+
#ifdef XSIMD_WITH_SSSE3
137+
#if !defined(_MSC_VER) || defined(__clang__)
138+
#error "XSIMD_WITH_SSSE3 can be set manually only with MSVC"
139+
#endif
140+
#elif defined(__SSSE3__)
127141
#define XSIMD_WITH_SSSE3 1
128142
#else
129143
#define XSIMD_WITH_SSSE3 0
@@ -133,8 +147,15 @@
133147
* @ingroup xsimd_config_macro
134148
*
135149
* Set to 1 if SSE4.1 is available at compile-time, to 0 otherwise.
150+
*
151+
* It can be set manually only with MSVC because MSVC doesn't define
152+
* __SSE4_1__ even when SSE4.1 is enabled.
136153
*/
137-
#ifdef __SSE4_1__
154+
#ifdef XSIMD_WITH_SSE4_1
155+
#if !defined(_MSC_VER) || defined(__clang__)
156+
#error "XSIMD_WITH_SSE4_1 can be set manually only with MSVC"
157+
#endif
158+
#elif defined(__SSE4_1__)
138159
#define XSIMD_WITH_SSE4_1 1
139160
#else
140161
#define XSIMD_WITH_SSE4_1 0
@@ -144,8 +165,15 @@
144165
* @ingroup xsimd_config_macro
145166
*
146167
* Set to 1 if SSE4.2 is available at compile-time, to 0 otherwise.
168+
*
169+
* It can be set manually only with MSVC because MSVC doesn't define
170+
* __SSE4_2__ even when SSE4.2 is enabled.
147171
*/
148-
#ifdef __SSE4_2__
172+
#ifdef XSIMD_WITH_SSE4_2
173+
#if !defined(_MSC_VER) || defined(__clang__)
174+
#error "XSIMD_WITH_SSE4_2 can be set manually only with MSVC"
175+
#endif
176+
#elif defined(__SSE4_2__)
149177
#define XSIMD_WITH_SSE4_2 1
150178
#else
151179
#define XSIMD_WITH_SSE4_2 0

0 commit comments

Comments
 (0)