Debian Codegraph @

third-party/simde/arm/neon/fma.h

raw
1 /* SPDX-License-Identifier: MIT
2 *
3 * Permission is hereby granted, free of charge, to any person
4 * obtaining a copy of this software and associated documentation
5 * files (the "Software"), to deal in the Software without
6 * restriction, including without limitation the rights to use, copy,
7 * modify, merge, publish, distribute, sublicense, and/or sell copies
8 * of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Copyright:
24 * 2021 Atharva Nimbalkar <[email protected]>
25 */
26
27 #if !defined(SIMDE_ARM_NEON_FMA_H)
28 #define SIMDE_ARM_NEON_FMA_H
29
30 #include "add.h"
31 #include "mul.h"
32
33 HEDLEY_DIAGNOSTIC_PUSH
34 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
35 SIMDE_BEGIN_DECLS_
36
37 SIMDE_FUNCTION_ATTRIBUTES
38 simde_float32x2_t
39 simde_vfma_f32(simde_float32x2_t a, simde_float32x2_t b, simde_float32x2_t c) {
40 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE) && (defined(__ARM_FEATURE_FMA) && __ARM_FEATURE_FMA)
41 return vfma_f32(a, b, c);
42 #else
43 return simde_vadd_f32(a, simde_vmul_f32(b, c));
44 #endif
45 }
46 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
47 #undef vfma_f32
48 #define vfma_f32(a, b, c) simde_vfma_f32(a, b, c)
49 #endif
50
51 SIMDE_FUNCTION_ATTRIBUTES
52 simde_float64x1_t
53 simde_vfma_f64(simde_float64x1_t a, simde_float64x1_t b, simde_float64x1_t c) {
54 #if defined(SIMDE_ARM_NEON_A64V8_NATIVE) && (defined(__ARM_FEATURE_FMA) && __ARM_FEATURE_FMA)
55 return vfma_f64(a, b, c);
56 #else
57 return simde_vadd_f64(a, simde_vmul_f64(b, c));
58 #endif
59 }
60 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
61 #undef vfma_f64
62 #define vfma_f64(a, b, c) simde_vfma_f64(a, b, c)
63 #endif
64
65 SIMDE_FUNCTION_ATTRIBUTES
66 simde_float32x4_t
67 simde_vfmaq_f32(simde_float32x4_t a, simde_float32x4_t b, simde_float32x4_t c) {
68 #if defined(SIMDE_ARM_NEON_A32V7_NATIVE) && (defined(__ARM_FEATURE_FMA) && __ARM_FEATURE_FMA)
69 return vfmaq_f32(a, b, c);
70 #elif defined(SIMDE_POWER_ALTIVEC_P6_NATIVE)
71 return vec_madd(b, c, a);
72 #elif \
73 defined(SIMDE_X86_FMA_NATIVE)
74 simde_float32x4_private
75 r_,
76 a_ = simde_float32x4_to_private(a),
77 b_ = simde_float32x4_to_private(b),
78 c_ = simde_float32x4_to_private(c);
79
80 #if defined(SIMDE_X86_FMA_NATIVE)
81 r_.m128 = _mm_fmadd_ps(b_.m128, c_.m128, a_.m128);
82 #endif
83
84 return simde_float32x4_from_private(r_);
85 #else
86 return simde_vaddq_f32(a, simde_vmulq_f32(b, c));
87 #endif
88 }
89 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
90 #undef vfmaq_f32
91 #define vfmaq_f32(a, b, c) simde_vfmaq_f32(a, b, c)
92 #endif
93
94 SIMDE_FUNCTION_ATTRIBUTES
95 simde_float64x2_t
96 simde_vfmaq_f64(simde_float64x2_t a, simde_float64x2_t b, simde_float64x2_t c) {
97 #if defined(SIMDE_ARM_NEON_A64V8_NATIVE) && (defined(__ARM_FEATURE_FMA) && __ARM_FEATURE_FMA)
98 return vfmaq_f64(a, b, c);
99 #elif defined(SIMDE_POWER_ALTIVEC_P7_NATIVE) || defined(SIMDE_ZARCH_ZVECTOR_13_NATIVE)
100 return vec_madd(b, c, a);
101 #elif \
102 defined(SIMDE_X86_FMA_NATIVE)
103 simde_float64x2_private
104 r_,
105 a_ = simde_float64x2_to_private(a),
106 b_ = simde_float64x2_to_private(b),
107 c_ = simde_float64x2_to_private(c);
108
109 #if defined(SIMDE_X86_FMA_NATIVE)
110 r_.m128d = _mm_fmadd_pd(b_.m128d, c_.m128d, a_.m128d);
111 #endif
112
113 return simde_float64x2_from_private(r_);
114 #else
115 return simde_vaddq_f64(a, simde_vmulq_f64(b, c));
116 #endif
117 }
118 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
119 #undef vfmaq_f64
120 #define vfmaq_f64(a, b, c) simde_vfmaq_f64(a, b, c)
121 #endif
122
123 SIMDE_END_DECLS_
124 HEDLEY_DIAGNOSTIC_POP
125
126 #endif /* !defined(SIMDE_ARM_NEON_CMLA_H) */