Skip to content

Commit 604eb61

Browse files
committed
fix: guard reassociation_barrier entirely by XSIMD_REASSOCIATIVE_MATH
- Wrap the entire reassociation_barrier implementation (including RISC-V scalar overloads) in #if XSIMD_REASSOCIATIVE_MATH so the function is a true no-op when the compiler cannot reassociate floating-point ops. - Remove redundant #elif XSIMD_REASSOCIATIVE_MATH inner guard; the "+m" fallback now applies to all unknown targets within the outer guard. - Guard the RVV batch overload with XSIMD_REASSOCIATIVE_MATH as well. - Update test_exp condition to also match XSIMD_REASSOCIATIVE_MATH so approximate comparison is used whenever reassociation is active.
1 parent 9c7754b commit 604eb61

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

include/xsimd/arch/common/xsimd_common_details.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,19 @@ namespace xsimd
123123
// RISC-V RVV "+vr" (V register; GCC 15+ / Clang 20+)
124124
//
125125
// On unknown targets the "+m" fallback spills; it is
126-
// guarded by XSIMD_REASSOCIATIVE_MATH so it is only
127-
// emitted when the compiler can actually reassociate.
126+
// only emitted when the compiler can actually reassociate.
128127
template <class T>
129128
XSIMD_INLINE void reassociation_barrier(T& x, const char*) noexcept
130129
{
131-
#if XSIMD_WITH_INLINE_ASM && !defined(__EMSCRIPTEN__)
130+
#if XSIMD_REASSOCIATIVE_MATH && XSIMD_WITH_INLINE_ASM && !defined(__EMSCRIPTEN__)
132131
#if XSIMD_WITH_SSE2
133132
__asm__ volatile("" : "+x"(x));
134133
#elif XSIMD_WITH_NEON || XSIMD_WITH_SVE
135134
__asm__ volatile("" : "+w"(x));
136135
#elif XSIMD_WITH_VSX
137136
__asm__ volatile("" : "+wa"(x));
138-
#elif XSIMD_REASSOCIATIVE_MATH
139-
__asm__ volatile("" : "+m"(x));
140137
#else
141-
(void)x;
138+
__asm__ volatile("" : "+m"(x));
142139
#endif
143140
#else
144141
(void)x;
@@ -148,7 +145,7 @@ namespace xsimd
148145
// RISC-V scalar float/double: use F/D registers instead of
149146
// spilling through "+m". These overloads also serve
150147
// emulated batches on RISC-V via the std::array overload.
151-
#if XSIMD_WITH_INLINE_ASM && defined(__riscv)
148+
#if XSIMD_REASSOCIATIVE_MATH && XSIMD_WITH_INLINE_ASM && defined(__riscv)
152149
XSIMD_INLINE void reassociation_barrier(float& x, const char*) noexcept
153150
{
154151
__asm__ volatile("" : "+f"(x));
@@ -169,7 +166,7 @@ namespace xsimd
169166
template <class T, class A>
170167
XSIMD_INLINE void reassociation_barrier(batch<T, A>& b, const char* reason) noexcept
171168
{
172-
#if XSIMD_WITH_RVV && XSIMD_WITH_INLINE_ASM && ((__GNUC__ >= 15) || (__clang_major__ >= 20))
169+
#if XSIMD_REASSOCIATIVE_MATH && XSIMD_WITH_RVV && XSIMD_WITH_INLINE_ASM && ((__GNUC__ >= 15) || (__clang_major__ >= 20))
173170
__asm__ volatile("" : "+vr"(b.data.value.value));
174171
(void)reason;
175172
#else

test/test_xsimd_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ struct xsimd_api_float_types_functions
591591
void test_exp()
592592
{
593593
value_type val(2);
594-
#ifdef __FAST_MATH__
594+
#if defined(__FAST_MATH__) || XSIMD_REASSOCIATIVE_MATH
595595
CHECK_EQ(extract(xsimd::exp(T(val))), doctest::Approx(std::exp(val)));
596596
#else
597597
CHECK_EQ(extract(xsimd::exp(T(val))), std::exp(val));

0 commit comments

Comments
 (0)