2 * ARM AdvSIMD / SVE Vector Operations
4 * Copyright (c) 2018 Linaro
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
23 #include "tcg/tcg-gvec-desc.h"
24 #include "fpu/softfloat.h"
27 /* Note that vector data is stored in host-endian 64-bit chunks,
28 so addressing units smaller than that needs a host-endian fixup. */
29 #ifdef HOST_WORDS_BIGENDIAN
30 #define H1(x) ((x) ^ 7)
31 #define H2(x) ((x) ^ 3)
32 #define H4(x) ((x) ^ 1)
39 #define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
41 static void clear_tail(void *vd
, uintptr_t opr_sz
, uintptr_t max_sz
)
43 uint64_t *d
= vd
+ opr_sz
;
46 for (i
= opr_sz
; i
< max_sz
; i
+= 8) {
51 /* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */
52 static uint16_t inl_qrdmlah_s16(CPUARMState
*env
, int16_t src1
,
53 int16_t src2
, int16_t src3
)
56 * = ((a3 << 16) + ((e1 * e2) << 1) + (1 << 15)) >> 16
57 * = ((a3 << 15) + (e1 * e2) + (1 << 14)) >> 15
59 int32_t ret
= (int32_t)src1
* src2
;
60 ret
= ((int32_t)src3
<< 15) + ret
+ (1 << 14);
62 if (ret
!= (int16_t)ret
) {
64 ret
= (ret
< 0 ? -0x8000 : 0x7fff);
69 uint32_t HELPER(neon_qrdmlah_s16
)(CPUARMState
*env
, uint32_t src1
,
70 uint32_t src2
, uint32_t src3
)
72 uint16_t e1
= inl_qrdmlah_s16(env
, src1
, src2
, src3
);
73 uint16_t e2
= inl_qrdmlah_s16(env
, src1
>> 16, src2
>> 16, src3
>> 16);
74 return deposit32(e1
, 16, 16, e2
);
77 void HELPER(gvec_qrdmlah_s16
)(void *vd
, void *vn
, void *vm
,
78 void *ve
, uint32_t desc
)
80 uintptr_t opr_sz
= simd_oprsz(desc
);
84 CPUARMState
*env
= ve
;
87 for (i
= 0; i
< opr_sz
/ 2; ++i
) {
88 d
[i
] = inl_qrdmlah_s16(env
, n
[i
], m
[i
], d
[i
]);
90 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
93 /* Signed saturating rounding doubling multiply-subtract high half, 16-bit */
94 static uint16_t inl_qrdmlsh_s16(CPUARMState
*env
, int16_t src1
,
95 int16_t src2
, int16_t src3
)
97 /* Similarly, using subtraction:
98 * = ((a3 << 16) - ((e1 * e2) << 1) + (1 << 15)) >> 16
99 * = ((a3 << 15) - (e1 * e2) + (1 << 14)) >> 15
101 int32_t ret
= (int32_t)src1
* src2
;
102 ret
= ((int32_t)src3
<< 15) - ret
+ (1 << 14);
104 if (ret
!= (int16_t)ret
) {
106 ret
= (ret
< 0 ? -0x8000 : 0x7fff);
111 uint32_t HELPER(neon_qrdmlsh_s16
)(CPUARMState
*env
, uint32_t src1
,
112 uint32_t src2
, uint32_t src3
)
114 uint16_t e1
= inl_qrdmlsh_s16(env
, src1
, src2
, src3
);
115 uint16_t e2
= inl_qrdmlsh_s16(env
, src1
>> 16, src2
>> 16, src3
>> 16);
116 return deposit32(e1
, 16, 16, e2
);
119 void HELPER(gvec_qrdmlsh_s16
)(void *vd
, void *vn
, void *vm
,
120 void *ve
, uint32_t desc
)
122 uintptr_t opr_sz
= simd_oprsz(desc
);
126 CPUARMState
*env
= ve
;
129 for (i
= 0; i
< opr_sz
/ 2; ++i
) {
130 d
[i
] = inl_qrdmlsh_s16(env
, n
[i
], m
[i
], d
[i
]);
132 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
135 /* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */
136 uint32_t HELPER(neon_qrdmlah_s32
)(CPUARMState
*env
, int32_t src1
,
137 int32_t src2
, int32_t src3
)
139 /* Simplify similarly to int_qrdmlah_s16 above. */
140 int64_t ret
= (int64_t)src1
* src2
;
141 ret
= ((int64_t)src3
<< 31) + ret
+ (1 << 30);
143 if (ret
!= (int32_t)ret
) {
145 ret
= (ret
< 0 ? INT32_MIN
: INT32_MAX
);
150 void HELPER(gvec_qrdmlah_s32
)(void *vd
, void *vn
, void *vm
,
151 void *ve
, uint32_t desc
)
153 uintptr_t opr_sz
= simd_oprsz(desc
);
157 CPUARMState
*env
= ve
;
160 for (i
= 0; i
< opr_sz
/ 4; ++i
) {
161 d
[i
] = helper_neon_qrdmlah_s32(env
, n
[i
], m
[i
], d
[i
]);
163 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
166 /* Signed saturating rounding doubling multiply-subtract high half, 32-bit */
167 uint32_t HELPER(neon_qrdmlsh_s32
)(CPUARMState
*env
, int32_t src1
,
168 int32_t src2
, int32_t src3
)
170 /* Simplify similarly to int_qrdmlsh_s16 above. */
171 int64_t ret
= (int64_t)src1
* src2
;
172 ret
= ((int64_t)src3
<< 31) - ret
+ (1 << 30);
174 if (ret
!= (int32_t)ret
) {
176 ret
= (ret
< 0 ? INT32_MIN
: INT32_MAX
);
181 void HELPER(gvec_qrdmlsh_s32
)(void *vd
, void *vn
, void *vm
,
182 void *ve
, uint32_t desc
)
184 uintptr_t opr_sz
= simd_oprsz(desc
);
188 CPUARMState
*env
= ve
;
191 for (i
= 0; i
< opr_sz
/ 4; ++i
) {
192 d
[i
] = helper_neon_qrdmlsh_s32(env
, n
[i
], m
[i
], d
[i
]);
194 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
197 /* Integer 8 and 16-bit dot-product.
199 * Note that for the loops herein, host endianness does not matter
200 * with respect to the ordering of data within the 64-bit lanes.
201 * All elements are treated equally, no matter where they are.
204 void HELPER(gvec_sdot_b
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
206 intptr_t i
, opr_sz
= simd_oprsz(desc
);
208 int8_t *n
= vn
, *m
= vm
;
210 for (i
= 0; i
< opr_sz
/ 4; ++i
) {
211 d
[i
] += n
[i
* 4 + 0] * m
[i
* 4 + 0]
212 + n
[i
* 4 + 1] * m
[i
* 4 + 1]
213 + n
[i
* 4 + 2] * m
[i
* 4 + 2]
214 + n
[i
* 4 + 3] * m
[i
* 4 + 3];
216 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
219 void HELPER(gvec_udot_b
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
221 intptr_t i
, opr_sz
= simd_oprsz(desc
);
223 uint8_t *n
= vn
, *m
= vm
;
225 for (i
= 0; i
< opr_sz
/ 4; ++i
) {
226 d
[i
] += n
[i
* 4 + 0] * m
[i
* 4 + 0]
227 + n
[i
* 4 + 1] * m
[i
* 4 + 1]
228 + n
[i
* 4 + 2] * m
[i
* 4 + 2]
229 + n
[i
* 4 + 3] * m
[i
* 4 + 3];
231 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
234 void HELPER(gvec_sdot_h
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
236 intptr_t i
, opr_sz
= simd_oprsz(desc
);
238 int16_t *n
= vn
, *m
= vm
;
240 for (i
= 0; i
< opr_sz
/ 8; ++i
) {
241 d
[i
] += (int64_t)n
[i
* 4 + 0] * m
[i
* 4 + 0]
242 + (int64_t)n
[i
* 4 + 1] * m
[i
* 4 + 1]
243 + (int64_t)n
[i
* 4 + 2] * m
[i
* 4 + 2]
244 + (int64_t)n
[i
* 4 + 3] * m
[i
* 4 + 3];
246 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
249 void HELPER(gvec_udot_h
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
251 intptr_t i
, opr_sz
= simd_oprsz(desc
);
253 uint16_t *n
= vn
, *m
= vm
;
255 for (i
= 0; i
< opr_sz
/ 8; ++i
) {
256 d
[i
] += (uint64_t)n
[i
* 4 + 0] * m
[i
* 4 + 0]
257 + (uint64_t)n
[i
* 4 + 1] * m
[i
* 4 + 1]
258 + (uint64_t)n
[i
* 4 + 2] * m
[i
* 4 + 2]
259 + (uint64_t)n
[i
* 4 + 3] * m
[i
* 4 + 3];
261 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
264 void HELPER(gvec_sdot_idx_b
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
266 intptr_t i
, segend
, opr_sz
= simd_oprsz(desc
), opr_sz_4
= opr_sz
/ 4;
267 intptr_t index
= simd_data(desc
);
270 int8_t *m_indexed
= (int8_t *)vm
+ index
* 4;
272 /* Notice the special case of opr_sz == 8, from aa64/aa32 advsimd.
273 * Otherwise opr_sz is a multiple of 16.
275 segend
= MIN(4, opr_sz_4
);
278 int8_t m0
= m_indexed
[i
* 4 + 0];
279 int8_t m1
= m_indexed
[i
* 4 + 1];
280 int8_t m2
= m_indexed
[i
* 4 + 2];
281 int8_t m3
= m_indexed
[i
* 4 + 3];
284 d
[i
] += n
[i
* 4 + 0] * m0
288 } while (++i
< segend
);
290 } while (i
< opr_sz_4
);
292 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
295 void HELPER(gvec_udot_idx_b
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
297 intptr_t i
, segend
, opr_sz
= simd_oprsz(desc
), opr_sz_4
= opr_sz
/ 4;
298 intptr_t index
= simd_data(desc
);
301 uint8_t *m_indexed
= (uint8_t *)vm
+ index
* 4;
303 /* Notice the special case of opr_sz == 8, from aa64/aa32 advsimd.
304 * Otherwise opr_sz is a multiple of 16.
306 segend
= MIN(4, opr_sz_4
);
309 uint8_t m0
= m_indexed
[i
* 4 + 0];
310 uint8_t m1
= m_indexed
[i
* 4 + 1];
311 uint8_t m2
= m_indexed
[i
* 4 + 2];
312 uint8_t m3
= m_indexed
[i
* 4 + 3];
315 d
[i
] += n
[i
* 4 + 0] * m0
319 } while (++i
< segend
);
321 } while (i
< opr_sz_4
);
323 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
326 void HELPER(gvec_sdot_idx_h
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
328 intptr_t i
, opr_sz
= simd_oprsz(desc
), opr_sz_8
= opr_sz
/ 8;
329 intptr_t index
= simd_data(desc
);
332 int16_t *m_indexed
= (int16_t *)vm
+ index
* 4;
334 /* This is supported by SVE only, so opr_sz is always a multiple of 16.
335 * Process the entire segment all at once, writing back the results
336 * only after we've consumed all of the inputs.
338 for (i
= 0; i
< opr_sz_8
; i
+= 2) {
341 d0
= n
[i
* 4 + 0] * (int64_t)m_indexed
[i
* 4 + 0];
342 d0
+= n
[i
* 4 + 1] * (int64_t)m_indexed
[i
* 4 + 1];
343 d0
+= n
[i
* 4 + 2] * (int64_t)m_indexed
[i
* 4 + 2];
344 d0
+= n
[i
* 4 + 3] * (int64_t)m_indexed
[i
* 4 + 3];
345 d1
= n
[i
* 4 + 4] * (int64_t)m_indexed
[i
* 4 + 0];
346 d1
+= n
[i
* 4 + 5] * (int64_t)m_indexed
[i
* 4 + 1];
347 d1
+= n
[i
* 4 + 6] * (int64_t)m_indexed
[i
* 4 + 2];
348 d1
+= n
[i
* 4 + 7] * (int64_t)m_indexed
[i
* 4 + 3];
354 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
357 void HELPER(gvec_udot_idx_h
)(void *vd
, void *vn
, void *vm
, uint32_t desc
)
359 intptr_t i
, opr_sz
= simd_oprsz(desc
), opr_sz_8
= opr_sz
/ 8;
360 intptr_t index
= simd_data(desc
);
363 uint16_t *m_indexed
= (uint16_t *)vm
+ index
* 4;
365 /* This is supported by SVE only, so opr_sz is always a multiple of 16.
366 * Process the entire segment all at once, writing back the results
367 * only after we've consumed all of the inputs.
369 for (i
= 0; i
< opr_sz_8
; i
+= 2) {
372 d0
= n
[i
* 4 + 0] * (uint64_t)m_indexed
[i
* 4 + 0];
373 d0
+= n
[i
* 4 + 1] * (uint64_t)m_indexed
[i
* 4 + 1];
374 d0
+= n
[i
* 4 + 2] * (uint64_t)m_indexed
[i
* 4 + 2];
375 d0
+= n
[i
* 4 + 3] * (uint64_t)m_indexed
[i
* 4 + 3];
376 d1
= n
[i
* 4 + 4] * (uint64_t)m_indexed
[i
* 4 + 0];
377 d1
+= n
[i
* 4 + 5] * (uint64_t)m_indexed
[i
* 4 + 1];
378 d1
+= n
[i
* 4 + 6] * (uint64_t)m_indexed
[i
* 4 + 2];
379 d1
+= n
[i
* 4 + 7] * (uint64_t)m_indexed
[i
* 4 + 3];
385 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
388 void HELPER(gvec_fcaddh
)(void *vd
, void *vn
, void *vm
,
389 void *vfpst
, uint32_t desc
)
391 uintptr_t opr_sz
= simd_oprsz(desc
);
395 float_status
*fpst
= vfpst
;
396 uint32_t neg_real
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
397 uint32_t neg_imag
= neg_real
^ 1;
400 /* Shift boolean to the sign bit so we can xor to negate. */
404 for (i
= 0; i
< opr_sz
/ 2; i
+= 2) {
405 float16 e0
= n
[H2(i
)];
406 float16 e1
= m
[H2(i
+ 1)] ^ neg_imag
;
407 float16 e2
= n
[H2(i
+ 1)];
408 float16 e3
= m
[H2(i
)] ^ neg_real
;
410 d
[H2(i
)] = float16_add(e0
, e1
, fpst
);
411 d
[H2(i
+ 1)] = float16_add(e2
, e3
, fpst
);
413 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
416 void HELPER(gvec_fcadds
)(void *vd
, void *vn
, void *vm
,
417 void *vfpst
, uint32_t desc
)
419 uintptr_t opr_sz
= simd_oprsz(desc
);
423 float_status
*fpst
= vfpst
;
424 uint32_t neg_real
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
425 uint32_t neg_imag
= neg_real
^ 1;
428 /* Shift boolean to the sign bit so we can xor to negate. */
432 for (i
= 0; i
< opr_sz
/ 4; i
+= 2) {
433 float32 e0
= n
[H4(i
)];
434 float32 e1
= m
[H4(i
+ 1)] ^ neg_imag
;
435 float32 e2
= n
[H4(i
+ 1)];
436 float32 e3
= m
[H4(i
)] ^ neg_real
;
438 d
[H4(i
)] = float32_add(e0
, e1
, fpst
);
439 d
[H4(i
+ 1)] = float32_add(e2
, e3
, fpst
);
441 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
444 void HELPER(gvec_fcaddd
)(void *vd
, void *vn
, void *vm
,
445 void *vfpst
, uint32_t desc
)
447 uintptr_t opr_sz
= simd_oprsz(desc
);
451 float_status
*fpst
= vfpst
;
452 uint64_t neg_real
= extract64(desc
, SIMD_DATA_SHIFT
, 1);
453 uint64_t neg_imag
= neg_real
^ 1;
456 /* Shift boolean to the sign bit so we can xor to negate. */
460 for (i
= 0; i
< opr_sz
/ 8; i
+= 2) {
462 float64 e1
= m
[i
+ 1] ^ neg_imag
;
463 float64 e2
= n
[i
+ 1];
464 float64 e3
= m
[i
] ^ neg_real
;
466 d
[i
] = float64_add(e0
, e1
, fpst
);
467 d
[i
+ 1] = float64_add(e2
, e3
, fpst
);
469 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
472 void HELPER(gvec_fcmlah
)(void *vd
, void *vn
, void *vm
,
473 void *vfpst
, uint32_t desc
)
475 uintptr_t opr_sz
= simd_oprsz(desc
);
479 float_status
*fpst
= vfpst
;
480 intptr_t flip
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
481 uint32_t neg_imag
= extract32(desc
, SIMD_DATA_SHIFT
+ 1, 1);
482 uint32_t neg_real
= flip
^ neg_imag
;
485 /* Shift boolean to the sign bit so we can xor to negate. */
489 for (i
= 0; i
< opr_sz
/ 2; i
+= 2) {
490 float16 e2
= n
[H2(i
+ flip
)];
491 float16 e1
= m
[H2(i
+ flip
)] ^ neg_real
;
493 float16 e3
= m
[H2(i
+ 1 - flip
)] ^ neg_imag
;
495 d
[H2(i
)] = float16_muladd(e2
, e1
, d
[H2(i
)], 0, fpst
);
496 d
[H2(i
+ 1)] = float16_muladd(e4
, e3
, d
[H2(i
+ 1)], 0, fpst
);
498 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
501 void HELPER(gvec_fcmlah_idx
)(void *vd
, void *vn
, void *vm
,
502 void *vfpst
, uint32_t desc
)
504 uintptr_t opr_sz
= simd_oprsz(desc
);
508 float_status
*fpst
= vfpst
;
509 intptr_t flip
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
510 uint32_t neg_imag
= extract32(desc
, SIMD_DATA_SHIFT
+ 1, 1);
511 intptr_t index
= extract32(desc
, SIMD_DATA_SHIFT
+ 2, 2);
512 uint32_t neg_real
= flip
^ neg_imag
;
513 intptr_t elements
= opr_sz
/ sizeof(float16
);
514 intptr_t eltspersegment
= 16 / sizeof(float16
);
517 /* Shift boolean to the sign bit so we can xor to negate. */
521 for (i
= 0; i
< elements
; i
+= eltspersegment
) {
522 float16 mr
= m
[H2(i
+ 2 * index
+ 0)];
523 float16 mi
= m
[H2(i
+ 2 * index
+ 1)];
524 float16 e1
= neg_real
^ (flip
? mi
: mr
);
525 float16 e3
= neg_imag
^ (flip
? mr
: mi
);
527 for (j
= i
; j
< i
+ eltspersegment
; j
+= 2) {
528 float16 e2
= n
[H2(j
+ flip
)];
531 d
[H2(j
)] = float16_muladd(e2
, e1
, d
[H2(j
)], 0, fpst
);
532 d
[H2(j
+ 1)] = float16_muladd(e4
, e3
, d
[H2(j
+ 1)], 0, fpst
);
535 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
538 void HELPER(gvec_fcmlas
)(void *vd
, void *vn
, void *vm
,
539 void *vfpst
, uint32_t desc
)
541 uintptr_t opr_sz
= simd_oprsz(desc
);
545 float_status
*fpst
= vfpst
;
546 intptr_t flip
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
547 uint32_t neg_imag
= extract32(desc
, SIMD_DATA_SHIFT
+ 1, 1);
548 uint32_t neg_real
= flip
^ neg_imag
;
551 /* Shift boolean to the sign bit so we can xor to negate. */
555 for (i
= 0; i
< opr_sz
/ 4; i
+= 2) {
556 float32 e2
= n
[H4(i
+ flip
)];
557 float32 e1
= m
[H4(i
+ flip
)] ^ neg_real
;
559 float32 e3
= m
[H4(i
+ 1 - flip
)] ^ neg_imag
;
561 d
[H4(i
)] = float32_muladd(e2
, e1
, d
[H4(i
)], 0, fpst
);
562 d
[H4(i
+ 1)] = float32_muladd(e4
, e3
, d
[H4(i
+ 1)], 0, fpst
);
564 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
567 void HELPER(gvec_fcmlas_idx
)(void *vd
, void *vn
, void *vm
,
568 void *vfpst
, uint32_t desc
)
570 uintptr_t opr_sz
= simd_oprsz(desc
);
574 float_status
*fpst
= vfpst
;
575 intptr_t flip
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
576 uint32_t neg_imag
= extract32(desc
, SIMD_DATA_SHIFT
+ 1, 1);
577 intptr_t index
= extract32(desc
, SIMD_DATA_SHIFT
+ 2, 2);
578 uint32_t neg_real
= flip
^ neg_imag
;
579 intptr_t elements
= opr_sz
/ sizeof(float32
);
580 intptr_t eltspersegment
= 16 / sizeof(float32
);
583 /* Shift boolean to the sign bit so we can xor to negate. */
587 for (i
= 0; i
< elements
; i
+= eltspersegment
) {
588 float32 mr
= m
[H4(i
+ 2 * index
+ 0)];
589 float32 mi
= m
[H4(i
+ 2 * index
+ 1)];
590 float32 e1
= neg_real
^ (flip
? mi
: mr
);
591 float32 e3
= neg_imag
^ (flip
? mr
: mi
);
593 for (j
= i
; j
< i
+ eltspersegment
; j
+= 2) {
594 float32 e2
= n
[H4(j
+ flip
)];
597 d
[H4(j
)] = float32_muladd(e2
, e1
, d
[H4(j
)], 0, fpst
);
598 d
[H4(j
+ 1)] = float32_muladd(e4
, e3
, d
[H4(j
+ 1)], 0, fpst
);
601 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
604 void HELPER(gvec_fcmlad
)(void *vd
, void *vn
, void *vm
,
605 void *vfpst
, uint32_t desc
)
607 uintptr_t opr_sz
= simd_oprsz(desc
);
611 float_status
*fpst
= vfpst
;
612 intptr_t flip
= extract32(desc
, SIMD_DATA_SHIFT
, 1);
613 uint64_t neg_imag
= extract32(desc
, SIMD_DATA_SHIFT
+ 1, 1);
614 uint64_t neg_real
= flip
^ neg_imag
;
617 /* Shift boolean to the sign bit so we can xor to negate. */
621 for (i
= 0; i
< opr_sz
/ 8; i
+= 2) {
622 float64 e2
= n
[i
+ flip
];
623 float64 e1
= m
[i
+ flip
] ^ neg_real
;
625 float64 e3
= m
[i
+ 1 - flip
] ^ neg_imag
;
627 d
[i
] = float64_muladd(e2
, e1
, d
[i
], 0, fpst
);
628 d
[i
+ 1] = float64_muladd(e4
, e3
, d
[i
+ 1], 0, fpst
);
630 clear_tail(d
, opr_sz
, simd_maxsz(desc
));
633 #define DO_2OP(NAME, FUNC, TYPE) \
634 void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \
636 intptr_t i, oprsz = simd_oprsz(desc); \
637 TYPE *d = vd, *n = vn; \
638 for (i = 0; i < oprsz / sizeof(TYPE); i++) { \
639 d[i] = FUNC(n[i], stat); \
643 DO_2OP(gvec_frecpe_h
, helper_recpe_f16
, float16
)
644 DO_2OP(gvec_frecpe_s
, helper_recpe_f32
, float32
)
645 DO_2OP(gvec_frecpe_d
, helper_recpe_f64
, float64
)
647 DO_2OP(gvec_frsqrte_h
, helper_rsqrte_f16
, float16
)
648 DO_2OP(gvec_frsqrte_s
, helper_rsqrte_f32
, float32
)
649 DO_2OP(gvec_frsqrte_d
, helper_rsqrte_f64
, float64
)
653 /* Floating-point trigonometric starting value.
654 * See the ARM ARM pseudocode function FPTrigSMul.
656 static float16
float16_ftsmul(float16 op1
, uint16_t op2
, float_status
*stat
)
658 float16 result
= float16_mul(op1
, op1
, stat
);
659 if (!float16_is_any_nan(result
)) {
660 result
= float16_set_sign(result
, op2
& 1);
665 static float32
float32_ftsmul(float32 op1
, uint32_t op2
, float_status
*stat
)
667 float32 result
= float32_mul(op1
, op1
, stat
);
668 if (!float32_is_any_nan(result
)) {
669 result
= float32_set_sign(result
, op2
& 1);
674 static float64
float64_ftsmul(float64 op1
, uint64_t op2
, float_status
*stat
)
676 float64 result
= float64_mul(op1
, op1
, stat
);
677 if (!float64_is_any_nan(result
)) {
678 result
= float64_set_sign(result
, op2
& 1);
683 #define DO_3OP(NAME, FUNC, TYPE) \
684 void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \
686 intptr_t i, oprsz = simd_oprsz(desc); \
687 TYPE *d = vd, *n = vn, *m = vm; \
688 for (i = 0; i < oprsz / sizeof(TYPE); i++) { \
689 d[i] = FUNC(n[i], m[i], stat); \
693 DO_3OP(gvec_fadd_h
, float16_add
, float16
)
694 DO_3OP(gvec_fadd_s
, float32_add
, float32
)
695 DO_3OP(gvec_fadd_d
, float64_add
, float64
)
697 DO_3OP(gvec_fsub_h
, float16_sub
, float16
)
698 DO_3OP(gvec_fsub_s
, float32_sub
, float32
)
699 DO_3OP(gvec_fsub_d
, float64_sub
, float64
)
701 DO_3OP(gvec_fmul_h
, float16_mul
, float16
)
702 DO_3OP(gvec_fmul_s
, float32_mul
, float32
)
703 DO_3OP(gvec_fmul_d
, float64_mul
, float64
)
705 DO_3OP(gvec_ftsmul_h
, float16_ftsmul
, float16
)
706 DO_3OP(gvec_ftsmul_s
, float32_ftsmul
, float32
)
707 DO_3OP(gvec_ftsmul_d
, float64_ftsmul
, float64
)
709 #ifdef TARGET_AARCH64
711 DO_3OP(gvec_recps_h
, helper_recpsf_f16
, float16
)
712 DO_3OP(gvec_recps_s
, helper_recpsf_f32
, float32
)
713 DO_3OP(gvec_recps_d
, helper_recpsf_f64
, float64
)
715 DO_3OP(gvec_rsqrts_h
, helper_rsqrtsf_f16
, float16
)
716 DO_3OP(gvec_rsqrts_s
, helper_rsqrtsf_f32
, float32
)
717 DO_3OP(gvec_rsqrts_d
, helper_rsqrtsf_f64
, float64
)
722 /* For the indexed ops, SVE applies the index per 128-bit vector segment.
723 * For AdvSIMD, there is of course only one such vector segment.
726 #define DO_MUL_IDX(NAME, TYPE, H) \
727 void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \
729 intptr_t i, j, oprsz = simd_oprsz(desc), segment = 16 / sizeof(TYPE); \
730 intptr_t idx = simd_data(desc); \
731 TYPE *d = vd, *n = vn, *m = vm; \
732 for (i = 0; i < oprsz / sizeof(TYPE); i += segment) { \
733 TYPE mm = m[H(i + idx)]; \
734 for (j = 0; j < segment; j++) { \
735 d[i + j] = TYPE##_mul(n[i + j], mm, stat); \
740 DO_MUL_IDX(gvec_fmul_idx_h
, float16
, H2
)
741 DO_MUL_IDX(gvec_fmul_idx_s
, float32
, H4
)
742 DO_MUL_IDX(gvec_fmul_idx_d
, float64
, )
746 #define DO_FMLA_IDX(NAME, TYPE, H) \
747 void HELPER(NAME)(void *vd, void *vn, void *vm, void *va, \
748 void *stat, uint32_t desc) \
750 intptr_t i, j, oprsz = simd_oprsz(desc), segment = 16 / sizeof(TYPE); \
751 TYPE op1_neg = extract32(desc, SIMD_DATA_SHIFT, 1); \
752 intptr_t idx = desc >> (SIMD_DATA_SHIFT + 1); \
753 TYPE *d = vd, *n = vn, *m = vm, *a = va; \
754 op1_neg <<= (8 * sizeof(TYPE) - 1); \
755 for (i = 0; i < oprsz / sizeof(TYPE); i += segment) { \
756 TYPE mm = m[H(i + idx)]; \
757 for (j = 0; j < segment; j++) { \
758 d[i + j] = TYPE##_muladd(n[i + j] ^ op1_neg, \
759 mm, a[i + j], 0, stat); \
764 DO_FMLA_IDX(gvec_fmla_idx_h
, float16
, H2
)
765 DO_FMLA_IDX(gvec_fmla_idx_s
, float32
, H4
)
766 DO_FMLA_IDX(gvec_fmla_idx_d
, float64
, )