2 * ARM NEON vector operations.
4 * Copyright (c) 2007, 2008 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GNU GPL v2.
9 #include "qemu/osdep.h"
12 #include "exec/helper-proto.h"
13 #include "fpu/softfloat.h"
15 #define SIGNBIT (uint32_t)0x80000000
16 #define SIGNBIT64 ((uint64_t)1 << 63)
18 #define SET_QC() env->vfp.qc[0] = 1
20 #define NEON_TYPE1(name, type) \
25 #ifdef HOST_WORDS_BIGENDIAN
26 #define NEON_TYPE2(name, type) \
32 #define NEON_TYPE4(name, type) \
41 #define NEON_TYPE2(name, type) \
47 #define NEON_TYPE4(name, type) \
57 NEON_TYPE4(s8
, int8_t)
58 NEON_TYPE4(u8
, uint8_t)
59 NEON_TYPE2(s16
, int16_t)
60 NEON_TYPE2(u16
, uint16_t)
61 NEON_TYPE1(s32
, int32_t)
62 NEON_TYPE1(u32
, uint32_t)
67 /* Copy from a uint32_t to a vector structure type. */
68 #define NEON_UNPACK(vtype, dest, val) do { \
77 /* Copy from a vector structure type to a uint32_t. */
78 #define NEON_PACK(vtype, dest, val) do { \
88 NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1);
90 NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
91 NEON_FN(vdest.v2, vsrc1.v2, vsrc2.v2);
93 NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
94 NEON_FN(vdest.v2, vsrc1.v2, vsrc2.v2); \
95 NEON_FN(vdest.v3, vsrc1.v3, vsrc2.v3); \
96 NEON_FN(vdest.v4, vsrc1.v4, vsrc2.v4);
98 #define NEON_VOP_BODY(vtype, n) \
104 NEON_UNPACK(vtype, vsrc1, arg1); \
105 NEON_UNPACK(vtype, vsrc2, arg2); \
107 NEON_PACK(vtype, res, vdest); \
111 #define NEON_VOP(name, vtype, n) \
112 uint32_t HELPER(glue(neon_,name))(uint32_t arg1, uint32_t arg2) \
113 NEON_VOP_BODY(vtype, n)
115 #define NEON_VOP_ENV(name, vtype, n) \
116 uint32_t HELPER(glue(neon_,name))(CPUARMState *env, uint32_t arg1, uint32_t arg2) \
117 NEON_VOP_BODY(vtype, n)
119 /* Pairwise operations. */
120 /* For 32-bit elements each segment only contains a single element, so
121 the elementwise and pairwise operations are the same. */
123 NEON_FN(vdest.v1, vsrc1.v1, vsrc1.v2); \
124 NEON_FN(vdest.v2, vsrc2.v1, vsrc2.v2);
126 NEON_FN(vdest.v1, vsrc1.v1, vsrc1.v2); \
127 NEON_FN(vdest.v2, vsrc1.v3, vsrc1.v4); \
128 NEON_FN(vdest.v3, vsrc2.v1, vsrc2.v2); \
129 NEON_FN(vdest.v4, vsrc2.v3, vsrc2.v4); \
131 #define NEON_POP(name, vtype, n) \
132 uint32_t HELPER(glue(neon_,name))(uint32_t arg1, uint32_t arg2) \
138 NEON_UNPACK(vtype, vsrc1, arg1); \
139 NEON_UNPACK(vtype, vsrc2, arg2); \
141 NEON_PACK(vtype, res, vdest); \
145 /* Unary operators. */
146 #define NEON_VOP1(name, vtype, n) \
147 uint32_t HELPER(glue(neon_,name))(uint32_t arg) \
151 NEON_UNPACK(vtype, vsrc1, arg); \
153 NEON_PACK(vtype, arg, vdest); \
158 #define NEON_USAT(dest, src1, src2, type) do { \
159 uint32_t tmp = (uint32_t)src1 + (uint32_t)src2; \
160 if (tmp != (type)tmp) { \
166 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint8_t)
167 NEON_VOP_ENV(qadd_u8
, neon_u8
, 4)
169 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint16_t)
170 NEON_VOP_ENV(qadd_u16
, neon_u16
, 2)
174 uint32_t HELPER(neon_qadd_u32
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
176 uint32_t res
= a
+ b
;
184 uint64_t HELPER(neon_qadd_u64
)(CPUARMState
*env
, uint64_t src1
, uint64_t src2
)
196 #define NEON_SSAT(dest, src1, src2, type) do { \
197 int32_t tmp = (uint32_t)src1 + (uint32_t)src2; \
198 if (tmp != (type)tmp) { \
201 tmp = (1 << (sizeof(type) * 8 - 1)) - 1; \
203 tmp = 1 << (sizeof(type) * 8 - 1); \
208 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int8_t)
209 NEON_VOP_ENV(qadd_s8
, neon_s8
, 4)
211 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int16_t)
212 NEON_VOP_ENV(qadd_s16
, neon_s16
, 2)
216 uint32_t HELPER(neon_qadd_s32
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
218 uint32_t res
= a
+ b
;
219 if (((res
^ a
) & SIGNBIT
) && !((a
^ b
) & SIGNBIT
)) {
221 res
= ~(((int32_t)a
>> 31) ^ SIGNBIT
);
226 uint64_t HELPER(neon_qadd_s64
)(CPUARMState
*env
, uint64_t src1
, uint64_t src2
)
231 if (((res
^ src1
) & SIGNBIT64
) && !((src1
^ src2
) & SIGNBIT64
)) {
233 res
= ((int64_t)src1
>> 63) ^ ~SIGNBIT64
;
238 /* Unsigned saturating accumulate of signed value
240 * Op1/Rn is treated as signed
241 * Op2/Rd is treated as unsigned
243 * Explicit casting is used to ensure the correct sign extension of
244 * inputs. The result is treated as a unsigned value and saturated as such.
246 * We use a macro for the 8/16 bit cases which expects signed integers of va,
247 * vb, and vr for interim calculation and an unsigned 32 bit result value r.
250 #define USATACC(bits, shift) \
252 va = sextract32(a, shift, bits); \
253 vb = extract32(b, shift, bits); \
255 if (vr > UINT##bits##_MAX) { \
257 vr = UINT##bits##_MAX; \
258 } else if (vr < 0) { \
262 r = deposit32(r, shift, bits, vr); \
265 uint32_t HELPER(neon_uqadd_s8
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
277 uint32_t HELPER(neon_uqadd_s16
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
289 uint32_t HELPER(neon_uqadd_s32
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
291 int64_t va
= (int32_t)a
;
292 int64_t vb
= (uint32_t)b
;
293 int64_t vr
= va
+ vb
;
294 if (vr
> UINT32_MAX
) {
304 uint64_t HELPER(neon_uqadd_s64
)(CPUARMState
*env
, uint64_t a
, uint64_t b
)
308 /* We only need to look at the pattern of SIGN bits to detect
311 if (~a
& b
& ~res
& SIGNBIT64
) {
314 } else if (a
& ~b
& res
& SIGNBIT64
) {
321 /* Signed saturating accumulate of unsigned value
323 * Op1/Rn is treated as unsigned
324 * Op2/Rd is treated as signed
326 * The result is treated as a signed value and saturated as such
328 * We use a macro for the 8/16 bit cases which expects signed integers of va,
329 * vb, and vr for interim calculation and an unsigned 32 bit result value r.
332 #define SSATACC(bits, shift) \
334 va = extract32(a, shift, bits); \
335 vb = sextract32(b, shift, bits); \
337 if (vr > INT##bits##_MAX) { \
339 vr = INT##bits##_MAX; \
340 } else if (vr < INT##bits##_MIN) { \
342 vr = INT##bits##_MIN; \
344 r = deposit32(r, shift, bits, vr); \
347 uint32_t HELPER(neon_sqadd_u8
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
359 uint32_t HELPER(neon_sqadd_u16
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
372 uint32_t HELPER(neon_sqadd_u32
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
375 int64_t op1
= (uint32_t)a
;
376 int64_t op2
= (int32_t)b
;
378 if (res
> INT32_MAX
) {
381 } else if (res
< INT32_MIN
) {
388 uint64_t HELPER(neon_sqadd_u64
)(CPUARMState
*env
, uint64_t a
, uint64_t b
)
392 /* We only need to look at the pattern of SIGN bits to detect an overflow */
395 | (a
& ~b
)) & SIGNBIT64
) {
403 #define NEON_USAT(dest, src1, src2, type) do { \
404 uint32_t tmp = (uint32_t)src1 - (uint32_t)src2; \
405 if (tmp != (type)tmp) { \
411 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint8_t)
412 NEON_VOP_ENV(qsub_u8
, neon_u8
, 4)
414 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint16_t)
415 NEON_VOP_ENV(qsub_u16
, neon_u16
, 2)
419 uint32_t HELPER(neon_qsub_u32
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
421 uint32_t res
= a
- b
;
429 uint64_t HELPER(neon_qsub_u64
)(CPUARMState
*env
, uint64_t src1
, uint64_t src2
)
442 #define NEON_SSAT(dest, src1, src2, type) do { \
443 int32_t tmp = (uint32_t)src1 - (uint32_t)src2; \
444 if (tmp != (type)tmp) { \
447 tmp = (1 << (sizeof(type) * 8 - 1)) - 1; \
449 tmp = 1 << (sizeof(type) * 8 - 1); \
454 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int8_t)
455 NEON_VOP_ENV(qsub_s8
, neon_s8
, 4)
457 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int16_t)
458 NEON_VOP_ENV(qsub_s16
, neon_s16
, 2)
462 uint32_t HELPER(neon_qsub_s32
)(CPUARMState
*env
, uint32_t a
, uint32_t b
)
464 uint32_t res
= a
- b
;
465 if (((res
^ a
) & SIGNBIT
) && ((a
^ b
) & SIGNBIT
)) {
467 res
= ~(((int32_t)a
>> 31) ^ SIGNBIT
);
472 uint64_t HELPER(neon_qsub_s64
)(CPUARMState
*env
, uint64_t src1
, uint64_t src2
)
477 if (((res
^ src1
) & SIGNBIT64
) && ((src1
^ src2
) & SIGNBIT64
)) {
479 res
= ((int64_t)src1
>> 63) ^ ~SIGNBIT64
;
484 #define NEON_FN(dest, src1, src2) dest = (src1 + src2) >> 1
485 NEON_VOP(hadd_s8
, neon_s8
, 4)
486 NEON_VOP(hadd_u8
, neon_u8
, 4)
487 NEON_VOP(hadd_s16
, neon_s16
, 2)
488 NEON_VOP(hadd_u16
, neon_u16
, 2)
491 int32_t HELPER(neon_hadd_s32
)(int32_t src1
, int32_t src2
)
495 dest
= (src1
>> 1) + (src2
>> 1);
501 uint32_t HELPER(neon_hadd_u32
)(uint32_t src1
, uint32_t src2
)
505 dest
= (src1
>> 1) + (src2
>> 1);
511 #define NEON_FN(dest, src1, src2) dest = (src1 + src2 + 1) >> 1
512 NEON_VOP(rhadd_s8
, neon_s8
, 4)
513 NEON_VOP(rhadd_u8
, neon_u8
, 4)
514 NEON_VOP(rhadd_s16
, neon_s16
, 2)
515 NEON_VOP(rhadd_u16
, neon_u16
, 2)
518 int32_t HELPER(neon_rhadd_s32
)(int32_t src1
, int32_t src2
)
522 dest
= (src1
>> 1) + (src2
>> 1);
523 if ((src1
| src2
) & 1)
528 uint32_t HELPER(neon_rhadd_u32
)(uint32_t src1
, uint32_t src2
)
532 dest
= (src1
>> 1) + (src2
>> 1);
533 if ((src1
| src2
) & 1)
538 #define NEON_FN(dest, src1, src2) dest = (src1 - src2) >> 1
539 NEON_VOP(hsub_s8
, neon_s8
, 4)
540 NEON_VOP(hsub_u8
, neon_u8
, 4)
541 NEON_VOP(hsub_s16
, neon_s16
, 2)
542 NEON_VOP(hsub_u16
, neon_u16
, 2)
545 int32_t HELPER(neon_hsub_s32
)(int32_t src1
, int32_t src2
)
549 dest
= (src1
>> 1) - (src2
>> 1);
550 if ((~src1
) & src2
& 1)
555 uint32_t HELPER(neon_hsub_u32
)(uint32_t src1
, uint32_t src2
)
559 dest
= (src1
>> 1) - (src2
>> 1);
560 if ((~src1
) & src2
& 1)
565 #define NEON_FN(dest, src1, src2) dest = (src1 < src2) ? src1 : src2
566 NEON_POP(pmin_s8
, neon_s8
, 4)
567 NEON_POP(pmin_u8
, neon_u8
, 4)
568 NEON_POP(pmin_s16
, neon_s16
, 2)
569 NEON_POP(pmin_u16
, neon_u16
, 2)
572 #define NEON_FN(dest, src1, src2) dest = (src1 > src2) ? src1 : src2
573 NEON_POP(pmax_s8
, neon_s8
, 4)
574 NEON_POP(pmax_u8
, neon_u8
, 4)
575 NEON_POP(pmax_s16
, neon_s16
, 2)
576 NEON_POP(pmax_u16
, neon_u16
, 2)
579 #define NEON_FN(dest, src1, src2) do { \
581 tmp = (int8_t)src2; \
582 if (tmp >= (ssize_t)sizeof(src1) * 8 || \
583 tmp <= -(ssize_t)sizeof(src1) * 8) { \
585 } else if (tmp < 0) { \
586 dest = src1 >> -tmp; \
588 dest = src1 << tmp; \
590 NEON_VOP(shl_u16
, neon_u16
, 2)
593 #define NEON_FN(dest, src1, src2) do { \
595 tmp = (int8_t)src2; \
596 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
598 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
599 dest = src1 >> (sizeof(src1) * 8 - 1); \
600 } else if (tmp < 0) { \
601 dest = src1 >> -tmp; \
603 dest = src1 << tmp; \
605 NEON_VOP(shl_s16
, neon_s16
, 2)
608 #define NEON_FN(dest, src1, src2) do { \
610 tmp = (int8_t)src2; \
611 if ((tmp >= (ssize_t)sizeof(src1) * 8) \
612 || (tmp <= -(ssize_t)sizeof(src1) * 8)) { \
614 } else if (tmp < 0) { \
615 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
617 dest = src1 << tmp; \
619 NEON_VOP(rshl_s8
, neon_s8
, 4)
620 NEON_VOP(rshl_s16
, neon_s16
, 2)
623 /* The addition of the rounding constant may overflow, so we use an
624 * intermediate 64 bit accumulator. */
625 uint32_t HELPER(neon_rshl_s32
)(uint32_t valop
, uint32_t shiftop
)
628 int32_t val
= (int32_t)valop
;
629 int8_t shift
= (int8_t)shiftop
;
630 if ((shift
>= 32) || (shift
<= -32)) {
632 } else if (shift
< 0) {
633 int64_t big_dest
= ((int64_t)val
+ (1 << (-1 - shift
)));
634 dest
= big_dest
>> -shift
;
641 /* Handling addition overflow with 64 bit input values is more
642 * tricky than with 32 bit values. */
643 uint64_t HELPER(neon_rshl_s64
)(uint64_t valop
, uint64_t shiftop
)
645 int8_t shift
= (int8_t)shiftop
;
647 if ((shift
>= 64) || (shift
<= -64)) {
649 } else if (shift
< 0) {
650 val
>>= (-shift
- 1);
651 if (val
== INT64_MAX
) {
652 /* In this case, it means that the rounding constant is 1,
653 * and the addition would overflow. Return the actual
654 * result directly. */
655 val
= 0x4000000000000000LL
;
666 #define NEON_FN(dest, src1, src2) do { \
668 tmp = (int8_t)src2; \
669 if (tmp >= (ssize_t)sizeof(src1) * 8 || \
670 tmp < -(ssize_t)sizeof(src1) * 8) { \
672 } else if (tmp == -(ssize_t)sizeof(src1) * 8) { \
673 dest = src1 >> (-tmp - 1); \
674 } else if (tmp < 0) { \
675 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
677 dest = src1 << tmp; \
679 NEON_VOP(rshl_u8
, neon_u8
, 4)
680 NEON_VOP(rshl_u16
, neon_u16
, 2)
683 /* The addition of the rounding constant may overflow, so we use an
684 * intermediate 64 bit accumulator. */
685 uint32_t HELPER(neon_rshl_u32
)(uint32_t val
, uint32_t shiftop
)
688 int8_t shift
= (int8_t)shiftop
;
689 if (shift
>= 32 || shift
< -32) {
691 } else if (shift
== -32) {
693 } else if (shift
< 0) {
694 uint64_t big_dest
= ((uint64_t)val
+ (1 << (-1 - shift
)));
695 dest
= big_dest
>> -shift
;
702 /* Handling addition overflow with 64 bit input values is more
703 * tricky than with 32 bit values. */
704 uint64_t HELPER(neon_rshl_u64
)(uint64_t val
, uint64_t shiftop
)
706 int8_t shift
= (uint8_t)shiftop
;
707 if (shift
>= 64 || shift
< -64) {
709 } else if (shift
== -64) {
710 /* Rounding a 1-bit result just preserves that bit. */
712 } else if (shift
< 0) {
713 val
>>= (-shift
- 1);
714 if (val
== UINT64_MAX
) {
715 /* In this case, it means that the rounding constant is 1,
716 * and the addition would overflow. Return the actual
717 * result directly. */
718 val
= 0x8000000000000000ULL
;
729 #define NEON_FN(dest, src1, src2) do { \
731 tmp = (int8_t)src2; \
732 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
739 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
741 } else if (tmp < 0) { \
742 dest = src1 >> -tmp; \
744 dest = src1 << tmp; \
745 if ((dest >> tmp) != src1) { \
750 NEON_VOP_ENV(qshl_u8
, neon_u8
, 4)
751 NEON_VOP_ENV(qshl_u16
, neon_u16
, 2)
752 NEON_VOP_ENV(qshl_u32
, neon_u32
, 1)
755 uint64_t HELPER(neon_qshl_u64
)(CPUARMState
*env
, uint64_t val
, uint64_t shiftop
)
757 int8_t shift
= (int8_t)shiftop
;
763 } else if (shift
<= -64) {
765 } else if (shift
< 0) {
770 if ((val
>> shift
) != tmp
) {
778 #define NEON_FN(dest, src1, src2) do { \
780 tmp = (int8_t)src2; \
781 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
784 dest = (uint32_t)(1 << (sizeof(src1) * 8 - 1)); \
791 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
793 } else if (tmp < 0) { \
794 dest = src1 >> -tmp; \
796 dest = src1 << tmp; \
797 if ((dest >> tmp) != src1) { \
799 dest = (uint32_t)(1 << (sizeof(src1) * 8 - 1)); \
805 NEON_VOP_ENV(qshl_s8
, neon_s8
, 4)
806 NEON_VOP_ENV(qshl_s16
, neon_s16
, 2)
807 NEON_VOP_ENV(qshl_s32
, neon_s32
, 1)
810 uint64_t HELPER(neon_qshl_s64
)(CPUARMState
*env
, uint64_t valop
, uint64_t shiftop
)
812 int8_t shift
= (uint8_t)shiftop
;
817 val
= (val
>> 63) ^ ~SIGNBIT64
;
819 } else if (shift
<= -64) {
821 } else if (shift
< 0) {
826 if ((val
>> shift
) != tmp
) {
828 val
= (tmp
>> 63) ^ ~SIGNBIT64
;
834 #define NEON_FN(dest, src1, src2) do { \
835 if (src1 & (1 << (sizeof(src1) * 8 - 1))) { \
840 tmp = (int8_t)src2; \
841 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
848 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
850 } else if (tmp < 0) { \
851 dest = src1 >> -tmp; \
853 dest = src1 << tmp; \
854 if ((dest >> tmp) != src1) { \
860 NEON_VOP_ENV(qshlu_s8
, neon_u8
, 4)
861 NEON_VOP_ENV(qshlu_s16
, neon_u16
, 2)
864 uint32_t HELPER(neon_qshlu_s32
)(CPUARMState
*env
, uint32_t valop
, uint32_t shiftop
)
866 if ((int32_t)valop
< 0) {
870 return helper_neon_qshl_u32(env
, valop
, shiftop
);
873 uint64_t HELPER(neon_qshlu_s64
)(CPUARMState
*env
, uint64_t valop
, uint64_t shiftop
)
875 if ((int64_t)valop
< 0) {
879 return helper_neon_qshl_u64(env
, valop
, shiftop
);
882 #define NEON_FN(dest, src1, src2) do { \
884 tmp = (int8_t)src2; \
885 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
892 } else if (tmp < -(ssize_t)sizeof(src1) * 8) { \
894 } else if (tmp == -(ssize_t)sizeof(src1) * 8) { \
895 dest = src1 >> (sizeof(src1) * 8 - 1); \
896 } else if (tmp < 0) { \
897 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
899 dest = src1 << tmp; \
900 if ((dest >> tmp) != src1) { \
905 NEON_VOP_ENV(qrshl_u8
, neon_u8
, 4)
906 NEON_VOP_ENV(qrshl_u16
, neon_u16
, 2)
909 /* The addition of the rounding constant may overflow, so we use an
910 * intermediate 64 bit accumulator. */
911 uint32_t HELPER(neon_qrshl_u32
)(CPUARMState
*env
, uint32_t val
, uint32_t shiftop
)
914 int8_t shift
= (int8_t)shiftop
;
922 } else if (shift
< -32) {
924 } else if (shift
== -32) {
926 } else if (shift
< 0) {
927 uint64_t big_dest
= ((uint64_t)val
+ (1 << (-1 - shift
)));
928 dest
= big_dest
>> -shift
;
931 if ((dest
>> shift
) != val
) {
939 /* Handling addition overflow with 64 bit input values is more
940 * tricky than with 32 bit values. */
941 uint64_t HELPER(neon_qrshl_u64
)(CPUARMState
*env
, uint64_t val
, uint64_t shiftop
)
943 int8_t shift
= (int8_t)shiftop
;
949 } else if (shift
< -64) {
951 } else if (shift
== -64) {
953 } else if (shift
< 0) {
954 val
>>= (-shift
- 1);
955 if (val
== UINT64_MAX
) {
956 /* In this case, it means that the rounding constant is 1,
957 * and the addition would overflow. Return the actual
958 * result directly. */
959 val
= 0x8000000000000000ULL
;
967 if ((val
>> shift
) != tmp
) {
975 #define NEON_FN(dest, src1, src2) do { \
977 tmp = (int8_t)src2; \
978 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
981 dest = (typeof(dest))(1 << (sizeof(src1) * 8 - 1)); \
988 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
990 } else if (tmp < 0) { \
991 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
993 dest = src1 << tmp; \
994 if ((dest >> tmp) != src1) { \
996 dest = (uint32_t)(1 << (sizeof(src1) * 8 - 1)); \
1002 NEON_VOP_ENV(qrshl_s8
, neon_s8
, 4)
1003 NEON_VOP_ENV(qrshl_s16
, neon_s16
, 2)
1006 /* The addition of the rounding constant may overflow, so we use an
1007 * intermediate 64 bit accumulator. */
1008 uint32_t HELPER(neon_qrshl_s32
)(CPUARMState
*env
, uint32_t valop
, uint32_t shiftop
)
1011 int32_t val
= (int32_t)valop
;
1012 int8_t shift
= (int8_t)shiftop
;
1016 dest
= (val
>> 31) ^ ~SIGNBIT
;
1020 } else if (shift
<= -32) {
1022 } else if (shift
< 0) {
1023 int64_t big_dest
= ((int64_t)val
+ (1 << (-1 - shift
)));
1024 dest
= big_dest
>> -shift
;
1026 dest
= val
<< shift
;
1027 if ((dest
>> shift
) != val
) {
1029 dest
= (val
>> 31) ^ ~SIGNBIT
;
1035 /* Handling addition overflow with 64 bit input values is more
1036 * tricky than with 32 bit values. */
1037 uint64_t HELPER(neon_qrshl_s64
)(CPUARMState
*env
, uint64_t valop
, uint64_t shiftop
)
1039 int8_t shift
= (uint8_t)shiftop
;
1040 int64_t val
= valop
;
1045 val
= (val
>> 63) ^ ~SIGNBIT64
;
1047 } else if (shift
<= -64) {
1049 } else if (shift
< 0) {
1050 val
>>= (-shift
- 1);
1051 if (val
== INT64_MAX
) {
1052 /* In this case, it means that the rounding constant is 1,
1053 * and the addition would overflow. Return the actual
1054 * result directly. */
1055 val
= 0x4000000000000000ULL
;
1063 if ((val
>> shift
) != tmp
) {
1065 val
= (tmp
>> 63) ^ ~SIGNBIT64
;
1071 uint32_t HELPER(neon_add_u8
)(uint32_t a
, uint32_t b
)
1074 mask
= (a
^ b
) & 0x80808080u
;
1077 return (a
+ b
) ^ mask
;
1080 uint32_t HELPER(neon_add_u16
)(uint32_t a
, uint32_t b
)
1083 mask
= (a
^ b
) & 0x80008000u
;
1086 return (a
+ b
) ^ mask
;
1089 #define NEON_FN(dest, src1, src2) dest = src1 + src2
1090 NEON_POP(padd_u8
, neon_u8
, 4)
1091 NEON_POP(padd_u16
, neon_u16
, 2)
1094 #define NEON_FN(dest, src1, src2) dest = src1 - src2
1095 NEON_VOP(sub_u8
, neon_u8
, 4)
1096 NEON_VOP(sub_u16
, neon_u16
, 2)
1099 #define NEON_FN(dest, src1, src2) dest = src1 * src2
1100 NEON_VOP(mul_u8
, neon_u8
, 4)
1101 NEON_VOP(mul_u16
, neon_u16
, 2)
1104 #define NEON_FN(dest, src1, src2) dest = (src1 & src2) ? -1 : 0
1105 NEON_VOP(tst_u8
, neon_u8
, 4)
1106 NEON_VOP(tst_u16
, neon_u16
, 2)
1107 NEON_VOP(tst_u32
, neon_u32
, 1)
1110 /* Count Leading Sign/Zero Bits. */
1111 static inline int do_clz8(uint8_t x
)
1119 static inline int do_clz16(uint16_t x
)
1122 for (n
= 16; x
; n
--)
1127 #define NEON_FN(dest, src, dummy) dest = do_clz8(src)
1128 NEON_VOP1(clz_u8
, neon_u8
, 4)
1131 #define NEON_FN(dest, src, dummy) dest = do_clz16(src)
1132 NEON_VOP1(clz_u16
, neon_u16
, 2)
1135 #define NEON_FN(dest, src, dummy) dest = do_clz8((src < 0) ? ~src : src) - 1
1136 NEON_VOP1(cls_s8
, neon_s8
, 4)
1139 #define NEON_FN(dest, src, dummy) dest = do_clz16((src < 0) ? ~src : src) - 1
1140 NEON_VOP1(cls_s16
, neon_s16
, 2)
1143 uint32_t HELPER(neon_cls_s32
)(uint32_t x
)
1148 for (count
= 32; x
; count
--)
1154 uint32_t HELPER(neon_cnt_u8
)(uint32_t x
)
1156 x
= (x
& 0x55555555) + ((x
>> 1) & 0x55555555);
1157 x
= (x
& 0x33333333) + ((x
>> 2) & 0x33333333);
1158 x
= (x
& 0x0f0f0f0f) + ((x
>> 4) & 0x0f0f0f0f);
1162 /* Reverse bits in each 8 bit word */
1163 uint32_t HELPER(neon_rbit_u8
)(uint32_t x
)
1165 x
= ((x
& 0xf0f0f0f0) >> 4)
1166 | ((x
& 0x0f0f0f0f) << 4);
1167 x
= ((x
& 0x88888888) >> 3)
1168 | ((x
& 0x44444444) >> 1)
1169 | ((x
& 0x22222222) << 1)
1170 | ((x
& 0x11111111) << 3);
1174 #define NEON_QDMULH16(dest, src1, src2, round) do { \
1175 uint32_t tmp = (int32_t)(int16_t) src1 * (int16_t) src2; \
1176 if ((tmp ^ (tmp << 1)) & SIGNBIT) { \
1178 tmp = (tmp >> 31) ^ ~SIGNBIT; \
1183 int32_t old = tmp; \
1185 if ((int32_t)tmp < old) { \
1187 tmp = SIGNBIT - 1; \
1192 #define NEON_FN(dest, src1, src2) NEON_QDMULH16(dest, src1, src2, 0)
1193 NEON_VOP_ENV(qdmulh_s16
, neon_s16
, 2)
1195 #define NEON_FN(dest, src1, src2) NEON_QDMULH16(dest, src1, src2, 1)
1196 NEON_VOP_ENV(qrdmulh_s16
, neon_s16
, 2)
1198 #undef NEON_QDMULH16
1200 #define NEON_QDMULH32(dest, src1, src2, round) do { \
1201 uint64_t tmp = (int64_t)(int32_t) src1 * (int32_t) src2; \
1202 if ((tmp ^ (tmp << 1)) & SIGNBIT64) { \
1204 tmp = (tmp >> 63) ^ ~SIGNBIT64; \
1209 int64_t old = tmp; \
1210 tmp += (int64_t)1 << 31; \
1211 if ((int64_t)tmp < old) { \
1213 tmp = SIGNBIT64 - 1; \
1218 #define NEON_FN(dest, src1, src2) NEON_QDMULH32(dest, src1, src2, 0)
1219 NEON_VOP_ENV(qdmulh_s32
, neon_s32
, 1)
1221 #define NEON_FN(dest, src1, src2) NEON_QDMULH32(dest, src1, src2, 1)
1222 NEON_VOP_ENV(qrdmulh_s32
, neon_s32
, 1)
1224 #undef NEON_QDMULH32
1226 uint32_t HELPER(neon_narrow_u8
)(uint64_t x
)
1228 return (x
& 0xffu
) | ((x
>> 8) & 0xff00u
) | ((x
>> 16) & 0xff0000u
)
1229 | ((x
>> 24) & 0xff000000u
);
1232 uint32_t HELPER(neon_narrow_u16
)(uint64_t x
)
1234 return (x
& 0xffffu
) | ((x
>> 16) & 0xffff0000u
);
1237 uint32_t HELPER(neon_narrow_high_u8
)(uint64_t x
)
1239 return ((x
>> 8) & 0xff) | ((x
>> 16) & 0xff00)
1240 | ((x
>> 24) & 0xff0000) | ((x
>> 32) & 0xff000000);
1243 uint32_t HELPER(neon_narrow_high_u16
)(uint64_t x
)
1245 return ((x
>> 16) & 0xffff) | ((x
>> 32) & 0xffff0000);
1248 uint32_t HELPER(neon_narrow_round_high_u8
)(uint64_t x
)
1250 x
&= 0xff80ff80ff80ff80ull
;
1251 x
+= 0x0080008000800080ull
;
1252 return ((x
>> 8) & 0xff) | ((x
>> 16) & 0xff00)
1253 | ((x
>> 24) & 0xff0000) | ((x
>> 32) & 0xff000000);
1256 uint32_t HELPER(neon_narrow_round_high_u16
)(uint64_t x
)
1258 x
&= 0xffff8000ffff8000ull
;
1259 x
+= 0x0000800000008000ull
;
1260 return ((x
>> 16) & 0xffff) | ((x
>> 32) & 0xffff0000);
1263 uint32_t HELPER(neon_unarrow_sat8
)(CPUARMState
*env
, uint64_t x
)
1279 res |= (uint32_t)d << (n / 2); \
1290 uint32_t HELPER(neon_narrow_sat_u8
)(CPUARMState
*env
, uint64_t x
)
1303 res |= (uint32_t)d << (n / 2);
1313 uint32_t HELPER(neon_narrow_sat_s8
)(CPUARMState
*env
, uint64_t x
)
1320 if (s != (int8_t)s) { \
1321 d = (s >> 15) ^ 0x7f; \
1326 res |= (uint32_t)d << (n / 2);
1336 uint32_t HELPER(neon_unarrow_sat16
)(CPUARMState
*env
, uint64_t x
)
1341 if (low
& 0x80000000) {
1344 } else if (low
> 0xffff) {
1349 if (high
& 0x80000000) {
1352 } else if (high
> 0xffff) {
1356 return low
| (high
<< 16);
1359 uint32_t HELPER(neon_narrow_sat_u16
)(CPUARMState
*env
, uint64_t x
)
1369 if (high
> 0xffff) {
1373 return low
| (high
<< 16);
1376 uint32_t HELPER(neon_narrow_sat_s16
)(CPUARMState
*env
, uint64_t x
)
1381 if (low
!= (int16_t)low
) {
1382 low
= (low
>> 31) ^ 0x7fff;
1386 if (high
!= (int16_t)high
) {
1387 high
= (high
>> 31) ^ 0x7fff;
1390 return (uint16_t)low
| (high
<< 16);
1393 uint32_t HELPER(neon_unarrow_sat32
)(CPUARMState
*env
, uint64_t x
)
1395 if (x
& 0x8000000000000000ull
) {
1399 if (x
> 0xffffffffu
) {
1406 uint32_t HELPER(neon_narrow_sat_u32
)(CPUARMState
*env
, uint64_t x
)
1408 if (x
> 0xffffffffu
) {
1415 uint32_t HELPER(neon_narrow_sat_s32
)(CPUARMState
*env
, uint64_t x
)
1417 if ((int64_t)x
!= (int32_t)x
) {
1419 return ((int64_t)x
>> 63) ^ 0x7fffffff;
1424 uint64_t HELPER(neon_widen_u8
)(uint32_t x
)
1429 tmp
= (uint8_t)(x
>> 8);
1431 tmp
= (uint8_t)(x
>> 16);
1433 tmp
= (uint8_t)(x
>> 24);
1438 uint64_t HELPER(neon_widen_s8
)(uint32_t x
)
1442 ret
= (uint16_t)(int8_t)x
;
1443 tmp
= (uint16_t)(int8_t)(x
>> 8);
1445 tmp
= (uint16_t)(int8_t)(x
>> 16);
1447 tmp
= (uint16_t)(int8_t)(x
>> 24);
1452 uint64_t HELPER(neon_widen_u16
)(uint32_t x
)
1454 uint64_t high
= (uint16_t)(x
>> 16);
1455 return ((uint16_t)x
) | (high
<< 32);
1458 uint64_t HELPER(neon_widen_s16
)(uint32_t x
)
1460 uint64_t high
= (int16_t)(x
>> 16);
1461 return ((uint32_t)(int16_t)x
) | (high
<< 32);
1464 uint64_t HELPER(neon_addl_u16
)(uint64_t a
, uint64_t b
)
1467 mask
= (a
^ b
) & 0x8000800080008000ull
;
1468 a
&= ~0x8000800080008000ull
;
1469 b
&= ~0x8000800080008000ull
;
1470 return (a
+ b
) ^ mask
;
1473 uint64_t HELPER(neon_addl_u32
)(uint64_t a
, uint64_t b
)
1476 mask
= (a
^ b
) & 0x8000000080000000ull
;
1477 a
&= ~0x8000000080000000ull
;
1478 b
&= ~0x8000000080000000ull
;
1479 return (a
+ b
) ^ mask
;
1482 uint64_t HELPER(neon_paddl_u16
)(uint64_t a
, uint64_t b
)
1487 tmp
= a
& 0x0000ffff0000ffffull
;
1488 tmp
+= (a
>> 16) & 0x0000ffff0000ffffull
;
1489 tmp2
= b
& 0xffff0000ffff0000ull
;
1490 tmp2
+= (b
<< 16) & 0xffff0000ffff0000ull
;
1491 return ( tmp
& 0xffff)
1492 | ((tmp
>> 16) & 0xffff0000ull
)
1493 | ((tmp2
<< 16) & 0xffff00000000ull
)
1494 | ( tmp2
& 0xffff000000000000ull
);
1497 uint64_t HELPER(neon_paddl_u32
)(uint64_t a
, uint64_t b
)
1499 uint32_t low
= a
+ (a
>> 32);
1500 uint32_t high
= b
+ (b
>> 32);
1501 return low
+ ((uint64_t)high
<< 32);
1504 uint64_t HELPER(neon_subl_u16
)(uint64_t a
, uint64_t b
)
1507 mask
= (a
^ ~b
) & 0x8000800080008000ull
;
1508 a
|= 0x8000800080008000ull
;
1509 b
&= ~0x8000800080008000ull
;
1510 return (a
- b
) ^ mask
;
1513 uint64_t HELPER(neon_subl_u32
)(uint64_t a
, uint64_t b
)
1516 mask
= (a
^ ~b
) & 0x8000000080000000ull
;
1517 a
|= 0x8000000080000000ull
;
1518 b
&= ~0x8000000080000000ull
;
1519 return (a
- b
) ^ mask
;
1522 uint64_t HELPER(neon_addl_saturate_s32
)(CPUARMState
*env
, uint64_t a
, uint64_t b
)
1530 if (((low
^ x
) & SIGNBIT
) && !((x
^ y
) & SIGNBIT
)) {
1532 low
= ((int32_t)x
>> 31) ^ ~SIGNBIT
;
1537 if (((high
^ x
) & SIGNBIT
) && !((x
^ y
) & SIGNBIT
)) {
1539 high
= ((int32_t)x
>> 31) ^ ~SIGNBIT
;
1541 return low
| ((uint64_t)high
<< 32);
1544 uint64_t HELPER(neon_addl_saturate_s64
)(CPUARMState
*env
, uint64_t a
, uint64_t b
)
1549 if (((result
^ a
) & SIGNBIT64
) && !((a
^ b
) & SIGNBIT64
)) {
1551 result
= ((int64_t)a
>> 63) ^ ~SIGNBIT64
;
1556 /* We have to do the arithmetic in a larger type than
1557 * the input type, because for example with a signed 32 bit
1558 * op the absolute difference can overflow a signed 32 bit value.
1560 #define DO_ABD(dest, x, y, intype, arithtype) do { \
1561 arithtype tmp_x = (intype)(x); \
1562 arithtype tmp_y = (intype)(y); \
1563 dest = ((tmp_x > tmp_y) ? tmp_x - tmp_y : tmp_y - tmp_x); \
1566 uint64_t HELPER(neon_abdl_u16
)(uint32_t a
, uint32_t b
)
1570 DO_ABD(result
, a
, b
, uint8_t, uint32_t);
1571 DO_ABD(tmp
, a
>> 8, b
>> 8, uint8_t, uint32_t);
1572 result
|= tmp
<< 16;
1573 DO_ABD(tmp
, a
>> 16, b
>> 16, uint8_t, uint32_t);
1574 result
|= tmp
<< 32;
1575 DO_ABD(tmp
, a
>> 24, b
>> 24, uint8_t, uint32_t);
1576 result
|= tmp
<< 48;
1580 uint64_t HELPER(neon_abdl_s16
)(uint32_t a
, uint32_t b
)
1584 DO_ABD(result
, a
, b
, int8_t, int32_t);
1585 DO_ABD(tmp
, a
>> 8, b
>> 8, int8_t, int32_t);
1586 result
|= tmp
<< 16;
1587 DO_ABD(tmp
, a
>> 16, b
>> 16, int8_t, int32_t);
1588 result
|= tmp
<< 32;
1589 DO_ABD(tmp
, a
>> 24, b
>> 24, int8_t, int32_t);
1590 result
|= tmp
<< 48;
1594 uint64_t HELPER(neon_abdl_u32
)(uint32_t a
, uint32_t b
)
1598 DO_ABD(result
, a
, b
, uint16_t, uint32_t);
1599 DO_ABD(tmp
, a
>> 16, b
>> 16, uint16_t, uint32_t);
1600 return result
| (tmp
<< 32);
1603 uint64_t HELPER(neon_abdl_s32
)(uint32_t a
, uint32_t b
)
1607 DO_ABD(result
, a
, b
, int16_t, int32_t);
1608 DO_ABD(tmp
, a
>> 16, b
>> 16, int16_t, int32_t);
1609 return result
| (tmp
<< 32);
1612 uint64_t HELPER(neon_abdl_u64
)(uint32_t a
, uint32_t b
)
1615 DO_ABD(result
, a
, b
, uint32_t, uint64_t);
1619 uint64_t HELPER(neon_abdl_s64
)(uint32_t a
, uint32_t b
)
1622 DO_ABD(result
, a
, b
, int32_t, int64_t);
1627 /* Widening multiply. Named type is the source type. */
1628 #define DO_MULL(dest, x, y, type1, type2) do { \
1631 dest = (type2)((type2)tmp_x * (type2)tmp_y); \
1634 uint64_t HELPER(neon_mull_u8
)(uint32_t a
, uint32_t b
)
1639 DO_MULL(result
, a
, b
, uint8_t, uint16_t);
1640 DO_MULL(tmp
, a
>> 8, b
>> 8, uint8_t, uint16_t);
1641 result
|= tmp
<< 16;
1642 DO_MULL(tmp
, a
>> 16, b
>> 16, uint8_t, uint16_t);
1643 result
|= tmp
<< 32;
1644 DO_MULL(tmp
, a
>> 24, b
>> 24, uint8_t, uint16_t);
1645 result
|= tmp
<< 48;
1649 uint64_t HELPER(neon_mull_s8
)(uint32_t a
, uint32_t b
)
1654 DO_MULL(result
, a
, b
, int8_t, uint16_t);
1655 DO_MULL(tmp
, a
>> 8, b
>> 8, int8_t, uint16_t);
1656 result
|= tmp
<< 16;
1657 DO_MULL(tmp
, a
>> 16, b
>> 16, int8_t, uint16_t);
1658 result
|= tmp
<< 32;
1659 DO_MULL(tmp
, a
>> 24, b
>> 24, int8_t, uint16_t);
1660 result
|= tmp
<< 48;
1664 uint64_t HELPER(neon_mull_u16
)(uint32_t a
, uint32_t b
)
1669 DO_MULL(result
, a
, b
, uint16_t, uint32_t);
1670 DO_MULL(tmp
, a
>> 16, b
>> 16, uint16_t, uint32_t);
1671 return result
| (tmp
<< 32);
1674 uint64_t HELPER(neon_mull_s16
)(uint32_t a
, uint32_t b
)
1679 DO_MULL(result
, a
, b
, int16_t, uint32_t);
1680 DO_MULL(tmp
, a
>> 16, b
>> 16, int16_t, uint32_t);
1681 return result
| (tmp
<< 32);
1684 uint64_t HELPER(neon_negl_u16
)(uint64_t x
)
1688 result
= (uint16_t)-x
;
1690 result
|= (uint64_t)tmp
<< 16;
1692 result
|= (uint64_t)tmp
<< 32;
1694 result
|= (uint64_t)tmp
<< 48;
1698 uint64_t HELPER(neon_negl_u32
)(uint64_t x
)
1701 uint32_t high
= -(x
>> 32);
1702 return low
| ((uint64_t)high
<< 32);
1705 /* Saturating sign manipulation. */
1706 /* ??? Make these use NEON_VOP1 */
1707 #define DO_QABS8(x) do { \
1708 if (x == (int8_t)0x80) { \
1711 } else if (x < 0) { \
1714 uint32_t HELPER(neon_qabs_s8
)(CPUARMState
*env
, uint32_t x
)
1717 NEON_UNPACK(neon_s8
, vec
, x
);
1722 NEON_PACK(neon_s8
, x
, vec
);
1727 #define DO_QNEG8(x) do { \
1728 if (x == (int8_t)0x80) { \
1734 uint32_t HELPER(neon_qneg_s8
)(CPUARMState
*env
, uint32_t x
)
1737 NEON_UNPACK(neon_s8
, vec
, x
);
1742 NEON_PACK(neon_s8
, x
, vec
);
1747 #define DO_QABS16(x) do { \
1748 if (x == (int16_t)0x8000) { \
1751 } else if (x < 0) { \
1754 uint32_t HELPER(neon_qabs_s16
)(CPUARMState
*env
, uint32_t x
)
1757 NEON_UNPACK(neon_s16
, vec
, x
);
1760 NEON_PACK(neon_s16
, x
, vec
);
1765 #define DO_QNEG16(x) do { \
1766 if (x == (int16_t)0x8000) { \
1772 uint32_t HELPER(neon_qneg_s16
)(CPUARMState
*env
, uint32_t x
)
1775 NEON_UNPACK(neon_s16
, vec
, x
);
1778 NEON_PACK(neon_s16
, x
, vec
);
1783 uint32_t HELPER(neon_qabs_s32
)(CPUARMState
*env
, uint32_t x
)
1788 } else if ((int32_t)x
< 0) {
1794 uint32_t HELPER(neon_qneg_s32
)(CPUARMState
*env
, uint32_t x
)
1805 uint64_t HELPER(neon_qabs_s64
)(CPUARMState
*env
, uint64_t x
)
1807 if (x
== SIGNBIT64
) {
1810 } else if ((int64_t)x
< 0) {
1816 uint64_t HELPER(neon_qneg_s64
)(CPUARMState
*env
, uint64_t x
)
1818 if (x
== SIGNBIT64
) {
1827 /* NEON Float helpers. */
1829 /* Floating point comparisons produce an integer result.
1830 * Note that EQ doesn't signal InvalidOp for QNaNs but GE and GT do.
1831 * Softfloat routines return 0/1, which we convert to the 0/-1 Neon requires.
1833 uint32_t HELPER(neon_ceq_f32
)(uint32_t a
, uint32_t b
, void *fpstp
)
1835 float_status
*fpst
= fpstp
;
1836 return -float32_eq_quiet(make_float32(a
), make_float32(b
), fpst
);
1839 uint32_t HELPER(neon_cge_f32
)(uint32_t a
, uint32_t b
, void *fpstp
)
1841 float_status
*fpst
= fpstp
;
1842 return -float32_le(make_float32(b
), make_float32(a
), fpst
);
1845 uint32_t HELPER(neon_cgt_f32
)(uint32_t a
, uint32_t b
, void *fpstp
)
1847 float_status
*fpst
= fpstp
;
1848 return -float32_lt(make_float32(b
), make_float32(a
), fpst
);
1851 uint32_t HELPER(neon_acge_f32
)(uint32_t a
, uint32_t b
, void *fpstp
)
1853 float_status
*fpst
= fpstp
;
1854 float32 f0
= float32_abs(make_float32(a
));
1855 float32 f1
= float32_abs(make_float32(b
));
1856 return -float32_le(f1
, f0
, fpst
);
1859 uint32_t HELPER(neon_acgt_f32
)(uint32_t a
, uint32_t b
, void *fpstp
)
1861 float_status
*fpst
= fpstp
;
1862 float32 f0
= float32_abs(make_float32(a
));
1863 float32 f1
= float32_abs(make_float32(b
));
1864 return -float32_lt(f1
, f0
, fpst
);
1867 uint64_t HELPER(neon_acge_f64
)(uint64_t a
, uint64_t b
, void *fpstp
)
1869 float_status
*fpst
= fpstp
;
1870 float64 f0
= float64_abs(make_float64(a
));
1871 float64 f1
= float64_abs(make_float64(b
));
1872 return -float64_le(f1
, f0
, fpst
);
1875 uint64_t HELPER(neon_acgt_f64
)(uint64_t a
, uint64_t b
, void *fpstp
)
1877 float_status
*fpst
= fpstp
;
1878 float64 f0
= float64_abs(make_float64(a
));
1879 float64 f1
= float64_abs(make_float64(b
));
1880 return -float64_lt(f1
, f0
, fpst
);
1883 #define ELEM(V, N, SIZE) (((V) >> ((N) * (SIZE))) & ((1ull << (SIZE)) - 1))
1885 void HELPER(neon_qunzip8
)(void *vd
, void *vm
)
1887 uint64_t *rd
= vd
, *rm
= vm
;
1888 uint64_t zd0
= rd
[0], zd1
= rd
[1];
1889 uint64_t zm0
= rm
[0], zm1
= rm
[1];
1891 uint64_t d0
= ELEM(zd0
, 0, 8) | (ELEM(zd0
, 2, 8) << 8)
1892 | (ELEM(zd0
, 4, 8) << 16) | (ELEM(zd0
, 6, 8) << 24)
1893 | (ELEM(zd1
, 0, 8) << 32) | (ELEM(zd1
, 2, 8) << 40)
1894 | (ELEM(zd1
, 4, 8) << 48) | (ELEM(zd1
, 6, 8) << 56);
1895 uint64_t d1
= ELEM(zm0
, 0, 8) | (ELEM(zm0
, 2, 8) << 8)
1896 | (ELEM(zm0
, 4, 8) << 16) | (ELEM(zm0
, 6, 8) << 24)
1897 | (ELEM(zm1
, 0, 8) << 32) | (ELEM(zm1
, 2, 8) << 40)
1898 | (ELEM(zm1
, 4, 8) << 48) | (ELEM(zm1
, 6, 8) << 56);
1899 uint64_t m0
= ELEM(zd0
, 1, 8) | (ELEM(zd0
, 3, 8) << 8)
1900 | (ELEM(zd0
, 5, 8) << 16) | (ELEM(zd0
, 7, 8) << 24)
1901 | (ELEM(zd1
, 1, 8) << 32) | (ELEM(zd1
, 3, 8) << 40)
1902 | (ELEM(zd1
, 5, 8) << 48) | (ELEM(zd1
, 7, 8) << 56);
1903 uint64_t m1
= ELEM(zm0
, 1, 8) | (ELEM(zm0
, 3, 8) << 8)
1904 | (ELEM(zm0
, 5, 8) << 16) | (ELEM(zm0
, 7, 8) << 24)
1905 | (ELEM(zm1
, 1, 8) << 32) | (ELEM(zm1
, 3, 8) << 40)
1906 | (ELEM(zm1
, 5, 8) << 48) | (ELEM(zm1
, 7, 8) << 56);
1914 void HELPER(neon_qunzip16
)(void *vd
, void *vm
)
1916 uint64_t *rd
= vd
, *rm
= vm
;
1917 uint64_t zd0
= rd
[0], zd1
= rd
[1];
1918 uint64_t zm0
= rm
[0], zm1
= rm
[1];
1920 uint64_t d0
= ELEM(zd0
, 0, 16) | (ELEM(zd0
, 2, 16) << 16)
1921 | (ELEM(zd1
, 0, 16) << 32) | (ELEM(zd1
, 2, 16) << 48);
1922 uint64_t d1
= ELEM(zm0
, 0, 16) | (ELEM(zm0
, 2, 16) << 16)
1923 | (ELEM(zm1
, 0, 16) << 32) | (ELEM(zm1
, 2, 16) << 48);
1924 uint64_t m0
= ELEM(zd0
, 1, 16) | (ELEM(zd0
, 3, 16) << 16)
1925 | (ELEM(zd1
, 1, 16) << 32) | (ELEM(zd1
, 3, 16) << 48);
1926 uint64_t m1
= ELEM(zm0
, 1, 16) | (ELEM(zm0
, 3, 16) << 16)
1927 | (ELEM(zm1
, 1, 16) << 32) | (ELEM(zm1
, 3, 16) << 48);
1935 void HELPER(neon_qunzip32
)(void *vd
, void *vm
)
1937 uint64_t *rd
= vd
, *rm
= vm
;
1938 uint64_t zd0
= rd
[0], zd1
= rd
[1];
1939 uint64_t zm0
= rm
[0], zm1
= rm
[1];
1941 uint64_t d0
= ELEM(zd0
, 0, 32) | (ELEM(zd1
, 0, 32) << 32);
1942 uint64_t d1
= ELEM(zm0
, 0, 32) | (ELEM(zm1
, 0, 32) << 32);
1943 uint64_t m0
= ELEM(zd0
, 1, 32) | (ELEM(zd1
, 1, 32) << 32);
1944 uint64_t m1
= ELEM(zm0
, 1, 32) | (ELEM(zm1
, 1, 32) << 32);
1952 void HELPER(neon_unzip8
)(void *vd
, void *vm
)
1954 uint64_t *rd
= vd
, *rm
= vm
;
1955 uint64_t zd
= rd
[0], zm
= rm
[0];
1957 uint64_t d0
= ELEM(zd
, 0, 8) | (ELEM(zd
, 2, 8) << 8)
1958 | (ELEM(zd
, 4, 8) << 16) | (ELEM(zd
, 6, 8) << 24)
1959 | (ELEM(zm
, 0, 8) << 32) | (ELEM(zm
, 2, 8) << 40)
1960 | (ELEM(zm
, 4, 8) << 48) | (ELEM(zm
, 6, 8) << 56);
1961 uint64_t m0
= ELEM(zd
, 1, 8) | (ELEM(zd
, 3, 8) << 8)
1962 | (ELEM(zd
, 5, 8) << 16) | (ELEM(zd
, 7, 8) << 24)
1963 | (ELEM(zm
, 1, 8) << 32) | (ELEM(zm
, 3, 8) << 40)
1964 | (ELEM(zm
, 5, 8) << 48) | (ELEM(zm
, 7, 8) << 56);
1970 void HELPER(neon_unzip16
)(void *vd
, void *vm
)
1972 uint64_t *rd
= vd
, *rm
= vm
;
1973 uint64_t zd
= rd
[0], zm
= rm
[0];
1975 uint64_t d0
= ELEM(zd
, 0, 16) | (ELEM(zd
, 2, 16) << 16)
1976 | (ELEM(zm
, 0, 16) << 32) | (ELEM(zm
, 2, 16) << 48);
1977 uint64_t m0
= ELEM(zd
, 1, 16) | (ELEM(zd
, 3, 16) << 16)
1978 | (ELEM(zm
, 1, 16) << 32) | (ELEM(zm
, 3, 16) << 48);
1984 void HELPER(neon_qzip8
)(void *vd
, void *vm
)
1986 uint64_t *rd
= vd
, *rm
= vm
;
1987 uint64_t zd0
= rd
[0], zd1
= rd
[1];
1988 uint64_t zm0
= rm
[0], zm1
= rm
[1];
1990 uint64_t d0
= ELEM(zd0
, 0, 8) | (ELEM(zm0
, 0, 8) << 8)
1991 | (ELEM(zd0
, 1, 8) << 16) | (ELEM(zm0
, 1, 8) << 24)
1992 | (ELEM(zd0
, 2, 8) << 32) | (ELEM(zm0
, 2, 8) << 40)
1993 | (ELEM(zd0
, 3, 8) << 48) | (ELEM(zm0
, 3, 8) << 56);
1994 uint64_t d1
= ELEM(zd0
, 4, 8) | (ELEM(zm0
, 4, 8) << 8)
1995 | (ELEM(zd0
, 5, 8) << 16) | (ELEM(zm0
, 5, 8) << 24)
1996 | (ELEM(zd0
, 6, 8) << 32) | (ELEM(zm0
, 6, 8) << 40)
1997 | (ELEM(zd0
, 7, 8) << 48) | (ELEM(zm0
, 7, 8) << 56);
1998 uint64_t m0
= ELEM(zd1
, 0, 8) | (ELEM(zm1
, 0, 8) << 8)
1999 | (ELEM(zd1
, 1, 8) << 16) | (ELEM(zm1
, 1, 8) << 24)
2000 | (ELEM(zd1
, 2, 8) << 32) | (ELEM(zm1
, 2, 8) << 40)
2001 | (ELEM(zd1
, 3, 8) << 48) | (ELEM(zm1
, 3, 8) << 56);
2002 uint64_t m1
= ELEM(zd1
, 4, 8) | (ELEM(zm1
, 4, 8) << 8)
2003 | (ELEM(zd1
, 5, 8) << 16) | (ELEM(zm1
, 5, 8) << 24)
2004 | (ELEM(zd1
, 6, 8) << 32) | (ELEM(zm1
, 6, 8) << 40)
2005 | (ELEM(zd1
, 7, 8) << 48) | (ELEM(zm1
, 7, 8) << 56);
2013 void HELPER(neon_qzip16
)(void *vd
, void *vm
)
2015 uint64_t *rd
= vd
, *rm
= vm
;
2016 uint64_t zd0
= rd
[0], zd1
= rd
[1];
2017 uint64_t zm0
= rm
[0], zm1
= rm
[1];
2019 uint64_t d0
= ELEM(zd0
, 0, 16) | (ELEM(zm0
, 0, 16) << 16)
2020 | (ELEM(zd0
, 1, 16) << 32) | (ELEM(zm0
, 1, 16) << 48);
2021 uint64_t d1
= ELEM(zd0
, 2, 16) | (ELEM(zm0
, 2, 16) << 16)
2022 | (ELEM(zd0
, 3, 16) << 32) | (ELEM(zm0
, 3, 16) << 48);
2023 uint64_t m0
= ELEM(zd1
, 0, 16) | (ELEM(zm1
, 0, 16) << 16)
2024 | (ELEM(zd1
, 1, 16) << 32) | (ELEM(zm1
, 1, 16) << 48);
2025 uint64_t m1
= ELEM(zd1
, 2, 16) | (ELEM(zm1
, 2, 16) << 16)
2026 | (ELEM(zd1
, 3, 16) << 32) | (ELEM(zm1
, 3, 16) << 48);
2034 void HELPER(neon_qzip32
)(void *vd
, void *vm
)
2036 uint64_t *rd
= vd
, *rm
= vm
;
2037 uint64_t zd0
= rd
[0], zd1
= rd
[1];
2038 uint64_t zm0
= rm
[0], zm1
= rm
[1];
2040 uint64_t d0
= ELEM(zd0
, 0, 32) | (ELEM(zm0
, 0, 32) << 32);
2041 uint64_t d1
= ELEM(zd0
, 1, 32) | (ELEM(zm0
, 1, 32) << 32);
2042 uint64_t m0
= ELEM(zd1
, 0, 32) | (ELEM(zm1
, 0, 32) << 32);
2043 uint64_t m1
= ELEM(zd1
, 1, 32) | (ELEM(zm1
, 1, 32) << 32);
2051 void HELPER(neon_zip8
)(void *vd
, void *vm
)
2053 uint64_t *rd
= vd
, *rm
= vm
;
2054 uint64_t zd
= rd
[0], zm
= rm
[0];
2056 uint64_t d0
= ELEM(zd
, 0, 8) | (ELEM(zm
, 0, 8) << 8)
2057 | (ELEM(zd
, 1, 8) << 16) | (ELEM(zm
, 1, 8) << 24)
2058 | (ELEM(zd
, 2, 8) << 32) | (ELEM(zm
, 2, 8) << 40)
2059 | (ELEM(zd
, 3, 8) << 48) | (ELEM(zm
, 3, 8) << 56);
2060 uint64_t m0
= ELEM(zd
, 4, 8) | (ELEM(zm
, 4, 8) << 8)
2061 | (ELEM(zd
, 5, 8) << 16) | (ELEM(zm
, 5, 8) << 24)
2062 | (ELEM(zd
, 6, 8) << 32) | (ELEM(zm
, 6, 8) << 40)
2063 | (ELEM(zd
, 7, 8) << 48) | (ELEM(zm
, 7, 8) << 56);
2069 void HELPER(neon_zip16
)(void *vd
, void *vm
)
2071 uint64_t *rd
= vd
, *rm
= vm
;
2072 uint64_t zd
= rd
[0], zm
= rm
[0];
2074 uint64_t d0
= ELEM(zd
, 0, 16) | (ELEM(zm
, 0, 16) << 16)
2075 | (ELEM(zd
, 1, 16) << 32) | (ELEM(zm
, 1, 16) << 48);
2076 uint64_t m0
= ELEM(zd
, 2, 16) | (ELEM(zm
, 2, 16) << 16)
2077 | (ELEM(zd
, 3, 16) << 32) | (ELEM(zm
, 3, 16) << 48);