41#if defined(__aarch64__)
42static inline int32_t saturate_32bit_to_16bit(int32_t a) {
44 asm (
"fmov s0, %w[a]\n"
53#elif defined(__thumb2__)
54static inline int32_t saturate_32bit_to_16bit(int32_t a) {
56 asm (
"ssat %[ret], #16, %[a]"
63static inline int32_t saturate_32bit_to_16bit(int32_t a) {
65 asm (
"vmov.s32 d0[0], %[a]\n"
67 "vmov.s16 %[ret], d0[0]\n"
75#define WORD2INT(x) (saturate_32bit_to_16bit(x))
77#define OVERRIDE_INNER_PRODUCT_SINGLE
79#if defined(__aarch64__)
80static inline int32_t inner_product_single(
const int16_t *a,
const int16_t *b,
unsigned int len)
83 uint32_t remainder = len % 16;
84 len = len - remainder;
86 asm volatile (
" cmp %w[len], #0\n"
88 " ld1 {v16.4h}, [%[b]], #8\n"
89 " ld1 {v20.4h}, [%[a]], #8\n"
90 " subs %w[remainder], %w[remainder], #4\n"
91 " smull v0.4s, v16.4h, v20.4h\n"
95 " ld1 {v16.4h, v17.4h, v18.4h, v19.4h}, [%[b]], #32\n"
96 " ld1 {v20.4h, v21.4h, v22.4h, v23.4h}, [%[a]], #32\n"
97 " subs %w[len], %w[len], #16\n"
98 " smull v0.4s, v16.4h, v20.4h\n"
99 " smlal v0.4s, v17.4h, v21.4h\n"
100 " smlal v0.4s, v18.4h, v22.4h\n"
101 " smlal v0.4s, v19.4h, v23.4h\n"
104 " ld1 {v16.4h, v17.4h, v18.4h, v19.4h}, [%[b]], #32\n"
105 " ld1 {v20.4h, v21.4h, v22.4h, v23.4h}, [%[a]], #32\n"
106 " subs %w[len], %w[len], #16\n"
107 " smlal v0.4s, v16.4h, v20.4h\n"
108 " smlal v0.4s, v17.4h, v21.4h\n"
109 " smlal v0.4s, v18.4h, v22.4h\n"
110 " smlal v0.4s, v19.4h, v23.4h\n"
113 " cmp %w[remainder], #0\n"
116 " ld1 {v18.4h}, [%[b]], #8\n"
117 " ld1 {v22.4h}, [%[a]], #8\n"
118 " subs %w[remainder], %w[remainder], #4\n"
119 " smlal v0.4s, v18.4h, v22.4h\n"
122 " saddlv d0, v0.4s\n"
124 " sqrshrn h0, s0, #15\n"
125 " sxtl v0.4s, v0.4h\n"
126 " fmov %w[ret], s0\n"
127 : [ret]
"=r" (ret), [a]
"+r" (a), [b]
"+r" (b),
128 [len]
"+r" (len), [remainder]
"+r" (remainder)
131 "v16",
"v17",
"v18",
"v19",
"v20",
"v21",
"v22",
"v23");
135static inline int32_t inner_product_single(
const int16_t *a,
const int16_t *b,
unsigned int len)
138 uint32_t remainder = len % 16;
139 len = len - remainder;
141 asm volatile (
" cmp %[len], #0\n"
143 " vld1.16 {d16}, [%[b]]!\n"
144 " vld1.16 {d20}, [%[a]]!\n"
145 " subs %[remainder], %[remainder], #4\n"
146 " vmull.s16 q0, d16, d20\n"
150 " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"
151 " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"
152 " subs %[len], %[len], #16\n"
153 " vmull.s16 q0, d16, d20\n"
154 " vmlal.s16 q0, d17, d21\n"
155 " vmlal.s16 q0, d18, d22\n"
156 " vmlal.s16 q0, d19, d23\n"
159 " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"
160 " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"
161 " subs %[len], %[len], #16\n"
162 " vmlal.s16 q0, d16, d20\n"
163 " vmlal.s16 q0, d17, d21\n"
164 " vmlal.s16 q0, d18, d22\n"
165 " vmlal.s16 q0, d19, d23\n"
168 " cmp %[remainder], #0\n"
171 " vld1.16 {d16}, [%[b]]!\n"
172 " vld1.16 {d20}, [%[a]]!\n"
173 " subs %[remainder], %[remainder], #4\n"
174 " vmlal.s16 q0, d16, d20\n"
177 " vaddl.s32 q0, d0, d1\n"
178 " vadd.s64 d0, d0, d1\n"
179 " vqmovn.s64 d0, q0\n"
180 " vqrshrn.s32 d0, q0, #15\n"
181 " vmov.s16 %[ret], d0[0]\n"
182 : [ret]
"=r" (ret), [a]
"+r" (a), [b]
"+r" (b),
183 [len]
"+r" (len), [remainder]
"+r" (remainder)
186 "d16",
"d17",
"d18",
"d19",
"d20",
"d21",
"d22",
"d23");
192#elif defined(FLOATING_POINT)
193#if defined(__aarch64__)
194static inline int32_t saturate_float_to_16bit(
float a) {
196 asm (
"fcvtas s1, %s[a]\n"
198 "sxtl v1.4s, v1.4h\n"
206static inline int32_t saturate_float_to_16bit(
float a) {
208 asm (
"vmov.f32 d0[0], %[a]\n"
209 "vcvt.s32.f32 d0, d0, #15\n"
210 "vqrshrn.s32 d0, q0, #15\n"
211 "vmov.s16 %[ret], d0[0]\n"
220#define WORD2INT(x) (saturate_float_to_16bit(x))
222#define OVERRIDE_INNER_PRODUCT_SINGLE
224#if defined(__aarch64__)
225static inline float inner_product_single(
const float *a,
const float *b,
unsigned int len)
228 uint32_t remainder = len % 16;
229 len = len - remainder;
231 asm volatile (
" cmp %w[len], #0\n"
233 " ld1 {v16.4s}, [%[b]], #16\n"
234 " ld1 {v20.4s}, [%[a]], #16\n"
235 " subs %w[remainder], %w[remainder], #4\n"
236 " fmul v1.4s, v16.4s, v20.4s\n"
240 " ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%[b]], #64\n"
241 " ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%[a]], #64\n"
242 " subs %w[len], %w[len], #16\n"
243 " fmul v1.4s, v16.4s, v20.4s\n"
244 " fmul v2.4s, v17.4s, v21.4s\n"
245 " fmul v3.4s, v18.4s, v22.4s\n"
246 " fmul v4.4s, v19.4s, v23.4s\n"
249 " ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%[b]], #64\n"
250 " ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%[a]], #64\n"
251 " subs %w[len], %w[len], #16\n"
252 " fmla v1.4s, v16.4s, v20.4s\n"
253 " fmla v2.4s, v17.4s, v21.4s\n"
254 " fmla v3.4s, v18.4s, v22.4s\n"
255 " fmla v4.4s, v19.4s, v23.4s\n"
258 " fadd v16.4s, v1.4s, v2.4s\n"
259 " fadd v17.4s, v3.4s, v4.4s\n"
260 " cmp %w[remainder], #0\n"
261 " fadd v1.4s, v16.4s, v17.4s\n"
264 " ld1 {v18.4s}, [%[b]], #16\n"
265 " ld1 {v22.4s}, [%[a]], #16\n"
266 " subs %w[remainder], %w[remainder], #4\n"
267 " fmla v1.4s, v18.4s, v22.4s\n"
270 " faddp v1.4s, v1.4s, v1.4s\n"
271 " faddp %[ret].4s, v1.4s, v1.4s\n"
272 : [ret]
"=w" (ret), [a]
"+r" (a), [b]
"+r" (b),
273 [len]
"+r" (len), [remainder]
"+r" (remainder)
275 :
"cc",
"v1",
"v2",
"v3",
"v4",
276 "v16",
"v17",
"v18",
"v19",
"v20",
"v21",
"v22",
"v23");
280static inline float inner_product_single(
const float *a,
const float *b,
unsigned int len)
283 uint32_t remainder = len % 16;
284 len = len - remainder;
286 asm volatile (
" cmp %[len], #0\n"
288 " vld1.32 {q4}, [%[b]]!\n"
289 " vld1.32 {q8}, [%[a]]!\n"
290 " subs %[remainder], %[remainder], #4\n"
291 " vmul.f32 q0, q4, q8\n"
295 " vld1.32 {q4, q5}, [%[b]]!\n"
296 " vld1.32 {q8, q9}, [%[a]]!\n"
297 " vld1.32 {q6, q7}, [%[b]]!\n"
298 " vld1.32 {q10, q11}, [%[a]]!\n"
299 " subs %[len], %[len], #16\n"
300 " vmul.f32 q0, q4, q8\n"
301 " vmul.f32 q1, q5, q9\n"
302 " vmul.f32 q2, q6, q10\n"
303 " vmul.f32 q3, q7, q11\n"
306 " vld1.32 {q4, q5}, [%[b]]!\n"
307 " vld1.32 {q8, q9}, [%[a]]!\n"
308 " vld1.32 {q6, q7}, [%[b]]!\n"
309 " vld1.32 {q10, q11}, [%[a]]!\n"
310 " subs %[len], %[len], #16\n"
311 " vmla.f32 q0, q4, q8\n"
312 " vmla.f32 q1, q5, q9\n"
313 " vmla.f32 q2, q6, q10\n"
314 " vmla.f32 q3, q7, q11\n"
317 " vadd.f32 q4, q0, q1\n"
318 " vadd.f32 q5, q2, q3\n"
319 " cmp %[remainder], #0\n"
320 " vadd.f32 q0, q4, q5\n"
323 " vld1.32 {q6}, [%[b]]!\n"
324 " vld1.32 {q10}, [%[a]]!\n"
325 " subs %[remainder], %[remainder], #4\n"
326 " vmla.f32 q0, q6, q10\n"
329 " vadd.f32 d0, d0, d1\n"
330 " vpadd.f32 d0, d0, d0\n"
331 " vmov.f32 %[ret], d0[0]\n"
332 : [ret]
"=r" (ret), [a]
"+r" (a), [b]
"+r" (b),
333 [len]
"+l" (len), [remainder]
"+l" (remainder)
335 :
"cc",
"q0",
"q1",
"q2",
"q3",
336 "q4",
"q5",
"q6",
"q7",
"q8",
"q9",
"q10",
"q11");