Skip to content

Commit 3cea665

Browse files
committed
fix: detect GNU inline asm support on clang-cl
1 parent 7a674b9 commit 3cea665

9 files changed

Lines changed: 29 additions & 8 deletions

File tree

include/xsimd/arch/common/xsimd_common_details.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace xsimd
120120
template <class T>
121121
XSIMD_INLINE void reassociation_barrier(T& x, memory_barrier_tag) noexcept
122122
{
123-
#if defined(__GNUC__)
123+
#if XSIMD_WITH_GNU_INLINE_ASM
124124
__asm__ volatile("" : : "r"(&x) : "memory");
125125
#else
126126
(void)x;

include/xsimd/arch/xsimd_neon.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ namespace xsimd
167167
template <class T>
168168
XSIMD_INLINE void reassociation_barrier(T& x, arm_barrier_tag) noexcept
169169
{
170-
#if defined(__GNUC__)
170+
#if XSIMD_WITH_GNU_INLINE_ASM
171171
__asm__ volatile("" : "+w"(x));
172172
#else
173173
detail::reassociation_barrier(x, memory_barrier_tag {});

include/xsimd/arch/xsimd_neon64.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ namespace xsimd
709709
return vcvtnq_s32_f32(self);
710710
}
711711

712-
#if !defined(__GNUC__)
712+
#if !XSIMD_WITH_GNU_INLINE_ASM
713713
template <class A>
714714
XSIMD_INLINE batch<int64_t, A> nearbyint_as_int(batch<double, A> const& self,
715715
requires_arch<neon64>) noexcept

include/xsimd/arch/xsimd_rvv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ namespace xsimd
297297
template <class T>
298298
XSIMD_INLINE void reassociation_barrier(T& x, rvv_barrier_tag) noexcept
299299
{
300-
#if defined(__GNUC__)
300+
#if XSIMD_WITH_GNU_INLINE_ASM
301301
__asm__ volatile("" : "+vr"(x));
302302
#else
303303
detail::reassociation_barrier(x, memory_barrier_tag {});

include/xsimd/arch/xsimd_sse2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace xsimd
4545
template <class T>
4646
XSIMD_INLINE void reassociation_barrier(T& x, x86_barrier_tag) noexcept
4747
{
48-
#if defined(__GNUC__) && XSIMD_TARGET_X86
48+
#if XSIMD_WITH_GNU_INLINE_ASM && XSIMD_TARGET_X86
4949
__asm__ volatile("" : "+x"(x));
5050
#else
5151
detail::reassociation_barrier(x, memory_barrier_tag {});

include/xsimd/arch/xsimd_vsx.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace xsimd
4444
template <class T>
4545
XSIMD_INLINE void reassociation_barrier(T& x, vsx_barrier_tag) noexcept
4646
{
47-
#if defined(__GNUC__)
47+
#if XSIMD_WITH_GNU_INLINE_ASM
4848
__asm__ volatile("" : "+wa"(x));
4949
#else
5050
detail::reassociation_barrier(x, memory_barrier_tag {});

include/xsimd/config/xsimd_config.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@
4444
#define XSIMD_TARGET_X86 0
4545
#endif
4646

47+
/**
48+
* @ingroup xsimd_config_macro
49+
*
50+
* Set to 1 if GNU-style extended inline assembly is available, to 0 otherwise.
51+
*/
52+
/* clang-cl runs in MSVC-compatibility mode and does not define __GNUC__
53+
* by default. Clang only emits __GNUC__ when GNUCVersion != 0:
54+
* https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/InitPreprocessor.cpp
55+
* and GNUCVersion defaults to 0:
56+
* https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/LangOptions.def
57+
* Clang still supports GNU-style extended asm there. */
58+
#if defined(__GNUC__) || defined(__clang__)
59+
#define XSIMD_WITH_GNU_INLINE_ASM 1
60+
#else
61+
#define XSIMD_WITH_GNU_INLINE_ASM 0
62+
#endif
63+
4764
/**
4865
* @ingroup xsimd_config_macro
4966
*

include/xsimd/config/xsimd_cpu_features_x86.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ namespace xsimd
533533
__cpuid(buf, leaf);
534534
std::memcpy(reg.data(), buf, sizeof(buf));
535535

536-
#elif defined(__GNUC__) || defined(__clang__)
536+
#elif XSIMD_WITH_GNU_INLINE_ASM
537537

538538
#if defined(__i386__) && defined(__PIC__)
539539
// %ebx may be the PIC register
@@ -561,7 +561,7 @@ namespace xsimd
561561
#error "_MSC_VER < 1400 is not supported"
562562
#endif
563563

564-
#elif defined(__GNUC__)
564+
#elif XSIMD_WITH_GNU_INLINE_ASM
565565
x86_reg32_t xcr0 = {};
566566
__asm__(
567567
"xorl %%ecx, %%ecx\n"

test/test_arch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ static_assert(xsimd::supported_architectures::contains<xsimd::default_arch>(), "
2525
static_assert(xsimd::all_architectures::contains<xsimd::default_arch>(), "default arch is a valid arch");
2626
#endif
2727

28+
#if defined(__clang__) && defined(_MSC_VER)
29+
static_assert(XSIMD_WITH_GNU_INLINE_ASM, "clang-cl should expose GNU-style inline asm support");
30+
#endif
31+
2832
#if !XSIMD_WITH_SVE
2933
static_assert((std::is_base_of<xsimd::neon64, xsimd::default_arch>::value || !xsimd::neon64::supported()), "on arm, without sve, the best we can do is neon64");
3034
#endif

0 commit comments

Comments
 (0)