Skip to content

Commit 0929f1a

Browse files
authored
fix: route avxvnni FMA ops through fma3<avx2> kernels (#1368)
batch<T, avxvnni> derived from avx2, so fnma/fnms fell back to the generic neg(x*y)+z form (vxorpd + vfmadd) instead of the hardware vfnmadd/vfnmsub kernels registered for fma3<avx2>. This bites -march=native on Alder/Meteor Lake and Zen 5, where default_arch resolves to avxvnni. Derive avxvnni from fma3<avx2> instead. fma3<avx2> always derives from avx2 and its kernels are guarded by XSIMD_WITH_FMA3_AVX2, so when FMA is disabled the base is transparent and dispatch falls through to avx2 unchanged. Validated under Intel SDE across avxvnni+FMA (-adl), fma3<avx2> (-hsw), avx2-only (-hsw) and avxvnni-without-FMA (-adl): correct results, full test_batch suite passes, vfnmadd emitted only where FMA is enabled.
1 parent 5d2490f commit 0929f1a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

include/xsimd/types/xsimd_avxvnni_register.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define XSIMD_AVXVNNI_REGISTER_HPP
1414

1515
#include "./xsimd_avx2_register.hpp"
16+
#include "./xsimd_fma3_avx2_register.hpp"
1617

1718
namespace xsimd
1819
{
@@ -21,7 +22,12 @@ namespace xsimd
2122
*
2223
* AVXVNNI instructions
2324
*/
24-
struct avxvnni : avx2
25+
// Derive from fma3<avx2> rather than avx2 so the FMA3 kernels (fnma/fnms ->
26+
// vfnmadd) are in avxvnni's dispatch chain instead of the generic neg(x*y)+z
27+
// fallback. fma3<avx2> always derives from avx2 and its kernels are only
28+
// registered when XSIMD_WITH_FMA3_AVX2, so when FMA is disabled this base is
29+
// transparent (dispatch falls straight through to avx2).
30+
struct avxvnni : fma3<avx2>
2531
{
2632
static constexpr bool supported() noexcept { return XSIMD_WITH_AVXVNNI; }
2733
static constexpr bool available() noexcept { return true; }

0 commit comments

Comments
 (0)