Argon 0.1.0
Loading...
Searching...
No Matches
simde_fused.hpp
Go to the documentation of this file.
1#pragma once
7
9
10#include <cmath>
11#include <cstddef>
12#include <cstring>
13
14namespace neon {
15namespace detail {
17template <typename V>
18[[gnu::always_inline]] inline V fused_lanes(V a, V b, V c, float sign) {
19 constexpr size_t N = sizeof(V) / sizeof(float);
20 float la[N], lb[N], lc[N];
21 std::memcpy(la, &a, sizeof(V));
22 std::memcpy(lb, &b, sizeof(V));
23 std::memcpy(lc, &c, sizeof(V));
24 for (size_t i = 0; i < N; ++i)
25 la[i] = std::fma(sign * lb[i], lc[i], la[i]);
26 V r;
27 std::memcpy(&r, la, sizeof(V));
28 return r;
29}
30} // namespace detail
31
32// clang-format off
34[[gnu::always_inline]] inline float32x2_t multiply_add_fused(float32x2_t a, float32x2_t b, float32x2_t c) { return detail::fused_lanes(a, b, c, 1.0f); }
36[[gnu::always_inline]] inline float32x2_t multiply_subtract_fused(float32x2_t a, float32x2_t b, float32x2_t c) { return detail::fused_lanes(a, b, c, -1.0f); }
38[[gnu::always_inline]] inline float32x4_t multiply_add_fused(float32x4_t a, float32x4_t b, float32x4_t c) { return detail::fused_lanes(a, b, c, 1.0f); }
40[[gnu::always_inline]] inline float32x4_t multiply_subtract_fused(float32x4_t a, float32x4_t b, float32x4_t c) { return detail::fused_lanes(a, b, c, -1.0f); }
42[[gnu::always_inline]] inline float32x2_t multiply_add_fused(float32x2_t a, float32x2_t b, float32_t c) { return multiply_add_fused(a, b, vdup_n_f32(c)); }
44[[gnu::always_inline]] inline float32x2_t multiply_subtract_fused(float32x2_t a, float32x2_t b, float32_t c) { return multiply_subtract_fused(a, b, vdup_n_f32(c)); }
46[[gnu::always_inline]] inline float32x4_t multiply_add_fused(float32x4_t a, float32x4_t b, float32_t c) { return multiply_add_fused(a, b, vdupq_n_f32(c)); }
48[[gnu::always_inline]] inline float32x4_t multiply_subtract_fused(float32x4_t a, float32x4_t b, float32_t c) { return multiply_subtract_fused(a, b, vdupq_n_f32(c)); }
49// clang-format on
50} // namespace neon
V fused_lanes(V a, V b, V c, float sign)
a + sign * (b * c) per lane, one rounding; sign is +1 or -1 (negating b * c is exact).
Definition simde_fused.hpp:18
float32x2_t multiply_subtract_fused(float32x2_t a, float32x2_t b, float32x2_t c)
Fused a - (b * c), one rounding.
Definition simde_fused.hpp:36
float32x2_t multiply_add_fused(float32x2_t a, float32x2_t b, float32x2_t c)
Fused a + (b * c), one rounding.
Definition simde_fused.hpp:34
SIMDe's NEON implementation (x86 and other non-Arm hosts) under the NEON intrinsic names.