2 * ARM NEON vector operations.
4 * Copyright (c) 2007, 2008 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GNU GPL v2.
16 #define SIGNBIT (uint32_t)0x80000000
17 #define SIGNBIT64 ((uint64_t)1 << 63)
19 #define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] = CPSR_Q
21 static float_status neon_float_status
;
22 #define NFS &neon_float_status
24 /* Helper routines to perform bitwise copies between float and int. */
25 static inline float32
vfp_itos(uint32_t i
)
36 static inline uint32_t vfp_stoi(float32 s
)
47 #define NEON_TYPE1(name, type) \
52 #ifdef HOST_WORDS_BIGENDIAN
53 #define NEON_TYPE2(name, type) \
59 #define NEON_TYPE4(name, type) \
68 #define NEON_TYPE2(name, type) \
74 #define NEON_TYPE4(name, type) \
84 NEON_TYPE4(s8
, int8_t)
85 NEON_TYPE4(u8
, uint8_t)
86 NEON_TYPE2(s16
, int16_t)
87 NEON_TYPE2(u16
, uint16_t)
88 NEON_TYPE1(s32
, int32_t)
89 NEON_TYPE1(u32
, uint32_t)
94 /* Copy from a uint32_t to a vector structure type. */
95 #define NEON_UNPACK(vtype, dest, val) do { \
104 /* Copy from a vector structure type to a uint32_t. */
105 #define NEON_PACK(vtype, dest, val) do { \
115 NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1);
117 NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
118 NEON_FN(vdest.v2, vsrc1.v2, vsrc2.v2);
120 NEON_FN(vdest.v1, vsrc1.v1, vsrc2.v1); \
121 NEON_FN(vdest.v2, vsrc1.v2, vsrc2.v2); \
122 NEON_FN(vdest.v3, vsrc1.v3, vsrc2.v3); \
123 NEON_FN(vdest.v4, vsrc1.v4, vsrc2.v4);
125 #define NEON_VOP_BODY(vtype, n) \
131 NEON_UNPACK(vtype, vsrc1, arg1); \
132 NEON_UNPACK(vtype, vsrc2, arg2); \
134 NEON_PACK(vtype, res, vdest); \
138 #define NEON_VOP(name, vtype, n) \
139 uint32_t HELPER(glue(neon_,name))(uint32_t arg1, uint32_t arg2) \
140 NEON_VOP_BODY(vtype, n)
142 #define NEON_VOP_ENV(name, vtype, n) \
143 uint32_t HELPER(glue(neon_,name))(CPUState *env, uint32_t arg1, uint32_t arg2) \
144 NEON_VOP_BODY(vtype, n)
146 /* Pairwise operations. */
147 /* For 32-bit elements each segment only contains a single element, so
148 the elementwise and pairwise operations are the same. */
150 NEON_FN(vdest.v1, vsrc1.v1, vsrc1.v2); \
151 NEON_FN(vdest.v2, vsrc2.v1, vsrc2.v2);
153 NEON_FN(vdest.v1, vsrc1.v1, vsrc1.v2); \
154 NEON_FN(vdest.v2, vsrc1.v3, vsrc1.v4); \
155 NEON_FN(vdest.v3, vsrc2.v1, vsrc2.v2); \
156 NEON_FN(vdest.v4, vsrc2.v3, vsrc2.v4); \
158 #define NEON_POP(name, vtype, n) \
159 uint32_t HELPER(glue(neon_,name))(uint32_t arg1, uint32_t arg2) \
165 NEON_UNPACK(vtype, vsrc1, arg1); \
166 NEON_UNPACK(vtype, vsrc2, arg2); \
168 NEON_PACK(vtype, res, vdest); \
172 /* Unary operators. */
173 #define NEON_VOP1(name, vtype, n) \
174 uint32_t HELPER(glue(neon_,name))(uint32_t arg) \
178 NEON_UNPACK(vtype, vsrc1, arg); \
180 NEON_PACK(vtype, arg, vdest); \
185 #define NEON_USAT(dest, src1, src2, type) do { \
186 uint32_t tmp = (uint32_t)src1 + (uint32_t)src2; \
187 if (tmp != (type)tmp) { \
193 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint8_t)
194 NEON_VOP_ENV(qadd_u8
, neon_u8
, 4)
196 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint16_t)
197 NEON_VOP_ENV(qadd_u16
, neon_u16
, 2)
201 uint32_t HELPER(neon_qadd_u32
)(CPUState
*env
, uint32_t a
, uint32_t b
)
203 uint32_t res
= a
+ b
;
211 uint64_t HELPER(neon_qadd_u64
)(CPUState
*env
, uint64_t src1
, uint64_t src2
)
223 #define NEON_SSAT(dest, src1, src2, type) do { \
224 int32_t tmp = (uint32_t)src1 + (uint32_t)src2; \
225 if (tmp != (type)tmp) { \
228 tmp = (1 << (sizeof(type) * 8 - 1)) - 1; \
230 tmp = 1 << (sizeof(type) * 8 - 1); \
235 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int8_t)
236 NEON_VOP_ENV(qadd_s8
, neon_s8
, 4)
238 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int16_t)
239 NEON_VOP_ENV(qadd_s16
, neon_s16
, 2)
243 uint32_t HELPER(neon_qadd_s32
)(CPUState
*env
, uint32_t a
, uint32_t b
)
245 uint32_t res
= a
+ b
;
246 if (((res
^ a
) & SIGNBIT
) && !((a
^ b
) & SIGNBIT
)) {
248 res
= ~(((int32_t)a
>> 31) ^ SIGNBIT
);
253 uint64_t HELPER(neon_qadd_s64
)(CPUState
*env
, uint64_t src1
, uint64_t src2
)
258 if (((res
^ src1
) & SIGNBIT64
) && !((src1
^ src2
) & SIGNBIT64
)) {
260 res
= ((int64_t)src1
>> 63) ^ ~SIGNBIT64
;
265 #define NEON_USAT(dest, src1, src2, type) do { \
266 uint32_t tmp = (uint32_t)src1 - (uint32_t)src2; \
267 if (tmp != (type)tmp) { \
273 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint8_t)
274 NEON_VOP_ENV(qsub_u8
, neon_u8
, 4)
276 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint16_t)
277 NEON_VOP_ENV(qsub_u16
, neon_u16
, 2)
281 uint32_t HELPER(neon_qsub_u32
)(CPUState
*env
, uint32_t a
, uint32_t b
)
283 uint32_t res
= a
- b
;
291 uint64_t HELPER(neon_qsub_u64
)(CPUState
*env
, uint64_t src1
, uint64_t src2
)
304 #define NEON_SSAT(dest, src1, src2, type) do { \
305 int32_t tmp = (uint32_t)src1 - (uint32_t)src2; \
306 if (tmp != (type)tmp) { \
309 tmp = (1 << (sizeof(type) * 8 - 1)) - 1; \
311 tmp = 1 << (sizeof(type) * 8 - 1); \
316 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int8_t)
317 NEON_VOP_ENV(qsub_s8
, neon_s8
, 4)
319 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int16_t)
320 NEON_VOP_ENV(qsub_s16
, neon_s16
, 2)
324 uint32_t HELPER(neon_qsub_s32
)(CPUState
*env
, uint32_t a
, uint32_t b
)
326 uint32_t res
= a
- b
;
327 if (((res
^ a
) & SIGNBIT
) && ((a
^ b
) & SIGNBIT
)) {
329 res
= ~(((int32_t)a
>> 31) ^ SIGNBIT
);
334 uint64_t HELPER(neon_qsub_s64
)(CPUState
*env
, uint64_t src1
, uint64_t src2
)
339 if (((res
^ src1
) & SIGNBIT64
) && ((src1
^ src2
) & SIGNBIT64
)) {
341 res
= ((int64_t)src1
>> 63) ^ ~SIGNBIT64
;
346 #define NEON_FN(dest, src1, src2) dest = (src1 + src2) >> 1
347 NEON_VOP(hadd_s8
, neon_s8
, 4)
348 NEON_VOP(hadd_u8
, neon_u8
, 4)
349 NEON_VOP(hadd_s16
, neon_s16
, 2)
350 NEON_VOP(hadd_u16
, neon_u16
, 2)
353 int32_t HELPER(neon_hadd_s32
)(int32_t src1
, int32_t src2
)
357 dest
= (src1
>> 1) + (src2
>> 1);
363 uint32_t HELPER(neon_hadd_u32
)(uint32_t src1
, uint32_t src2
)
367 dest
= (src1
>> 1) + (src2
>> 1);
373 #define NEON_FN(dest, src1, src2) dest = (src1 + src2 + 1) >> 1
374 NEON_VOP(rhadd_s8
, neon_s8
, 4)
375 NEON_VOP(rhadd_u8
, neon_u8
, 4)
376 NEON_VOP(rhadd_s16
, neon_s16
, 2)
377 NEON_VOP(rhadd_u16
, neon_u16
, 2)
380 int32_t HELPER(neon_rhadd_s32
)(int32_t src1
, int32_t src2
)
384 dest
= (src1
>> 1) + (src2
>> 1);
385 if ((src1
| src2
) & 1)
390 uint32_t HELPER(neon_rhadd_u32
)(uint32_t src1
, uint32_t src2
)
394 dest
= (src1
>> 1) + (src2
>> 1);
395 if ((src1
| src2
) & 1)
400 #define NEON_FN(dest, src1, src2) dest = (src1 - src2) >> 1
401 NEON_VOP(hsub_s8
, neon_s8
, 4)
402 NEON_VOP(hsub_u8
, neon_u8
, 4)
403 NEON_VOP(hsub_s16
, neon_s16
, 2)
404 NEON_VOP(hsub_u16
, neon_u16
, 2)
407 int32_t HELPER(neon_hsub_s32
)(int32_t src1
, int32_t src2
)
411 dest
= (src1
>> 1) - (src2
>> 1);
412 if ((~src1
) & src2
& 1)
417 uint32_t HELPER(neon_hsub_u32
)(uint32_t src1
, uint32_t src2
)
421 dest
= (src1
>> 1) - (src2
>> 1);
422 if ((~src1
) & src2
& 1)
427 #define NEON_FN(dest, src1, src2) dest = (src1 > src2) ? ~0 : 0
428 NEON_VOP(cgt_s8
, neon_s8
, 4)
429 NEON_VOP(cgt_u8
, neon_u8
, 4)
430 NEON_VOP(cgt_s16
, neon_s16
, 2)
431 NEON_VOP(cgt_u16
, neon_u16
, 2)
432 NEON_VOP(cgt_s32
, neon_s32
, 1)
433 NEON_VOP(cgt_u32
, neon_u32
, 1)
436 #define NEON_FN(dest, src1, src2) dest = (src1 >= src2) ? ~0 : 0
437 NEON_VOP(cge_s8
, neon_s8
, 4)
438 NEON_VOP(cge_u8
, neon_u8
, 4)
439 NEON_VOP(cge_s16
, neon_s16
, 2)
440 NEON_VOP(cge_u16
, neon_u16
, 2)
441 NEON_VOP(cge_s32
, neon_s32
, 1)
442 NEON_VOP(cge_u32
, neon_u32
, 1)
445 #define NEON_FN(dest, src1, src2) dest = (src1 < src2) ? src1 : src2
446 NEON_VOP(min_s8
, neon_s8
, 4)
447 NEON_VOP(min_u8
, neon_u8
, 4)
448 NEON_VOP(min_s16
, neon_s16
, 2)
449 NEON_VOP(min_u16
, neon_u16
, 2)
450 NEON_VOP(min_s32
, neon_s32
, 1)
451 NEON_VOP(min_u32
, neon_u32
, 1)
452 NEON_POP(pmin_s8
, neon_s8
, 4)
453 NEON_POP(pmin_u8
, neon_u8
, 4)
454 NEON_POP(pmin_s16
, neon_s16
, 2)
455 NEON_POP(pmin_u16
, neon_u16
, 2)
458 #define NEON_FN(dest, src1, src2) dest = (src1 > src2) ? src1 : src2
459 NEON_VOP(max_s8
, neon_s8
, 4)
460 NEON_VOP(max_u8
, neon_u8
, 4)
461 NEON_VOP(max_s16
, neon_s16
, 2)
462 NEON_VOP(max_u16
, neon_u16
, 2)
463 NEON_VOP(max_s32
, neon_s32
, 1)
464 NEON_VOP(max_u32
, neon_u32
, 1)
465 NEON_POP(pmax_s8
, neon_s8
, 4)
466 NEON_POP(pmax_u8
, neon_u8
, 4)
467 NEON_POP(pmax_s16
, neon_s16
, 2)
468 NEON_POP(pmax_u16
, neon_u16
, 2)
471 #define NEON_FN(dest, src1, src2) \
472 dest = (src1 > src2) ? (src1 - src2) : (src2 - src1)
473 NEON_VOP(abd_s8
, neon_s8
, 4)
474 NEON_VOP(abd_u8
, neon_u8
, 4)
475 NEON_VOP(abd_s16
, neon_s16
, 2)
476 NEON_VOP(abd_u16
, neon_u16
, 2)
477 NEON_VOP(abd_s32
, neon_s32
, 1)
478 NEON_VOP(abd_u32
, neon_u32
, 1)
481 #define NEON_FN(dest, src1, src2) do { \
483 tmp = (int8_t)src2; \
484 if (tmp >= (ssize_t)sizeof(src1) * 8 || \
485 tmp <= -(ssize_t)sizeof(src1) * 8) { \
487 } else if (tmp < 0) { \
488 dest = src1 >> -tmp; \
490 dest = src1 << tmp; \
492 NEON_VOP(shl_u8
, neon_u8
, 4)
493 NEON_VOP(shl_u16
, neon_u16
, 2)
494 NEON_VOP(shl_u32
, neon_u32
, 1)
497 uint64_t HELPER(neon_shl_u64
)(uint64_t val
, uint64_t shiftop
)
499 int8_t shift
= (int8_t)shiftop
;
500 if (shift
>= 64 || shift
<= -64) {
502 } else if (shift
< 0) {
510 #define NEON_FN(dest, src1, src2) do { \
512 tmp = (int8_t)src2; \
513 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
515 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
516 dest = src1 >> (sizeof(src1) * 8 - 1); \
517 } else if (tmp < 0) { \
518 dest = src1 >> -tmp; \
520 dest = src1 << tmp; \
522 NEON_VOP(shl_s8
, neon_s8
, 4)
523 NEON_VOP(shl_s16
, neon_s16
, 2)
524 NEON_VOP(shl_s32
, neon_s32
, 1)
527 uint64_t HELPER(neon_shl_s64
)(uint64_t valop
, uint64_t shiftop
)
529 int8_t shift
= (int8_t)shiftop
;
533 } else if (shift
<= -64) {
535 } else if (shift
< 0) {
543 #define NEON_FN(dest, src1, src2) do { \
545 tmp = (int8_t)src2; \
546 if ((tmp >= (ssize_t)sizeof(src1) * 8) \
547 || (tmp <= -(ssize_t)sizeof(src1) * 8)) { \
549 } else if (tmp < 0) { \
550 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
552 dest = src1 << tmp; \
554 NEON_VOP(rshl_s8
, neon_s8
, 4)
555 NEON_VOP(rshl_s16
, neon_s16
, 2)
558 /* The addition of the rounding constant may overflow, so we use an
559 * intermediate 64 bits accumulator. */
560 uint32_t HELPER(neon_rshl_s32
)(uint32_t valop
, uint32_t shiftop
)
563 int32_t val
= (int32_t)valop
;
564 int8_t shift
= (int8_t)shiftop
;
565 if ((shift
>= 32) || (shift
<= -32)) {
567 } else if (shift
< 0) {
568 int64_t big_dest
= ((int64_t)val
+ (1 << (-1 - shift
)));
569 dest
= big_dest
>> -shift
;
576 /* Handling addition overflow with 64 bits inputs values is more
577 * tricky than with 32 bits values. */
578 uint64_t HELPER(neon_rshl_s64
)(uint64_t valop
, uint64_t shiftop
)
580 int8_t shift
= (int8_t)shiftop
;
582 if ((shift
>= 64) || (shift
<= -64)) {
584 } else if (shift
< 0) {
585 val
>>= (-shift
- 1);
586 if (val
== INT64_MAX
) {
587 /* In this case, it means that the rounding constant is 1,
588 * and the addition would overflow. Return the actual
589 * result directly. */
590 val
= 0x4000000000000000LL
;
601 #define NEON_FN(dest, src1, src2) do { \
603 tmp = (int8_t)src2; \
604 if (tmp >= (ssize_t)sizeof(src1) * 8 || \
605 tmp < -(ssize_t)sizeof(src1) * 8) { \
607 } else if (tmp == -(ssize_t)sizeof(src1) * 8) { \
608 dest = src1 >> (-tmp - 1); \
609 } else if (tmp < 0) { \
610 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
612 dest = src1 << tmp; \
614 NEON_VOP(rshl_u8
, neon_u8
, 4)
615 NEON_VOP(rshl_u16
, neon_u16
, 2)
618 /* The addition of the rounding constant may overflow, so we use an
619 * intermediate 64 bits accumulator. */
620 uint32_t HELPER(neon_rshl_u32
)(uint32_t val
, uint32_t shiftop
)
623 int8_t shift
= (int8_t)shiftop
;
624 if (shift
>= 32 || shift
< -32) {
626 } else if (shift
== -32) {
628 } else if (shift
< 0) {
629 uint64_t big_dest
= ((uint64_t)val
+ (1 << (-1 - shift
)));
630 dest
= big_dest
>> -shift
;
637 /* Handling addition overflow with 64 bits inputs values is more
638 * tricky than with 32 bits values. */
639 uint64_t HELPER(neon_rshl_u64
)(uint64_t val
, uint64_t shiftop
)
641 int8_t shift
= (uint8_t)shiftop
;
642 if (shift
>= 64 || shift
< -64) {
644 } else if (shift
== -64) {
645 /* Rounding a 1-bit result just preserves that bit. */
647 } else if (shift
< 0) {
648 val
>>= (-shift
- 1);
649 if (val
== UINT64_MAX
) {
650 /* In this case, it means that the rounding constant is 1,
651 * and the addition would overflow. Return the actual
652 * result directly. */
653 val
= 0x8000000000000000ULL
;
664 #define NEON_FN(dest, src1, src2) do { \
666 tmp = (int8_t)src2; \
667 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
674 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
676 } else if (tmp < 0) { \
677 dest = src1 >> -tmp; \
679 dest = src1 << tmp; \
680 if ((dest >> tmp) != src1) { \
685 NEON_VOP_ENV(qshl_u8
, neon_u8
, 4)
686 NEON_VOP_ENV(qshl_u16
, neon_u16
, 2)
687 NEON_VOP_ENV(qshl_u32
, neon_u32
, 1)
690 uint64_t HELPER(neon_qshl_u64
)(CPUState
*env
, uint64_t val
, uint64_t shiftop
)
692 int8_t shift
= (int8_t)shiftop
;
698 } else if (shift
<= -64) {
700 } else if (shift
< 0) {
705 if ((val
>> shift
) != tmp
) {
713 #define NEON_FN(dest, src1, src2) do { \
715 tmp = (int8_t)src2; \
716 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
719 dest = (uint32_t)(1 << (sizeof(src1) * 8 - 1)); \
726 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
728 } else if (tmp < 0) { \
729 dest = src1 >> -tmp; \
731 dest = src1 << tmp; \
732 if ((dest >> tmp) != src1) { \
734 dest = (uint32_t)(1 << (sizeof(src1) * 8 - 1)); \
740 NEON_VOP_ENV(qshl_s8
, neon_s8
, 4)
741 NEON_VOP_ENV(qshl_s16
, neon_s16
, 2)
742 NEON_VOP_ENV(qshl_s32
, neon_s32
, 1)
745 uint64_t HELPER(neon_qshl_s64
)(CPUState
*env
, uint64_t valop
, uint64_t shiftop
)
747 int8_t shift
= (uint8_t)shiftop
;
752 val
= (val
>> 63) ^ ~SIGNBIT64
;
754 } else if (shift
<= -64) {
756 } else if (shift
< 0) {
761 if ((val
>> shift
) != tmp
) {
763 val
= (tmp
>> 63) ^ ~SIGNBIT64
;
769 #define NEON_FN(dest, src1, src2) do { \
770 if (src1 & (1 << (sizeof(src1) * 8 - 1))) { \
775 tmp = (int8_t)src2; \
776 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
783 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
785 } else if (tmp < 0) { \
786 dest = src1 >> -tmp; \
788 dest = src1 << tmp; \
789 if ((dest >> tmp) != src1) { \
795 NEON_VOP_ENV(qshlu_s8
, neon_u8
, 4)
796 NEON_VOP_ENV(qshlu_s16
, neon_u16
, 2)
799 uint32_t HELPER(neon_qshlu_s32
)(CPUState
*env
, uint32_t valop
, uint32_t shiftop
)
801 if ((int32_t)valop
< 0) {
805 return helper_neon_qshl_u32(env
, valop
, shiftop
);
808 uint64_t HELPER(neon_qshlu_s64
)(CPUState
*env
, uint64_t valop
, uint64_t shiftop
)
810 if ((int64_t)valop
< 0) {
814 return helper_neon_qshl_u64(env
, valop
, shiftop
);
817 /* FIXME: This is wrong. */
818 #define NEON_FN(dest, src1, src2) do { \
820 tmp = (int8_t)src2; \
821 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
828 } else if (tmp < -(ssize_t)sizeof(src1) * 8) { \
830 } else if (tmp == -(ssize_t)sizeof(src1) * 8) { \
831 dest = src1 >> (sizeof(src1) * 8 - 1); \
832 } else if (tmp < 0) { \
833 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
835 dest = src1 << tmp; \
836 if ((dest >> tmp) != src1) { \
841 NEON_VOP_ENV(qrshl_u8
, neon_u8
, 4)
842 NEON_VOP_ENV(qrshl_u16
, neon_u16
, 2)
845 /* The addition of the rounding constant may overflow, so we use an
846 * intermediate 64 bits accumulator. */
847 uint32_t HELPER(neon_qrshl_u32
)(CPUState
*env
, uint32_t val
, uint32_t shiftop
)
850 int8_t shift
= (int8_t)shiftop
;
858 } else if (shift
< -32) {
860 } else if (shift
== -32) {
862 } else if (shift
< 0) {
863 uint64_t big_dest
= ((uint64_t)val
+ (1 << (-1 - shift
)));
864 dest
= big_dest
>> -shift
;
867 if ((dest
>> shift
) != val
) {
875 /* Handling addition overflow with 64 bits inputs values is more
876 * tricky than with 32 bits values. */
877 uint64_t HELPER(neon_qrshl_u64
)(CPUState
*env
, uint64_t val
, uint64_t shiftop
)
879 int8_t shift
= (int8_t)shiftop
;
885 } else if (shift
< -64) {
887 } else if (shift
== -64) {
889 } else if (shift
< 0) {
890 val
>>= (-shift
- 1);
891 if (val
== UINT64_MAX
) {
892 /* In this case, it means that the rounding constant is 1,
893 * and the addition would overflow. Return the actual
894 * result directly. */
895 val
= 0x8000000000000000ULL
;
903 if ((val
>> shift
) != tmp
) {
911 #define NEON_FN(dest, src1, src2) do { \
913 tmp = (int8_t)src2; \
914 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
917 dest = (1 << (sizeof(src1) * 8 - 1)); \
924 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
926 } else if (tmp < 0) { \
927 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
929 dest = src1 << tmp; \
930 if ((dest >> tmp) != src1) { \
932 dest = (uint32_t)(1 << (sizeof(src1) * 8 - 1)); \
938 NEON_VOP_ENV(qrshl_s8
, neon_s8
, 4)
939 NEON_VOP_ENV(qrshl_s16
, neon_s16
, 2)
942 /* The addition of the rounding constant may overflow, so we use an
943 * intermediate 64 bits accumulator. */
944 uint32_t HELPER(neon_qrshl_s32
)(CPUState
*env
, uint32_t valop
, uint32_t shiftop
)
947 int32_t val
= (int32_t)valop
;
948 int8_t shift
= (int8_t)shiftop
;
952 dest
= (val
>> 31) ^ ~SIGNBIT
;
956 } else if (shift
<= -32) {
958 } else if (shift
< 0) {
959 int64_t big_dest
= ((int64_t)val
+ (1 << (-1 - shift
)));
960 dest
= big_dest
>> -shift
;
963 if ((dest
>> shift
) != val
) {
965 dest
= (val
>> 31) ^ ~SIGNBIT
;
971 /* Handling addition overflow with 64 bits inputs values is more
972 * tricky than with 32 bits values. */
973 uint64_t HELPER(neon_qrshl_s64
)(CPUState
*env
, uint64_t valop
, uint64_t shiftop
)
975 int8_t shift
= (uint8_t)shiftop
;
981 val
= (val
>> 63) ^ ~SIGNBIT64
;
983 } else if (shift
<= -64) {
985 } else if (shift
< 0) {
986 val
>>= (-shift
- 1);
987 if (val
== INT64_MAX
) {
988 /* In this case, it means that the rounding constant is 1,
989 * and the addition would overflow. Return the actual
990 * result directly. */
991 val
= 0x4000000000000000ULL
;
999 if ((val
>> shift
) != tmp
) {
1001 val
= (tmp
>> 63) ^ ~SIGNBIT64
;
1007 uint32_t HELPER(neon_add_u8
)(uint32_t a
, uint32_t b
)
1010 mask
= (a
^ b
) & 0x80808080u
;
1013 return (a
+ b
) ^ mask
;
1016 uint32_t HELPER(neon_add_u16
)(uint32_t a
, uint32_t b
)
1019 mask
= (a
^ b
) & 0x80008000u
;
1022 return (a
+ b
) ^ mask
;
1025 #define NEON_FN(dest, src1, src2) dest = src1 + src2
1026 NEON_POP(padd_u8
, neon_u8
, 4)
1027 NEON_POP(padd_u16
, neon_u16
, 2)
1030 #define NEON_FN(dest, src1, src2) dest = src1 - src2
1031 NEON_VOP(sub_u8
, neon_u8
, 4)
1032 NEON_VOP(sub_u16
, neon_u16
, 2)
1035 #define NEON_FN(dest, src1, src2) dest = src1 * src2
1036 NEON_VOP(mul_u8
, neon_u8
, 4)
1037 NEON_VOP(mul_u16
, neon_u16
, 2)
1040 /* Polynomial multiplication is like integer multiplication except the
1041 partial products are XORed, not added. */
1042 uint32_t HELPER(neon_mul_p8
)(uint32_t op1
, uint32_t op2
)
1052 mask
|= (0xff << 8);
1053 if (op1
& (1 << 16))
1054 mask
|= (0xff << 16);
1055 if (op1
& (1 << 24))
1056 mask
|= (0xff << 24);
1057 result
^= op2
& mask
;
1058 op1
= (op1
>> 1) & 0x7f7f7f7f;
1059 op2
= (op2
<< 1) & 0xfefefefe;
1064 uint64_t HELPER(neon_mull_p8
)(uint32_t op1
, uint32_t op2
)
1066 uint64_t result
= 0;
1068 uint64_t op2ex
= op2
;
1069 op2ex
= (op2ex
& 0xff) |
1070 ((op2ex
& 0xff00) << 8) |
1071 ((op2ex
& 0xff0000) << 16) |
1072 ((op2ex
& 0xff000000) << 24);
1078 if (op1
& (1 << 8)) {
1079 mask
|= (0xffffU
<< 16);
1081 if (op1
& (1 << 16)) {
1082 mask
|= (0xffffULL
<< 32);
1084 if (op1
& (1 << 24)) {
1085 mask
|= (0xffffULL
<< 48);
1087 result
^= op2ex
& mask
;
1088 op1
= (op1
>> 1) & 0x7f7f7f7f;
1094 #define NEON_FN(dest, src1, src2) dest = (src1 & src2) ? -1 : 0
1095 NEON_VOP(tst_u8
, neon_u8
, 4)
1096 NEON_VOP(tst_u16
, neon_u16
, 2)
1097 NEON_VOP(tst_u32
, neon_u32
, 1)
1100 #define NEON_FN(dest, src1, src2) dest = (src1 == src2) ? -1 : 0
1101 NEON_VOP(ceq_u8
, neon_u8
, 4)
1102 NEON_VOP(ceq_u16
, neon_u16
, 2)
1103 NEON_VOP(ceq_u32
, neon_u32
, 1)
1106 #define NEON_FN(dest, src, dummy) dest = (src < 0) ? -src : src
1107 NEON_VOP1(abs_s8
, neon_s8
, 4)
1108 NEON_VOP1(abs_s16
, neon_s16
, 2)
1111 /* Count Leading Sign/Zero Bits. */
1112 static inline int do_clz8(uint8_t x
)
1120 static inline int do_clz16(uint16_t x
)
1123 for (n
= 16; x
; n
--)
1128 #define NEON_FN(dest, src, dummy) dest = do_clz8(src)
1129 NEON_VOP1(clz_u8
, neon_u8
, 4)
1132 #define NEON_FN(dest, src, dummy) dest = do_clz16(src)
1133 NEON_VOP1(clz_u16
, neon_u16
, 2)
1136 #define NEON_FN(dest, src, dummy) dest = do_clz8((src < 0) ? ~src : src) - 1
1137 NEON_VOP1(cls_s8
, neon_s8
, 4)
1140 #define NEON_FN(dest, src, dummy) dest = do_clz16((src < 0) ? ~src : src) - 1
1141 NEON_VOP1(cls_s16
, neon_s16
, 2)
1144 uint32_t HELPER(neon_cls_s32
)(uint32_t x
)
1149 for (count
= 32; x
; count
--)
1155 uint32_t HELPER(neon_cnt_u8
)(uint32_t x
)
1157 x
= (x
& 0x55555555) + ((x
>> 1) & 0x55555555);
1158 x
= (x
& 0x33333333) + ((x
>> 2) & 0x33333333);
1159 x
= (x
& 0x0f0f0f0f) + ((x
>> 4) & 0x0f0f0f0f);
1163 #define NEON_QDMULH16(dest, src1, src2, round) do { \
1164 uint32_t tmp = (int32_t)(int16_t) src1 * (int16_t) src2; \
1165 if ((tmp ^ (tmp << 1)) & SIGNBIT) { \
1167 tmp = (tmp >> 31) ^ ~SIGNBIT; \
1172 int32_t old = tmp; \
1174 if ((int32_t)tmp < old) { \
1176 tmp = SIGNBIT - 1; \
1181 #define NEON_FN(dest, src1, src2) NEON_QDMULH16(dest, src1, src2, 0)
1182 NEON_VOP_ENV(qdmulh_s16
, neon_s16
, 2)
1184 #define NEON_FN(dest, src1, src2) NEON_QDMULH16(dest, src1, src2, 1)
1185 NEON_VOP_ENV(qrdmulh_s16
, neon_s16
, 2)
1187 #undef NEON_QDMULH16
1189 #define NEON_QDMULH32(dest, src1, src2, round) do { \
1190 uint64_t tmp = (int64_t)(int32_t) src1 * (int32_t) src2; \
1191 if ((tmp ^ (tmp << 1)) & SIGNBIT64) { \
1193 tmp = (tmp >> 63) ^ ~SIGNBIT64; \
1198 int64_t old = tmp; \
1199 tmp += (int64_t)1 << 31; \
1200 if ((int64_t)tmp < old) { \
1202 tmp = SIGNBIT64 - 1; \
1207 #define NEON_FN(dest, src1, src2) NEON_QDMULH32(dest, src1, src2, 0)
1208 NEON_VOP_ENV(qdmulh_s32
, neon_s32
, 1)
1210 #define NEON_FN(dest, src1, src2) NEON_QDMULH32(dest, src1, src2, 1)
1211 NEON_VOP_ENV(qrdmulh_s32
, neon_s32
, 1)
1213 #undef NEON_QDMULH32
1215 uint32_t HELPER(neon_narrow_u8
)(uint64_t x
)
1217 return (x
& 0xffu
) | ((x
>> 8) & 0xff00u
) | ((x
>> 16) & 0xff0000u
)
1218 | ((x
>> 24) & 0xff000000u
);
1221 uint32_t HELPER(neon_narrow_u16
)(uint64_t x
)
1223 return (x
& 0xffffu
) | ((x
>> 16) & 0xffff0000u
);
1226 uint32_t HELPER(neon_narrow_high_u8
)(uint64_t x
)
1228 return ((x
>> 8) & 0xff) | ((x
>> 16) & 0xff00)
1229 | ((x
>> 24) & 0xff0000) | ((x
>> 32) & 0xff000000);
1232 uint32_t HELPER(neon_narrow_high_u16
)(uint64_t x
)
1234 return ((x
>> 16) & 0xffff) | ((x
>> 32) & 0xffff0000);
1237 uint32_t HELPER(neon_narrow_round_high_u8
)(uint64_t x
)
1239 x
&= 0xff80ff80ff80ff80ull
;
1240 x
+= 0x0080008000800080ull
;
1241 return ((x
>> 8) & 0xff) | ((x
>> 16) & 0xff00)
1242 | ((x
>> 24) & 0xff0000) | ((x
>> 32) & 0xff000000);
1245 uint32_t HELPER(neon_narrow_round_high_u16
)(uint64_t x
)
1247 x
&= 0xffff8000ffff8000ull
;
1248 x
+= 0x0000800000008000ull
;
1249 return ((x
>> 16) & 0xffff) | ((x
>> 32) & 0xffff0000);
1252 uint32_t HELPER(neon_unarrow_sat8
)(CPUState
*env
, uint64_t x
)
1268 res |= (uint32_t)d << (n / 2); \
1279 uint32_t HELPER(neon_narrow_sat_u8
)(CPUState
*env
, uint64_t x
)
1292 res |= (uint32_t)d << (n / 2);
1302 uint32_t HELPER(neon_narrow_sat_s8
)(CPUState
*env
, uint64_t x
)
1309 if (s != (int8_t)s) { \
1310 d = (s >> 15) ^ 0x7f; \
1315 res |= (uint32_t)d << (n / 2);
1325 uint32_t HELPER(neon_unarrow_sat16
)(CPUState
*env
, uint64_t x
)
1330 if (low
& 0x80000000) {
1333 } else if (low
> 0xffff) {
1338 if (high
& 0x80000000) {
1341 } else if (high
> 0xffff) {
1345 return low
| (high
<< 16);
1348 uint32_t HELPER(neon_narrow_sat_u16
)(CPUState
*env
, uint64_t x
)
1358 if (high
> 0xffff) {
1362 return low
| (high
<< 16);
1365 uint32_t HELPER(neon_narrow_sat_s16
)(CPUState
*env
, uint64_t x
)
1370 if (low
!= (int16_t)low
) {
1371 low
= (low
>> 31) ^ 0x7fff;
1375 if (high
!= (int16_t)high
) {
1376 high
= (high
>> 31) ^ 0x7fff;
1379 return (uint16_t)low
| (high
<< 16);
1382 uint32_t HELPER(neon_unarrow_sat32
)(CPUState
*env
, uint64_t x
)
1384 if (x
& 0x8000000000000000ull
) {
1388 if (x
> 0xffffffffu
) {
1395 uint32_t HELPER(neon_narrow_sat_u32
)(CPUState
*env
, uint64_t x
)
1397 if (x
> 0xffffffffu
) {
1404 uint32_t HELPER(neon_narrow_sat_s32
)(CPUState
*env
, uint64_t x
)
1406 if ((int64_t)x
!= (int32_t)x
) {
1408 return ((int64_t)x
>> 63) ^ 0x7fffffff;
1413 uint64_t HELPER(neon_widen_u8
)(uint32_t x
)
1418 tmp
= (uint8_t)(x
>> 8);
1420 tmp
= (uint8_t)(x
>> 16);
1422 tmp
= (uint8_t)(x
>> 24);
1427 uint64_t HELPER(neon_widen_s8
)(uint32_t x
)
1431 ret
= (uint16_t)(int8_t)x
;
1432 tmp
= (uint16_t)(int8_t)(x
>> 8);
1434 tmp
= (uint16_t)(int8_t)(x
>> 16);
1436 tmp
= (uint16_t)(int8_t)(x
>> 24);
1441 uint64_t HELPER(neon_widen_u16
)(uint32_t x
)
1443 uint64_t high
= (uint16_t)(x
>> 16);
1444 return ((uint16_t)x
) | (high
<< 32);
1447 uint64_t HELPER(neon_widen_s16
)(uint32_t x
)
1449 uint64_t high
= (int16_t)(x
>> 16);
1450 return ((uint32_t)(int16_t)x
) | (high
<< 32);
1453 uint64_t HELPER(neon_addl_u16
)(uint64_t a
, uint64_t b
)
1456 mask
= (a
^ b
) & 0x8000800080008000ull
;
1457 a
&= ~0x8000800080008000ull
;
1458 b
&= ~0x8000800080008000ull
;
1459 return (a
+ b
) ^ mask
;
1462 uint64_t HELPER(neon_addl_u32
)(uint64_t a
, uint64_t b
)
1465 mask
= (a
^ b
) & 0x8000000080000000ull
;
1466 a
&= ~0x8000000080000000ull
;
1467 b
&= ~0x8000000080000000ull
;
1468 return (a
+ b
) ^ mask
;
1471 uint64_t HELPER(neon_paddl_u16
)(uint64_t a
, uint64_t b
)
1476 tmp
= a
& 0x0000ffff0000ffffull
;
1477 tmp
+= (a
>> 16) & 0x0000ffff0000ffffull
;
1478 tmp2
= b
& 0xffff0000ffff0000ull
;
1479 tmp2
+= (b
<< 16) & 0xffff0000ffff0000ull
;
1480 return ( tmp
& 0xffff)
1481 | ((tmp
>> 16) & 0xffff0000ull
)
1482 | ((tmp2
<< 16) & 0xffff00000000ull
)
1483 | ( tmp2
& 0xffff000000000000ull
);
1486 uint64_t HELPER(neon_paddl_u32
)(uint64_t a
, uint64_t b
)
1488 uint32_t low
= a
+ (a
>> 32);
1489 uint32_t high
= b
+ (b
>> 32);
1490 return low
+ ((uint64_t)high
<< 32);
1493 uint64_t HELPER(neon_subl_u16
)(uint64_t a
, uint64_t b
)
1496 mask
= (a
^ ~b
) & 0x8000800080008000ull
;
1497 a
|= 0x8000800080008000ull
;
1498 b
&= ~0x8000800080008000ull
;
1499 return (a
- b
) ^ mask
;
1502 uint64_t HELPER(neon_subl_u32
)(uint64_t a
, uint64_t b
)
1505 mask
= (a
^ ~b
) & 0x8000000080000000ull
;
1506 a
|= 0x8000000080000000ull
;
1507 b
&= ~0x8000000080000000ull
;
1508 return (a
- b
) ^ mask
;
1511 uint64_t HELPER(neon_addl_saturate_s32
)(CPUState
*env
, uint64_t a
, uint64_t b
)
1519 if (((low
^ x
) & SIGNBIT
) && !((x
^ y
) & SIGNBIT
)) {
1521 low
= ((int32_t)x
>> 31) ^ ~SIGNBIT
;
1526 if (((high
^ x
) & SIGNBIT
) && !((x
^ y
) & SIGNBIT
)) {
1528 high
= ((int32_t)x
>> 31) ^ ~SIGNBIT
;
1530 return low
| ((uint64_t)high
<< 32);
1533 uint64_t HELPER(neon_addl_saturate_s64
)(CPUState
*env
, uint64_t a
, uint64_t b
)
1538 if (((result
^ a
) & SIGNBIT64
) && !((a
^ b
) & SIGNBIT64
)) {
1540 result
= ((int64_t)a
>> 63) ^ ~SIGNBIT64
;
1545 #define DO_ABD(dest, x, y, type) do { \
1548 dest = ((tmp_x > tmp_y) ? tmp_x - tmp_y : tmp_y - tmp_x); \
1551 uint64_t HELPER(neon_abdl_u16
)(uint32_t a
, uint32_t b
)
1555 DO_ABD(result
, a
, b
, uint8_t);
1556 DO_ABD(tmp
, a
>> 8, b
>> 8, uint8_t);
1557 result
|= tmp
<< 16;
1558 DO_ABD(tmp
, a
>> 16, b
>> 16, uint8_t);
1559 result
|= tmp
<< 32;
1560 DO_ABD(tmp
, a
>> 24, b
>> 24, uint8_t);
1561 result
|= tmp
<< 48;
1565 uint64_t HELPER(neon_abdl_s16
)(uint32_t a
, uint32_t b
)
1569 DO_ABD(result
, a
, b
, int8_t);
1570 DO_ABD(tmp
, a
>> 8, b
>> 8, int8_t);
1571 result
|= tmp
<< 16;
1572 DO_ABD(tmp
, a
>> 16, b
>> 16, int8_t);
1573 result
|= tmp
<< 32;
1574 DO_ABD(tmp
, a
>> 24, b
>> 24, int8_t);
1575 result
|= tmp
<< 48;
1579 uint64_t HELPER(neon_abdl_u32
)(uint32_t a
, uint32_t b
)
1583 DO_ABD(result
, a
, b
, uint16_t);
1584 DO_ABD(tmp
, a
>> 16, b
>> 16, uint16_t);
1585 return result
| (tmp
<< 32);
1588 uint64_t HELPER(neon_abdl_s32
)(uint32_t a
, uint32_t b
)
1592 DO_ABD(result
, a
, b
, int16_t);
1593 DO_ABD(tmp
, a
>> 16, b
>> 16, int16_t);
1594 return result
| (tmp
<< 32);
1597 uint64_t HELPER(neon_abdl_u64
)(uint32_t a
, uint32_t b
)
1600 DO_ABD(result
, a
, b
, uint32_t);
1604 uint64_t HELPER(neon_abdl_s64
)(uint32_t a
, uint32_t b
)
1607 DO_ABD(result
, a
, b
, int32_t);
1612 /* Widening multiply. Named type is the source type. */
1613 #define DO_MULL(dest, x, y, type1, type2) do { \
1616 dest = (type2)((type2)tmp_x * (type2)tmp_y); \
1619 uint64_t HELPER(neon_mull_u8
)(uint32_t a
, uint32_t b
)
1624 DO_MULL(result
, a
, b
, uint8_t, uint16_t);
1625 DO_MULL(tmp
, a
>> 8, b
>> 8, uint8_t, uint16_t);
1626 result
|= tmp
<< 16;
1627 DO_MULL(tmp
, a
>> 16, b
>> 16, uint8_t, uint16_t);
1628 result
|= tmp
<< 32;
1629 DO_MULL(tmp
, a
>> 24, b
>> 24, uint8_t, uint16_t);
1630 result
|= tmp
<< 48;
1634 uint64_t HELPER(neon_mull_s8
)(uint32_t a
, uint32_t b
)
1639 DO_MULL(result
, a
, b
, int8_t, uint16_t);
1640 DO_MULL(tmp
, a
>> 8, b
>> 8, int8_t, uint16_t);
1641 result
|= tmp
<< 16;
1642 DO_MULL(tmp
, a
>> 16, b
>> 16, int8_t, uint16_t);
1643 result
|= tmp
<< 32;
1644 DO_MULL(tmp
, a
>> 24, b
>> 24, int8_t, uint16_t);
1645 result
|= tmp
<< 48;
1649 uint64_t HELPER(neon_mull_u16
)(uint32_t a
, uint32_t b
)
1654 DO_MULL(result
, a
, b
, uint16_t, uint32_t);
1655 DO_MULL(tmp
, a
>> 16, b
>> 16, uint16_t, uint32_t);
1656 return result
| (tmp
<< 32);
1659 uint64_t HELPER(neon_mull_s16
)(uint32_t a
, uint32_t b
)
1664 DO_MULL(result
, a
, b
, int16_t, uint32_t);
1665 DO_MULL(tmp
, a
>> 16, b
>> 16, int16_t, uint32_t);
1666 return result
| (tmp
<< 32);
1669 uint64_t HELPER(neon_negl_u16
)(uint64_t x
)
1673 result
= (uint16_t)-x
;
1675 result
|= (uint64_t)tmp
<< 16;
1677 result
|= (uint64_t)tmp
<< 32;
1679 result
|= (uint64_t)tmp
<< 48;
1683 uint64_t HELPER(neon_negl_u32
)(uint64_t x
)
1686 uint32_t high
= -(x
>> 32);
1687 return low
| ((uint64_t)high
<< 32);
1690 /* FIXME: There should be a native op for this. */
1691 uint64_t HELPER(neon_negl_u64
)(uint64_t x
)
1696 /* Saturnating sign manuipulation. */
1697 /* ??? Make these use NEON_VOP1 */
1698 #define DO_QABS8(x) do { \
1699 if (x == (int8_t)0x80) { \
1702 } else if (x < 0) { \
1705 uint32_t HELPER(neon_qabs_s8
)(CPUState
*env
, uint32_t x
)
1708 NEON_UNPACK(neon_s8
, vec
, x
);
1713 NEON_PACK(neon_s8
, x
, vec
);
1718 #define DO_QNEG8(x) do { \
1719 if (x == (int8_t)0x80) { \
1725 uint32_t HELPER(neon_qneg_s8
)(CPUState
*env
, uint32_t x
)
1728 NEON_UNPACK(neon_s8
, vec
, x
);
1733 NEON_PACK(neon_s8
, x
, vec
);
1738 #define DO_QABS16(x) do { \
1739 if (x == (int16_t)0x8000) { \
1742 } else if (x < 0) { \
1745 uint32_t HELPER(neon_qabs_s16
)(CPUState
*env
, uint32_t x
)
1748 NEON_UNPACK(neon_s16
, vec
, x
);
1751 NEON_PACK(neon_s16
, x
, vec
);
1756 #define DO_QNEG16(x) do { \
1757 if (x == (int16_t)0x8000) { \
1763 uint32_t HELPER(neon_qneg_s16
)(CPUState
*env
, uint32_t x
)
1766 NEON_UNPACK(neon_s16
, vec
, x
);
1769 NEON_PACK(neon_s16
, x
, vec
);
1774 uint32_t HELPER(neon_qabs_s32
)(CPUState
*env
, uint32_t x
)
1779 } else if ((int32_t)x
< 0) {
1785 uint32_t HELPER(neon_qneg_s32
)(CPUState
*env
, uint32_t x
)
1796 /* NEON Float helpers. */
1797 uint32_t HELPER(neon_min_f32
)(uint32_t a
, uint32_t b
)
1799 float32 f0
= vfp_itos(a
);
1800 float32 f1
= vfp_itos(b
);
1801 return (float32_compare_quiet(f0
, f1
, NFS
) == -1) ? a
: b
;
1804 uint32_t HELPER(neon_max_f32
)(uint32_t a
, uint32_t b
)
1806 float32 f0
= vfp_itos(a
);
1807 float32 f1
= vfp_itos(b
);
1808 return (float32_compare_quiet(f0
, f1
, NFS
) == 1) ? a
: b
;
1811 uint32_t HELPER(neon_abd_f32
)(uint32_t a
, uint32_t b
)
1813 float32 f0
= vfp_itos(a
);
1814 float32 f1
= vfp_itos(b
);
1815 return vfp_stoi((float32_compare_quiet(f0
, f1
, NFS
) == 1)
1816 ? float32_sub(f0
, f1
, NFS
)
1817 : float32_sub(f1
, f0
, NFS
));
1820 uint32_t HELPER(neon_add_f32
)(uint32_t a
, uint32_t b
)
1822 return vfp_stoi(float32_add(vfp_itos(a
), vfp_itos(b
), NFS
));
1825 uint32_t HELPER(neon_sub_f32
)(uint32_t a
, uint32_t b
)
1827 return vfp_stoi(float32_sub(vfp_itos(a
), vfp_itos(b
), NFS
));
1830 uint32_t HELPER(neon_mul_f32
)(uint32_t a
, uint32_t b
)
1832 return vfp_stoi(float32_mul(vfp_itos(a
), vfp_itos(b
), NFS
));
1835 /* Floating point comparisons produce an integer result. */
1836 #define NEON_VOP_FCMP(name, cmp) \
1837 uint32_t HELPER(neon_##name)(uint32_t a, uint32_t b) \
1839 if (float32_compare_quiet(vfp_itos(a), vfp_itos(b), NFS) cmp 0) \
1845 NEON_VOP_FCMP(ceq_f32
, ==)
1846 NEON_VOP_FCMP(cge_f32
, >=)
1847 NEON_VOP_FCMP(cgt_f32
, >)
1849 uint32_t HELPER(neon_acge_f32
)(uint32_t a
, uint32_t b
)
1851 float32 f0
= float32_abs(vfp_itos(a
));
1852 float32 f1
= float32_abs(vfp_itos(b
));
1853 return (float32_compare_quiet(f0
, f1
,NFS
) >= 0) ? ~0 : 0;
1856 uint32_t HELPER(neon_acgt_f32
)(uint32_t a
, uint32_t b
)
1858 float32 f0
= float32_abs(vfp_itos(a
));
1859 float32 f1
= float32_abs(vfp_itos(b
));
1860 return (float32_compare_quiet(f0
, f1
, NFS
) > 0) ? ~0 : 0;
1863 #define ELEM(V, N, SIZE) (((V) >> ((N) * (SIZE))) & ((1ull << (SIZE)) - 1))
1865 void HELPER(neon_qunzip8
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1867 uint64_t zm0
= float64_val(env
->vfp
.regs
[rm
]);
1868 uint64_t zm1
= float64_val(env
->vfp
.regs
[rm
+ 1]);
1869 uint64_t zd0
= float64_val(env
->vfp
.regs
[rd
]);
1870 uint64_t zd1
= float64_val(env
->vfp
.regs
[rd
+ 1]);
1871 uint64_t d0
= ELEM(zd0
, 0, 8) | (ELEM(zd0
, 2, 8) << 8)
1872 | (ELEM(zd0
, 4, 8) << 16) | (ELEM(zd0
, 6, 8) << 24)
1873 | (ELEM(zd1
, 0, 8) << 32) | (ELEM(zd1
, 2, 8) << 40)
1874 | (ELEM(zd1
, 4, 8) << 48) | (ELEM(zd1
, 6, 8) << 56);
1875 uint64_t d1
= ELEM(zm0
, 0, 8) | (ELEM(zm0
, 2, 8) << 8)
1876 | (ELEM(zm0
, 4, 8) << 16) | (ELEM(zm0
, 6, 8) << 24)
1877 | (ELEM(zm1
, 0, 8) << 32) | (ELEM(zm1
, 2, 8) << 40)
1878 | (ELEM(zm1
, 4, 8) << 48) | (ELEM(zm1
, 6, 8) << 56);
1879 uint64_t m0
= ELEM(zd0
, 1, 8) | (ELEM(zd0
, 3, 8) << 8)
1880 | (ELEM(zd0
, 5, 8) << 16) | (ELEM(zd0
, 7, 8) << 24)
1881 | (ELEM(zd1
, 1, 8) << 32) | (ELEM(zd1
, 3, 8) << 40)
1882 | (ELEM(zd1
, 5, 8) << 48) | (ELEM(zd1
, 7, 8) << 56);
1883 uint64_t m1
= ELEM(zm0
, 1, 8) | (ELEM(zm0
, 3, 8) << 8)
1884 | (ELEM(zm0
, 5, 8) << 16) | (ELEM(zm0
, 7, 8) << 24)
1885 | (ELEM(zm1
, 1, 8) << 32) | (ELEM(zm1
, 3, 8) << 40)
1886 | (ELEM(zm1
, 5, 8) << 48) | (ELEM(zm1
, 7, 8) << 56);
1887 env
->vfp
.regs
[rm
] = make_float64(m0
);
1888 env
->vfp
.regs
[rm
+ 1] = make_float64(m1
);
1889 env
->vfp
.regs
[rd
] = make_float64(d0
);
1890 env
->vfp
.regs
[rd
+ 1] = make_float64(d1
);
1893 void HELPER(neon_qunzip16
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1895 uint64_t zm0
= float64_val(env
->vfp
.regs
[rm
]);
1896 uint64_t zm1
= float64_val(env
->vfp
.regs
[rm
+ 1]);
1897 uint64_t zd0
= float64_val(env
->vfp
.regs
[rd
]);
1898 uint64_t zd1
= float64_val(env
->vfp
.regs
[rd
+ 1]);
1899 uint64_t d0
= ELEM(zd0
, 0, 16) | (ELEM(zd0
, 2, 16) << 16)
1900 | (ELEM(zd1
, 0, 16) << 32) | (ELEM(zd1
, 2, 16) << 48);
1901 uint64_t d1
= ELEM(zm0
, 0, 16) | (ELEM(zm0
, 2, 16) << 16)
1902 | (ELEM(zm1
, 0, 16) << 32) | (ELEM(zm1
, 2, 16) << 48);
1903 uint64_t m0
= ELEM(zd0
, 1, 16) | (ELEM(zd0
, 3, 16) << 16)
1904 | (ELEM(zd1
, 1, 16) << 32) | (ELEM(zd1
, 3, 16) << 48);
1905 uint64_t m1
= ELEM(zm0
, 1, 16) | (ELEM(zm0
, 3, 16) << 16)
1906 | (ELEM(zm1
, 1, 16) << 32) | (ELEM(zm1
, 3, 16) << 48);
1907 env
->vfp
.regs
[rm
] = make_float64(m0
);
1908 env
->vfp
.regs
[rm
+ 1] = make_float64(m1
);
1909 env
->vfp
.regs
[rd
] = make_float64(d0
);
1910 env
->vfp
.regs
[rd
+ 1] = make_float64(d1
);
1913 void HELPER(neon_qunzip32
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1915 uint64_t zm0
= float64_val(env
->vfp
.regs
[rm
]);
1916 uint64_t zm1
= float64_val(env
->vfp
.regs
[rm
+ 1]);
1917 uint64_t zd0
= float64_val(env
->vfp
.regs
[rd
]);
1918 uint64_t zd1
= float64_val(env
->vfp
.regs
[rd
+ 1]);
1919 uint64_t d0
= ELEM(zd0
, 0, 32) | (ELEM(zd1
, 0, 32) << 32);
1920 uint64_t d1
= ELEM(zm0
, 0, 32) | (ELEM(zm1
, 0, 32) << 32);
1921 uint64_t m0
= ELEM(zd0
, 1, 32) | (ELEM(zd1
, 1, 32) << 32);
1922 uint64_t m1
= ELEM(zm0
, 1, 32) | (ELEM(zm1
, 1, 32) << 32);
1923 env
->vfp
.regs
[rm
] = make_float64(m0
);
1924 env
->vfp
.regs
[rm
+ 1] = make_float64(m1
);
1925 env
->vfp
.regs
[rd
] = make_float64(d0
);
1926 env
->vfp
.regs
[rd
+ 1] = make_float64(d1
);
1929 void HELPER(neon_unzip8
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1931 uint64_t zm
= float64_val(env
->vfp
.regs
[rm
]);
1932 uint64_t zd
= float64_val(env
->vfp
.regs
[rd
]);
1933 uint64_t d0
= ELEM(zd
, 0, 8) | (ELEM(zd
, 2, 8) << 8)
1934 | (ELEM(zd
, 4, 8) << 16) | (ELEM(zd
, 6, 8) << 24)
1935 | (ELEM(zm
, 0, 8) << 32) | (ELEM(zm
, 2, 8) << 40)
1936 | (ELEM(zm
, 4, 8) << 48) | (ELEM(zm
, 6, 8) << 56);
1937 uint64_t m0
= ELEM(zd
, 1, 8) | (ELEM(zd
, 3, 8) << 8)
1938 | (ELEM(zd
, 5, 8) << 16) | (ELEM(zd
, 7, 8) << 24)
1939 | (ELEM(zm
, 1, 8) << 32) | (ELEM(zm
, 3, 8) << 40)
1940 | (ELEM(zm
, 5, 8) << 48) | (ELEM(zm
, 7, 8) << 56);
1941 env
->vfp
.regs
[rm
] = make_float64(m0
);
1942 env
->vfp
.regs
[rd
] = make_float64(d0
);
1945 void HELPER(neon_unzip16
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1947 uint64_t zm
= float64_val(env
->vfp
.regs
[rm
]);
1948 uint64_t zd
= float64_val(env
->vfp
.regs
[rd
]);
1949 uint64_t d0
= ELEM(zd
, 0, 16) | (ELEM(zd
, 2, 16) << 16)
1950 | (ELEM(zm
, 0, 16) << 32) | (ELEM(zm
, 2, 16) << 48);
1951 uint64_t m0
= ELEM(zd
, 1, 16) | (ELEM(zd
, 3, 16) << 16)
1952 | (ELEM(zm
, 1, 16) << 32) | (ELEM(zm
, 3, 16) << 48);
1953 env
->vfp
.regs
[rm
] = make_float64(m0
);
1954 env
->vfp
.regs
[rd
] = make_float64(d0
);
1957 void HELPER(neon_qzip8
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1959 uint64_t zm0
= float64_val(env
->vfp
.regs
[rm
]);
1960 uint64_t zm1
= float64_val(env
->vfp
.regs
[rm
+ 1]);
1961 uint64_t zd0
= float64_val(env
->vfp
.regs
[rd
]);
1962 uint64_t zd1
= float64_val(env
->vfp
.regs
[rd
+ 1]);
1963 uint64_t d0
= ELEM(zd0
, 0, 8) | (ELEM(zm0
, 0, 8) << 8)
1964 | (ELEM(zd0
, 1, 8) << 16) | (ELEM(zm0
, 1, 8) << 24)
1965 | (ELEM(zd0
, 2, 8) << 32) | (ELEM(zm0
, 2, 8) << 40)
1966 | (ELEM(zd0
, 3, 8) << 48) | (ELEM(zm0
, 3, 8) << 56);
1967 uint64_t d1
= ELEM(zd0
, 4, 8) | (ELEM(zm0
, 4, 8) << 8)
1968 | (ELEM(zd0
, 5, 8) << 16) | (ELEM(zm0
, 5, 8) << 24)
1969 | (ELEM(zd0
, 6, 8) << 32) | (ELEM(zm0
, 6, 8) << 40)
1970 | (ELEM(zd0
, 7, 8) << 48) | (ELEM(zm0
, 7, 8) << 56);
1971 uint64_t m0
= ELEM(zd1
, 0, 8) | (ELEM(zm1
, 0, 8) << 8)
1972 | (ELEM(zd1
, 1, 8) << 16) | (ELEM(zm1
, 1, 8) << 24)
1973 | (ELEM(zd1
, 2, 8) << 32) | (ELEM(zm1
, 2, 8) << 40)
1974 | (ELEM(zd1
, 3, 8) << 48) | (ELEM(zm1
, 3, 8) << 56);
1975 uint64_t m1
= ELEM(zd1
, 4, 8) | (ELEM(zm1
, 4, 8) << 8)
1976 | (ELEM(zd1
, 5, 8) << 16) | (ELEM(zm1
, 5, 8) << 24)
1977 | (ELEM(zd1
, 6, 8) << 32) | (ELEM(zm1
, 6, 8) << 40)
1978 | (ELEM(zd1
, 7, 8) << 48) | (ELEM(zm1
, 7, 8) << 56);
1979 env
->vfp
.regs
[rm
] = make_float64(m0
);
1980 env
->vfp
.regs
[rm
+ 1] = make_float64(m1
);
1981 env
->vfp
.regs
[rd
] = make_float64(d0
);
1982 env
->vfp
.regs
[rd
+ 1] = make_float64(d1
);
1985 void HELPER(neon_qzip16
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
1987 uint64_t zm0
= float64_val(env
->vfp
.regs
[rm
]);
1988 uint64_t zm1
= float64_val(env
->vfp
.regs
[rm
+ 1]);
1989 uint64_t zd0
= float64_val(env
->vfp
.regs
[rd
]);
1990 uint64_t zd1
= float64_val(env
->vfp
.regs
[rd
+ 1]);
1991 uint64_t d0
= ELEM(zd0
, 0, 16) | (ELEM(zm0
, 0, 16) << 16)
1992 | (ELEM(zd0
, 1, 16) << 32) | (ELEM(zm0
, 1, 16) << 48);
1993 uint64_t d1
= ELEM(zd0
, 2, 16) | (ELEM(zm0
, 2, 16) << 16)
1994 | (ELEM(zd0
, 3, 16) << 32) | (ELEM(zm0
, 3, 16) << 48);
1995 uint64_t m0
= ELEM(zd1
, 0, 16) | (ELEM(zm1
, 0, 16) << 16)
1996 | (ELEM(zd1
, 1, 16) << 32) | (ELEM(zm1
, 1, 16) << 48);
1997 uint64_t m1
= ELEM(zd1
, 2, 16) | (ELEM(zm1
, 2, 16) << 16)
1998 | (ELEM(zd1
, 3, 16) << 32) | (ELEM(zm1
, 3, 16) << 48);
1999 env
->vfp
.regs
[rm
] = make_float64(m0
);
2000 env
->vfp
.regs
[rm
+ 1] = make_float64(m1
);
2001 env
->vfp
.regs
[rd
] = make_float64(d0
);
2002 env
->vfp
.regs
[rd
+ 1] = make_float64(d1
);
2005 void HELPER(neon_qzip32
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
2007 uint64_t zm0
= float64_val(env
->vfp
.regs
[rm
]);
2008 uint64_t zm1
= float64_val(env
->vfp
.regs
[rm
+ 1]);
2009 uint64_t zd0
= float64_val(env
->vfp
.regs
[rd
]);
2010 uint64_t zd1
= float64_val(env
->vfp
.regs
[rd
+ 1]);
2011 uint64_t d0
= ELEM(zd0
, 0, 32) | (ELEM(zm0
, 0, 32) << 32);
2012 uint64_t d1
= ELEM(zd0
, 1, 32) | (ELEM(zm0
, 1, 32) << 32);
2013 uint64_t m0
= ELEM(zd1
, 0, 32) | (ELEM(zm1
, 0, 32) << 32);
2014 uint64_t m1
= ELEM(zd1
, 1, 32) | (ELEM(zm1
, 1, 32) << 32);
2015 env
->vfp
.regs
[rm
] = make_float64(m0
);
2016 env
->vfp
.regs
[rm
+ 1] = make_float64(m1
);
2017 env
->vfp
.regs
[rd
] = make_float64(d0
);
2018 env
->vfp
.regs
[rd
+ 1] = make_float64(d1
);
2021 void HELPER(neon_zip8
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
2023 uint64_t zm
= float64_val(env
->vfp
.regs
[rm
]);
2024 uint64_t zd
= float64_val(env
->vfp
.regs
[rd
]);
2025 uint64_t d0
= ELEM(zd
, 0, 8) | (ELEM(zm
, 0, 8) << 8)
2026 | (ELEM(zd
, 1, 8) << 16) | (ELEM(zm
, 1, 8) << 24)
2027 | (ELEM(zd
, 2, 8) << 32) | (ELEM(zm
, 2, 8) << 40)
2028 | (ELEM(zd
, 3, 8) << 48) | (ELEM(zm
, 3, 8) << 56);
2029 uint64_t m0
= ELEM(zd
, 4, 8) | (ELEM(zm
, 4, 8) << 8)
2030 | (ELEM(zd
, 5, 8) << 16) | (ELEM(zm
, 5, 8) << 24)
2031 | (ELEM(zd
, 6, 8) << 32) | (ELEM(zm
, 6, 8) << 40)
2032 | (ELEM(zd
, 7, 8) << 48) | (ELEM(zm
, 7, 8) << 56);
2033 env
->vfp
.regs
[rm
] = make_float64(m0
);
2034 env
->vfp
.regs
[rd
] = make_float64(d0
);
2037 void HELPER(neon_zip16
)(CPUState
*env
, uint32_t rd
, uint32_t rm
)
2039 uint64_t zm
= float64_val(env
->vfp
.regs
[rm
]);
2040 uint64_t zd
= float64_val(env
->vfp
.regs
[rd
]);
2041 uint64_t d0
= ELEM(zd
, 0, 16) | (ELEM(zm
, 0, 16) << 16)
2042 | (ELEM(zd
, 1, 16) << 32) | (ELEM(zm
, 1, 16) << 48);
2043 uint64_t m0
= ELEM(zd
, 2, 16) | (ELEM(zm
, 2, 16) << 16)
2044 | (ELEM(zd
, 3, 16) << 32) | (ELEM(zm
, 3, 16) << 48);
2045 env
->vfp
.regs
[rm
] = make_float64(m0
);
2046 env
->vfp
.regs
[rd
] = make_float64(d0
);