diff --git a/libsrc/core/simd_generic.hpp b/libsrc/core/simd_generic.hpp index e6fdb68b..5186784b 100644 --- a/libsrc/core/simd_generic.hpp +++ b/libsrc/core/simd_generic.hpp @@ -726,6 +726,57 @@ namespace ngcore } } + // TODO: specialize for AVX, ... + template + NETGEN_INLINE auto SwapPairs (SIMD a) + { + if constexpr(N==1) { + // static_assert(false); + return a; + } + else if constexpr(N==2) { + return SIMD (a.Hi(), a.Lo()); + } + else { + return SIMD (SwapPairs(a.Lo()), SwapPairs(a.Hi())); + } + } + + + template + NETGEN_INLINE auto HSum128 (SIMD a) + { + if constexpr(N==1) { + // static_assert(false); + return a; + } + else if constexpr(N==2) { + return a; + } + else { + return HSum128(a.Lo()) + HSum128(a.Hi()); + } + } + + + // TODO: specialize for AVX, ... + // a*b+-c (even: -, odd: +) + template + NETGEN_INLINE auto FMAddSub (SIMD a, SIMD b, SIMD c) + { + if constexpr(N==1) { + // static_assert(false); + return a*b-c; + } + else if constexpr(N==2) { + return SIMD (a.Lo()*b.Lo()-c.Lo(), + a.Hi()*b.Hi()+c.Hi()); + } + else { + return SIMD (FMAddSub(a.Lo(), b.Lo(), c.Lo()), + FMAddSub(a.Hi(), b.Hi(), c.Hi())); + } + } }