Debian Codegraph @

third-party/simde/arm/neon/dot.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 * 2020 Evan Nemerson <[email protected]>
25 * 2020 Sean Maher <[email protected]> (Copyright owned by Google, LLC)
26 */
27
28 #if !defined(SIMDE_ARM_NEON_DOT_H)
29 #define SIMDE_ARM_NEON_DOT_H
30
31 #include "types.h"
32
33 #include "add.h"
34 #include "combine.h"
35 #include "dup_n.h"
36 #include "get_low.h"
37 #include "get_high.h"
38 #include "paddl.h"
39 #include "movn.h"
40 #include "mull.h"
41
42 HEDLEY_DIAGNOSTIC_PUSH
43 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
44 SIMDE_BEGIN_DECLS_
45
46 SIMDE_FUNCTION_ATTRIBUTES
47 simde_int32x2_t
48 simde_vdot_s32(simde_int32x2_t r, simde_int8x8_t a, simde_int8x8_t b) {
49 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(__ARM_FEATURE_DOTPROD)
50 return vdot_s32(r, a, b);
51 #elif defined(SIMDE_ARM_NEON_A32V7_NATIVE)
52 return simde_vadd_s32(r, simde_vmovn_s64(simde_vpaddlq_s32(simde_vpaddlq_s16(simde_vmull_s8(a, b)))));
53 #else
54 simde_int32x2_private r_;
55 simde_int8x8_private
56 a_ = simde_int8x8_to_private(a),
57 b_ = simde_int8x8_to_private(b);
58 for (int i = 0 ; i < 2 ; i++) {
59 int32_t acc = 0;
60 SIMDE_VECTORIZE_REDUCTION(+:acc)
61 for (int j = 0 ; j < 4 ; j++) {
62 const int idx = j + (i << 2);
63 acc += HEDLEY_STATIC_CAST(int32_t, a_.values[idx]) * HEDLEY_STATIC_CAST(int32_t, b_.values[idx]);
64 }
65 r_.values[i] = acc;
66 }
67 return simde_vadd_s32(r, simde_int32x2_from_private(r_));
68 #endif
69 }
70 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES) || (defined(SIMDE_ENABLE_NATIVE_ALIASES) && !defined(__ARM_FEATURE_DOTPROD))
71 #undef vdot_s32
72 #define vdot_s32(r, a, b) simde_vdot_s32((r), (a), (b))
73 #endif
74
75 SIMDE_FUNCTION_ATTRIBUTES
76 simde_uint32x2_t
77 simde_vdot_u32(simde_uint32x2_t r, simde_uint8x8_t a, simde_uint8x8_t b) {
78 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(__ARM_FEATURE_DOTPROD)
79 return vdot_u32(r, a, b);
80 #elif defined(SIMDE_ARM_NEON_A32V7_NATIVE)
81 return simde_vadd_u32(r, simde_vmovn_u64(simde_vpaddlq_u32(simde_vpaddlq_u16(simde_vmull_u8(a, b)))));
82 #else
83 simde_uint32x2_private r_;
84 simde_uint8x8_private
85 a_ = simde_uint8x8_to_private(a),
86 b_ = simde_uint8x8_to_private(b);
87
88 for (int i = 0 ; i < 2 ; i++) {
89 uint32_t acc = 0;
90 SIMDE_VECTORIZE_REDUCTION(+:acc)
91 for (int j = 0 ; j < 4 ; j++) {
92 const int idx = j + (i << 2);
93 acc += HEDLEY_STATIC_CAST(uint32_t, a_.values[idx]) * HEDLEY_STATIC_CAST(uint32_t, b_.values[idx]);
94 }
95 r_.values[i] = acc;
96 }
97 return simde_vadd_u32(r, simde_uint32x2_from_private(r_));
98 #endif
99 }
100 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES) || (defined(SIMDE_ENABLE_NATIVE_ALIASES) && !defined(__ARM_FEATURE_DOTPROD))
101 #undef vdot_u32
102 #define vdot_u32(r, a, b) simde_vdot_u32((r), (a), (b))
103 #endif
104
105 SIMDE_FUNCTION_ATTRIBUTES
106 simde_int32x4_t
107 simde_vdotq_s32(simde_int32x4_t r, simde_int8x16_t a, simde_int8x16_t b) {
108 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(__ARM_FEATURE_DOTPROD)
109 return vdotq_s32(r, a, b);
110 #elif defined(SIMDE_ARM_NEON_A32V7_NATIVE)
111 return simde_vaddq_s32(r,
112 simde_vcombine_s32(simde_vmovn_s64(simde_vpaddlq_s32(simde_vpaddlq_s16(simde_vmull_s8(simde_vget_low_s8(a), simde_vget_low_s8(b))))),
113 simde_vmovn_s64(simde_vpaddlq_s32(simde_vpaddlq_s16(simde_vmull_s8(simde_vget_high_s8(a), simde_vget_high_s8(b)))))));
114 #else
115 simde_int32x4_private r_;
116 simde_int8x16_private
117 a_ = simde_int8x16_to_private(a),
118 b_ = simde_int8x16_to_private(b);
119 for (int i = 0 ; i < 4 ; i++) {
120 int32_t acc = 0;
121 SIMDE_VECTORIZE_REDUCTION(+:acc)
122 for (int j = 0 ; j < 4 ; j++) {
123 const int idx = j + (i << 2);
124 acc += HEDLEY_STATIC_CAST(int32_t, a_.values[idx]) * HEDLEY_STATIC_CAST(int32_t, b_.values[idx]);
125 }
126 r_.values[i] = acc;
127 }
128 return simde_vaddq_s32(r, simde_int32x4_from_private(r_));
129 #endif
130 }
131 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES) || (defined(SIMDE_ENABLE_NATIVE_ALIASES) && !defined(__ARM_FEATURE_DOTPROD))
132 #undef vdotq_s32
133 #define vdotq_s32(r, a, b) simde_vdotq_s32((r), (a), (b))
134 #endif
135
136 SIMDE_FUNCTION_ATTRIBUTES
137 simde_uint32x4_t
138 simde_vdotq_u32(simde_uint32x4_t r, simde_uint8x16_t a, simde_uint8x16_t b) {
139 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE) && defined(__ARM_FEATURE_DOTPROD)
140 return vdotq_u32(r, a, b);
141 #elif defined(SIMDE_ARM_NEON_A32V7_NATIVE)
142 return simde_vaddq_u32(r,
143 simde_vcombine_u32(simde_vmovn_u64(simde_vpaddlq_u32(simde_vpaddlq_u16(simde_vmull_u8(simde_vget_low_u8(a), simde_vget_low_u8(b))))),
144 simde_vmovn_u64(simde_vpaddlq_u32(simde_vpaddlq_u16(simde_vmull_u8(simde_vget_high_u8(a), simde_vget_high_u8(b)))))));
145 #else
146 simde_uint32x4_private r_;
147 simde_uint8x16_private
148 a_ = simde_uint8x16_to_private(a),
149 b_ = simde_uint8x16_to_private(b);
150 for (int i = 0 ; i < 4 ; i++) {
151 uint32_t acc = 0;
152 SIMDE_VECTORIZE_REDUCTION(+:acc)
153 for (int j = 0 ; j < 4 ; j++) {
154 const int idx = j + (i << 2);
155 acc += HEDLEY_STATIC_CAST(uint32_t, a_.values[idx]) * HEDLEY_STATIC_CAST(uint32_t, b_.values[idx]);
156 }
157 r_.values[i] = acc;
158 }
159 return simde_vaddq_u32(r, simde_uint32x4_from_private(r_));
160 #endif
161 }
162 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES) || (defined(SIMDE_ENABLE_NATIVE_ALIASES) && !defined(__ARM_FEATURE_DOTPROD))
163 #undef vdotq_u32
164 #define vdotq_u32(r, a, b) simde_vdotq_u32((r), (a), (b))
165 #endif
166
167
168 SIMDE_END_DECLS_
169 HEDLEY_DIAGNOSTIC_POP
170
171 #endif /* !defined(SIMDE_ARM_NEON_DOT_H) */