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 #define NEON_SSAT(dest, src1, src2, type) do { \
202 int32_t tmp = (uint32_t)src1 + (uint32_t)src2; \
203 if (tmp != (type)tmp) { \
206 tmp = (1 << (sizeof(type) * 8 - 1)) - 1; \
208 tmp = 1 << (sizeof(type) * 8 - 1); \
213 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int8_t)
214 NEON_VOP_ENV(qadd_s8
, neon_s8
, 4)
216 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int16_t)
217 NEON_VOP_ENV(qadd_s16
, neon_s16
, 2)
221 #define NEON_USAT(dest, src1, src2, type) do { \
222 uint32_t tmp = (uint32_t)src1 - (uint32_t)src2; \
223 if (tmp != (type)tmp) { \
229 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint8_t)
230 NEON_VOP_ENV(qsub_u8
, neon_u8
, 4)
232 #define NEON_FN(dest, src1, src2) NEON_USAT(dest, src1, src2, uint16_t)
233 NEON_VOP_ENV(qsub_u16
, neon_u16
, 2)
237 #define NEON_SSAT(dest, src1, src2, type) do { \
238 int32_t tmp = (uint32_t)src1 - (uint32_t)src2; \
239 if (tmp != (type)tmp) { \
242 tmp = (1 << (sizeof(type) * 8 - 1)) - 1; \
244 tmp = 1 << (sizeof(type) * 8 - 1); \
249 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int8_t)
250 NEON_VOP_ENV(qsub_s8
, neon_s8
, 4)
252 #define NEON_FN(dest, src1, src2) NEON_SSAT(dest, src1, src2, int16_t)
253 NEON_VOP_ENV(qsub_s16
, neon_s16
, 2)
257 #define NEON_FN(dest, src1, src2) dest = (src1 + src2) >> 1
258 NEON_VOP(hadd_s8
, neon_s8
, 4)
259 NEON_VOP(hadd_u8
, neon_u8
, 4)
260 NEON_VOP(hadd_s16
, neon_s16
, 2)
261 NEON_VOP(hadd_u16
, neon_u16
, 2)
264 int32_t HELPER(neon_hadd_s32
)(int32_t src1
, int32_t src2
)
268 dest
= (src1
>> 1) + (src2
>> 1);
274 uint32_t HELPER(neon_hadd_u32
)(uint32_t src1
, uint32_t src2
)
278 dest
= (src1
>> 1) + (src2
>> 1);
284 #define NEON_FN(dest, src1, src2) dest = (src1 + src2 + 1) >> 1
285 NEON_VOP(rhadd_s8
, neon_s8
, 4)
286 NEON_VOP(rhadd_u8
, neon_u8
, 4)
287 NEON_VOP(rhadd_s16
, neon_s16
, 2)
288 NEON_VOP(rhadd_u16
, neon_u16
, 2)
291 int32_t HELPER(neon_rhadd_s32
)(int32_t src1
, int32_t src2
)
295 dest
= (src1
>> 1) + (src2
>> 1);
296 if ((src1
| src2
) & 1)
301 uint32_t HELPER(neon_rhadd_u32
)(uint32_t src1
, uint32_t src2
)
305 dest
= (src1
>> 1) + (src2
>> 1);
306 if ((src1
| src2
) & 1)
311 #define NEON_FN(dest, src1, src2) dest = (src1 - src2) >> 1
312 NEON_VOP(hsub_s8
, neon_s8
, 4)
313 NEON_VOP(hsub_u8
, neon_u8
, 4)
314 NEON_VOP(hsub_s16
, neon_s16
, 2)
315 NEON_VOP(hsub_u16
, neon_u16
, 2)
318 int32_t HELPER(neon_hsub_s32
)(int32_t src1
, int32_t src2
)
322 dest
= (src1
>> 1) - (src2
>> 1);
323 if ((~src1
) & src2
& 1)
328 uint32_t HELPER(neon_hsub_u32
)(uint32_t src1
, uint32_t src2
)
332 dest
= (src1
>> 1) - (src2
>> 1);
333 if ((~src1
) & src2
& 1)
338 #define NEON_FN(dest, src1, src2) dest = (src1 > src2) ? ~0 : 0
339 NEON_VOP(cgt_s8
, neon_s8
, 4)
340 NEON_VOP(cgt_u8
, neon_u8
, 4)
341 NEON_VOP(cgt_s16
, neon_s16
, 2)
342 NEON_VOP(cgt_u16
, neon_u16
, 2)
343 NEON_VOP(cgt_s32
, neon_s32
, 1)
344 NEON_VOP(cgt_u32
, neon_u32
, 1)
347 #define NEON_FN(dest, src1, src2) dest = (src1 >= src2) ? ~0 : 0
348 NEON_VOP(cge_s8
, neon_s8
, 4)
349 NEON_VOP(cge_u8
, neon_u8
, 4)
350 NEON_VOP(cge_s16
, neon_s16
, 2)
351 NEON_VOP(cge_u16
, neon_u16
, 2)
352 NEON_VOP(cge_s32
, neon_s32
, 1)
353 NEON_VOP(cge_u32
, neon_u32
, 1)
356 #define NEON_FN(dest, src1, src2) dest = (src1 < src2) ? src1 : src2
357 NEON_VOP(min_s8
, neon_s8
, 4)
358 NEON_VOP(min_u8
, neon_u8
, 4)
359 NEON_VOP(min_s16
, neon_s16
, 2)
360 NEON_VOP(min_u16
, neon_u16
, 2)
361 NEON_VOP(min_s32
, neon_s32
, 1)
362 NEON_VOP(min_u32
, neon_u32
, 1)
363 NEON_POP(pmin_s8
, neon_s8
, 4)
364 NEON_POP(pmin_u8
, neon_u8
, 4)
365 NEON_POP(pmin_s16
, neon_s16
, 2)
366 NEON_POP(pmin_u16
, neon_u16
, 2)
369 #define NEON_FN(dest, src1, src2) dest = (src1 > src2) ? src1 : src2
370 NEON_VOP(max_s8
, neon_s8
, 4)
371 NEON_VOP(max_u8
, neon_u8
, 4)
372 NEON_VOP(max_s16
, neon_s16
, 2)
373 NEON_VOP(max_u16
, neon_u16
, 2)
374 NEON_VOP(max_s32
, neon_s32
, 1)
375 NEON_VOP(max_u32
, neon_u32
, 1)
376 NEON_POP(pmax_s8
, neon_s8
, 4)
377 NEON_POP(pmax_u8
, neon_u8
, 4)
378 NEON_POP(pmax_s16
, neon_s16
, 2)
379 NEON_POP(pmax_u16
, neon_u16
, 2)
382 #define NEON_FN(dest, src1, src2) \
383 dest = (src1 > src2) ? (src1 - src2) : (src2 - src1)
384 NEON_VOP(abd_s8
, neon_s8
, 4)
385 NEON_VOP(abd_u8
, neon_u8
, 4)
386 NEON_VOP(abd_s16
, neon_s16
, 2)
387 NEON_VOP(abd_u16
, neon_u16
, 2)
388 NEON_VOP(abd_s32
, neon_s32
, 1)
389 NEON_VOP(abd_u32
, neon_u32
, 1)
392 #define NEON_FN(dest, src1, src2) do { \
394 tmp = (int8_t)src2; \
395 if (tmp >= (ssize_t)sizeof(src1) * 8 || \
396 tmp <= -(ssize_t)sizeof(src1) * 8) { \
398 } else if (tmp < 0) { \
399 dest = src1 >> -tmp; \
401 dest = src1 << tmp; \
403 NEON_VOP(shl_u8
, neon_u8
, 4)
404 NEON_VOP(shl_u16
, neon_u16
, 2)
405 NEON_VOP(shl_u32
, neon_u32
, 1)
408 uint64_t HELPER(neon_shl_u64
)(uint64_t val
, uint64_t shiftop
)
410 int8_t shift
= (int8_t)shiftop
;
411 if (shift
>= 64 || shift
<= -64) {
413 } else if (shift
< 0) {
421 #define NEON_FN(dest, src1, src2) do { \
423 tmp = (int8_t)src2; \
424 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
426 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
427 dest = src1 >> (sizeof(src1) * 8 - 1); \
428 } else if (tmp < 0) { \
429 dest = src1 >> -tmp; \
431 dest = src1 << tmp; \
433 NEON_VOP(shl_s8
, neon_s8
, 4)
434 NEON_VOP(shl_s16
, neon_s16
, 2)
435 NEON_VOP(shl_s32
, neon_s32
, 1)
438 uint64_t HELPER(neon_shl_s64
)(uint64_t valop
, uint64_t shiftop
)
440 int8_t shift
= (int8_t)shiftop
;
444 } else if (shift
<= -64) {
446 } else if (shift
< 0) {
454 #define NEON_FN(dest, src1, src2) do { \
456 tmp = (int8_t)src2; \
457 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
459 } else if (tmp < -(ssize_t)sizeof(src1) * 8) { \
460 dest = src1 >> (sizeof(src1) * 8 - 1); \
461 } else if (tmp == -(ssize_t)sizeof(src1) * 8) { \
462 dest = src1 >> (tmp - 1); \
465 } else if (tmp < 0) { \
466 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
468 dest = src1 << tmp; \
470 NEON_VOP(rshl_s8
, neon_s8
, 4)
471 NEON_VOP(rshl_s16
, neon_s16
, 2)
472 NEON_VOP(rshl_s32
, neon_s32
, 1)
475 uint64_t HELPER(neon_rshl_s64
)(uint64_t valop
, uint64_t shiftop
)
477 int8_t shift
= (int8_t)shiftop
;
481 } else if (shift
< -64) {
483 } else if (shift
== -63) {
487 } else if (shift
< 0) {
488 val
= (val
+ ((int64_t)1 << (-1 - shift
))) >> -shift
;
495 #define NEON_FN(dest, src1, src2) do { \
497 tmp = (int8_t)src2; \
498 if (tmp >= (ssize_t)sizeof(src1) * 8 || \
499 tmp < -(ssize_t)sizeof(src1) * 8) { \
501 } else if (tmp == -(ssize_t)sizeof(src1) * 8) { \
502 dest = src1 >> (tmp - 1); \
503 } else if (tmp < 0) { \
504 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
506 dest = src1 << tmp; \
508 NEON_VOP(rshl_u8
, neon_u8
, 4)
509 NEON_VOP(rshl_u16
, neon_u16
, 2)
510 NEON_VOP(rshl_u32
, neon_u32
, 1)
513 uint64_t HELPER(neon_rshl_u64
)(uint64_t val
, uint64_t shiftop
)
515 int8_t shift
= (uint8_t)shiftop
;
516 if (shift
>= 64 || shift
< 64) {
518 } else if (shift
== -64) {
519 /* Rounding a 1-bit result just preserves that bit. */
522 val
= (val
+ ((uint64_t)1 << (-1 - shift
))) >> -shift
;
530 #define NEON_FN(dest, src1, src2) do { \
532 tmp = (int8_t)src2; \
533 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
540 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
542 } else if (tmp < 0) { \
543 dest = src1 >> -tmp; \
545 dest = src1 << tmp; \
546 if ((dest >> tmp) != src1) { \
551 NEON_VOP_ENV(qshl_u8
, neon_u8
, 4)
552 NEON_VOP_ENV(qshl_u16
, neon_u16
, 2)
553 NEON_VOP_ENV(qshl_u32
, neon_u32
, 1)
556 uint64_t HELPER(neon_qshl_u64
)(CPUState
*env
, uint64_t val
, uint64_t shiftop
)
558 int8_t shift
= (int8_t)shiftop
;
566 } else if (shift
<= -64) {
568 } else if (shift
< 0) {
573 if ((val
>> shift
) != tmp
) {
581 #define NEON_FN(dest, src1, src2) do { \
583 tmp = (int8_t)src2; \
584 if (tmp >= (ssize_t)sizeof(src1) * 8) { \
588 } else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
590 } else if (tmp < 0) { \
591 dest = src1 >> -tmp; \
593 dest = src1 << tmp; \
594 if ((dest >> tmp) != src1) { \
599 NEON_VOP_ENV(qshl_s8
, neon_s8
, 4)
600 NEON_VOP_ENV(qshl_s16
, neon_s16
, 2)
601 NEON_VOP_ENV(qshl_s32
, neon_s32
, 1)
604 uint64_t HELPER(neon_qshl_s64
)(CPUState
*env
, uint64_t valop
, uint64_t shiftop
)
606 int8_t shift
= (uint8_t)shiftop
;
611 val
= (val
>> 63) & ~SIGNBIT64
;
613 } else if (shift
<= 64) {
615 } else if (shift
< 0) {
620 if ((val
>> shift
) != tmp
) {
622 val
= (tmp
>> 63) ^ ~SIGNBIT64
;
629 /* FIXME: This is wrong. */
630 #define NEON_FN(dest, src1, src2) do { \
632 tmp = (int8_t)src2; \
634 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
636 dest = src1 << tmp; \
637 if ((dest >> tmp) != src1) { \
642 NEON_VOP_ENV(qrshl_u8
, neon_u8
, 4)
643 NEON_VOP_ENV(qrshl_u16
, neon_u16
, 2)
644 NEON_VOP_ENV(qrshl_u32
, neon_u32
, 1)
647 uint64_t HELPER(neon_qrshl_u64
)(CPUState
*env
, uint64_t val
, uint64_t shiftop
)
649 int8_t shift
= (int8_t)shiftop
;
651 val
= (val
+ (1 << (-1 - shift
))) >> -shift
;
655 if ((val
>> shift
) != tmp
) {
663 #define NEON_FN(dest, src1, src2) do { \
665 tmp = (int8_t)src2; \
667 dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
669 dest = src1 << tmp; \
670 if ((dest >> tmp) != src1) { \
675 NEON_VOP_ENV(qrshl_s8
, neon_s8
, 4)
676 NEON_VOP_ENV(qrshl_s16
, neon_s16
, 2)
677 NEON_VOP_ENV(qrshl_s32
, neon_s32
, 1)
680 uint64_t HELPER(neon_qrshl_s64
)(CPUState
*env
, uint64_t valop
, uint64_t shiftop
)
682 int8_t shift
= (uint8_t)shiftop
;
686 val
= (val
+ (1 << (-1 - shift
))) >> -shift
;
690 if ((val
>> shift
) != tmp
) {
698 uint32_t HELPER(neon_add_u8
)(uint32_t a
, uint32_t b
)
701 mask
= (a
^ b
) & 0x80808080u
;
704 return (a
+ b
) ^ mask
;
707 uint32_t HELPER(neon_add_u16
)(uint32_t a
, uint32_t b
)
710 mask
= (a
^ b
) & 0x80008000u
;
713 return (a
+ b
) ^ mask
;
716 #define NEON_FN(dest, src1, src2) dest = src1 + src2
717 NEON_POP(padd_u8
, neon_u8
, 4)
718 NEON_POP(padd_u16
, neon_u16
, 2)
721 #define NEON_FN(dest, src1, src2) dest = src1 - src2
722 NEON_VOP(sub_u8
, neon_u8
, 4)
723 NEON_VOP(sub_u16
, neon_u16
, 2)
726 #define NEON_FN(dest, src1, src2) dest = src1 * src2
727 NEON_VOP(mul_u8
, neon_u8
, 4)
728 NEON_VOP(mul_u16
, neon_u16
, 2)
731 /* Polynomial multiplication is like integer multiplication except the
732 partial products are XORed, not added. */
733 uint32_t HELPER(neon_mul_p8
)(uint32_t op1
, uint32_t op2
)
745 mask
|= (0xff << 16);
747 mask
|= (0xff << 24);
748 result
^= op2
& mask
;
749 op1
= (op1
>> 1) & 0x7f7f7f7f;
750 op2
= (op2
<< 1) & 0xfefefefe;
755 #define NEON_FN(dest, src1, src2) dest = (src1 & src2) ? -1 : 0
756 NEON_VOP(tst_u8
, neon_u8
, 4)
757 NEON_VOP(tst_u16
, neon_u16
, 2)
758 NEON_VOP(tst_u32
, neon_u32
, 1)
761 #define NEON_FN(dest, src1, src2) dest = (src1 == src2) ? -1 : 0
762 NEON_VOP(ceq_u8
, neon_u8
, 4)
763 NEON_VOP(ceq_u16
, neon_u16
, 2)
764 NEON_VOP(ceq_u32
, neon_u32
, 1)
767 #define NEON_FN(dest, src, dummy) dest = (src < 0) ? -src : src
768 NEON_VOP1(abs_s8
, neon_s8
, 4)
769 NEON_VOP1(abs_s16
, neon_s16
, 2)
772 /* Count Leading Sign/Zero Bits. */
773 static inline int do_clz8(uint8_t x
)
781 static inline int do_clz16(uint16_t x
)
789 #define NEON_FN(dest, src, dummy) dest = do_clz8(src)
790 NEON_VOP1(clz_u8
, neon_u8
, 4)
793 #define NEON_FN(dest, src, dummy) dest = do_clz16(src)
794 NEON_VOP1(clz_u16
, neon_u16
, 2)
797 #define NEON_FN(dest, src, dummy) dest = do_clz8((src < 0) ? ~src : src) - 1
798 NEON_VOP1(cls_s8
, neon_s8
, 4)
801 #define NEON_FN(dest, src, dummy) dest = do_clz16((src < 0) ? ~src : src) - 1
802 NEON_VOP1(cls_s16
, neon_s16
, 2)
805 uint32_t HELPER(neon_cls_s32
)(uint32_t x
)
810 for (count
= 32; x
; count
--)
816 uint32_t HELPER(neon_cnt_u8
)(uint32_t x
)
818 x
= (x
& 0x55555555) + ((x
>> 1) & 0x55555555);
819 x
= (x
& 0x33333333) + ((x
>> 2) & 0x33333333);
820 x
= (x
& 0x0f0f0f0f) + ((x
>> 4) & 0x0f0f0f0f);
824 #define NEON_QDMULH16(dest, src1, src2, round) do { \
825 uint32_t tmp = (int32_t)(int16_t) src1 * (int16_t) src2; \
826 if ((tmp ^ (tmp << 1)) & SIGNBIT) { \
828 tmp = (tmp >> 31) ^ ~SIGNBIT; \
834 if ((int32_t)tmp < old) { \
841 #define NEON_FN(dest, src1, src2) NEON_QDMULH16(dest, src1, src2, 0)
842 NEON_VOP_ENV(qdmulh_s16
, neon_s16
, 2)
844 #define NEON_FN(dest, src1, src2) NEON_QDMULH16(dest, src1, src2, 1)
845 NEON_VOP_ENV(qrdmulh_s16
, neon_s16
, 2)
849 #define NEON_QDMULH32(dest, src1, src2, round) do { \
850 uint64_t tmp = (int64_t)(int32_t) src1 * (int32_t) src2; \
851 if ((tmp ^ (tmp << 1)) & SIGNBIT64) { \
853 tmp = (tmp >> 63) ^ ~SIGNBIT64; \
859 tmp += (int64_t)1 << 31; \
860 if ((int64_t)tmp < old) { \
862 tmp = SIGNBIT64 - 1; \
867 #define NEON_FN(dest, src1, src2) NEON_QDMULH32(dest, src1, src2, 0)
868 NEON_VOP_ENV(qdmulh_s32
, neon_s32
, 1)
870 #define NEON_FN(dest, src1, src2) NEON_QDMULH32(dest, src1, src2, 1)
871 NEON_VOP_ENV(qrdmulh_s32
, neon_s32
, 1)
875 uint32_t HELPER(neon_narrow_u8
)(uint64_t x
)
877 return (x
& 0xffu
) | ((x
>> 8) & 0xff00u
) | ((x
>> 16) & 0xff0000u
)
878 | ((x
>> 24) & 0xff000000u
);
881 uint32_t HELPER(neon_narrow_u16
)(uint64_t x
)
883 return (x
& 0xffffu
) | ((x
>> 16) & 0xffff0000u
);
886 uint32_t HELPER(neon_narrow_high_u8
)(uint64_t x
)
888 return ((x
>> 8) & 0xff) | ((x
>> 16) & 0xff00)
889 | ((x
>> 24) & 0xff0000) | ((x
>> 32) & 0xff000000);
892 uint32_t HELPER(neon_narrow_high_u16
)(uint64_t x
)
894 return ((x
>> 16) & 0xffff) | ((x
>> 32) & 0xffff0000);
897 uint32_t HELPER(neon_narrow_round_high_u8
)(uint64_t x
)
899 x
&= 0xff80ff80ff80ff80ull
;
900 x
+= 0x0080008000800080ull
;
901 return ((x
>> 8) & 0xff) | ((x
>> 16) & 0xff00)
902 | ((x
>> 24) & 0xff0000) | ((x
>> 32) & 0xff000000);
905 uint32_t HELPER(neon_narrow_round_high_u16
)(uint64_t x
)
907 x
&= 0xffff8000ffff8000ull
;
908 x
+= 0x0000800000008000ull
;
909 return ((x
>> 16) & 0xffff) | ((x
>> 32) & 0xffff0000);
912 uint32_t HELPER(neon_narrow_sat_u8
)(CPUState
*env
, uint64_t x
)
925 res |= (uint32_t)d << (n / 2);
935 uint32_t HELPER(neon_narrow_sat_s8
)(CPUState
*env
, uint64_t x
)
942 if (s != (int8_t)s) { \
943 d = (s >> 15) ^ 0x7f; \
948 res |= (uint32_t)d << (n / 2);
958 uint32_t HELPER(neon_narrow_sat_u16
)(CPUState
*env
, uint64_t x
)
972 return low
| (high
<< 16);
975 uint32_t HELPER(neon_narrow_sat_s16
)(CPUState
*env
, uint64_t x
)
980 if (low
!= (int16_t)low
) {
981 low
= (low
>> 31) ^ 0x7fff;
985 if (high
!= (int16_t)high
) {
986 high
= (high
>> 31) ^ 0x7fff;
989 return (uint16_t)low
| (high
<< 16);
992 uint32_t HELPER(neon_narrow_sat_u32
)(CPUState
*env
, uint64_t x
)
994 if (x
> 0xffffffffu
) {
1001 uint32_t HELPER(neon_narrow_sat_s32
)(CPUState
*env
, uint64_t x
)
1003 if ((int64_t)x
!= (int32_t)x
) {
1005 return (x
>> 63) ^ 0x7fffffff;
1010 uint64_t HELPER(neon_widen_u8
)(uint32_t x
)
1015 tmp
= (uint8_t)(x
>> 8);
1017 tmp
= (uint8_t)(x
>> 16);
1019 tmp
= (uint8_t)(x
>> 24);
1024 uint64_t HELPER(neon_widen_s8
)(uint32_t x
)
1028 ret
= (uint16_t)(int8_t)x
;
1029 tmp
= (uint16_t)(int8_t)(x
>> 8);
1031 tmp
= (uint16_t)(int8_t)(x
>> 16);
1033 tmp
= (uint16_t)(int8_t)(x
>> 24);
1038 uint64_t HELPER(neon_widen_u16
)(uint32_t x
)
1040 uint64_t high
= (uint16_t)(x
>> 16);
1041 return ((uint16_t)x
) | (high
<< 32);
1044 uint64_t HELPER(neon_widen_s16
)(uint32_t x
)
1046 uint64_t high
= (int16_t)(x
>> 16);
1047 return ((uint32_t)(int16_t)x
) | (high
<< 32);
1050 uint64_t HELPER(neon_addl_u16
)(uint64_t a
, uint64_t b
)
1053 mask
= (a
^ b
) & 0x8000800080008000ull
;
1054 a
&= ~0x8000800080008000ull
;
1055 b
&= ~0x8000800080008000ull
;
1056 return (a
+ b
) ^ mask
;
1059 uint64_t HELPER(neon_addl_u32
)(uint64_t a
, uint64_t b
)
1062 mask
= (a
^ b
) & 0x8000000080000000ull
;
1063 a
&= ~0x8000000080000000ull
;
1064 b
&= ~0x8000000080000000ull
;
1065 return (a
+ b
) ^ mask
;
1068 uint64_t HELPER(neon_paddl_u16
)(uint64_t a
, uint64_t b
)
1073 tmp
= a
& 0x0000ffff0000ffffull
;
1074 tmp
+= (a
>> 16) & 0x0000ffff0000ffffull
;
1075 tmp2
= b
& 0xffff0000ffff0000ull
;
1076 tmp2
+= (b
<< 16) & 0xffff0000ffff0000ull
;
1077 return ( tmp
& 0xffff)
1078 | ((tmp
>> 16) & 0xffff0000ull
)
1079 | ((tmp2
<< 16) & 0xffff00000000ull
)
1080 | ( tmp2
& 0xffff000000000000ull
);
1083 uint64_t HELPER(neon_paddl_u32
)(uint64_t a
, uint64_t b
)
1085 uint32_t low
= a
+ (a
>> 32);
1086 uint32_t high
= b
+ (b
>> 32);
1087 return low
+ ((uint64_t)high
<< 32);
1090 uint64_t HELPER(neon_subl_u16
)(uint64_t a
, uint64_t b
)
1093 mask
= (a
^ ~b
) & 0x8000800080008000ull
;
1094 a
|= 0x8000800080008000ull
;
1095 b
&= ~0x8000800080008000ull
;
1096 return (a
- b
) ^ mask
;
1099 uint64_t HELPER(neon_subl_u32
)(uint64_t a
, uint64_t b
)
1102 mask
= (a
^ ~b
) & 0x8000000080000000ull
;
1103 a
|= 0x8000000080000000ull
;
1104 b
&= ~0x8000000080000000ull
;
1105 return (a
- b
) ^ mask
;
1108 uint64_t HELPER(neon_addl_saturate_s32
)(CPUState
*env
, uint64_t a
, uint64_t b
)
1116 if (((low
^ x
) & SIGNBIT
) && !((x
^ y
) & SIGNBIT
)) {
1118 low
= ((int32_t)x
>> 31) ^ ~SIGNBIT
;
1123 if (((high
^ x
) & SIGNBIT
) && !((x
^ y
) & SIGNBIT
)) {
1125 high
= ((int32_t)x
>> 31) ^ ~SIGNBIT
;
1127 return low
| ((uint64_t)high
<< 32);
1130 uint64_t HELPER(neon_addl_saturate_s64
)(CPUState
*env
, uint64_t a
, uint64_t b
)
1135 if (((result
^ a
) & SIGNBIT64
) && !((a
^ b
) & SIGNBIT64
)) {
1137 result
= ((int64_t)a
>> 63) ^ ~SIGNBIT64
;
1142 #define DO_ABD(dest, x, y, type) do { \
1145 dest = ((tmp_x > tmp_y) ? tmp_x - tmp_y : tmp_y - tmp_x); \
1148 uint64_t HELPER(neon_abdl_u16
)(uint32_t a
, uint32_t b
)
1152 DO_ABD(result
, a
, b
, uint8_t);
1153 DO_ABD(tmp
, a
>> 8, b
>> 8, uint8_t);
1154 result
|= tmp
<< 16;
1155 DO_ABD(tmp
, a
>> 16, b
>> 16, uint8_t);
1156 result
|= tmp
<< 32;
1157 DO_ABD(tmp
, a
>> 24, b
>> 24, uint8_t);
1158 result
|= tmp
<< 48;
1162 uint64_t HELPER(neon_abdl_s16
)(uint32_t a
, uint32_t b
)
1166 DO_ABD(result
, a
, b
, int8_t);
1167 DO_ABD(tmp
, a
>> 8, b
>> 8, int8_t);
1168 result
|= tmp
<< 16;
1169 DO_ABD(tmp
, a
>> 16, b
>> 16, int8_t);
1170 result
|= tmp
<< 32;
1171 DO_ABD(tmp
, a
>> 24, b
>> 24, int8_t);
1172 result
|= tmp
<< 48;
1176 uint64_t HELPER(neon_abdl_u32
)(uint32_t a
, uint32_t b
)
1180 DO_ABD(result
, a
, b
, uint16_t);
1181 DO_ABD(tmp
, a
>> 16, b
>> 16, uint16_t);
1182 return result
| (tmp
<< 32);
1185 uint64_t HELPER(neon_abdl_s32
)(uint32_t a
, uint32_t b
)
1189 DO_ABD(result
, a
, b
, int16_t);
1190 DO_ABD(tmp
, a
>> 16, b
>> 16, int16_t);
1191 return result
| (tmp
<< 32);
1194 uint64_t HELPER(neon_abdl_u64
)(uint32_t a
, uint32_t b
)
1197 DO_ABD(result
, a
, b
, uint32_t);
1201 uint64_t HELPER(neon_abdl_s64
)(uint32_t a
, uint32_t b
)
1204 DO_ABD(result
, a
, b
, int32_t);
1209 /* Widening multiply. Named type is the source type. */
1210 #define DO_MULL(dest, x, y, type1, type2) do { \
1213 dest = (type2)((type2)tmp_x * (type2)tmp_y); \
1216 uint64_t HELPER(neon_mull_u8
)(uint32_t a
, uint32_t b
)
1221 DO_MULL(result
, a
, b
, uint8_t, uint16_t);
1222 DO_MULL(tmp
, a
>> 8, b
>> 8, uint8_t, uint16_t);
1223 result
|= tmp
<< 16;
1224 DO_MULL(tmp
, a
>> 16, b
>> 16, uint8_t, uint16_t);
1225 result
|= tmp
<< 32;
1226 DO_MULL(tmp
, a
>> 24, b
>> 24, uint8_t, uint16_t);
1227 result
|= tmp
<< 48;
1231 uint64_t HELPER(neon_mull_s8
)(uint32_t a
, uint32_t b
)
1236 DO_MULL(result
, a
, b
, int8_t, uint16_t);
1237 DO_MULL(tmp
, a
>> 8, b
>> 8, int8_t, uint16_t);
1238 result
|= tmp
<< 16;
1239 DO_MULL(tmp
, a
>> 16, b
>> 16, int8_t, uint16_t);
1240 result
|= tmp
<< 32;
1241 DO_MULL(tmp
, a
>> 24, b
>> 24, int8_t, uint16_t);
1242 result
|= tmp
<< 48;
1246 uint64_t HELPER(neon_mull_u16
)(uint32_t a
, uint32_t b
)
1251 DO_MULL(result
, a
, b
, uint16_t, uint32_t);
1252 DO_MULL(tmp
, a
>> 16, b
>> 16, uint16_t, uint32_t);
1253 return result
| (tmp
<< 32);
1256 uint64_t HELPER(neon_mull_s16
)(uint32_t a
, uint32_t b
)
1261 DO_MULL(result
, a
, b
, int16_t, uint32_t);
1262 DO_MULL(tmp
, a
>> 16, b
>> 16, int16_t, uint32_t);
1263 return result
| (tmp
<< 32);
1266 uint64_t HELPER(neon_negl_u16
)(uint64_t x
)
1270 result
= (uint16_t)-x
;
1272 result
|= (uint64_t)tmp
<< 16;
1274 result
|= (uint64_t)tmp
<< 32;
1276 result
|= (uint64_t)tmp
<< 48;
1281 uint64_t HELPER(neon_negl_u32
)(uint64_t x
)
1284 uint32_t high
= -(x
>> 32);
1285 return low
| ((uint64_t)high
<< 32);
1288 /* FIXME: There should be a native op for this. */
1289 uint64_t HELPER(neon_negl_u64
)(uint64_t x
)
1294 /* Saturnating sign manuipulation. */
1295 /* ??? Make these use NEON_VOP1 */
1296 #define DO_QABS8(x) do { \
1297 if (x == (int8_t)0x80) { \
1300 } else if (x < 0) { \
1303 uint32_t HELPER(neon_qabs_s8
)(CPUState
*env
, uint32_t x
)
1306 NEON_UNPACK(neon_s8
, vec
, x
);
1311 NEON_PACK(neon_s8
, x
, vec
);
1316 #define DO_QNEG8(x) do { \
1317 if (x == (int8_t)0x80) { \
1323 uint32_t HELPER(neon_qneg_s8
)(CPUState
*env
, uint32_t x
)
1326 NEON_UNPACK(neon_s8
, vec
, x
);
1331 NEON_PACK(neon_s8
, x
, vec
);
1336 #define DO_QABS16(x) do { \
1337 if (x == (int16_t)0x8000) { \
1340 } else if (x < 0) { \
1343 uint32_t HELPER(neon_qabs_s16
)(CPUState
*env
, uint32_t x
)
1346 NEON_UNPACK(neon_s16
, vec
, x
);
1349 NEON_PACK(neon_s16
, x
, vec
);
1354 #define DO_QNEG16(x) do { \
1355 if (x == (int16_t)0x8000) { \
1361 uint32_t HELPER(neon_qneg_s16
)(CPUState
*env
, uint32_t x
)
1364 NEON_UNPACK(neon_s16
, vec
, x
);
1367 NEON_PACK(neon_s16
, x
, vec
);
1372 uint32_t HELPER(neon_qabs_s32
)(CPUState
*env
, uint32_t x
)
1377 } else if ((int32_t)x
< 0) {
1383 uint32_t HELPER(neon_qneg_s32
)(CPUState
*env
, uint32_t x
)
1394 /* NEON Float helpers. */
1395 uint32_t HELPER(neon_min_f32
)(uint32_t a
, uint32_t b
)
1397 float32 f0
= vfp_itos(a
);
1398 float32 f1
= vfp_itos(b
);
1399 return (float32_compare_quiet(f0
, f1
, NFS
) == -1) ? a
: b
;
1402 uint32_t HELPER(neon_max_f32
)(uint32_t a
, uint32_t b
)
1404 float32 f0
= vfp_itos(a
);
1405 float32 f1
= vfp_itos(b
);
1406 return (float32_compare_quiet(f0
, f1
, NFS
) == 1) ? a
: b
;
1409 uint32_t HELPER(neon_abd_f32
)(uint32_t a
, uint32_t b
)
1411 float32 f0
= vfp_itos(a
);
1412 float32 f1
= vfp_itos(b
);
1413 return vfp_stoi((float32_compare_quiet(f0
, f1
, NFS
) == 1)
1414 ? float32_sub(f0
, f1
, NFS
)
1415 : float32_sub(f1
, f0
, NFS
));
1418 uint32_t HELPER(neon_add_f32
)(uint32_t a
, uint32_t b
)
1420 return vfp_stoi(float32_add(vfp_itos(a
), vfp_itos(b
), NFS
));
1423 uint32_t HELPER(neon_sub_f32
)(uint32_t a
, uint32_t b
)
1425 return vfp_stoi(float32_sub(vfp_itos(a
), vfp_itos(b
), NFS
));
1428 uint32_t HELPER(neon_mul_f32
)(uint32_t a
, uint32_t b
)
1430 return vfp_stoi(float32_mul(vfp_itos(a
), vfp_itos(b
), NFS
));
1433 /* Floating point comparisons produce an integer result. */
1434 #define NEON_VOP_FCMP(name, cmp) \
1435 uint32_t HELPER(neon_##name)(uint32_t a, uint32_t b) \
1437 if (float32_compare_quiet(vfp_itos(a), vfp_itos(b), NFS) cmp 0) \
1443 NEON_VOP_FCMP(ceq_f32
, ==)
1444 NEON_VOP_FCMP(cge_f32
, >=)
1445 NEON_VOP_FCMP(cgt_f32
, >)
1447 uint32_t HELPER(neon_acge_f32
)(uint32_t a
, uint32_t b
)
1449 float32 f0
= float32_abs(vfp_itos(a
));
1450 float32 f1
= float32_abs(vfp_itos(b
));
1451 return (float32_compare_quiet(f0
, f1
,NFS
) >= 0) ? ~0 : 0;
1454 uint32_t HELPER(neon_acgt_f32
)(uint32_t a
, uint32_t b
)
1456 float32 f0
= float32_abs(vfp_itos(a
));
1457 float32 f1
= float32_abs(vfp_itos(b
));
1458 return (float32_compare_quiet(f0
, f1
, NFS
) > 0) ? ~0 : 0;