2 * MIPS ASE DSP Instruction emulation helpers for QEMU.
4 * Copyright (c) 2012 Jia Liu <proljc@gmail.com>
5 * Dongxue Zhang <elta.era@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 /* As the byte ordering doesn't matter, i.e. all columns are treated
24 identically, these unions can be used directly. */
45 /*** MIPS DSP internal functions begin ***/
46 #define MIPSDSP_ABS(x) (((x) >= 0) ? x : -x)
47 #define MIPSDSP_OVERFLOW_ADD(a, b, c, d) (~(a ^ b) & (a ^ c) & d)
48 #define MIPSDSP_OVERFLOW_SUB(a, b, c, d) ((a ^ b) & (a ^ c) & d)
50 static inline void set_DSPControl_overflow_flag(uint32_t flag
, int position
,
53 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< position
;
56 static inline void set_DSPControl_carryflag(uint32_t flag
, CPUMIPSState
*env
)
58 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 13;
61 static inline uint32_t get_DSPControl_carryflag(CPUMIPSState
*env
)
63 return (env
->active_tc
.DSPControl
>> 13) & 0x01;
66 static inline void set_DSPControl_24(uint32_t flag
, int len
, CPUMIPSState
*env
)
70 filter
= ((0x01 << len
) - 1) << 24;
73 env
->active_tc
.DSPControl
&= filter
;
74 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 24;
77 static inline uint32_t get_DSPControl_24(int len
, CPUMIPSState
*env
)
81 filter
= (0x01 << len
) - 1;
83 return (env
->active_tc
.DSPControl
>> 24) & filter
;
86 static inline void set_DSPControl_pos(uint32_t pos
, CPUMIPSState
*env
)
90 dspc
= env
->active_tc
.DSPControl
;
92 dspc
= dspc
& 0xFFFFFFC0;
95 dspc
= dspc
& 0xFFFFFF80;
98 env
->active_tc
.DSPControl
= dspc
;
101 static inline uint32_t get_DSPControl_pos(CPUMIPSState
*env
)
106 dspc
= env
->active_tc
.DSPControl
;
108 #ifndef TARGET_MIPS64
117 static inline void set_DSPControl_efi(uint32_t flag
, CPUMIPSState
*env
)
119 env
->active_tc
.DSPControl
&= 0xFFFFBFFF;
120 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 14;
123 #define DO_MIPS_SAT_ABS(size) \
124 static inline int##size##_t mipsdsp_sat_abs##size(int##size##_t a, \
127 if (a == INT##size##_MIN) { \
128 set_DSPControl_overflow_flag(1, 20, env); \
129 return INT##size##_MAX; \
131 return MIPSDSP_ABS(a); \
137 #undef DO_MIPS_SAT_ABS
140 static inline int16_t mipsdsp_add_i16(int16_t a
, int16_t b
, CPUMIPSState
*env
)
146 if (MIPSDSP_OVERFLOW_ADD(a
, b
, tempI
, 0x8000)) {
147 set_DSPControl_overflow_flag(1, 20, env
);
153 static inline int16_t mipsdsp_sat_add_i16(int16_t a
, int16_t b
,
160 if (MIPSDSP_OVERFLOW_ADD(a
, b
, tempS
, 0x8000)) {
166 set_DSPControl_overflow_flag(1, 20, env
);
172 static inline int32_t mipsdsp_sat_add_i32(int32_t a
, int32_t b
,
179 if (MIPSDSP_OVERFLOW_ADD(a
, b
, tempI
, 0x80000000)) {
185 set_DSPControl_overflow_flag(1, 20, env
);
191 static inline uint8_t mipsdsp_add_u8(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
195 temp
= (uint16_t)a
+ (uint16_t)b
;
198 set_DSPControl_overflow_flag(1, 20, env
);
204 static inline uint16_t mipsdsp_add_u16(uint16_t a
, uint16_t b
,
209 temp
= (uint32_t)a
+ (uint32_t)b
;
211 if (temp
& 0x00010000) {
212 set_DSPControl_overflow_flag(1, 20, env
);
215 return temp
& 0xFFFF;
218 static inline uint8_t mipsdsp_sat_add_u8(uint8_t a
, uint8_t b
,
224 temp
= (uint16_t)a
+ (uint16_t)b
;
225 result
= temp
& 0xFF;
229 set_DSPControl_overflow_flag(1, 20, env
);
235 static inline uint16_t mipsdsp_sat_add_u16(uint16_t a
, uint16_t b
,
241 temp
= (uint32_t)a
+ (uint32_t)b
;
242 result
= temp
& 0xFFFF;
244 if (0x00010000 & temp
) {
246 set_DSPControl_overflow_flag(1, 20, env
);
252 static inline int32_t mipsdsp_sat32_acc_q31(int32_t acc
, int32_t a
,
256 int32_t temp32
, temp31
, result
;
259 #ifndef TARGET_MIPS64
260 temp
= ((uint64_t)env
->active_tc
.HI
[acc
] << 32) |
261 (uint64_t)env
->active_tc
.LO
[acc
];
263 temp
= (uint64_t)env
->active_tc
.LO
[acc
];
266 temp_sum
= (int64_t)a
+ temp
;
268 temp32
= (temp_sum
>> 32) & 0x01;
269 temp31
= (temp_sum
>> 31) & 0x01;
270 result
= temp_sum
& 0xFFFFFFFF;
273 This sat function may wrong, because user manual wrote:
274 temp127..0 ← temp + ( (signA) || a31..0
275 if ( temp32 ≠ temp31 ) then
276 if ( temp32 = 0 ) then
277 temp31..0 ← 0x80000000
279 temp31..0 ← 0x7FFFFFFF
281 DSPControlouflag:16+acc ← 1
284 if (temp32
!= temp31
) {
290 set_DSPControl_overflow_flag(1, 16 + acc
, env
);
296 /* a[0] is LO, a[1] is HI. */
297 static inline void mipsdsp_sat64_acc_add_q63(int64_t *ret
,
304 ret
[0] = env
->active_tc
.LO
[ac
] + a
[0];
305 ret
[1] = env
->active_tc
.HI
[ac
] + a
[1];
307 if (((uint64_t)ret
[0] < (uint64_t)env
->active_tc
.LO
[ac
]) &&
308 ((uint64_t)ret
[0] < (uint64_t)a
[0])) {
312 if (temp64
!= ((ret
[0] >> 63) & 0x01)) {
314 ret
[0] = (0x01ull
<< 63);
317 ret
[0] = (0x01ull
<< 63) - 1;
320 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
324 static inline void mipsdsp_sat64_acc_sub_q63(int64_t *ret
,
331 ret
[0] = env
->active_tc
.LO
[ac
] - a
[0];
332 ret
[1] = env
->active_tc
.HI
[ac
] - a
[1];
334 if ((uint64_t)ret
[0] > (uint64_t)env
->active_tc
.LO
[ac
]) {
338 if (temp64
!= ((ret
[0] >> 63) & 0x01)) {
340 ret
[0] = (0x01ull
<< 63);
343 ret
[0] = (0x01ull
<< 63) - 1;
346 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
350 static inline int32_t mipsdsp_mul_i16_i16(int16_t a
, int16_t b
,
355 temp
= (int32_t)a
* (int32_t)b
;
357 if ((temp
> (int)0x7FFF) || (temp
< (int)0xFFFF8000)) {
358 set_DSPControl_overflow_flag(1, 21, env
);
365 static inline int32_t mipsdsp_mul_u16_u16(int32_t a
, int32_t b
)
370 static inline int32_t mipsdsp_mul_i32_i32(int32_t a
, int32_t b
)
375 static inline int32_t mipsdsp_sat16_mul_i16_i16(int16_t a
, int16_t b
,
380 temp
= (int32_t)a
* (int32_t)b
;
382 if (temp
> (int)0x7FFF) {
384 set_DSPControl_overflow_flag(1, 21, env
);
385 } else if (temp
< (int)0xffff8000) {
387 set_DSPControl_overflow_flag(1, 21, env
);
394 static inline int32_t mipsdsp_mul_q15_q15_overflowflag21(uint16_t a
, uint16_t b
,
399 if ((a
== 0x8000) && (b
== 0x8000)) {
401 set_DSPControl_overflow_flag(1, 21, env
);
403 temp
= ((int32_t)(int16_t)a
* (int32_t)(int16_t)b
) << 1;
410 static inline uint8_t mipsdsp_rshift_u8(uint8_t a
, target_ulong mov
)
415 static inline uint16_t mipsdsp_rshift_u16(uint16_t a
, target_ulong mov
)
420 static inline int8_t mipsdsp_rashift8(int8_t a
, target_ulong mov
)
425 static inline int16_t mipsdsp_rashift16(int16_t a
, target_ulong mov
)
430 static inline int32_t mipsdsp_rashift32(int32_t a
, target_ulong mov
)
435 static inline int16_t mipsdsp_rshift1_add_q16(int16_t a
, int16_t b
)
439 temp
= (int32_t)a
+ (int32_t)b
;
441 return (temp
>> 1) & 0xFFFF;
444 /* round right shift */
445 static inline int16_t mipsdsp_rrshift1_add_q16(int16_t a
, int16_t b
)
449 temp
= (int32_t)a
+ (int32_t)b
;
452 return (temp
>> 1) & 0xFFFF;
455 static inline int32_t mipsdsp_rshift1_add_q32(int32_t a
, int32_t b
)
459 temp
= (int64_t)a
+ (int64_t)b
;
461 return (temp
>> 1) & 0xFFFFFFFF;
464 static inline int32_t mipsdsp_rrshift1_add_q32(int32_t a
, int32_t b
)
468 temp
= (int64_t)a
+ (int64_t)b
;
471 return (temp
>> 1) & 0xFFFFFFFF;
474 static inline uint8_t mipsdsp_rshift1_add_u8(uint8_t a
, uint8_t b
)
478 temp
= (uint16_t)a
+ (uint16_t)b
;
480 return (temp
>> 1) & 0x00FF;
483 static inline uint8_t mipsdsp_rrshift1_add_u8(uint8_t a
, uint8_t b
)
487 temp
= (uint16_t)a
+ (uint16_t)b
+ 1;
489 return (temp
>> 1) & 0x00FF;
492 static inline uint8_t mipsdsp_rshift1_sub_u8(uint8_t a
, uint8_t b
)
496 temp
= (uint16_t)a
- (uint16_t)b
;
498 return (temp
>> 1) & 0x00FF;
501 static inline uint8_t mipsdsp_rrshift1_sub_u8(uint8_t a
, uint8_t b
)
505 temp
= (uint16_t)a
- (uint16_t)b
+ 1;
507 return (temp
>> 1) & 0x00FF;
510 /* 128 bits long. p[0] is LO, p[1] is HI. */
511 static inline void mipsdsp_rndrashift_short_acc(int64_t *p
,
518 acc
= ((int64_t)env
->active_tc
.HI
[ac
] << 32) |
519 ((int64_t)env
->active_tc
.LO
[ac
] & 0xFFFFFFFF);
522 p
[1] = (acc
>> 63) & 0x01;
524 p
[0] = acc
>> (shift
- 1);
529 /* 128 bits long. p[0] is LO, p[1] is HI */
530 static inline void mipsdsp_rashift_acc(uint64_t *p
,
535 uint64_t tempB
, tempA
;
537 tempB
= env
->active_tc
.HI
[ac
];
538 tempA
= env
->active_tc
.LO
[ac
];
539 shift
= shift
& 0x1F;
545 p
[0] = (tempB
<< (64 - shift
)) | (tempA
>> shift
);
546 p
[1] = (int64_t)tempB
>> shift
;
550 /* 128 bits long. p[0] is LO, p[1] is HI , p[2] is sign of HI.*/
551 static inline void mipsdsp_rndrashift_acc(uint64_t *p
,
556 int64_t tempB
, tempA
;
558 tempB
= env
->active_tc
.HI
[ac
];
559 tempA
= env
->active_tc
.LO
[ac
];
560 shift
= shift
& 0x3F;
564 p
[1] = (tempB
<< 1) | (tempA
>> 63);
567 p
[0] = (tempB
<< (65 - shift
)) | (tempA
>> (shift
- 1));
568 p
[1] = (int64_t)tempB
>> (shift
- 1);
577 static inline int32_t mipsdsp_mul_q15_q15(int32_t ac
, uint16_t a
, uint16_t b
,
582 if ((a
== 0x8000) && (b
== 0x8000)) {
584 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
586 temp
= ((uint32_t)a
* (uint32_t)b
) << 1;
592 static inline int64_t mipsdsp_mul_q31_q31(int32_t ac
, uint32_t a
, uint32_t b
,
597 if ((a
== 0x80000000) && (b
== 0x80000000)) {
598 temp
= (0x01ull
<< 63) - 1;
599 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
601 temp
= ((uint64_t)a
* (uint64_t)b
) << 1;
607 static inline uint16_t mipsdsp_mul_u8_u8(uint8_t a
, uint8_t b
)
609 return (uint16_t)a
* (uint16_t)b
;
612 static inline uint16_t mipsdsp_mul_u8_u16(uint8_t a
, uint16_t b
,
617 tempI
= (uint32_t)a
* (uint32_t)b
;
618 if (tempI
> 0x0000FFFF) {
620 set_DSPControl_overflow_flag(1, 21, env
);
623 return tempI
& 0x0000FFFF;
626 static inline uint64_t mipsdsp_mul_u32_u32(uint32_t a
, uint32_t b
)
628 return (uint64_t)a
* (uint64_t)b
;
631 static inline int16_t mipsdsp_rndq15_mul_q15_q15(uint16_t a
, uint16_t b
,
636 if ((a
== 0x8000) && (b
== 0x8000)) {
638 set_DSPControl_overflow_flag(1, 21, env
);
641 temp
= temp
+ 0x00008000;
644 return (temp
& 0xFFFF0000) >> 16;
647 static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a
, uint16_t b
,
652 if ((a
== 0x8000) && (b
== 0x8000)) {
654 set_DSPControl_overflow_flag(1, 21, env
);
656 temp
= (int16_t)a
* (int16_t)b
;
660 return (temp
>> 16) & 0x0000FFFF;
663 static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a
,
668 temp
= (int32_t)a
+ 0x00008000;
670 if (a
> (int)0x7fff8000) {
672 set_DSPControl_overflow_flag(1, 22, env
);
675 return (temp
>> 16) & 0xFFFF;
678 static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a
,
684 sign
= (a
>> 15) & 0x01;
689 set_DSPControl_overflow_flag(1, 22, env
);
692 return (mag
>> 7) & 0xFFFF;
695 set_DSPControl_overflow_flag(1, 22, env
);
700 static inline uint8_t mipsdsp_lshift8(uint8_t a
, uint8_t s
, CPUMIPSState
*env
)
708 sign
= (a
>> 7) & 0x01;
710 discard
= (((0x01 << (8 - s
)) - 1) << s
) |
711 ((a
>> (6 - (s
- 1))) & ((0x01 << s
) - 1));
713 discard
= a
>> (6 - (s
- 1));
716 if (discard
!= 0x00) {
717 set_DSPControl_overflow_flag(1, 22, env
);
723 static inline uint16_t mipsdsp_lshift16(uint16_t a
, uint8_t s
,
732 sign
= (a
>> 15) & 0x01;
734 discard
= (((0x01 << (16 - s
)) - 1) << s
) |
735 ((a
>> (14 - (s
- 1))) & ((0x01 << s
) - 1));
737 discard
= a
>> (14 - (s
- 1));
740 if ((discard
!= 0x0000) && (discard
!= 0xFFFF)) {
741 set_DSPControl_overflow_flag(1, 22, env
);
748 static inline uint32_t mipsdsp_lshift32(uint32_t a
, uint8_t s
,
756 discard
= (int32_t)a
>> (31 - (s
- 1));
758 if ((discard
!= 0x00000000) && (discard
!= 0xFFFFFFFF)) {
759 set_DSPControl_overflow_flag(1, 22, env
);
765 static inline uint16_t mipsdsp_sat16_lshift(uint16_t a
, uint8_t s
,
774 sign
= (a
>> 15) & 0x01;
776 discard
= (((0x01 << (16 - s
)) - 1) << s
) |
777 ((a
>> (14 - (s
- 1))) & ((0x01 << s
) - 1));
779 discard
= a
>> (14 - (s
- 1));
782 if ((discard
!= 0x0000) && (discard
!= 0xFFFF)) {
783 set_DSPControl_overflow_flag(1, 22, env
);
784 return (sign
== 0) ? 0x7FFF : 0x8000;
791 static inline uint32_t mipsdsp_sat32_lshift(uint32_t a
, uint8_t s
,
800 sign
= (a
>> 31) & 0x01;
802 discard
= (((0x01 << (32 - s
)) - 1) << s
) |
803 ((a
>> (30 - (s
- 1))) & ((0x01 << s
) - 1));
805 discard
= a
>> (30 - (s
- 1));
808 if ((discard
!= 0x00000000) && (discard
!= 0xFFFFFFFF)) {
809 set_DSPControl_overflow_flag(1, 22, env
);
810 return (sign
== 0) ? 0x7FFFFFFF : 0x80000000;
817 static inline uint8_t mipsdsp_rnd8_rashift(uint8_t a
, uint8_t s
)
822 temp
= (uint32_t)a
<< 1;
824 temp
= (int32_t)(int8_t)a
>> (s
- 1);
827 return (temp
+ 1) >> 1;
830 static inline uint16_t mipsdsp_rnd16_rashift(uint16_t a
, uint8_t s
)
835 temp
= (uint32_t)a
<< 1;
837 temp
= (int32_t)(int16_t)a
>> (s
- 1);
840 return (temp
+ 1) >> 1;
843 static inline uint32_t mipsdsp_rnd32_rashift(uint32_t a
, uint8_t s
)
848 temp
= (uint64_t)a
<< 1;
850 temp
= (int64_t)(int32_t)a
>> (s
- 1);
854 return (temp
>> 1) & 0xFFFFFFFFull
;
857 static inline uint16_t mipsdsp_sub_i16(int16_t a
, int16_t b
, CPUMIPSState
*env
)
862 if (MIPSDSP_OVERFLOW_SUB(a
, b
, temp
, 0x8000)) {
863 set_DSPControl_overflow_flag(1, 20, env
);
869 static inline uint16_t mipsdsp_sat16_sub(int16_t a
, int16_t b
,
875 if (MIPSDSP_OVERFLOW_SUB(a
, b
, temp
, 0x8000)) {
881 set_DSPControl_overflow_flag(1, 20, env
);
887 static inline uint32_t mipsdsp_sat32_sub(int32_t a
, int32_t b
,
893 if (MIPSDSP_OVERFLOW_SUB(a
, b
, temp
, 0x80000000)) {
899 set_DSPControl_overflow_flag(1, 20, env
);
902 return temp
& 0xFFFFFFFFull
;
905 static inline uint16_t mipsdsp_rshift1_sub_q16(int16_t a
, int16_t b
)
909 temp
= (int32_t)a
- (int32_t)b
;
911 return (temp
>> 1) & 0x0000FFFF;
914 static inline uint16_t mipsdsp_rrshift1_sub_q16(int16_t a
, int16_t b
)
918 temp
= (int32_t)a
- (int32_t)b
;
921 return (temp
>> 1) & 0x0000FFFF;
924 static inline uint32_t mipsdsp_rshift1_sub_q32(int32_t a
, int32_t b
)
928 temp
= (int64_t)a
- (int64_t)b
;
930 return (temp
>> 1) & 0xFFFFFFFFull
;
933 static inline uint32_t mipsdsp_rrshift1_sub_q32(int32_t a
, int32_t b
)
937 temp
= (int64_t)a
- (int64_t)b
;
940 return (temp
>> 1) & 0xFFFFFFFFull
;
943 static inline uint16_t mipsdsp_sub_u16_u16(uint16_t a
, uint16_t b
,
949 temp
= (uint32_t)a
- (uint32_t)b
;
950 temp16
= (temp
>> 16) & 0x01;
952 set_DSPControl_overflow_flag(1, 20, env
);
954 return temp
& 0x0000FFFF;
957 static inline uint16_t mipsdsp_satu16_sub_u16_u16(uint16_t a
, uint16_t b
,
963 temp
= (uint32_t)a
- (uint32_t)b
;
964 temp16
= (temp
>> 16) & 0x01;
968 set_DSPControl_overflow_flag(1, 20, env
);
971 return temp
& 0x0000FFFF;
974 static inline uint8_t mipsdsp_sub_u8(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
979 temp
= (uint16_t)a
- (uint16_t)b
;
980 temp8
= (temp
>> 8) & 0x01;
982 set_DSPControl_overflow_flag(1, 20, env
);
985 return temp
& 0x00FF;
988 static inline uint8_t mipsdsp_satu8_sub(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
993 temp
= (uint16_t)a
- (uint16_t)b
;
994 temp8
= (temp
>> 8) & 0x01;
997 set_DSPControl_overflow_flag(1, 20, env
);
1000 return temp
& 0x00FF;
1003 static inline uint32_t mipsdsp_sub32(int32_t a
, int32_t b
, CPUMIPSState
*env
)
1008 if (MIPSDSP_OVERFLOW_SUB(a
, b
, temp
, 0x80000000)) {
1009 set_DSPControl_overflow_flag(1, 20, env
);
1015 static inline int32_t mipsdsp_add_i32(int32_t a
, int32_t b
, CPUMIPSState
*env
)
1021 if (MIPSDSP_OVERFLOW_ADD(a
, b
, temp
, 0x80000000)) {
1022 set_DSPControl_overflow_flag(1, 20, env
);
1028 static inline int32_t mipsdsp_cmp_eq(int32_t a
, int32_t b
)
1033 static inline int32_t mipsdsp_cmp_le(int32_t a
, int32_t b
)
1038 static inline int32_t mipsdsp_cmp_lt(int32_t a
, int32_t b
)
1043 static inline int32_t mipsdsp_cmpu_eq(uint32_t a
, uint32_t b
)
1048 static inline int32_t mipsdsp_cmpu_le(uint32_t a
, uint32_t b
)
1053 static inline int32_t mipsdsp_cmpu_lt(uint32_t a
, uint32_t b
)
1057 /*** MIPS DSP internal functions end ***/
1059 #define MIPSDSP_LHI 0xFFFFFFFF00000000ull
1060 #define MIPSDSP_LLO 0x00000000FFFFFFFFull
1061 #define MIPSDSP_HI 0xFFFF0000
1062 #define MIPSDSP_LO 0x0000FFFF
1063 #define MIPSDSP_Q3 0xFF000000
1064 #define MIPSDSP_Q2 0x00FF0000
1065 #define MIPSDSP_Q1 0x0000FF00
1066 #define MIPSDSP_Q0 0x000000FF
1068 #define MIPSDSP_SPLIT32_8(num, a, b, c, d) \
1070 a = (num >> 24) & MIPSDSP_Q0; \
1071 b = (num >> 16) & MIPSDSP_Q0; \
1072 c = (num >> 8) & MIPSDSP_Q0; \
1073 d = num & MIPSDSP_Q0; \
1076 #define MIPSDSP_SPLIT32_16(num, a, b) \
1078 a = (num >> 16) & MIPSDSP_LO; \
1079 b = num & MIPSDSP_LO; \
1082 #define MIPSDSP_RETURN32_8(a, b, c, d) ((target_long)(int32_t) \
1083 (((uint32_t)a << 24) | \
1084 (((uint32_t)b << 16) | \
1085 (((uint32_t)c << 8) | \
1086 ((uint32_t)d & 0xFF)))))
1087 #define MIPSDSP_RETURN32_16(a, b) ((target_long)(int32_t) \
1088 (((uint32_t)a << 16) | \
1089 ((uint32_t)b & 0xFFFF)))
1091 #ifdef TARGET_MIPS64
1092 #define MIPSDSP_SPLIT64_16(num, a, b, c, d) \
1094 a = (num >> 48) & MIPSDSP_LO; \
1095 b = (num >> 32) & MIPSDSP_LO; \
1096 c = (num >> 16) & MIPSDSP_LO; \
1097 d = num & MIPSDSP_LO; \
1100 #define MIPSDSP_SPLIT64_32(num, a, b) \
1102 a = (num >> 32) & MIPSDSP_LLO; \
1103 b = num & MIPSDSP_LLO; \
1106 #define MIPSDSP_RETURN64_16(a, b, c, d) (((uint64_t)a << 48) | \
1107 ((uint64_t)b << 32) | \
1108 ((uint64_t)c << 16) | \
1110 #define MIPSDSP_RETURN64_32(a, b) (((uint64_t)a << 32) | (uint64_t)b)
1113 /** DSP Arithmetic Sub-class insns **/
1114 #define MIPSDSP32_UNOP_ENV(name, func, element) \
1115 target_ulong helper_##name(target_ulong rt, CPUMIPSState *env) \
1118 unsigned int i, n; \
1120 n = sizeof(DSP32Value) / sizeof(dt.element[0]); \
1123 for (i = 0; i < n; i++) { \
1124 dt.element[i] = mipsdsp_##func(dt.element[i], env); \
1127 return (target_long)dt.sw[0]; \
1129 MIPSDSP32_UNOP_ENV(absq_s_ph
, sat_abs16
, sh
)
1130 MIPSDSP32_UNOP_ENV(absq_s_qb
, sat_abs8
, sb
)
1131 MIPSDSP32_UNOP_ENV(absq_s_w
, sat_abs32
, sw
)
1132 #undef MIPSDSP32_UNOP_ENV
1134 #if defined(TARGET_MIPS64)
1135 #define MIPSDSP64_UNOP_ENV(name, func, element) \
1136 target_ulong helper_##name(target_ulong rt, CPUMIPSState *env) \
1139 unsigned int i, n; \
1141 n = sizeof(DSP64Value) / sizeof(dt.element[0]); \
1144 for (i = 0; i < n; i++) { \
1145 dt.element[i] = mipsdsp_##func(dt.element[i], env); \
1150 MIPSDSP64_UNOP_ENV(absq_s_ob
, sat_abs8
, sb
)
1151 MIPSDSP64_UNOP_ENV(absq_s_qh
, sat_abs16
, sh
)
1152 MIPSDSP64_UNOP_ENV(absq_s_pw
, sat_abs32
, sw
)
1153 #undef MIPSDSP64_UNOP_ENV
1156 #define MIPSDSP32_BINOP(name, func, element) \
1157 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
1159 DSP32Value ds, dt; \
1160 unsigned int i, n; \
1162 n = sizeof(DSP32Value) / sizeof(ds.element[0]); \
1166 for (i = 0; i < n; i++) { \
1167 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i]); \
1170 return (target_long)ds.sw[0]; \
1172 MIPSDSP32_BINOP(addqh_ph
, rshift1_add_q16
, sh
);
1173 MIPSDSP32_BINOP(addqh_r_ph
, rrshift1_add_q16
, sh
);
1174 MIPSDSP32_BINOP(addqh_r_w
, rrshift1_add_q32
, sw
);
1175 MIPSDSP32_BINOP(addqh_w
, rshift1_add_q32
, sw
);
1176 MIPSDSP32_BINOP(adduh_qb
, rshift1_add_u8
, ub
);
1177 MIPSDSP32_BINOP(adduh_r_qb
, rrshift1_add_u8
, ub
);
1178 MIPSDSP32_BINOP(subqh_ph
, rshift1_sub_q16
, sh
);
1179 MIPSDSP32_BINOP(subqh_r_ph
, rrshift1_sub_q16
, sh
);
1180 MIPSDSP32_BINOP(subqh_r_w
, rrshift1_sub_q32
, sw
);
1181 MIPSDSP32_BINOP(subqh_w
, rshift1_sub_q32
, sw
);
1182 #undef MIPSDSP32_BINOP
1184 #define MIPSDSP32_BINOP_ENV(name, func, element) \
1185 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
1186 CPUMIPSState *env) \
1188 DSP32Value ds, dt; \
1189 unsigned int i, n; \
1191 n = sizeof(DSP32Value) / sizeof(ds.element[0]); \
1195 for (i = 0 ; i < n ; i++) { \
1196 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i], env); \
1199 return (target_long)ds.sw[0]; \
1201 MIPSDSP32_BINOP_ENV(addq_ph
, add_i16
, sh
)
1202 MIPSDSP32_BINOP_ENV(addq_s_ph
, sat_add_i16
, sh
)
1203 MIPSDSP32_BINOP_ENV(addq_s_w
, sat_add_i32
, sw
);
1204 MIPSDSP32_BINOP_ENV(addu_ph
, add_u16
, sh
)
1205 MIPSDSP32_BINOP_ENV(addu_qb
, add_u8
, ub
);
1206 MIPSDSP32_BINOP_ENV(addu_s_ph
, sat_add_u16
, sh
)
1207 MIPSDSP32_BINOP_ENV(addu_s_qb
, sat_add_u8
, ub
);
1208 MIPSDSP32_BINOP_ENV(subq_ph
, sub_i16
, sh
);
1209 MIPSDSP32_BINOP_ENV(subq_s_ph
, sat16_sub
, sh
);
1210 MIPSDSP32_BINOP_ENV(subq_s_w
, sat32_sub
, sw
);
1211 MIPSDSP32_BINOP_ENV(subu_ph
, sub_u16_u16
, sh
);
1212 MIPSDSP32_BINOP_ENV(subu_qb
, sub_u8
, ub
);
1213 MIPSDSP32_BINOP_ENV(subu_s_ph
, satu16_sub_u16_u16
, sh
);
1214 MIPSDSP32_BINOP_ENV(subu_s_qb
, satu8_sub
, ub
);
1215 #undef MIPSDSP32_BINOP_ENV
1217 #ifdef TARGET_MIPS64
1218 #define MIPSDSP64_BINOP(name, func, element) \
1219 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
1221 DSP64Value ds, dt; \
1222 unsigned int i, n; \
1224 n = sizeof(DSP64Value) / sizeof(ds.element[0]); \
1228 for (i = 0 ; i < n ; i++) { \
1229 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i]); \
1234 MIPSDSP64_BINOP(adduh_ob
, rshift1_add_u8
, ub
);
1235 MIPSDSP64_BINOP(adduh_r_ob
, rrshift1_add_u8
, ub
);
1236 MIPSDSP64_BINOP(subuh_ob
, rshift1_sub_u8
, ub
);
1237 MIPSDSP64_BINOP(subuh_r_ob
, rrshift1_sub_u8
, ub
);
1238 #undef MIPSDSP64_BINOP
1240 #define MIPSDSP64_BINOP_ENV(name, func, element) \
1241 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
1242 CPUMIPSState *env) \
1244 DSP64Value ds, dt; \
1245 unsigned int i, n; \
1247 n = sizeof(DSP64Value) / sizeof(ds.element[0]); \
1251 for (i = 0 ; i < n ; i++) { \
1252 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i], env); \
1257 MIPSDSP64_BINOP_ENV(addq_pw
, add_i32
, sw
);
1258 MIPSDSP64_BINOP_ENV(addq_qh
, add_i16
, sh
);
1259 MIPSDSP64_BINOP_ENV(addq_s_pw
, sat_add_i32
, sw
);
1260 MIPSDSP64_BINOP_ENV(addq_s_qh
, sat_add_i16
, sh
);
1261 MIPSDSP64_BINOP_ENV(addu_ob
, add_u8
, uh
);
1262 MIPSDSP64_BINOP_ENV(addu_qh
, add_u16
, uh
);
1263 MIPSDSP64_BINOP_ENV(addu_s_ob
, sat_add_u8
, uh
);
1264 MIPSDSP64_BINOP_ENV(addu_s_qh
, sat_add_u16
, uh
);
1265 MIPSDSP64_BINOP_ENV(subq_pw
, sub32
, sw
);
1266 MIPSDSP64_BINOP_ENV(subq_qh
, sub_i16
, sh
);
1267 MIPSDSP64_BINOP_ENV(subq_s_pw
, sat32_sub
, sw
);
1268 MIPSDSP64_BINOP_ENV(subq_s_qh
, sat16_sub
, sh
);
1269 MIPSDSP64_BINOP_ENV(subu_ob
, sub_u8
, uh
);
1270 MIPSDSP64_BINOP_ENV(subu_qh
, sub_u16_u16
, uh
);
1271 MIPSDSP64_BINOP_ENV(subu_s_ob
, satu8_sub
, uh
);
1272 MIPSDSP64_BINOP_ENV(subu_s_qh
, satu16_sub_u16_u16
, uh
);
1273 #undef MIPSDSP64_BINOP_ENV
1277 #define SUBUH_QB(name, var) \
1278 target_ulong helper_##name##_qb(target_ulong rs, target_ulong rt) \
1280 uint8_t rs3, rs2, rs1, rs0; \
1281 uint8_t rt3, rt2, rt1, rt0; \
1282 uint8_t tempD, tempC, tempB, tempA; \
1284 MIPSDSP_SPLIT32_8(rs, rs3, rs2, rs1, rs0); \
1285 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1287 tempD = ((uint16_t)rs3 - (uint16_t)rt3 + var) >> 1; \
1288 tempC = ((uint16_t)rs2 - (uint16_t)rt2 + var) >> 1; \
1289 tempB = ((uint16_t)rs1 - (uint16_t)rt1 + var) >> 1; \
1290 tempA = ((uint16_t)rs0 - (uint16_t)rt0 + var) >> 1; \
1292 return ((uint32_t)tempD << 24) | ((uint32_t)tempC << 16) | \
1293 ((uint32_t)tempB << 8) | ((uint32_t)tempA); \
1297 SUBUH_QB(subuh_r
, 1);
1301 target_ulong
helper_addsc(target_ulong rs
, target_ulong rt
, CPUMIPSState
*env
)
1303 uint64_t temp
, tempRs
, tempRt
;
1306 tempRs
= (uint64_t)rs
& MIPSDSP_LLO
;
1307 tempRt
= (uint64_t)rt
& MIPSDSP_LLO
;
1309 temp
= tempRs
+ tempRt
;
1310 flag
= (temp
& 0x0100000000ull
) >> 32;
1311 set_DSPControl_carryflag(flag
, env
);
1313 return (target_long
)(int32_t)(temp
& MIPSDSP_LLO
);
1316 target_ulong
helper_addwc(target_ulong rs
, target_ulong rt
, CPUMIPSState
*env
)
1319 int32_t temp32
, temp31
;
1322 tempL
= (int64_t)(int32_t)rs
+ (int64_t)(int32_t)rt
+
1323 get_DSPControl_carryflag(env
);
1324 temp31
= (tempL
>> 31) & 0x01;
1325 temp32
= (tempL
>> 32) & 0x01;
1327 if (temp31
!= temp32
) {
1328 set_DSPControl_overflow_flag(1, 20, env
);
1331 rd
= tempL
& MIPSDSP_LLO
;
1333 return (target_long
)(int32_t)rd
;
1336 target_ulong
helper_modsub(target_ulong rs
, target_ulong rt
)
1342 decr
= rt
& MIPSDSP_Q0
;
1343 lastindex
= (rt
>> 8) & MIPSDSP_LO
;
1345 if ((rs
& MIPSDSP_LLO
) == 0x00000000) {
1346 rd
= (target_ulong
)lastindex
;
1354 target_ulong
helper_raddu_w_qb(target_ulong rs
)
1356 target_ulong ret
= 0;
1361 for (i
= 0; i
< 4; i
++) {
1367 #if defined(TARGET_MIPS64)
1368 target_ulong
helper_raddu_l_ob(target_ulong rs
)
1370 target_ulong ret
= 0;
1375 for (i
= 0; i
< 8; i
++) {
1382 #define PRECR_QB_PH(name, a, b)\
1383 target_ulong helper_##name##_qb_ph(target_ulong rs, target_ulong rt) \
1385 uint8_t tempD, tempC, tempB, tempA; \
1387 tempD = (rs >> a) & MIPSDSP_Q0; \
1388 tempC = (rs >> b) & MIPSDSP_Q0; \
1389 tempB = (rt >> a) & MIPSDSP_Q0; \
1390 tempA = (rt >> b) & MIPSDSP_Q0; \
1392 return MIPSDSP_RETURN32_8(tempD, tempC, tempB, tempA); \
1395 PRECR_QB_PH(precr
, 16, 0);
1396 PRECR_QB_PH(precrq
, 24, 8);
1400 target_ulong
helper_precr_sra_ph_w(uint32_t sa
, target_ulong rs
,
1403 uint16_t tempB
, tempA
;
1405 tempB
= ((int32_t)rt
>> sa
) & MIPSDSP_LO
;
1406 tempA
= ((int32_t)rs
>> sa
) & MIPSDSP_LO
;
1408 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1411 target_ulong
helper_precr_sra_r_ph_w(uint32_t sa
,
1412 target_ulong rs
, target_ulong rt
)
1414 uint64_t tempB
, tempA
;
1416 /* If sa = 0, then (sa - 1) = -1 will case shift error, so we need else. */
1418 tempB
= (rt
& MIPSDSP_LO
) << 1;
1419 tempA
= (rs
& MIPSDSP_LO
) << 1;
1421 tempB
= ((int32_t)rt
>> (sa
- 1)) + 1;
1422 tempA
= ((int32_t)rs
>> (sa
- 1)) + 1;
1424 rt
= (((tempB
>> 1) & MIPSDSP_LO
) << 16) | ((tempA
>> 1) & MIPSDSP_LO
);
1426 return (target_long
)(int32_t)rt
;
1429 target_ulong
helper_precrq_ph_w(target_ulong rs
, target_ulong rt
)
1431 uint16_t tempB
, tempA
;
1433 tempB
= (rs
& MIPSDSP_HI
) >> 16;
1434 tempA
= (rt
& MIPSDSP_HI
) >> 16;
1436 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1439 target_ulong
helper_precrq_rs_ph_w(target_ulong rs
, target_ulong rt
,
1442 uint16_t tempB
, tempA
;
1444 tempB
= mipsdsp_trunc16_sat16_round(rs
, env
);
1445 tempA
= mipsdsp_trunc16_sat16_round(rt
, env
);
1447 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1450 #if defined(TARGET_MIPS64)
1451 target_ulong
helper_precr_ob_qh(target_ulong rs
, target_ulong rt
)
1453 uint8_t rs6
, rs4
, rs2
, rs0
;
1454 uint8_t rt6
, rt4
, rt2
, rt0
;
1457 rs6
= (rs
>> 48) & MIPSDSP_Q0
;
1458 rs4
= (rs
>> 32) & MIPSDSP_Q0
;
1459 rs2
= (rs
>> 16) & MIPSDSP_Q0
;
1460 rs0
= rs
& MIPSDSP_Q0
;
1461 rt6
= (rt
>> 48) & MIPSDSP_Q0
;
1462 rt4
= (rt
>> 32) & MIPSDSP_Q0
;
1463 rt2
= (rt
>> 16) & MIPSDSP_Q0
;
1464 rt0
= rt
& MIPSDSP_Q0
;
1466 temp
= ((uint64_t)rs6
<< 56) | ((uint64_t)rs4
<< 48) |
1467 ((uint64_t)rs2
<< 40) | ((uint64_t)rs0
<< 32) |
1468 ((uint64_t)rt6
<< 24) | ((uint64_t)rt4
<< 16) |
1469 ((uint64_t)rt2
<< 8) | (uint64_t)rt0
;
1474 #define PRECR_QH_PW(name, var) \
1475 target_ulong helper_precr_##name##_qh_pw(target_ulong rs, target_ulong rt, \
1478 uint16_t rs3, rs2, rs1, rs0; \
1479 uint16_t rt3, rt2, rt1, rt0; \
1480 uint16_t tempD, tempC, tempB, tempA; \
1482 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
1483 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1485 /* When sa = 0, we use rt2, rt0, rs2, rs0; \
1486 * when sa != 0, we use rt3, rt1, rs3, rs1. */ \
1488 tempD = rt2 << var; \
1489 tempC = rt0 << var; \
1490 tempB = rs2 << var; \
1491 tempA = rs0 << var; \
1493 tempD = (((int16_t)rt3 >> sa) + var) >> var; \
1494 tempC = (((int16_t)rt1 >> sa) + var) >> var; \
1495 tempB = (((int16_t)rs3 >> sa) + var) >> var; \
1496 tempA = (((int16_t)rs1 >> sa) + var) >> var; \
1499 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1502 PRECR_QH_PW(sra
, 0);
1503 PRECR_QH_PW(sra_r
, 1);
1507 target_ulong
helper_precrq_ob_qh(target_ulong rs
, target_ulong rt
)
1509 uint8_t rs6
, rs4
, rs2
, rs0
;
1510 uint8_t rt6
, rt4
, rt2
, rt0
;
1513 rs6
= (rs
>> 56) & MIPSDSP_Q0
;
1514 rs4
= (rs
>> 40) & MIPSDSP_Q0
;
1515 rs2
= (rs
>> 24) & MIPSDSP_Q0
;
1516 rs0
= (rs
>> 8) & MIPSDSP_Q0
;
1517 rt6
= (rt
>> 56) & MIPSDSP_Q0
;
1518 rt4
= (rt
>> 40) & MIPSDSP_Q0
;
1519 rt2
= (rt
>> 24) & MIPSDSP_Q0
;
1520 rt0
= (rt
>> 8) & MIPSDSP_Q0
;
1522 temp
= ((uint64_t)rs6
<< 56) | ((uint64_t)rs4
<< 48) |
1523 ((uint64_t)rs2
<< 40) | ((uint64_t)rs0
<< 32) |
1524 ((uint64_t)rt6
<< 24) | ((uint64_t)rt4
<< 16) |
1525 ((uint64_t)rt2
<< 8) | (uint64_t)rt0
;
1530 target_ulong
helper_precrq_qh_pw(target_ulong rs
, target_ulong rt
)
1532 uint16_t tempD
, tempC
, tempB
, tempA
;
1534 tempD
= (rs
>> 48) & MIPSDSP_LO
;
1535 tempC
= (rs
>> 16) & MIPSDSP_LO
;
1536 tempB
= (rt
>> 48) & MIPSDSP_LO
;
1537 tempA
= (rt
>> 16) & MIPSDSP_LO
;
1539 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1542 target_ulong
helper_precrq_rs_qh_pw(target_ulong rs
, target_ulong rt
,
1547 uint16_t tempD
, tempC
, tempB
, tempA
;
1549 rs2
= (rs
>> 32) & MIPSDSP_LLO
;
1550 rs0
= rs
& MIPSDSP_LLO
;
1551 rt2
= (rt
>> 32) & MIPSDSP_LLO
;
1552 rt0
= rt
& MIPSDSP_LLO
;
1554 tempD
= mipsdsp_trunc16_sat16_round(rs2
, env
);
1555 tempC
= mipsdsp_trunc16_sat16_round(rs0
, env
);
1556 tempB
= mipsdsp_trunc16_sat16_round(rt2
, env
);
1557 tempA
= mipsdsp_trunc16_sat16_round(rt0
, env
);
1559 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1562 target_ulong
helper_precrq_pw_l(target_ulong rs
, target_ulong rt
)
1564 uint32_t tempB
, tempA
;
1566 tempB
= (rs
>> 32) & MIPSDSP_LLO
;
1567 tempA
= (rt
>> 32) & MIPSDSP_LLO
;
1569 return MIPSDSP_RETURN64_32(tempB
, tempA
);
1573 target_ulong
helper_precrqu_s_qb_ph(target_ulong rs
, target_ulong rt
,
1576 uint8_t tempD
, tempC
, tempB
, tempA
;
1577 uint16_t rsh
, rsl
, rth
, rtl
;
1579 rsh
= (rs
& MIPSDSP_HI
) >> 16;
1580 rsl
= rs
& MIPSDSP_LO
;
1581 rth
= (rt
& MIPSDSP_HI
) >> 16;
1582 rtl
= rt
& MIPSDSP_LO
;
1584 tempD
= mipsdsp_sat8_reduce_precision(rsh
, env
);
1585 tempC
= mipsdsp_sat8_reduce_precision(rsl
, env
);
1586 tempB
= mipsdsp_sat8_reduce_precision(rth
, env
);
1587 tempA
= mipsdsp_sat8_reduce_precision(rtl
, env
);
1589 return MIPSDSP_RETURN32_8(tempD
, tempC
, tempB
, tempA
);
1592 #if defined(TARGET_MIPS64)
1593 target_ulong
helper_precrqu_s_ob_qh(target_ulong rs
, target_ulong rt
,
1597 uint16_t rs3
, rs2
, rs1
, rs0
;
1598 uint16_t rt3
, rt2
, rt1
, rt0
;
1604 MIPSDSP_SPLIT64_16(rs
, rs3
, rs2
, rs1
, rs0
);
1605 MIPSDSP_SPLIT64_16(rt
, rt3
, rt2
, rt1
, rt0
);
1607 temp
[7] = mipsdsp_sat8_reduce_precision(rs3
, env
);
1608 temp
[6] = mipsdsp_sat8_reduce_precision(rs2
, env
);
1609 temp
[5] = mipsdsp_sat8_reduce_precision(rs1
, env
);
1610 temp
[4] = mipsdsp_sat8_reduce_precision(rs0
, env
);
1611 temp
[3] = mipsdsp_sat8_reduce_precision(rt3
, env
);
1612 temp
[2] = mipsdsp_sat8_reduce_precision(rt2
, env
);
1613 temp
[1] = mipsdsp_sat8_reduce_precision(rt1
, env
);
1614 temp
[0] = mipsdsp_sat8_reduce_precision(rt0
, env
);
1616 for (i
= 0; i
< 8; i
++) {
1617 result
|= (uint64_t)temp
[i
] << (8 * i
);
1623 #define PRECEQ_PW(name, a, b) \
1624 target_ulong helper_preceq_pw_##name(target_ulong rt) \
1626 uint16_t tempB, tempA; \
1627 uint32_t tempBI, tempAI; \
1629 tempB = (rt >> a) & MIPSDSP_LO; \
1630 tempA = (rt >> b) & MIPSDSP_LO; \
1632 tempBI = (uint32_t)tempB << 16; \
1633 tempAI = (uint32_t)tempA << 16; \
1635 return MIPSDSP_RETURN64_32(tempBI, tempAI); \
1638 PRECEQ_PW(qhl
, 48, 32);
1639 PRECEQ_PW(qhr
, 16, 0);
1640 PRECEQ_PW(qhla
, 48, 16);
1641 PRECEQ_PW(qhra
, 32, 0);
1647 #define PRECEQU_PH(name, a, b) \
1648 target_ulong helper_precequ_ph_##name(target_ulong rt) \
1650 uint16_t tempB, tempA; \
1652 tempB = (rt >> a) & MIPSDSP_Q0; \
1653 tempA = (rt >> b) & MIPSDSP_Q0; \
1655 tempB = tempB << 7; \
1656 tempA = tempA << 7; \
1658 return MIPSDSP_RETURN32_16(tempB, tempA); \
1661 PRECEQU_PH(qbl
, 24, 16);
1662 PRECEQU_PH(qbr
, 8, 0);
1663 PRECEQU_PH(qbla
, 24, 8);
1664 PRECEQU_PH(qbra
, 16, 0);
1668 #if defined(TARGET_MIPS64)
1669 #define PRECEQU_QH(name, a, b, c, d) \
1670 target_ulong helper_precequ_qh_##name(target_ulong rt) \
1672 uint16_t tempD, tempC, tempB, tempA; \
1674 tempD = (rt >> a) & MIPSDSP_Q0; \
1675 tempC = (rt >> b) & MIPSDSP_Q0; \
1676 tempB = (rt >> c) & MIPSDSP_Q0; \
1677 tempA = (rt >> d) & MIPSDSP_Q0; \
1679 tempD = tempD << 7; \
1680 tempC = tempC << 7; \
1681 tempB = tempB << 7; \
1682 tempA = tempA << 7; \
1684 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1687 PRECEQU_QH(obl
, 56, 48, 40, 32);
1688 PRECEQU_QH(obr
, 24, 16, 8, 0);
1689 PRECEQU_QH(obla
, 56, 40, 24, 8);
1690 PRECEQU_QH(obra
, 48, 32, 16, 0);
1696 #define PRECEU_PH(name, a, b) \
1697 target_ulong helper_preceu_ph_##name(target_ulong rt) \
1699 uint16_t tempB, tempA; \
1701 tempB = (rt >> a) & MIPSDSP_Q0; \
1702 tempA = (rt >> b) & MIPSDSP_Q0; \
1704 return MIPSDSP_RETURN32_16(tempB, tempA); \
1707 PRECEU_PH(qbl
, 24, 16);
1708 PRECEU_PH(qbr
, 8, 0);
1709 PRECEU_PH(qbla
, 24, 8);
1710 PRECEU_PH(qbra
, 16, 0);
1714 #if defined(TARGET_MIPS64)
1715 #define PRECEU_QH(name, a, b, c, d) \
1716 target_ulong helper_preceu_qh_##name(target_ulong rt) \
1718 uint16_t tempD, tempC, tempB, tempA; \
1720 tempD = (rt >> a) & MIPSDSP_Q0; \
1721 tempC = (rt >> b) & MIPSDSP_Q0; \
1722 tempB = (rt >> c) & MIPSDSP_Q0; \
1723 tempA = (rt >> d) & MIPSDSP_Q0; \
1725 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1728 PRECEU_QH(obl
, 56, 48, 40, 32);
1729 PRECEU_QH(obr
, 24, 16, 8, 0);
1730 PRECEU_QH(obla
, 56, 40, 24, 8);
1731 PRECEU_QH(obra
, 48, 32, 16, 0);
1737 /** DSP GPR-Based Shift Sub-class insns **/
1738 #define SHIFT_QB(name, func) \
1739 target_ulong helper_##name##_qb(target_ulong sa, target_ulong rt) \
1741 uint8_t rt3, rt2, rt1, rt0; \
1745 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1747 rt3 = mipsdsp_##func(rt3, sa); \
1748 rt2 = mipsdsp_##func(rt2, sa); \
1749 rt1 = mipsdsp_##func(rt1, sa); \
1750 rt0 = mipsdsp_##func(rt0, sa); \
1752 return MIPSDSP_RETURN32_8(rt3, rt2, rt1, rt0); \
1755 #define SHIFT_QB_ENV(name, func) \
1756 target_ulong helper_##name##_qb(target_ulong sa, target_ulong rt,\
1757 CPUMIPSState *env) \
1759 uint8_t rt3, rt2, rt1, rt0; \
1763 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1765 rt3 = mipsdsp_##func(rt3, sa, env); \
1766 rt2 = mipsdsp_##func(rt2, sa, env); \
1767 rt1 = mipsdsp_##func(rt1, sa, env); \
1768 rt0 = mipsdsp_##func(rt0, sa, env); \
1770 return MIPSDSP_RETURN32_8(rt3, rt2, rt1, rt0); \
1773 SHIFT_QB_ENV(shll
, lshift8
);
1774 SHIFT_QB(shrl
, rshift_u8
);
1776 SHIFT_QB(shra
, rashift8
);
1777 SHIFT_QB(shra_r
, rnd8_rashift
);
1782 #if defined(TARGET_MIPS64)
1783 #define SHIFT_OB(name, func) \
1784 target_ulong helper_##name##_ob(target_ulong rt, target_ulong sa) \
1793 for (i = 0; i < 8; i++) { \
1794 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1795 rt_t[i] = mipsdsp_##func(rt_t[i], sa); \
1796 temp |= (uint64_t)rt_t[i] << (8 * i); \
1802 #define SHIFT_OB_ENV(name, func) \
1803 target_ulong helper_##name##_ob(target_ulong rt, target_ulong sa, \
1804 CPUMIPSState *env) \
1813 for (i = 0; i < 8; i++) { \
1814 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1815 rt_t[i] = mipsdsp_##func(rt_t[i], sa, env); \
1816 temp |= (uint64_t)rt_t[i] << (8 * i); \
1822 SHIFT_OB_ENV(shll
, lshift8
);
1823 SHIFT_OB(shrl
, rshift_u8
);
1825 SHIFT_OB(shra
, rashift8
);
1826 SHIFT_OB(shra_r
, rnd8_rashift
);
1833 #define SHIFT_PH(name, func) \
1834 target_ulong helper_##name##_ph(target_ulong sa, target_ulong rt, \
1835 CPUMIPSState *env) \
1837 uint16_t rth, rtl; \
1841 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
1843 rth = mipsdsp_##func(rth, sa, env); \
1844 rtl = mipsdsp_##func(rtl, sa, env); \
1846 return MIPSDSP_RETURN32_16(rth, rtl); \
1849 SHIFT_PH(shll
, lshift16
);
1850 SHIFT_PH(shll_s
, sat16_lshift
);
1854 #if defined(TARGET_MIPS64)
1855 #define SHIFT_QH(name, func) \
1856 target_ulong helper_##name##_qh(target_ulong rt, target_ulong sa) \
1858 uint16_t rt3, rt2, rt1, rt0; \
1862 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1864 rt3 = mipsdsp_##func(rt3, sa); \
1865 rt2 = mipsdsp_##func(rt2, sa); \
1866 rt1 = mipsdsp_##func(rt1, sa); \
1867 rt0 = mipsdsp_##func(rt0, sa); \
1869 return MIPSDSP_RETURN64_16(rt3, rt2, rt1, rt0); \
1872 #define SHIFT_QH_ENV(name, func) \
1873 target_ulong helper_##name##_qh(target_ulong rt, target_ulong sa, \
1874 CPUMIPSState *env) \
1876 uint16_t rt3, rt2, rt1, rt0; \
1880 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1882 rt3 = mipsdsp_##func(rt3, sa, env); \
1883 rt2 = mipsdsp_##func(rt2, sa, env); \
1884 rt1 = mipsdsp_##func(rt1, sa, env); \
1885 rt0 = mipsdsp_##func(rt0, sa, env); \
1887 return MIPSDSP_RETURN64_16(rt3, rt2, rt1, rt0); \
1890 SHIFT_QH_ENV(shll
, lshift16
);
1891 SHIFT_QH_ENV(shll_s
, sat16_lshift
);
1893 SHIFT_QH(shrl
, rshift_u16
);
1894 SHIFT_QH(shra
, rashift16
);
1895 SHIFT_QH(shra_r
, rnd16_rashift
);
1902 #define SHIFT_W(name, func) \
1903 target_ulong helper_##name##_w(target_ulong sa, target_ulong rt) \
1908 temp = mipsdsp_##func(rt, sa); \
1910 return (target_long)(int32_t)temp; \
1913 #define SHIFT_W_ENV(name, func) \
1914 target_ulong helper_##name##_w(target_ulong sa, target_ulong rt, \
1915 CPUMIPSState *env) \
1920 temp = mipsdsp_##func(rt, sa, env); \
1922 return (target_long)(int32_t)temp; \
1925 SHIFT_W_ENV(shll_s
, sat32_lshift
);
1926 SHIFT_W(shra_r
, rnd32_rashift
);
1931 #if defined(TARGET_MIPS64)
1932 #define SHIFT_PW(name, func) \
1933 target_ulong helper_##name##_pw(target_ulong rt, target_ulong sa) \
1935 uint32_t rt1, rt0; \
1938 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
1940 rt1 = mipsdsp_##func(rt1, sa); \
1941 rt0 = mipsdsp_##func(rt0, sa); \
1943 return MIPSDSP_RETURN64_32(rt1, rt0); \
1946 #define SHIFT_PW_ENV(name, func) \
1947 target_ulong helper_##name##_pw(target_ulong rt, target_ulong sa, \
1948 CPUMIPSState *env) \
1950 uint32_t rt1, rt0; \
1953 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
1955 rt1 = mipsdsp_##func(rt1, sa, env); \
1956 rt0 = mipsdsp_##func(rt0, sa, env); \
1958 return MIPSDSP_RETURN64_32(rt1, rt0); \
1961 SHIFT_PW_ENV(shll
, lshift32
);
1962 SHIFT_PW_ENV(shll_s
, sat32_lshift
);
1964 SHIFT_PW(shra
, rashift32
);
1965 SHIFT_PW(shra_r
, rnd32_rashift
);
1972 #define SHIFT_PH(name, func) \
1973 target_ulong helper_##name##_ph(target_ulong sa, target_ulong rt) \
1975 uint16_t rth, rtl; \
1979 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
1981 rth = mipsdsp_##func(rth, sa); \
1982 rtl = mipsdsp_##func(rtl, sa); \
1984 return MIPSDSP_RETURN32_16(rth, rtl); \
1987 SHIFT_PH(shrl
, rshift_u16
);
1988 SHIFT_PH(shra
, rashift16
);
1989 SHIFT_PH(shra_r
, rnd16_rashift
);
1993 /** DSP Multiply Sub-class insns **/
1994 /* Return value made up by two 16bits value.
1995 * FIXME give the macro a better name.
1997 #define MUL_RETURN32_16_PH(name, func, \
1998 rsmov1, rsmov2, rsfilter, \
1999 rtmov1, rtmov2, rtfilter) \
2000 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2001 CPUMIPSState *env) \
2003 uint16_t rsB, rsA, rtB, rtA; \
2005 rsB = (rs >> rsmov1) & rsfilter; \
2006 rsA = (rs >> rsmov2) & rsfilter; \
2007 rtB = (rt >> rtmov1) & rtfilter; \
2008 rtA = (rt >> rtmov2) & rtfilter; \
2010 rsB = mipsdsp_##func(rsB, rtB, env); \
2011 rsA = mipsdsp_##func(rsA, rtA, env); \
2013 return MIPSDSP_RETURN32_16(rsB, rsA); \
2016 MUL_RETURN32_16_PH(muleu_s_ph_qbl
, mul_u8_u16
, \
2017 24, 16, MIPSDSP_Q0
, \
2019 MUL_RETURN32_16_PH(muleu_s_ph_qbr
, mul_u8_u16
, \
2022 MUL_RETURN32_16_PH(mulq_rs_ph
, rndq15_mul_q15_q15
, \
2023 16, 0, MIPSDSP_LO
, \
2025 MUL_RETURN32_16_PH(mul_ph
, mul_i16_i16
, \
2026 16, 0, MIPSDSP_LO
, \
2028 MUL_RETURN32_16_PH(mul_s_ph
, sat16_mul_i16_i16
, \
2029 16, 0, MIPSDSP_LO
, \
2031 MUL_RETURN32_16_PH(mulq_s_ph
, sat16_mul_q15_q15
, \
2032 16, 0, MIPSDSP_LO
, \
2035 #undef MUL_RETURN32_16_PH
2037 #define MUL_RETURN32_32_ph(name, func, movbits) \
2038 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2039 CPUMIPSState *env) \
2044 rsh = (rs >> movbits) & MIPSDSP_LO; \
2045 rth = (rt >> movbits) & MIPSDSP_LO; \
2046 temp = mipsdsp_##func(rsh, rth, env); \
2048 return (target_long)(int32_t)temp; \
2051 MUL_RETURN32_32_ph(muleq_s_w_phl
, mul_q15_q15_overflowflag21
, 16);
2052 MUL_RETURN32_32_ph(muleq_s_w_phr
, mul_q15_q15_overflowflag21
, 0);
2054 #undef MUL_RETURN32_32_ph
2056 #define MUL_VOID_PH(name, use_ac_env) \
2057 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2058 CPUMIPSState *env) \
2060 int16_t rsh, rsl, rth, rtl; \
2061 int32_t tempB, tempA; \
2062 int64_t acc, dotp; \
2064 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
2065 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2067 if (use_ac_env == 1) { \
2068 tempB = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2069 tempA = mipsdsp_mul_q15_q15(ac, rsl, rtl, env); \
2071 tempB = mipsdsp_mul_u16_u16(rsh, rth); \
2072 tempA = mipsdsp_mul_u16_u16(rsl, rtl); \
2075 dotp = (int64_t)tempB - (int64_t)tempA; \
2076 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2077 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2078 dotp = dotp + acc; \
2079 env->active_tc.HI[ac] = (target_long)(int32_t) \
2080 ((dotp & MIPSDSP_LHI) >> 32); \
2081 env->active_tc.LO[ac] = (target_long)(int32_t)(dotp & MIPSDSP_LLO); \
2084 MUL_VOID_PH(mulsaq_s_w_ph
, 1);
2085 MUL_VOID_PH(mulsa_w_ph
, 0);
2089 #if defined(TARGET_MIPS64)
2090 #define MUL_RETURN64_16_QH(name, func, \
2091 rsmov1, rsmov2, rsmov3, rsmov4, rsfilter, \
2092 rtmov1, rtmov2, rtmov3, rtmov4, rtfilter) \
2093 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2094 CPUMIPSState *env) \
2096 uint16_t rs3, rs2, rs1, rs0; \
2097 uint16_t rt3, rt2, rt1, rt0; \
2098 uint16_t tempD, tempC, tempB, tempA; \
2100 rs3 = (rs >> rsmov1) & rsfilter; \
2101 rs2 = (rs >> rsmov2) & rsfilter; \
2102 rs1 = (rs >> rsmov3) & rsfilter; \
2103 rs0 = (rs >> rsmov4) & rsfilter; \
2104 rt3 = (rt >> rtmov1) & rtfilter; \
2105 rt2 = (rt >> rtmov2) & rtfilter; \
2106 rt1 = (rt >> rtmov3) & rtfilter; \
2107 rt0 = (rt >> rtmov4) & rtfilter; \
2109 tempD = mipsdsp_##func(rs3, rt3, env); \
2110 tempC = mipsdsp_##func(rs2, rt2, env); \
2111 tempB = mipsdsp_##func(rs1, rt1, env); \
2112 tempA = mipsdsp_##func(rs0, rt0, env); \
2114 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
2117 MUL_RETURN64_16_QH(muleu_s_qh_obl
, mul_u8_u16
, \
2118 56, 48, 40, 32, MIPSDSP_Q0
, \
2119 48, 32, 16, 0, MIPSDSP_LO
);
2120 MUL_RETURN64_16_QH(muleu_s_qh_obr
, mul_u8_u16
, \
2121 24, 16, 8, 0, MIPSDSP_Q0
, \
2122 48, 32, 16, 0, MIPSDSP_LO
);
2123 MUL_RETURN64_16_QH(mulq_rs_qh
, rndq15_mul_q15_q15
, \
2124 48, 32, 16, 0, MIPSDSP_LO
, \
2125 48, 32, 16, 0, MIPSDSP_LO
);
2127 #undef MUL_RETURN64_16_QH
2129 #define MUL_RETURN64_32_QH(name, \
2132 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2133 CPUMIPSState *env) \
2135 uint16_t rsB, rsA; \
2136 uint16_t rtB, rtA; \
2137 uint32_t tempB, tempA; \
2139 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2140 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2141 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2142 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2144 tempB = mipsdsp_mul_q15_q15(5, rsB, rtB, env); \
2145 tempA = mipsdsp_mul_q15_q15(5, rsA, rtA, env); \
2147 return ((uint64_t)tempB << 32) | (uint64_t)tempA; \
2150 MUL_RETURN64_32_QH(muleq_s_pw_qhl
, 48, 32, 48, 32);
2151 MUL_RETURN64_32_QH(muleq_s_pw_qhr
, 16, 0, 16, 0);
2153 #undef MUL_RETURN64_32_QH
2155 void helper_mulsaq_s_w_qh(target_ulong rs
, target_ulong rt
, uint32_t ac
,
2158 int16_t rs3
, rs2
, rs1
, rs0
;
2159 int16_t rt3
, rt2
, rt1
, rt0
;
2160 int32_t tempD
, tempC
, tempB
, tempA
;
2165 MIPSDSP_SPLIT64_16(rs
, rs3
, rs2
, rs1
, rs0
);
2166 MIPSDSP_SPLIT64_16(rt
, rt3
, rt2
, rt1
, rt0
);
2168 tempD
= mipsdsp_mul_q15_q15(ac
, rs3
, rt3
, env
);
2169 tempC
= mipsdsp_mul_q15_q15(ac
, rs2
, rt2
, env
);
2170 tempB
= mipsdsp_mul_q15_q15(ac
, rs1
, rt1
, env
);
2171 tempA
= mipsdsp_mul_q15_q15(ac
, rs0
, rt0
, env
);
2173 temp
[0] = ((int32_t)tempD
- (int32_t)tempC
) +
2174 ((int32_t)tempB
- (int32_t)tempA
);
2175 temp
[0] = (int64_t)(temp
[0] << 30) >> 30;
2176 if (((temp
[0] >> 33) & 0x01) == 0) {
2182 acc
[0] = env
->active_tc
.LO
[ac
];
2183 acc
[1] = env
->active_tc
.HI
[ac
];
2185 temp_sum
= acc
[0] + temp
[0];
2186 if (((uint64_t)temp_sum
< (uint64_t)acc
[0]) &&
2187 ((uint64_t)temp_sum
< (uint64_t)temp
[0])) {
2193 env
->active_tc
.HI
[ac
] = acc
[1];
2194 env
->active_tc
.LO
[ac
] = acc
[0];
2198 #define DP_QB(name, func, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2199 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2200 CPUMIPSState *env) \
2204 uint16_t tempB, tempA; \
2205 uint64_t tempC, dotp; \
2207 rs3 = (rs >> rsmov1) & MIPSDSP_Q0; \
2208 rs2 = (rs >> rsmov2) & MIPSDSP_Q0; \
2209 rt3 = (rt >> rtmov1) & MIPSDSP_Q0; \
2210 rt2 = (rt >> rtmov2) & MIPSDSP_Q0; \
2211 tempB = mipsdsp_##func(rs3, rt3); \
2212 tempA = mipsdsp_##func(rs2, rt2); \
2213 dotp = (int64_t)tempB + (int64_t)tempA; \
2215 tempC = (((uint64_t)env->active_tc.HI[ac] << 32) | \
2216 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO)) \
2219 tempC = (((uint64_t)env->active_tc.HI[ac] << 32) | \
2220 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO)) \
2224 env->active_tc.HI[ac] = (target_long)(int32_t) \
2225 ((tempC & MIPSDSP_LHI) >> 32); \
2226 env->active_tc.LO[ac] = (target_long)(int32_t)(tempC & MIPSDSP_LLO); \
2229 DP_QB(dpau_h_qbl
, mul_u8_u8
, 1, 24, 16, 24, 16);
2230 DP_QB(dpau_h_qbr
, mul_u8_u8
, 1, 8, 0, 8, 0);
2231 DP_QB(dpsu_h_qbl
, mul_u8_u8
, 0, 24, 16, 24, 16);
2232 DP_QB(dpsu_h_qbr
, mul_u8_u8
, 0, 8, 0, 8, 0);
2236 #if defined(TARGET_MIPS64)
2237 #define DP_OB(name, add_sub, \
2238 rsmov1, rsmov2, rsmov3, rsmov4, \
2239 rtmov1, rtmov2, rtmov3, rtmov4) \
2240 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2241 CPUMIPSState *env) \
2243 uint8_t rsD, rsC, rsB, rsA; \
2244 uint8_t rtD, rtC, rtB, rtA; \
2245 uint16_t tempD, tempC, tempB, tempA; \
2248 uint64_t temp_sum; \
2253 rsD = (rs >> rsmov1) & MIPSDSP_Q0; \
2254 rsC = (rs >> rsmov2) & MIPSDSP_Q0; \
2255 rsB = (rs >> rsmov3) & MIPSDSP_Q0; \
2256 rsA = (rs >> rsmov4) & MIPSDSP_Q0; \
2257 rtD = (rt >> rtmov1) & MIPSDSP_Q0; \
2258 rtC = (rt >> rtmov2) & MIPSDSP_Q0; \
2259 rtB = (rt >> rtmov3) & MIPSDSP_Q0; \
2260 rtA = (rt >> rtmov4) & MIPSDSP_Q0; \
2262 tempD = mipsdsp_mul_u8_u8(rsD, rtD); \
2263 tempC = mipsdsp_mul_u8_u8(rsC, rtC); \
2264 tempB = mipsdsp_mul_u8_u8(rsB, rtB); \
2265 tempA = mipsdsp_mul_u8_u8(rsA, rtA); \
2267 temp[0] = (uint64_t)tempD + (uint64_t)tempC + \
2268 (uint64_t)tempB + (uint64_t)tempA; \
2270 acc[0] = env->active_tc.LO[ac]; \
2271 acc[1] = env->active_tc.HI[ac]; \
2274 temp_sum = acc[0] + temp[0]; \
2275 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2276 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2279 temp[0] = temp_sum; \
2280 temp[1] = acc[1] + temp[1]; \
2282 temp_sum = acc[0] - temp[0]; \
2283 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2286 temp[0] = temp_sum; \
2287 temp[1] = acc[1] - temp[1]; \
2290 env->active_tc.HI[ac] = temp[1]; \
2291 env->active_tc.LO[ac] = temp[0]; \
2294 DP_OB(dpau_h_obl
, 1, 56, 48, 40, 32, 56, 48, 40, 32);
2295 DP_OB(dpau_h_obr
, 1, 24, 16, 8, 0, 24, 16, 8, 0);
2296 DP_OB(dpsu_h_obl
, 0, 56, 48, 40, 32, 56, 48, 40, 32);
2297 DP_OB(dpsu_h_obr
, 0, 24, 16, 8, 0, 24, 16, 8, 0);
2302 #define DP_NOFUNC_PH(name, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2303 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2304 CPUMIPSState *env) \
2306 int16_t rsB, rsA, rtB, rtA; \
2307 int32_t tempA, tempB; \
2310 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2311 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2312 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2313 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2315 tempB = (int32_t)rsB * (int32_t)rtB; \
2316 tempA = (int32_t)rsA * (int32_t)rtA; \
2318 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2319 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2322 acc = acc + ((int64_t)tempB + (int64_t)tempA); \
2324 acc = acc - ((int64_t)tempB + (int64_t)tempA); \
2327 env->active_tc.HI[ac] = (target_long)(int32_t)((acc & MIPSDSP_LHI) >> 32); \
2328 env->active_tc.LO[ac] = (target_long)(int32_t)(acc & MIPSDSP_LLO); \
2331 DP_NOFUNC_PH(dpa_w_ph
, 1, 16, 0, 16, 0);
2332 DP_NOFUNC_PH(dpax_w_ph
, 1, 16, 0, 0, 16);
2333 DP_NOFUNC_PH(dps_w_ph
, 0, 16, 0, 16, 0);
2334 DP_NOFUNC_PH(dpsx_w_ph
, 0, 16, 0, 0, 16);
2337 #define DP_HASFUNC_PH(name, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2338 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2339 CPUMIPSState *env) \
2341 int16_t rsB, rsA, rtB, rtA; \
2342 int32_t tempB, tempA; \
2343 int64_t acc, dotp; \
2345 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2346 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2347 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2348 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2350 tempB = mipsdsp_mul_q15_q15(ac, rsB, rtB, env); \
2351 tempA = mipsdsp_mul_q15_q15(ac, rsA, rtA, env); \
2353 dotp = (int64_t)tempB + (int64_t)tempA; \
2354 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2355 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2363 env->active_tc.HI[ac] = (target_long)(int32_t) \
2364 ((acc & MIPSDSP_LHI) >> 32); \
2365 env->active_tc.LO[ac] = (target_long)(int32_t) \
2366 (acc & MIPSDSP_LLO); \
2369 DP_HASFUNC_PH(dpaq_s_w_ph
, 1, 16, 0, 16, 0);
2370 DP_HASFUNC_PH(dpaqx_s_w_ph
, 1, 16, 0, 0, 16);
2371 DP_HASFUNC_PH(dpsq_s_w_ph
, 0, 16, 0, 16, 0);
2372 DP_HASFUNC_PH(dpsqx_s_w_ph
, 0, 16, 0, 0, 16);
2374 #undef DP_HASFUNC_PH
2376 #define DP_128OPERATION_PH(name, is_add) \
2377 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2378 CPUMIPSState *env) \
2380 int16_t rsh, rsl, rth, rtl; \
2381 int32_t tempB, tempA, tempC62_31, tempC63; \
2382 int64_t acc, dotp, tempC; \
2384 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
2385 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2387 tempB = mipsdsp_mul_q15_q15(ac, rsh, rtl, env); \
2388 tempA = mipsdsp_mul_q15_q15(ac, rsl, rth, env); \
2390 dotp = (int64_t)tempB + (int64_t)tempA; \
2391 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2392 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2394 tempC = acc + dotp; \
2396 tempC = acc - dotp; \
2398 tempC63 = (tempC >> 63) & 0x01; \
2399 tempC62_31 = (tempC >> 31) & 0xFFFFFFFF; \
2401 if ((tempC63 == 0) && (tempC62_31 != 0x00000000)) { \
2402 tempC = 0x7FFFFFFF; \
2403 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2406 if ((tempC63 == 1) && (tempC62_31 != 0xFFFFFFFF)) { \
2407 tempC = (int64_t)(int32_t)0x80000000; \
2408 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2411 env->active_tc.HI[ac] = (target_long)(int32_t) \
2412 ((tempC & MIPSDSP_LHI) >> 32); \
2413 env->active_tc.LO[ac] = (target_long)(int32_t) \
2414 (tempC & MIPSDSP_LLO); \
2417 DP_128OPERATION_PH(dpaqx_sa_w_ph
, 1);
2418 DP_128OPERATION_PH(dpsqx_sa_w_ph
, 0);
2420 #undef DP_128OPERATION_HP
2422 #if defined(TARGET_MIPS64)
2423 #define DP_QH(name, is_add, use_ac_env) \
2424 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2425 CPUMIPSState *env) \
2427 int32_t rs3, rs2, rs1, rs0; \
2428 int32_t rt3, rt2, rt1, rt0; \
2429 int32_t tempD, tempC, tempB, tempA; \
2434 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
2435 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
2438 tempD = mipsdsp_mul_q15_q15(ac, rs3, rt3, env); \
2439 tempC = mipsdsp_mul_q15_q15(ac, rs2, rt2, env); \
2440 tempB = mipsdsp_mul_q15_q15(ac, rs1, rt1, env); \
2441 tempA = mipsdsp_mul_q15_q15(ac, rs0, rt0, env); \
2443 tempD = mipsdsp_mul_u16_u16(rs3, rt3); \
2444 tempC = mipsdsp_mul_u16_u16(rs2, rt2); \
2445 tempB = mipsdsp_mul_u16_u16(rs1, rt1); \
2446 tempA = mipsdsp_mul_u16_u16(rs0, rt0); \
2449 temp[0] = (int64_t)tempD + (int64_t)tempC + \
2450 (int64_t)tempB + (int64_t)tempA; \
2452 if (temp[0] >= 0) { \
2458 acc[1] = env->active_tc.HI[ac]; \
2459 acc[0] = env->active_tc.LO[ac]; \
2462 temp_sum = acc[0] + temp[0]; \
2463 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2464 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2465 acc[1] = acc[1] + 1; \
2467 temp[0] = temp_sum; \
2468 temp[1] = acc[1] + temp[1]; \
2470 temp_sum = acc[0] - temp[0]; \
2471 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2472 acc[1] = acc[1] - 1; \
2474 temp[0] = temp_sum; \
2475 temp[1] = acc[1] - temp[1]; \
2478 env->active_tc.HI[ac] = temp[1]; \
2479 env->active_tc.LO[ac] = temp[0]; \
2482 DP_QH(dpa_w_qh
, 1, 0);
2483 DP_QH(dpaq_s_w_qh
, 1, 1);
2484 DP_QH(dps_w_qh
, 0, 0);
2485 DP_QH(dpsq_s_w_qh
, 0, 1);
2491 #define DP_L_W(name, is_add) \
2492 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2493 CPUMIPSState *env) \
2496 int64_t dotp, acc; \
2500 dotp = mipsdsp_mul_q31_q31(ac, rs, rt, env); \
2501 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2502 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2504 temp = acc + dotp; \
2505 overflow = MIPSDSP_OVERFLOW_ADD((uint64_t)acc, (uint64_t)dotp, \
2506 temp, (0x01ull << 63)); \
2508 temp = acc - dotp; \
2509 overflow = MIPSDSP_OVERFLOW_SUB((uint64_t)acc, (uint64_t)dotp, \
2510 temp, (0x01ull << 63)); \
2514 temp63 = (temp >> 63) & 0x01; \
2515 if (temp63 == 1) { \
2516 temp = (0x01ull << 63) - 1; \
2518 temp = 0x01ull << 63; \
2521 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2524 env->active_tc.HI[ac] = (target_long)(int32_t) \
2525 ((temp & MIPSDSP_LHI) >> 32); \
2526 env->active_tc.LO[ac] = (target_long)(int32_t) \
2527 (temp & MIPSDSP_LLO); \
2530 DP_L_W(dpaq_sa_l_w
, 1);
2531 DP_L_W(dpsq_sa_l_w
, 0);
2535 #if defined(TARGET_MIPS64)
2536 #define DP_L_PW(name, func) \
2537 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2538 CPUMIPSState *env) \
2542 int64_t tempB[2], tempA[2]; \
2550 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
2551 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2553 tempB[0] = mipsdsp_mul_q31_q31(ac, rs1, rt1, env); \
2554 tempA[0] = mipsdsp_mul_q31_q31(ac, rs0, rt0, env); \
2556 if (tempB[0] >= 0) { \
2562 if (tempA[0] >= 0) { \
2568 temp_sum = tempB[0] + tempA[0]; \
2569 if (((uint64_t)temp_sum < (uint64_t)tempB[0]) && \
2570 ((uint64_t)temp_sum < (uint64_t)tempA[0])) { \
2573 temp[0] = temp_sum; \
2574 temp[1] += tempB[1] + tempA[1]; \
2576 mipsdsp_##func(acc, ac, temp, env); \
2578 env->active_tc.HI[ac] = acc[1]; \
2579 env->active_tc.LO[ac] = acc[0]; \
2582 DP_L_PW(dpaq_sa_l_pw
, sat64_acc_add_q63
);
2583 DP_L_PW(dpsq_sa_l_pw
, sat64_acc_sub_q63
);
2587 void helper_mulsaq_s_l_pw(target_ulong rs
, target_ulong rt
, uint32_t ac
,
2592 int64_t tempB
[2], tempA
[2];
2597 rs1
= (rs
>> 32) & MIPSDSP_LLO
;
2598 rs0
= rs
& MIPSDSP_LLO
;
2599 rt1
= (rt
>> 32) & MIPSDSP_LLO
;
2600 rt0
= rt
& MIPSDSP_LLO
;
2602 tempB
[0] = mipsdsp_mul_q31_q31(ac
, rs1
, rt1
, env
);
2603 tempA
[0] = mipsdsp_mul_q31_q31(ac
, rs0
, rt0
, env
);
2605 if (tempB
[0] >= 0) {
2611 if (tempA
[0] >= 0) {
2617 acc
[0] = env
->active_tc
.LO
[ac
];
2618 acc
[1] = env
->active_tc
.HI
[ac
];
2620 temp_sum
= tempB
[0] - tempA
[0];
2621 if ((uint64_t)temp_sum
> (uint64_t)tempB
[0]) {
2625 temp
[1] = tempB
[1] - tempA
[1];
2627 if ((temp
[1] & 0x01) == 0) {
2633 temp_sum
= acc
[0] + temp
[0];
2634 if (((uint64_t)temp_sum
< (uint64_t)acc
[0]) &&
2635 ((uint64_t)temp_sum
< (uint64_t)temp
[0])) {
2641 env
->active_tc
.HI
[ac
] = acc
[1];
2642 env
->active_tc
.LO
[ac
] = acc
[0];
2646 #define MAQ_S_W(name, mov) \
2647 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2648 CPUMIPSState *env) \
2652 int64_t tempL, acc; \
2654 rsh = (rs >> mov) & MIPSDSP_LO; \
2655 rth = (rt >> mov) & MIPSDSP_LO; \
2656 tempA = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2657 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2658 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2659 tempL = (int64_t)tempA + acc; \
2660 env->active_tc.HI[ac] = (target_long)(int32_t) \
2661 ((tempL & MIPSDSP_LHI) >> 32); \
2662 env->active_tc.LO[ac] = (target_long)(int32_t) \
2663 (tempL & MIPSDSP_LLO); \
2666 MAQ_S_W(maq_s_w_phl
, 16);
2667 MAQ_S_W(maq_s_w_phr
, 0);
2671 #define MAQ_SA_W(name, mov) \
2672 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2673 CPUMIPSState *env) \
2678 rsh = (rs >> mov) & MIPSDSP_LO; \
2679 rth = (rt >> mov) & MIPSDSP_LO; \
2680 tempA = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2681 tempA = mipsdsp_sat32_acc_q31(ac, tempA, env); \
2683 env->active_tc.HI[ac] = (target_long)(int32_t)(((int64_t)tempA & \
2684 MIPSDSP_LHI) >> 32); \
2685 env->active_tc.LO[ac] = (target_long)(int32_t)((int64_t)tempA & \
2689 MAQ_SA_W(maq_sa_w_phl
, 16);
2690 MAQ_SA_W(maq_sa_w_phr
, 0);
2694 #define MULQ_W(name, addvar) \
2695 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2696 CPUMIPSState *env) \
2698 int32_t rs_t, rt_t; \
2702 rs_t = rs & MIPSDSP_LLO; \
2703 rt_t = rt & MIPSDSP_LLO; \
2705 if ((rs_t == 0x80000000) && (rt_t == 0x80000000)) { \
2706 tempL = 0x7FFFFFFF00000000ull; \
2707 set_DSPControl_overflow_flag(1, 21, env); \
2709 tempL = ((int64_t)rs_t * (int64_t)rt_t) << 1; \
2712 tempI = (tempL & MIPSDSP_LHI) >> 32; \
2714 return (target_long)(int32_t)tempI; \
2717 MULQ_W(mulq_s_w
, 0);
2718 MULQ_W(mulq_rs_w
, 0x80000000ull
);
2722 #if defined(TARGET_MIPS64)
2724 #define MAQ_S_W_QH(name, mov) \
2725 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2726 CPUMIPSState *env) \
2728 int16_t rs_t, rt_t; \
2737 rs_t = (rs >> mov) & MIPSDSP_LO; \
2738 rt_t = (rt >> mov) & MIPSDSP_LO; \
2739 temp_mul = mipsdsp_mul_q15_q15(ac, rs_t, rt_t, env); \
2741 temp[0] = (int64_t)temp_mul; \
2742 if (temp[0] >= 0) { \
2748 acc[0] = env->active_tc.LO[ac]; \
2749 acc[1] = env->active_tc.HI[ac]; \
2751 temp_sum = acc[0] + temp[0]; \
2752 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2753 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2756 acc[0] = temp_sum; \
2757 acc[1] += temp[1]; \
2759 env->active_tc.HI[ac] = acc[1]; \
2760 env->active_tc.LO[ac] = acc[0]; \
2763 MAQ_S_W_QH(maq_s_w_qhll
, 48);
2764 MAQ_S_W_QH(maq_s_w_qhlr
, 32);
2765 MAQ_S_W_QH(maq_s_w_qhrl
, 16);
2766 MAQ_S_W_QH(maq_s_w_qhrr
, 0);
2770 #define MAQ_SA_W(name, mov) \
2771 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2772 CPUMIPSState *env) \
2774 int16_t rs_t, rt_t; \
2778 rs_t = (rs >> mov) & MIPSDSP_LO; \
2779 rt_t = (rt >> mov) & MIPSDSP_LO; \
2780 temp = mipsdsp_mul_q15_q15(ac, rs_t, rt_t, env); \
2781 temp = mipsdsp_sat32_acc_q31(ac, temp, env); \
2783 acc[0] = (int64_t)(int32_t)temp; \
2784 if (acc[0] >= 0) { \
2790 env->active_tc.HI[ac] = acc[1]; \
2791 env->active_tc.LO[ac] = acc[0]; \
2794 MAQ_SA_W(maq_sa_w_qhll
, 48);
2795 MAQ_SA_W(maq_sa_w_qhlr
, 32);
2796 MAQ_SA_W(maq_sa_w_qhrl
, 16);
2797 MAQ_SA_W(maq_sa_w_qhrr
, 0);
2801 #define MAQ_S_L_PW(name, mov) \
2802 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2803 CPUMIPSState *env) \
2805 int32_t rs_t, rt_t; \
2813 rs_t = (rs >> mov) & MIPSDSP_LLO; \
2814 rt_t = (rt >> mov) & MIPSDSP_LLO; \
2816 temp[0] = mipsdsp_mul_q31_q31(ac, rs_t, rt_t, env); \
2817 if (temp[0] >= 0) { \
2823 acc[0] = env->active_tc.LO[ac]; \
2824 acc[1] = env->active_tc.HI[ac]; \
2826 temp_sum = acc[0] + temp[0]; \
2827 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2828 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2831 acc[0] = temp_sum; \
2832 acc[1] += temp[1]; \
2834 env->active_tc.HI[ac] = acc[1]; \
2835 env->active_tc.LO[ac] = acc[0]; \
2838 MAQ_S_L_PW(maq_s_l_pwl
, 32);
2839 MAQ_S_L_PW(maq_s_l_pwr
, 0);
2843 #define DM_OPERATE(name, func, is_add, sigext) \
2844 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2845 CPUMIPSState *env) \
2849 int64_t tempBL[2], tempAL[2]; \
2857 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
2858 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2861 tempBL[0] = (int64_t)mipsdsp_##func(rs1, rt1); \
2862 tempAL[0] = (int64_t)mipsdsp_##func(rs0, rt0); \
2864 if (tempBL[0] >= 0) { \
2867 tempBL[1] = ~0ull; \
2870 if (tempAL[0] >= 0) { \
2873 tempAL[1] = ~0ull; \
2876 tempBL[0] = mipsdsp_##func(rs1, rt1); \
2877 tempAL[0] = mipsdsp_##func(rs0, rt0); \
2882 acc[1] = env->active_tc.HI[ac]; \
2883 acc[0] = env->active_tc.LO[ac]; \
2885 temp_sum = tempBL[0] + tempAL[0]; \
2886 if (((uint64_t)temp_sum < (uint64_t)tempBL[0]) && \
2887 ((uint64_t)temp_sum < (uint64_t)tempAL[0])) { \
2890 temp[0] = temp_sum; \
2891 temp[1] += tempBL[1] + tempAL[1]; \
2894 temp_sum = acc[0] + temp[0]; \
2895 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2896 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2899 temp[0] = temp_sum; \
2900 temp[1] = acc[1] + temp[1]; \
2902 temp_sum = acc[0] - temp[0]; \
2903 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2906 temp[0] = temp_sum; \
2907 temp[1] = acc[1] - temp[1]; \
2910 env->active_tc.HI[ac] = temp[1]; \
2911 env->active_tc.LO[ac] = temp[0]; \
2914 DM_OPERATE(dmadd
, mul_i32_i32
, 1, 1);
2915 DM_OPERATE(dmaddu
, mul_u32_u32
, 1, 0);
2916 DM_OPERATE(dmsub
, mul_i32_i32
, 0, 1);
2917 DM_OPERATE(dmsubu
, mul_u32_u32
, 0, 0);
2921 /** DSP Bit/Manipulation Sub-class insns **/
2922 target_ulong
helper_bitrev(target_ulong rt
)
2928 temp
= rt
& MIPSDSP_LO
;
2930 for (i
= 0; i
< 16; i
++) {
2931 rd
= (rd
<< 1) | (temp
& 1);
2935 return (target_ulong
)rd
;
2938 #define BIT_INSV(name, posfilter, sizefilter, ret_type) \
2939 target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \
2942 uint32_t pos, size, msb, lsb; \
2943 target_ulong filter; \
2944 target_ulong temp, temprs, temprt; \
2945 target_ulong dspc; \
2947 dspc = env->active_tc.DSPControl; \
2949 pos = dspc & posfilter; \
2950 size = (dspc >> 7) & sizefilter; \
2952 msb = pos + size - 1; \
2955 if (lsb > msb || (msb > TARGET_LONG_BITS)) { \
2959 filter = ((int32_t)0x01 << size) - 1; \
2960 filter = filter << pos; \
2961 temprs = (rs << pos) & filter; \
2962 temprt = rt & ~filter; \
2963 temp = temprs | temprt; \
2965 return (target_long)(ret_type)temp; \
2968 BIT_INSV(insv
, 0x1F, 0x1F, int32_t);
2969 #ifdef TARGET_MIPS64
2970 BIT_INSV(dinsv
, 0x7F, 0x3F, target_long
);
2976 /** DSP Compare-Pick Sub-class insns **/
2977 #define CMP_HAS_RET(name, func, split_num, filter, bit_size) \
2978 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
2980 uint32_t rs_t, rt_t; \
2982 uint32_t temp = 0; \
2985 for (i = 0; i < split_num; i++) { \
2986 rs_t = (rs >> (bit_size * i)) & filter; \
2987 rt_t = (rt >> (bit_size * i)) & filter; \
2988 cc = mipsdsp_##func(rs_t, rt_t); \
2992 return (target_ulong)temp; \
2995 CMP_HAS_RET(cmpgu_eq_qb
, cmpu_eq
, 4, MIPSDSP_Q0
, 8);
2996 CMP_HAS_RET(cmpgu_lt_qb
, cmpu_lt
, 4, MIPSDSP_Q0
, 8);
2997 CMP_HAS_RET(cmpgu_le_qb
, cmpu_le
, 4, MIPSDSP_Q0
, 8);
2999 #ifdef TARGET_MIPS64
3000 CMP_HAS_RET(cmpgu_eq_ob
, cmpu_eq
, 8, MIPSDSP_Q0
, 8);
3001 CMP_HAS_RET(cmpgu_lt_ob
, cmpu_lt
, 8, MIPSDSP_Q0
, 8);
3002 CMP_HAS_RET(cmpgu_le_ob
, cmpu_le
, 8, MIPSDSP_Q0
, 8);
3008 #define CMP_NO_RET(name, func, split_num, filter, bit_size) \
3009 void helper_##name(target_ulong rs, target_ulong rt, \
3010 CPUMIPSState *env) \
3012 int##bit_size##_t rs_t, rt_t; \
3013 int##bit_size##_t flag = 0; \
3014 int##bit_size##_t cc; \
3017 for (i = 0; i < split_num; i++) { \
3018 rs_t = (rs >> (bit_size * i)) & filter; \
3019 rt_t = (rt >> (bit_size * i)) & filter; \
3021 cc = mipsdsp_##func((int32_t)rs_t, (int32_t)rt_t); \
3025 set_DSPControl_24(flag, split_num, env); \
3028 CMP_NO_RET(cmpu_eq_qb
, cmpu_eq
, 4, MIPSDSP_Q0
, 8);
3029 CMP_NO_RET(cmpu_lt_qb
, cmpu_lt
, 4, MIPSDSP_Q0
, 8);
3030 CMP_NO_RET(cmpu_le_qb
, cmpu_le
, 4, MIPSDSP_Q0
, 8);
3032 CMP_NO_RET(cmp_eq_ph
, cmp_eq
, 2, MIPSDSP_LO
, 16);
3033 CMP_NO_RET(cmp_lt_ph
, cmp_lt
, 2, MIPSDSP_LO
, 16);
3034 CMP_NO_RET(cmp_le_ph
, cmp_le
, 2, MIPSDSP_LO
, 16);
3036 #ifdef TARGET_MIPS64
3037 CMP_NO_RET(cmpu_eq_ob
, cmpu_eq
, 8, MIPSDSP_Q0
, 8);
3038 CMP_NO_RET(cmpu_lt_ob
, cmpu_lt
, 8, MIPSDSP_Q0
, 8);
3039 CMP_NO_RET(cmpu_le_ob
, cmpu_le
, 8, MIPSDSP_Q0
, 8);
3041 CMP_NO_RET(cmp_eq_qh
, cmp_eq
, 4, MIPSDSP_LO
, 16);
3042 CMP_NO_RET(cmp_lt_qh
, cmp_lt
, 4, MIPSDSP_LO
, 16);
3043 CMP_NO_RET(cmp_le_qh
, cmp_le
, 4, MIPSDSP_LO
, 16);
3045 CMP_NO_RET(cmp_eq_pw
, cmp_eq
, 2, MIPSDSP_LLO
, 32);
3046 CMP_NO_RET(cmp_lt_pw
, cmp_lt
, 2, MIPSDSP_LLO
, 32);
3047 CMP_NO_RET(cmp_le_pw
, cmp_le
, 2, MIPSDSP_LLO
, 32);
3051 #if defined(TARGET_MIPS64)
3053 #define CMPGDU_OB(name) \
3054 target_ulong helper_cmpgdu_##name##_ob(target_ulong rs, target_ulong rt, \
3055 CPUMIPSState *env) \
3058 uint8_t rs_t, rt_t; \
3063 for (i = 0; i < 8; i++) { \
3064 rs_t = (rs >> (8 * i)) & MIPSDSP_Q0; \
3065 rt_t = (rt >> (8 * i)) & MIPSDSP_Q0; \
3067 if (mipsdsp_cmpu_##name(rs_t, rt_t)) { \
3068 cond |= 0x01 << i; \
3072 set_DSPControl_24(cond, 8, env); \
3074 return (uint64_t)cond; \
3083 #define PICK_INSN(name, split_num, filter, bit_size, ret32bit) \
3084 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
3085 CPUMIPSState *env) \
3087 uint32_t rs_t, rt_t; \
3091 target_ulong result = 0; \
3093 dsp = env->active_tc.DSPControl; \
3094 for (i = 0; i < split_num; i++) { \
3095 rs_t = (rs >> (bit_size * i)) & filter; \
3096 rt_t = (rt >> (bit_size * i)) & filter; \
3097 cc = (dsp >> (24 + i)) & 0x01; \
3098 cc = cc == 1 ? rs_t : rt_t; \
3100 result |= (target_ulong)cc << (bit_size * i); \
3104 result = (target_long)(int32_t)(result & MIPSDSP_LLO); \
3110 PICK_INSN(pick_qb
, 4, MIPSDSP_Q0
, 8, 1);
3111 PICK_INSN(pick_ph
, 2, MIPSDSP_LO
, 16, 1);
3113 #ifdef TARGET_MIPS64
3114 PICK_INSN(pick_ob
, 8, MIPSDSP_Q0
, 8, 0);
3115 PICK_INSN(pick_qh
, 4, MIPSDSP_LO
, 16, 0);
3116 PICK_INSN(pick_pw
, 2, MIPSDSP_LLO
, 32, 0);
3120 target_ulong
helper_packrl_ph(target_ulong rs
, target_ulong rt
)
3124 rsl
= rs
& MIPSDSP_LO
;
3125 rth
= (rt
& MIPSDSP_HI
) >> 16;
3127 return (target_long
)(int32_t)((rsl
<< 16) | rth
);
3130 #if defined(TARGET_MIPS64)
3131 target_ulong
helper_packrl_pw(target_ulong rs
, target_ulong rt
)
3135 rs0
= rs
& MIPSDSP_LLO
;
3136 rt1
= (rt
>> 32) & MIPSDSP_LLO
;
3138 return ((uint64_t)rs0
<< 32) | (uint64_t)rt1
;
3142 /** DSP Accumulator and DSPControl Access Sub-class insns **/
3143 target_ulong
helper_extr_w(target_ulong ac
, target_ulong shift
,
3149 shift
= shift
& 0x1F;
3151 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3152 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3153 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3154 set_DSPControl_overflow_flag(1, 23, env
);
3157 tempI
= (tempDL
[0] >> 1) & MIPSDSP_LLO
;
3160 if (tempDL
[0] == 0) {
3164 if ((!(tempDL
[1] == 0 && (tempDL
[0] & MIPSDSP_LHI
) == 0x00)) &&
3165 (!(tempDL
[1] == 1 && (tempDL
[0] & MIPSDSP_LHI
) == MIPSDSP_LHI
))) {
3166 set_DSPControl_overflow_flag(1, 23, env
);
3169 return (target_long
)tempI
;
3172 target_ulong
helper_extr_r_w(target_ulong ac
, target_ulong shift
,
3177 shift
= shift
& 0x1F;
3179 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3180 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3181 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3182 set_DSPControl_overflow_flag(1, 23, env
);
3186 if (tempDL
[0] == 0) {
3190 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3191 (tempDL
[1] != 1 && (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3192 set_DSPControl_overflow_flag(1, 23, env
);
3195 return (target_long
)(int32_t)(tempDL
[0] >> 1);
3198 target_ulong
helper_extr_rs_w(target_ulong ac
, target_ulong shift
,
3201 int32_t tempI
, temp64
;
3204 shift
= shift
& 0x1F;
3206 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3207 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3208 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3209 set_DSPControl_overflow_flag(1, 23, env
);
3212 if (tempDL
[0] == 0) {
3215 tempI
= tempDL
[0] >> 1;
3217 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3218 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3225 set_DSPControl_overflow_flag(1, 23, env
);
3228 return (target_long
)tempI
;
3231 #if defined(TARGET_MIPS64)
3232 target_ulong
helper_dextr_w(target_ulong ac
, target_ulong shift
,
3237 shift
= shift
& 0x3F;
3239 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3241 return (int64_t)(int32_t)(temp
[0] >> 1);
3244 target_ulong
helper_dextr_r_w(target_ulong ac
, target_ulong shift
,
3250 shift
= shift
& 0x3F;
3251 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3261 temp128
= temp
[2] & 0x01;
3263 if ((temp128
!= 0 || temp
[1] != 0) &&
3264 (temp128
!= 1 || temp
[1] != ~0ull)) {
3265 set_DSPControl_overflow_flag(1, 23, env
);
3268 return (int64_t)(int32_t)(temp
[0] >> 1);
3271 target_ulong
helper_dextr_rs_w(target_ulong ac
, target_ulong shift
,
3277 shift
= shift
& 0x3F;
3278 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3288 temp128
= temp
[2] & 0x01;
3290 if ((temp128
!= 0 || temp
[1] != 0) &&
3291 (temp128
!= 1 || temp
[1] != ~0ull)) {
3293 temp
[0] = 0x0FFFFFFFF;
3295 temp
[0] = 0x0100000000ULL
;
3297 set_DSPControl_overflow_flag(1, 23, env
);
3300 return (int64_t)(int32_t)(temp
[0] >> 1);
3303 target_ulong
helper_dextr_l(target_ulong ac
, target_ulong shift
,
3307 target_ulong result
;
3309 shift
= shift
& 0x3F;
3311 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3312 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3317 target_ulong
helper_dextr_r_l(target_ulong ac
, target_ulong shift
,
3322 target_ulong result
;
3324 shift
= shift
& 0x3F;
3325 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3335 temp128
= temp
[2] & 0x01;
3337 if ((temp128
!= 0 || temp
[1] != 0) &&
3338 (temp128
!= 1 || temp
[1] != ~0ull)) {
3339 set_DSPControl_overflow_flag(1, 23, env
);
3342 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3347 target_ulong
helper_dextr_rs_l(target_ulong ac
, target_ulong shift
,
3352 target_ulong result
;
3354 shift
= shift
& 0x3F;
3355 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3365 temp128
= temp
[2] & 0x01;
3367 if ((temp128
!= 0 || temp
[1] != 0) &&
3368 (temp128
!= 1 || temp
[1] != ~0ull)) {
3370 temp
[1] &= ~0x00ull
- 1;
3371 temp
[0] |= ~0x00ull
- 1;
3376 set_DSPControl_overflow_flag(1, 23, env
);
3378 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3384 target_ulong
helper_extr_s_h(target_ulong ac
, target_ulong shift
,
3389 shift
= shift
& 0x1F;
3391 acc
= ((int64_t)env
->active_tc
.HI
[ac
] << 32) |
3392 ((int64_t)env
->active_tc
.LO
[ac
] & 0xFFFFFFFF);
3394 temp
= acc
>> shift
;
3396 if (temp
> (int64_t)0x7FFF) {
3398 set_DSPControl_overflow_flag(1, 23, env
);
3399 } else if (temp
< (int64_t)0xFFFFFFFFFFFF8000ULL
) {
3401 set_DSPControl_overflow_flag(1, 23, env
);
3404 return (target_long
)(int32_t)(temp
& 0xFFFFFFFF);
3408 #if defined(TARGET_MIPS64)
3409 target_ulong
helper_dextr_s_h(target_ulong ac
, target_ulong shift
,
3415 shift
= shift
& 0x1F;
3417 mipsdsp_rashift_acc((uint64_t *)temp
, ac
, shift
, env
);
3419 temp127
= (temp
[1] >> 63) & 0x01;
3421 if ((temp127
== 0) && (temp
[1] > 0 || temp
[0] > 32767)) {
3422 temp
[0] &= 0xFFFF0000;
3423 temp
[0] |= 0x00007FFF;
3424 set_DSPControl_overflow_flag(1, 23, env
);
3425 } else if ((temp127
== 1) &&
3426 (temp
[1] < 0xFFFFFFFFFFFFFFFFll
3427 || temp
[0] < 0xFFFFFFFFFFFF1000ll
)) {
3428 temp
[0] &= 0xFFFF0000;
3429 temp
[0] |= 0x00008000;
3430 set_DSPControl_overflow_flag(1, 23, env
);
3433 return (int64_t)(int16_t)(temp
[0] & MIPSDSP_LO
);
3438 target_ulong
helper_extp(target_ulong ac
, target_ulong size
, CPUMIPSState
*env
)
3448 start_pos
= get_DSPControl_pos(env
);
3449 sub
= start_pos
- (size
+ 1);
3451 acc
= ((uint64_t)env
->active_tc
.HI
[ac
] << 32) |
3452 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3453 temp
= (acc
>> (start_pos
- size
)) &
3454 (((uint32_t)0x01 << (size
+ 1)) - 1);
3455 set_DSPControl_efi(0, env
);
3457 set_DSPControl_efi(1, env
);
3460 return (target_ulong
)temp
;
3463 target_ulong
helper_extpdp(target_ulong ac
, target_ulong size
,
3473 start_pos
= get_DSPControl_pos(env
);
3474 sub
= start_pos
- (size
+ 1);
3476 acc
= ((uint64_t)env
->active_tc
.HI
[ac
] << 32) |
3477 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3478 temp
= (acc
>> (start_pos
- size
)) &
3479 (((uint32_t)0x01 << (size
+ 1)) - 1);
3481 set_DSPControl_pos(start_pos
- (size
+ 1), env
);
3482 set_DSPControl_efi(0, env
);
3484 set_DSPControl_efi(1, env
);
3487 return (target_ulong
)temp
;
3491 #if defined(TARGET_MIPS64)
3492 target_ulong
helper_dextp(target_ulong ac
, target_ulong size
, CPUMIPSState
*env
)
3497 uint64_t tempB
, tempA
;
3503 start_pos
= get_DSPControl_pos(env
);
3504 len
= start_pos
- size
;
3505 tempB
= env
->active_tc
.HI
[ac
];
3506 tempA
= env
->active_tc
.LO
[ac
];
3508 sub
= start_pos
- (size
+ 1);
3511 temp
= (tempB
<< (64 - len
)) | (tempA
>> len
);
3512 temp
= temp
& ((0x01 << (size
+ 1)) - 1);
3513 set_DSPControl_efi(0, env
);
3515 set_DSPControl_efi(1, env
);
3521 target_ulong
helper_dextpdp(target_ulong ac
, target_ulong size
,
3527 uint64_t tempB
, tempA
;
3532 start_pos
= get_DSPControl_pos(env
);
3533 len
= start_pos
- size
;
3534 tempB
= env
->active_tc
.HI
[ac
];
3535 tempA
= env
->active_tc
.LO
[ac
];
3537 sub
= start_pos
- (size
+ 1);
3540 temp
= (tempB
<< (64 - len
)) | (tempA
>> len
);
3541 temp
= temp
& ((0x01 << (size
+ 1)) - 1);
3542 set_DSPControl_pos(sub
, env
);
3543 set_DSPControl_efi(0, env
);
3545 set_DSPControl_efi(1, env
);
3553 void helper_shilo(target_ulong ac
, target_ulong rs
, CPUMIPSState
*env
)
3559 rs5_0
= (int8_t)(rs5_0
<< 2) >> 2;
3561 if (unlikely(rs5_0
== 0)) {
3565 acc
= (((uint64_t)env
->active_tc
.HI
[ac
] << 32) & MIPSDSP_LHI
) |
3566 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3569 temp
= acc
>> rs5_0
;
3571 temp
= acc
<< -rs5_0
;
3574 env
->active_tc
.HI
[ac
] = (target_ulong
)(int32_t)((temp
& MIPSDSP_LHI
) >> 32);
3575 env
->active_tc
.LO
[ac
] = (target_ulong
)(int32_t)(temp
& MIPSDSP_LLO
);
3578 #if defined(TARGET_MIPS64)
3579 void helper_dshilo(target_ulong shift
, target_ulong ac
, CPUMIPSState
*env
)
3582 uint64_t tempB
, tempA
;
3584 shift_t
= (int8_t)(shift
<< 1) >> 1;
3586 tempB
= env
->active_tc
.HI
[ac
];
3587 tempA
= env
->active_tc
.LO
[ac
];
3591 tempA
= (tempB
<< (64 - shift_t
)) | (tempA
>> shift_t
);
3592 tempB
= tempB
>> shift_t
;
3595 tempB
= (tempB
<< shift_t
) | (tempA
>> (64 - shift_t
));
3596 tempA
= tempA
<< shift_t
;
3600 env
->active_tc
.HI
[ac
] = tempB
;
3601 env
->active_tc
.LO
[ac
] = tempA
;
3605 void helper_mthlip(target_ulong ac
, target_ulong rs
, CPUMIPSState
*env
)
3607 int32_t tempA
, tempB
, pos
;
3610 tempB
= env
->active_tc
.LO
[ac
];
3611 env
->active_tc
.HI
[ac
] = (target_long
)tempB
;
3612 env
->active_tc
.LO
[ac
] = (target_long
)tempA
;
3613 pos
= get_DSPControl_pos(env
);
3618 set_DSPControl_pos(pos
+ 32, env
);
3622 #if defined(TARGET_MIPS64)
3623 void helper_dmthlip(target_ulong rs
, target_ulong ac
, CPUMIPSState
*env
)
3627 uint64_t tempB
, tempA
;
3632 tempB
= env
->active_tc
.LO
[ac_t
];
3634 env
->active_tc
.HI
[ac_t
] = tempB
;
3635 env
->active_tc
.LO
[ac_t
] = tempA
;
3637 pos
= get_DSPControl_pos(env
);
3641 set_DSPControl_pos(pos
, env
);
3646 void cpu_wrdsp(uint32_t rs
, uint32_t mask_num
, CPUMIPSState
*env
)
3650 uint32_t newbits
, overwrite
;
3654 overwrite
= 0xFFFFFFFF;
3655 dsp
= env
->active_tc
.DSPControl
;
3657 for (i
= 0; i
< 6; i
++) {
3658 mask
[i
] = (mask_num
>> i
) & 0x01;
3662 #if defined(TARGET_MIPS64)
3663 overwrite
&= 0xFFFFFF80;
3664 newbits
&= 0xFFFFFF80;
3665 newbits
|= 0x0000007F & rs
;
3667 overwrite
&= 0xFFFFFFC0;
3668 newbits
&= 0xFFFFFFC0;
3669 newbits
|= 0x0000003F & rs
;
3674 overwrite
&= 0xFFFFE07F;
3675 newbits
&= 0xFFFFE07F;
3676 newbits
|= 0x00001F80 & rs
;
3680 overwrite
&= 0xFFFFDFFF;
3681 newbits
&= 0xFFFFDFFF;
3682 newbits
|= 0x00002000 & rs
;
3686 overwrite
&= 0xFF00FFFF;
3687 newbits
&= 0xFF00FFFF;
3688 newbits
|= 0x00FF0000 & rs
;
3692 overwrite
&= 0x00FFFFFF;
3693 newbits
&= 0x00FFFFFF;
3694 #if defined(TARGET_MIPS64)
3695 newbits
|= 0xFF000000 & rs
;
3697 newbits
|= 0x0F000000 & rs
;
3702 overwrite
&= 0xFFFFBFFF;
3703 newbits
&= 0xFFFFBFFF;
3704 newbits
|= 0x00004000 & rs
;
3707 dsp
= dsp
& overwrite
;
3708 dsp
= dsp
| newbits
;
3709 env
->active_tc
.DSPControl
= dsp
;
3712 void helper_wrdsp(target_ulong rs
, target_ulong mask_num
, CPUMIPSState
*env
)
3714 return cpu_wrdsp(rs
, mask_num
, env
);
3717 uint32_t cpu_rddsp(uint32_t mask_num
, CPUMIPSState
*env
)
3725 for (i
= 0; i
< 6; i
++) {
3726 mask
[i
] = (mask_num
& ruler
) >> i
;
3731 dsp
= env
->active_tc
.DSPControl
;
3734 #if defined(TARGET_MIPS64)
3742 temp
|= dsp
& 0x1F80;
3746 temp
|= dsp
& 0x2000;
3750 temp
|= dsp
& 0x00FF0000;
3754 #if defined(TARGET_MIPS64)
3755 temp
|= dsp
& 0xFF000000;
3757 temp
|= dsp
& 0x0F000000;
3762 temp
|= dsp
& 0x4000;
3768 target_ulong
helper_rddsp(target_ulong mask_num
, CPUMIPSState
*env
)
3770 return cpu_rddsp(mask_num
, env
);
3783 #undef MIPSDSP_SPLIT32_8
3784 #undef MIPSDSP_SPLIT32_16
3786 #undef MIPSDSP_RETURN32_8
3787 #undef MIPSDSP_RETURN32_16
3789 #ifdef TARGET_MIPS64
3790 #undef MIPSDSP_SPLIT64_16
3791 #undef MIPSDSP_SPLIT64_32
3792 #undef MIPSDSP_RETURN64_16
3793 #undef MIPSDSP_RETURN64_32