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(a, b, c, d) (!(!((a ^ b ^ -1) & (a ^ c) & d)))
49 static inline void set_DSPControl_overflow_flag(uint32_t flag
, int position
,
52 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< position
;
55 static inline void set_DSPControl_carryflag(uint32_t flag
, CPUMIPSState
*env
)
57 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 13;
60 static inline uint32_t get_DSPControl_carryflag(CPUMIPSState
*env
)
62 return (env
->active_tc
.DSPControl
>> 13) & 0x01;
65 static inline void set_DSPControl_24(uint32_t flag
, int len
, CPUMIPSState
*env
)
69 filter
= ((0x01 << len
) - 1) << 24;
72 env
->active_tc
.DSPControl
&= filter
;
73 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 24;
76 static inline uint32_t get_DSPControl_24(int len
, CPUMIPSState
*env
)
80 filter
= (0x01 << len
) - 1;
82 return (env
->active_tc
.DSPControl
>> 24) & filter
;
85 static inline void set_DSPControl_pos(uint32_t pos
, CPUMIPSState
*env
)
89 dspc
= env
->active_tc
.DSPControl
;
91 dspc
= dspc
& 0xFFFFFFC0;
94 dspc
= dspc
& 0xFFFFFF80;
97 env
->active_tc
.DSPControl
= dspc
;
100 static inline uint32_t get_DSPControl_pos(CPUMIPSState
*env
)
105 dspc
= env
->active_tc
.DSPControl
;
107 #ifndef TARGET_MIPS64
116 static inline void set_DSPControl_efi(uint32_t flag
, CPUMIPSState
*env
)
118 env
->active_tc
.DSPControl
&= 0xFFFFBFFF;
119 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 14;
122 #define DO_MIPS_SAT_ABS(size) \
123 static inline int##size##_t mipsdsp_sat_abs##size(int##size##_t a, \
126 if (a == INT##size##_MIN) { \
127 set_DSPControl_overflow_flag(1, 20, env); \
128 return INT##size##_MAX; \
130 return MIPSDSP_ABS(a); \
136 #undef DO_MIPS_SAT_ABS
139 static inline int16_t mipsdsp_add_i16(int16_t a
, int16_t b
, CPUMIPSState
*env
)
145 if (MIPSDSP_OVERFLOW(a
, b
, tempI
, 0x8000)) {
146 set_DSPControl_overflow_flag(1, 20, env
);
152 static inline int16_t mipsdsp_sat_add_i16(int16_t a
, int16_t b
,
159 if (MIPSDSP_OVERFLOW(a
, b
, tempS
, 0x8000)) {
165 set_DSPControl_overflow_flag(1, 20, env
);
171 static inline int32_t mipsdsp_sat_add_i32(int32_t a
, int32_t b
,
178 if (MIPSDSP_OVERFLOW(a
, b
, tempI
, 0x80000000)) {
184 set_DSPControl_overflow_flag(1, 20, env
);
190 static inline uint8_t mipsdsp_add_u8(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
194 temp
= (uint16_t)a
+ (uint16_t)b
;
197 set_DSPControl_overflow_flag(1, 20, env
);
203 static inline uint16_t mipsdsp_add_u16(uint16_t a
, uint16_t b
,
208 temp
= (uint32_t)a
+ (uint32_t)b
;
210 if (temp
& 0x00010000) {
211 set_DSPControl_overflow_flag(1, 20, env
);
214 return temp
& 0xFFFF;
217 static inline uint8_t mipsdsp_sat_add_u8(uint8_t a
, uint8_t b
,
223 temp
= (uint16_t)a
+ (uint16_t)b
;
224 result
= temp
& 0xFF;
228 set_DSPControl_overflow_flag(1, 20, env
);
234 static inline uint16_t mipsdsp_sat_add_u16(uint16_t a
, uint16_t b
,
240 temp
= (uint32_t)a
+ (uint32_t)b
;
241 result
= temp
& 0xFFFF;
243 if (0x00010000 & temp
) {
245 set_DSPControl_overflow_flag(1, 20, env
);
251 static inline int32_t mipsdsp_sat32_acc_q31(int32_t acc
, int32_t a
,
255 int32_t temp32
, temp31
, result
;
258 #ifndef TARGET_MIPS64
259 temp
= ((uint64_t)env
->active_tc
.HI
[acc
] << 32) |
260 (uint64_t)env
->active_tc
.LO
[acc
];
262 temp
= (uint64_t)env
->active_tc
.LO
[acc
];
265 temp_sum
= (int64_t)a
+ temp
;
267 temp32
= (temp_sum
>> 32) & 0x01;
268 temp31
= (temp_sum
>> 31) & 0x01;
269 result
= temp_sum
& 0xFFFFFFFF;
272 This sat function may wrong, because user manual wrote:
273 temp127..0 ← temp + ( (signA) || a31..0
274 if ( temp32 ≠ temp31 ) then
275 if ( temp32 = 0 ) then
276 temp31..0 ← 0x80000000
278 temp31..0 ← 0x7FFFFFFF
280 DSPControlouflag:16+acc ← 1
283 if (temp32
!= temp31
) {
289 set_DSPControl_overflow_flag(1, 16 + acc
, env
);
295 /* a[0] is LO, a[1] is HI. */
296 static inline void mipsdsp_sat64_acc_add_q63(int64_t *ret
,
303 ret
[0] = env
->active_tc
.LO
[ac
] + a
[0];
304 ret
[1] = env
->active_tc
.HI
[ac
] + a
[1];
306 if (((uint64_t)ret
[0] < (uint64_t)env
->active_tc
.LO
[ac
]) &&
307 ((uint64_t)ret
[0] < (uint64_t)a
[0])) {
311 if (temp64
!= ((ret
[0] >> 63) & 0x01)) {
313 ret
[0] = (0x01ull
<< 63);
316 ret
[0] = (0x01ull
<< 63) - 1;
319 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
323 static inline void mipsdsp_sat64_acc_sub_q63(int64_t *ret
,
330 ret
[0] = env
->active_tc
.LO
[ac
] - a
[0];
331 ret
[1] = env
->active_tc
.HI
[ac
] - a
[1];
333 if ((uint64_t)ret
[0] > (uint64_t)env
->active_tc
.LO
[ac
]) {
337 if (temp64
!= ((ret
[0] >> 63) & 0x01)) {
339 ret
[0] = (0x01ull
<< 63);
342 ret
[0] = (0x01ull
<< 63) - 1;
345 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
349 static inline int32_t mipsdsp_mul_i16_i16(int16_t a
, int16_t b
,
354 temp
= (int32_t)a
* (int32_t)b
;
356 if ((temp
> (int)0x7FFF) || (temp
< (int)0xFFFF8000)) {
357 set_DSPControl_overflow_flag(1, 21, env
);
364 static inline int32_t mipsdsp_mul_u16_u16(int32_t a
, int32_t b
)
369 static inline int32_t mipsdsp_mul_i32_i32(int32_t a
, int32_t b
)
374 static inline int32_t mipsdsp_sat16_mul_i16_i16(int16_t a
, int16_t b
,
379 temp
= (int32_t)a
* (int32_t)b
;
381 if (temp
> (int)0x7FFF) {
383 set_DSPControl_overflow_flag(1, 21, env
);
384 } else if (temp
< (int)0xffff8000) {
386 set_DSPControl_overflow_flag(1, 21, env
);
393 static inline int32_t mipsdsp_mul_q15_q15_overflowflag21(uint16_t a
, uint16_t b
,
398 if ((a
== 0x8000) && (b
== 0x8000)) {
400 set_DSPControl_overflow_flag(1, 21, env
);
402 temp
= ((int32_t)(int16_t)a
* (int32_t)(int16_t)b
) << 1;
409 static inline uint8_t mipsdsp_rshift_u8(uint8_t a
, target_ulong mov
)
414 static inline uint16_t mipsdsp_rshift_u16(uint16_t a
, target_ulong mov
)
419 static inline int8_t mipsdsp_rashift8(int8_t a
, target_ulong mov
)
424 static inline int16_t mipsdsp_rashift16(int16_t a
, target_ulong mov
)
429 static inline int32_t mipsdsp_rashift32(int32_t a
, target_ulong mov
)
434 static inline int16_t mipsdsp_rshift1_add_q16(int16_t a
, int16_t b
)
438 temp
= (int32_t)a
+ (int32_t)b
;
440 return (temp
>> 1) & 0xFFFF;
443 /* round right shift */
444 static inline int16_t mipsdsp_rrshift1_add_q16(int16_t a
, int16_t b
)
448 temp
= (int32_t)a
+ (int32_t)b
;
451 return (temp
>> 1) & 0xFFFF;
454 static inline int32_t mipsdsp_rshift1_add_q32(int32_t a
, int32_t b
)
458 temp
= (int64_t)a
+ (int64_t)b
;
460 return (temp
>> 1) & 0xFFFFFFFF;
463 static inline int32_t mipsdsp_rrshift1_add_q32(int32_t a
, int32_t b
)
467 temp
= (int64_t)a
+ (int64_t)b
;
470 return (temp
>> 1) & 0xFFFFFFFF;
473 static inline uint8_t mipsdsp_rshift1_add_u8(uint8_t a
, uint8_t b
)
477 temp
= (uint16_t)a
+ (uint16_t)b
;
479 return (temp
>> 1) & 0x00FF;
482 static inline uint8_t mipsdsp_rrshift1_add_u8(uint8_t a
, uint8_t b
)
486 temp
= (uint16_t)a
+ (uint16_t)b
+ 1;
488 return (temp
>> 1) & 0x00FF;
491 static inline uint8_t mipsdsp_rshift1_sub_u8(uint8_t a
, uint8_t b
)
495 temp
= (uint16_t)a
- (uint16_t)b
;
497 return (temp
>> 1) & 0x00FF;
500 static inline uint8_t mipsdsp_rrshift1_sub_u8(uint8_t a
, uint8_t b
)
504 temp
= (uint16_t)a
- (uint16_t)b
+ 1;
506 return (temp
>> 1) & 0x00FF;
509 /* 128 bits long. p[0] is LO, p[1] is HI. */
510 static inline void mipsdsp_rndrashift_short_acc(int64_t *p
,
517 acc
= ((int64_t)env
->active_tc
.HI
[ac
] << 32) |
518 ((int64_t)env
->active_tc
.LO
[ac
] & 0xFFFFFFFF);
521 p
[1] = (acc
>> 63) & 0x01;
523 p
[0] = acc
>> (shift
- 1);
528 /* 128 bits long. p[0] is LO, p[1] is HI */
529 static inline void mipsdsp_rashift_acc(uint64_t *p
,
534 uint64_t tempB
, tempA
;
536 tempB
= env
->active_tc
.HI
[ac
];
537 tempA
= env
->active_tc
.LO
[ac
];
538 shift
= shift
& 0x1F;
544 p
[0] = (tempB
<< (64 - shift
)) | (tempA
>> shift
);
545 p
[1] = (int64_t)tempB
>> shift
;
549 /* 128 bits long. p[0] is LO, p[1] is HI , p[2] is sign of HI.*/
550 static inline void mipsdsp_rndrashift_acc(uint64_t *p
,
555 int64_t tempB
, tempA
;
557 tempB
= env
->active_tc
.HI
[ac
];
558 tempA
= env
->active_tc
.LO
[ac
];
559 shift
= shift
& 0x3F;
563 p
[1] = (tempB
<< 1) | (tempA
>> 63);
566 p
[0] = (tempB
<< (65 - shift
)) | (tempA
>> (shift
- 1));
567 p
[1] = (int64_t)tempB
>> (shift
- 1);
576 static inline int32_t mipsdsp_mul_q15_q15(int32_t ac
, uint16_t a
, uint16_t b
,
581 if ((a
== 0x8000) && (b
== 0x8000)) {
583 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
585 temp
= ((uint32_t)a
* (uint32_t)b
) << 1;
591 static inline int64_t mipsdsp_mul_q31_q31(int32_t ac
, uint32_t a
, uint32_t b
,
596 if ((a
== 0x80000000) && (b
== 0x80000000)) {
597 temp
= (0x01ull
<< 63) - 1;
598 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
600 temp
= ((uint64_t)a
* (uint64_t)b
) << 1;
606 static inline uint16_t mipsdsp_mul_u8_u8(uint8_t a
, uint8_t b
)
608 return (uint16_t)a
* (uint16_t)b
;
611 static inline uint16_t mipsdsp_mul_u8_u16(uint8_t a
, uint16_t b
,
616 tempI
= (uint32_t)a
* (uint32_t)b
;
617 if (tempI
> 0x0000FFFF) {
619 set_DSPControl_overflow_flag(1, 21, env
);
622 return tempI
& 0x0000FFFF;
625 static inline uint64_t mipsdsp_mul_u32_u32(uint32_t a
, uint32_t b
)
627 return (uint64_t)a
* (uint64_t)b
;
630 static inline int16_t mipsdsp_rndq15_mul_q15_q15(uint16_t a
, uint16_t b
,
635 if ((a
== 0x8000) && (b
== 0x8000)) {
637 set_DSPControl_overflow_flag(1, 21, env
);
640 temp
= temp
+ 0x00008000;
643 return (temp
& 0xFFFF0000) >> 16;
646 static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a
, uint16_t b
,
651 if ((a
== 0x8000) && (b
== 0x8000)) {
653 set_DSPControl_overflow_flag(1, 21, env
);
655 temp
= ((uint32_t)a
* (uint32_t)b
);
659 return (temp
>> 16) & 0x0000FFFF;
662 static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a
,
667 temp
= (int32_t)a
+ 0x00008000;
669 if (a
> (int)0x7fff8000) {
671 set_DSPControl_overflow_flag(1, 22, env
);
674 return (temp
>> 16) & 0xFFFF;
677 static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a
,
683 sign
= (a
>> 15) & 0x01;
688 set_DSPControl_overflow_flag(1, 22, env
);
691 return (mag
>> 7) & 0xFFFF;
694 set_DSPControl_overflow_flag(1, 22, env
);
699 static inline uint8_t mipsdsp_lshift8(uint8_t a
, uint8_t s
, CPUMIPSState
*env
)
707 sign
= (a
>> 7) & 0x01;
709 discard
= (((0x01 << (8 - s
)) - 1) << s
) |
710 ((a
>> (6 - (s
- 1))) & ((0x01 << s
) - 1));
712 discard
= a
>> (6 - (s
- 1));
715 if (discard
!= 0x00) {
716 set_DSPControl_overflow_flag(1, 22, env
);
722 static inline uint16_t mipsdsp_lshift16(uint16_t a
, uint8_t s
,
731 sign
= (a
>> 15) & 0x01;
733 discard
= (((0x01 << (16 - s
)) - 1) << s
) |
734 ((a
>> (14 - (s
- 1))) & ((0x01 << s
) - 1));
736 discard
= a
>> (14 - (s
- 1));
739 if ((discard
!= 0x0000) && (discard
!= 0xFFFF)) {
740 set_DSPControl_overflow_flag(1, 22, env
);
747 static inline uint32_t mipsdsp_lshift32(uint32_t a
, uint8_t s
,
755 discard
= (int32_t)a
>> (31 - (s
- 1));
757 if ((discard
!= 0x00000000) && (discard
!= 0xFFFFFFFF)) {
758 set_DSPControl_overflow_flag(1, 22, env
);
764 static inline uint16_t mipsdsp_sat16_lshift(uint16_t a
, uint8_t s
,
773 sign
= (a
>> 15) & 0x01;
775 discard
= (((0x01 << (16 - s
)) - 1) << s
) |
776 ((a
>> (14 - (s
- 1))) & ((0x01 << s
) - 1));
778 discard
= a
>> (14 - (s
- 1));
781 if ((discard
!= 0x0000) && (discard
!= 0xFFFF)) {
782 set_DSPControl_overflow_flag(1, 22, env
);
783 return (sign
== 0) ? 0x7FFF : 0x8000;
790 static inline uint32_t mipsdsp_sat32_lshift(uint32_t a
, uint8_t s
,
799 sign
= (a
>> 31) & 0x01;
801 discard
= (((0x01 << (32 - s
)) - 1) << s
) |
802 ((a
>> (30 - (s
- 1))) & ((0x01 << s
) - 1));
804 discard
= a
>> (30 - (s
- 1));
807 if ((discard
!= 0x00000000) && (discard
!= 0xFFFFFFFF)) {
808 set_DSPControl_overflow_flag(1, 22, env
);
809 return (sign
== 0) ? 0x7FFFFFFF : 0x80000000;
816 static inline uint8_t mipsdsp_rnd8_rashift(uint8_t a
, uint8_t s
)
821 temp
= (uint32_t)a
<< 1;
823 temp
= (int32_t)(int8_t)a
>> (s
- 1);
826 return (temp
+ 1) >> 1;
829 static inline uint16_t mipsdsp_rnd16_rashift(uint16_t a
, uint8_t s
)
834 temp
= (uint32_t)a
<< 1;
836 temp
= (int32_t)(int16_t)a
>> (s
- 1);
839 return (temp
+ 1) >> 1;
842 static inline uint32_t mipsdsp_rnd32_rashift(uint32_t a
, uint8_t s
)
847 temp
= (uint64_t)a
<< 1;
849 temp
= (int64_t)(int32_t)a
>> (s
- 1);
853 return (temp
>> 1) & 0xFFFFFFFFull
;
856 static inline uint16_t mipsdsp_sub_i16(int16_t a
, int16_t b
, CPUMIPSState
*env
)
861 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x8000)) {
862 set_DSPControl_overflow_flag(1, 20, env
);
868 static inline uint16_t mipsdsp_sat16_sub(int16_t a
, int16_t b
,
874 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x8000)) {
880 set_DSPControl_overflow_flag(1, 20, env
);
886 static inline uint32_t mipsdsp_sat32_sub(int32_t a
, int32_t b
,
892 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x80000000)) {
898 set_DSPControl_overflow_flag(1, 20, env
);
901 return temp
& 0xFFFFFFFFull
;
904 static inline uint16_t mipsdsp_rshift1_sub_q16(int16_t a
, int16_t b
)
908 temp
= (int32_t)a
- (int32_t)b
;
910 return (temp
>> 1) & 0x0000FFFF;
913 static inline uint16_t mipsdsp_rrshift1_sub_q16(int16_t a
, int16_t b
)
917 temp
= (int32_t)a
- (int32_t)b
;
920 return (temp
>> 1) & 0x0000FFFF;
923 static inline uint32_t mipsdsp_rshift1_sub_q32(int32_t a
, int32_t b
)
927 temp
= (int64_t)a
- (int64_t)b
;
929 return (temp
>> 1) & 0xFFFFFFFFull
;
932 static inline uint32_t mipsdsp_rrshift1_sub_q32(int32_t a
, int32_t b
)
936 temp
= (int64_t)a
- (int64_t)b
;
939 return (temp
>> 1) & 0xFFFFFFFFull
;
942 static inline uint16_t mipsdsp_sub_u16_u16(uint16_t a
, uint16_t b
,
948 temp
= (uint32_t)a
- (uint32_t)b
;
949 temp16
= (temp
>> 16) & 0x01;
951 set_DSPControl_overflow_flag(1, 20, env
);
953 return temp
& 0x0000FFFF;
956 static inline uint16_t mipsdsp_satu16_sub_u16_u16(uint16_t a
, uint16_t b
,
962 temp
= (uint32_t)a
- (uint32_t)b
;
963 temp16
= (temp
>> 16) & 0x01;
967 set_DSPControl_overflow_flag(1, 20, env
);
970 return temp
& 0x0000FFFF;
973 static inline uint8_t mipsdsp_sub_u8(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
978 temp
= (uint16_t)a
- (uint16_t)b
;
979 temp8
= (temp
>> 8) & 0x01;
981 set_DSPControl_overflow_flag(1, 20, env
);
984 return temp
& 0x00FF;
987 static inline uint8_t mipsdsp_satu8_sub(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
992 temp
= (uint16_t)a
- (uint16_t)b
;
993 temp8
= (temp
>> 8) & 0x01;
996 set_DSPControl_overflow_flag(1, 20, env
);
999 return temp
& 0x00FF;
1002 static inline uint32_t mipsdsp_sub32(int32_t a
, int32_t b
, CPUMIPSState
*env
)
1007 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x80000000)) {
1008 set_DSPControl_overflow_flag(1, 20, env
);
1014 static inline int32_t mipsdsp_add_i32(int32_t a
, int32_t b
, CPUMIPSState
*env
)
1020 if (MIPSDSP_OVERFLOW(a
, b
, temp
, 0x80000000)) {
1021 set_DSPControl_overflow_flag(1, 20, env
);
1027 static inline int32_t mipsdsp_cmp_eq(int32_t a
, int32_t b
)
1032 static inline int32_t mipsdsp_cmp_le(int32_t a
, int32_t b
)
1037 static inline int32_t mipsdsp_cmp_lt(int32_t a
, int32_t b
)
1042 static inline int32_t mipsdsp_cmpu_eq(uint32_t a
, uint32_t b
)
1047 static inline int32_t mipsdsp_cmpu_le(uint32_t a
, uint32_t b
)
1052 static inline int32_t mipsdsp_cmpu_lt(uint32_t a
, uint32_t b
)
1056 /*** MIPS DSP internal functions end ***/
1058 #define MIPSDSP_LHI 0xFFFFFFFF00000000ull
1059 #define MIPSDSP_LLO 0x00000000FFFFFFFFull
1060 #define MIPSDSP_HI 0xFFFF0000
1061 #define MIPSDSP_LO 0x0000FFFF
1062 #define MIPSDSP_Q3 0xFF000000
1063 #define MIPSDSP_Q2 0x00FF0000
1064 #define MIPSDSP_Q1 0x0000FF00
1065 #define MIPSDSP_Q0 0x000000FF
1067 #define MIPSDSP_SPLIT32_8(num, a, b, c, d) \
1069 a = (num >> 24) & MIPSDSP_Q0; \
1070 b = (num >> 16) & MIPSDSP_Q0; \
1071 c = (num >> 8) & MIPSDSP_Q0; \
1072 d = num & MIPSDSP_Q0; \
1075 #define MIPSDSP_SPLIT32_16(num, a, b) \
1077 a = (num >> 16) & MIPSDSP_LO; \
1078 b = num & MIPSDSP_LO; \
1081 #define MIPSDSP_RETURN32_8(a, b, c, d) ((target_long)(int32_t) \
1082 (((uint32_t)a << 24) | \
1083 (((uint32_t)b << 16) | \
1084 (((uint32_t)c << 8) | \
1085 ((uint32_t)d & 0xFF)))))
1086 #define MIPSDSP_RETURN32_16(a, b) ((target_long)(int32_t) \
1087 (((uint32_t)a << 16) | \
1088 ((uint32_t)b & 0xFFFF)))
1090 #ifdef TARGET_MIPS64
1091 #define MIPSDSP_SPLIT64_16(num, a, b, c, d) \
1093 a = (num >> 48) & MIPSDSP_LO; \
1094 b = (num >> 32) & MIPSDSP_LO; \
1095 c = (num >> 16) & MIPSDSP_LO; \
1096 d = num & MIPSDSP_LO; \
1099 #define MIPSDSP_SPLIT64_32(num, a, b) \
1101 a = (num >> 32) & MIPSDSP_LLO; \
1102 b = num & MIPSDSP_LLO; \
1105 #define MIPSDSP_RETURN64_16(a, b, c, d) (((uint64_t)a << 48) | \
1106 ((uint64_t)b << 32) | \
1107 ((uint64_t)c << 16) | \
1109 #define MIPSDSP_RETURN64_32(a, b) (((uint64_t)a << 32) | (uint64_t)b)
1112 /** DSP Arithmetic Sub-class insns **/
1113 #define MIPSDSP32_BINOP(name, func, element) \
1114 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
1116 DSP32Value ds, dt; \
1117 unsigned int i, n; \
1119 n = sizeof(DSP32Value) / sizeof(ds.element[0]); \
1123 for (i = 0; i < n; i++) { \
1124 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i]); \
1127 return (target_long)ds.sw[0]; \
1129 MIPSDSP32_BINOP(addqh_ph
, rshift1_add_q16
, sh
);
1130 MIPSDSP32_BINOP(addqh_r_ph
, rrshift1_add_q16
, sh
);
1131 MIPSDSP32_BINOP(addqh_r_w
, rrshift1_add_q32
, sw
);
1132 MIPSDSP32_BINOP(addqh_w
, rshift1_add_q32
, sw
);
1133 MIPSDSP32_BINOP(adduh_qb
, rshift1_add_u8
, ub
);
1134 MIPSDSP32_BINOP(adduh_r_qb
, rrshift1_add_u8
, ub
);
1135 MIPSDSP32_BINOP(subqh_ph
, rshift1_sub_q16
, sh
);
1136 MIPSDSP32_BINOP(subqh_r_ph
, rrshift1_sub_q16
, sh
);
1137 MIPSDSP32_BINOP(subqh_r_w
, rrshift1_sub_q32
, sw
);
1138 MIPSDSP32_BINOP(subqh_w
, rshift1_sub_q32
, sw
);
1139 #undef MIPSDSP32_BINOP
1141 #define MIPSDSP32_BINOP_ENV(name, func, element) \
1142 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
1143 CPUMIPSState *env) \
1145 DSP32Value ds, dt; \
1146 unsigned int i, n; \
1148 n = sizeof(DSP32Value) / sizeof(ds.element[0]); \
1152 for (i = 0 ; i < n ; i++) { \
1153 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i], env); \
1156 return (target_long)ds.sw[0]; \
1158 MIPSDSP32_BINOP_ENV(addq_ph
, add_i16
, sh
)
1159 MIPSDSP32_BINOP_ENV(addq_s_ph
, sat_add_i16
, sh
)
1160 MIPSDSP32_BINOP_ENV(addq_s_w
, sat_add_i32
, sw
);
1161 MIPSDSP32_BINOP_ENV(addu_ph
, add_u16
, sh
)
1162 MIPSDSP32_BINOP_ENV(addu_qb
, add_u8
, ub
);
1163 MIPSDSP32_BINOP_ENV(addu_s_ph
, sat_add_u16
, sh
)
1164 MIPSDSP32_BINOP_ENV(addu_s_qb
, sat_add_u8
, ub
);
1165 MIPSDSP32_BINOP_ENV(subq_ph
, sub_i16
, sh
);
1166 MIPSDSP32_BINOP_ENV(subq_s_ph
, sat16_sub
, sh
);
1167 MIPSDSP32_BINOP_ENV(subq_s_w
, sat32_sub
, sw
);
1168 MIPSDSP32_BINOP_ENV(subu_ph
, sub_u16_u16
, sh
);
1169 MIPSDSP32_BINOP_ENV(subu_qb
, sub_u8
, ub
);
1170 MIPSDSP32_BINOP_ENV(subu_s_ph
, satu16_sub_u16_u16
, sh
);
1171 MIPSDSP32_BINOP_ENV(subu_s_qb
, satu8_sub
, ub
);
1172 #undef MIPSDSP32_BINOP_ENV
1174 #ifdef TARGET_MIPS64
1175 #define MIPSDSP64_BINOP(name, func, element) \
1176 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
1178 DSP64Value ds, dt; \
1179 unsigned int i, n; \
1181 n = sizeof(DSP64Value) / sizeof(ds.element[0]); \
1185 for (i = 0 ; i < n ; i++) { \
1186 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i]); \
1191 MIPSDSP64_BINOP(adduh_ob
, rshift1_add_u8
, ub
);
1192 MIPSDSP64_BINOP(adduh_r_ob
, rrshift1_add_u8
, ub
);
1193 MIPSDSP64_BINOP(subuh_ob
, rshift1_sub_u8
, ub
);
1194 MIPSDSP64_BINOP(subuh_r_ob
, rrshift1_sub_u8
, ub
);
1195 #undef MIPSDSP64_BINOP
1197 #define MIPSDSP64_BINOP_ENV(name, func, element) \
1198 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
1199 CPUMIPSState *env) \
1201 DSP64Value ds, dt; \
1202 unsigned int i, n; \
1204 n = sizeof(DSP64Value) / sizeof(ds.element[0]); \
1208 for (i = 0 ; i < n ; i++) { \
1209 ds.element[i] = mipsdsp_##func(ds.element[i], dt.element[i], env); \
1214 MIPSDSP64_BINOP_ENV(addq_pw
, add_i32
, sw
);
1215 MIPSDSP64_BINOP_ENV(addq_qh
, add_i16
, sh
);
1216 MIPSDSP64_BINOP_ENV(addq_s_pw
, sat_add_i32
, sw
);
1217 MIPSDSP64_BINOP_ENV(addq_s_qh
, sat_add_i16
, sh
);
1218 MIPSDSP64_BINOP_ENV(addu_ob
, add_u8
, uh
);
1219 MIPSDSP64_BINOP_ENV(addu_qh
, add_u16
, uh
);
1220 MIPSDSP64_BINOP_ENV(addu_s_ob
, sat_add_u8
, uh
);
1221 MIPSDSP64_BINOP_ENV(addu_s_qh
, sat_add_u16
, uh
);
1222 MIPSDSP64_BINOP_ENV(subq_pw
, sub32
, sw
);
1223 MIPSDSP64_BINOP_ENV(subq_qh
, sub_i16
, sh
);
1224 MIPSDSP64_BINOP_ENV(subq_s_pw
, sat32_sub
, sw
);
1225 MIPSDSP64_BINOP_ENV(subq_s_qh
, sat16_sub
, sh
);
1226 MIPSDSP64_BINOP_ENV(subu_ob
, sub_u8
, uh
);
1227 MIPSDSP64_BINOP_ENV(subu_qh
, sub_u16_u16
, uh
);
1228 MIPSDSP64_BINOP_ENV(subu_s_ob
, satu8_sub
, uh
);
1229 MIPSDSP64_BINOP_ENV(subu_s_qh
, satu16_sub_u16_u16
, uh
);
1230 #undef MIPSDSP64_BINOP_ENV
1234 target_ulong
helper_absq_s_w(target_ulong rt
, CPUMIPSState
*env
)
1238 rd
= mipsdsp_sat_abs32(rt
, env
);
1240 return (target_ulong
)rd
;
1244 #define SUBUH_QB(name, var) \
1245 target_ulong helper_##name##_qb(target_ulong rs, target_ulong rt) \
1247 uint8_t rs3, rs2, rs1, rs0; \
1248 uint8_t rt3, rt2, rt1, rt0; \
1249 uint8_t tempD, tempC, tempB, tempA; \
1251 MIPSDSP_SPLIT32_8(rs, rs3, rs2, rs1, rs0); \
1252 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1254 tempD = ((uint16_t)rs3 - (uint16_t)rt3 + var) >> 1; \
1255 tempC = ((uint16_t)rs2 - (uint16_t)rt2 + var) >> 1; \
1256 tempB = ((uint16_t)rs1 - (uint16_t)rt1 + var) >> 1; \
1257 tempA = ((uint16_t)rs0 - (uint16_t)rt0 + var) >> 1; \
1259 return ((uint32_t)tempD << 24) | ((uint32_t)tempC << 16) | \
1260 ((uint32_t)tempB << 8) | ((uint32_t)tempA); \
1264 SUBUH_QB(subuh_r
, 1);
1268 target_ulong
helper_addsc(target_ulong rs
, target_ulong rt
, CPUMIPSState
*env
)
1270 uint64_t temp
, tempRs
, tempRt
;
1273 tempRs
= (uint64_t)rs
& MIPSDSP_LLO
;
1274 tempRt
= (uint64_t)rt
& MIPSDSP_LLO
;
1276 temp
= tempRs
+ tempRt
;
1277 flag
= (temp
& 0x0100000000ull
) >> 32;
1278 set_DSPControl_carryflag(flag
, env
);
1280 return (target_long
)(int32_t)(temp
& MIPSDSP_LLO
);
1283 target_ulong
helper_addwc(target_ulong rs
, target_ulong rt
, CPUMIPSState
*env
)
1286 int32_t temp32
, temp31
;
1289 tempL
= (int64_t)(int32_t)rs
+ (int64_t)(int32_t)rt
+
1290 get_DSPControl_carryflag(env
);
1291 temp31
= (tempL
>> 31) & 0x01;
1292 temp32
= (tempL
>> 32) & 0x01;
1294 if (temp31
!= temp32
) {
1295 set_DSPControl_overflow_flag(1, 20, env
);
1298 rd
= tempL
& MIPSDSP_LLO
;
1300 return (target_long
)(int32_t)rd
;
1303 target_ulong
helper_modsub(target_ulong rs
, target_ulong rt
)
1309 decr
= rt
& MIPSDSP_Q0
;
1310 lastindex
= (rt
>> 8) & MIPSDSP_LO
;
1312 if ((rs
& MIPSDSP_LLO
) == 0x00000000) {
1313 rd
= (target_ulong
)lastindex
;
1321 target_ulong
helper_raddu_w_qb(target_ulong rs
)
1323 uint8_t rs3
, rs2
, rs1
, rs0
;
1326 MIPSDSP_SPLIT32_8(rs
, rs3
, rs2
, rs1
, rs0
);
1328 temp
= (uint16_t)rs3
+ (uint16_t)rs2
+ (uint16_t)rs1
+ (uint16_t)rs0
;
1330 return (target_ulong
)temp
;
1333 #if defined(TARGET_MIPS64)
1334 target_ulong
helper_raddu_l_ob(target_ulong rs
)
1342 for (i
= 0; i
< 8; i
++) {
1343 rs_t
[i
] = (rs
>> (8 * i
)) & MIPSDSP_Q0
;
1344 temp
+= (uint64_t)rs_t
[i
];
1351 target_ulong
helper_absq_s_qb(target_ulong rt
, CPUMIPSState
*env
)
1353 uint8_t tempD
, tempC
, tempB
, tempA
;
1355 MIPSDSP_SPLIT32_8(rt
, tempD
, tempC
, tempB
, tempA
);
1357 tempD
= mipsdsp_sat_abs8(tempD
, env
);
1358 tempC
= mipsdsp_sat_abs8(tempC
, env
);
1359 tempB
= mipsdsp_sat_abs8(tempB
, env
);
1360 tempA
= mipsdsp_sat_abs8(tempA
, env
);
1362 return MIPSDSP_RETURN32_8(tempD
, tempC
, tempB
, tempA
);
1365 target_ulong
helper_absq_s_ph(target_ulong rt
, CPUMIPSState
*env
)
1367 uint16_t tempB
, tempA
;
1369 MIPSDSP_SPLIT32_16(rt
, tempB
, tempA
);
1371 tempB
= mipsdsp_sat_abs16 (tempB
, env
);
1372 tempA
= mipsdsp_sat_abs16 (tempA
, env
);
1374 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1377 #if defined(TARGET_MIPS64)
1378 target_ulong
helper_absq_s_ob(target_ulong rt
, CPUMIPSState
*env
)
1384 for (i
= 0; i
< 8; i
++) {
1385 temp
[i
] = (rt
>> (8 * i
)) & MIPSDSP_Q0
;
1386 temp
[i
] = mipsdsp_sat_abs8(temp
[i
], env
);
1389 for (i
= 0; i
< 8; i
++) {
1390 result
= (uint64_t)(uint8_t)temp
[i
] << (8 * i
);
1396 target_ulong
helper_absq_s_qh(target_ulong rt
, CPUMIPSState
*env
)
1398 int16_t tempD
, tempC
, tempB
, tempA
;
1400 MIPSDSP_SPLIT64_16(rt
, tempD
, tempC
, tempB
, tempA
);
1402 tempD
= mipsdsp_sat_abs16(tempD
, env
);
1403 tempC
= mipsdsp_sat_abs16(tempC
, env
);
1404 tempB
= mipsdsp_sat_abs16(tempB
, env
);
1405 tempA
= mipsdsp_sat_abs16(tempA
, env
);
1407 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1410 target_ulong
helper_absq_s_pw(target_ulong rt
, CPUMIPSState
*env
)
1412 int32_t tempB
, tempA
;
1414 MIPSDSP_SPLIT64_32(rt
, tempB
, tempA
);
1416 tempB
= mipsdsp_sat_abs32(tempB
, env
);
1417 tempA
= mipsdsp_sat_abs32(tempA
, env
);
1419 return MIPSDSP_RETURN64_32(tempB
, tempA
);
1423 #define PRECR_QB_PH(name, a, b)\
1424 target_ulong helper_##name##_qb_ph(target_ulong rs, target_ulong rt) \
1426 uint8_t tempD, tempC, tempB, tempA; \
1428 tempD = (rs >> a) & MIPSDSP_Q0; \
1429 tempC = (rs >> b) & MIPSDSP_Q0; \
1430 tempB = (rt >> a) & MIPSDSP_Q0; \
1431 tempA = (rt >> b) & MIPSDSP_Q0; \
1433 return MIPSDSP_RETURN32_8(tempD, tempC, tempB, tempA); \
1436 PRECR_QB_PH(precr
, 16, 0);
1437 PRECR_QB_PH(precrq
, 24, 8);
1441 target_ulong
helper_precr_sra_ph_w(uint32_t sa
, target_ulong rs
,
1444 uint16_t tempB
, tempA
;
1446 tempB
= ((int32_t)rt
>> sa
) & MIPSDSP_LO
;
1447 tempA
= ((int32_t)rs
>> sa
) & MIPSDSP_LO
;
1449 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1452 target_ulong
helper_precr_sra_r_ph_w(uint32_t sa
,
1453 target_ulong rs
, target_ulong rt
)
1455 uint64_t tempB
, tempA
;
1457 /* If sa = 0, then (sa - 1) = -1 will case shift error, so we need else. */
1459 tempB
= (rt
& MIPSDSP_LO
) << 1;
1460 tempA
= (rs
& MIPSDSP_LO
) << 1;
1462 tempB
= ((int32_t)rt
>> (sa
- 1)) + 1;
1463 tempA
= ((int32_t)rs
>> (sa
- 1)) + 1;
1465 rt
= (((tempB
>> 1) & MIPSDSP_LO
) << 16) | ((tempA
>> 1) & MIPSDSP_LO
);
1467 return (target_long
)(int32_t)rt
;
1470 target_ulong
helper_precrq_ph_w(target_ulong rs
, target_ulong rt
)
1472 uint16_t tempB
, tempA
;
1474 tempB
= (rs
& MIPSDSP_HI
) >> 16;
1475 tempA
= (rt
& MIPSDSP_HI
) >> 16;
1477 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1480 target_ulong
helper_precrq_rs_ph_w(target_ulong rs
, target_ulong rt
,
1483 uint16_t tempB
, tempA
;
1485 tempB
= mipsdsp_trunc16_sat16_round(rs
, env
);
1486 tempA
= mipsdsp_trunc16_sat16_round(rt
, env
);
1488 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1491 #if defined(TARGET_MIPS64)
1492 target_ulong
helper_precr_ob_qh(target_ulong rs
, target_ulong rt
)
1494 uint8_t rs6
, rs4
, rs2
, rs0
;
1495 uint8_t rt6
, rt4
, rt2
, rt0
;
1498 rs6
= (rs
>> 48) & MIPSDSP_Q0
;
1499 rs4
= (rs
>> 32) & MIPSDSP_Q0
;
1500 rs2
= (rs
>> 16) & MIPSDSP_Q0
;
1501 rs0
= rs
& MIPSDSP_Q0
;
1502 rt6
= (rt
>> 48) & MIPSDSP_Q0
;
1503 rt4
= (rt
>> 32) & MIPSDSP_Q0
;
1504 rt2
= (rt
>> 16) & MIPSDSP_Q0
;
1505 rt0
= rt
& MIPSDSP_Q0
;
1507 temp
= ((uint64_t)rs6
<< 56) | ((uint64_t)rs4
<< 48) |
1508 ((uint64_t)rs2
<< 40) | ((uint64_t)rs0
<< 32) |
1509 ((uint64_t)rt6
<< 24) | ((uint64_t)rt4
<< 16) |
1510 ((uint64_t)rt2
<< 8) | (uint64_t)rt0
;
1515 #define PRECR_QH_PW(name, var) \
1516 target_ulong helper_precr_##name##_qh_pw(target_ulong rs, target_ulong rt, \
1519 uint16_t rs3, rs2, rs1, rs0; \
1520 uint16_t rt3, rt2, rt1, rt0; \
1521 uint16_t tempD, tempC, tempB, tempA; \
1523 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
1524 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1526 /* When sa = 0, we use rt2, rt0, rs2, rs0; \
1527 * when sa != 0, we use rt3, rt1, rs3, rs1. */ \
1529 tempD = rt2 << var; \
1530 tempC = rt0 << var; \
1531 tempB = rs2 << var; \
1532 tempA = rs0 << var; \
1534 tempD = (((int16_t)rt3 >> sa) + var) >> var; \
1535 tempC = (((int16_t)rt1 >> sa) + var) >> var; \
1536 tempB = (((int16_t)rs3 >> sa) + var) >> var; \
1537 tempA = (((int16_t)rs1 >> sa) + var) >> var; \
1540 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1543 PRECR_QH_PW(sra
, 0);
1544 PRECR_QH_PW(sra_r
, 1);
1548 target_ulong
helper_precrq_ob_qh(target_ulong rs
, target_ulong rt
)
1550 uint8_t rs6
, rs4
, rs2
, rs0
;
1551 uint8_t rt6
, rt4
, rt2
, rt0
;
1554 rs6
= (rs
>> 56) & MIPSDSP_Q0
;
1555 rs4
= (rs
>> 40) & MIPSDSP_Q0
;
1556 rs2
= (rs
>> 24) & MIPSDSP_Q0
;
1557 rs0
= (rs
>> 8) & MIPSDSP_Q0
;
1558 rt6
= (rt
>> 56) & MIPSDSP_Q0
;
1559 rt4
= (rt
>> 40) & MIPSDSP_Q0
;
1560 rt2
= (rt
>> 24) & MIPSDSP_Q0
;
1561 rt0
= (rt
>> 8) & MIPSDSP_Q0
;
1563 temp
= ((uint64_t)rs6
<< 56) | ((uint64_t)rs4
<< 48) |
1564 ((uint64_t)rs2
<< 40) | ((uint64_t)rs0
<< 32) |
1565 ((uint64_t)rt6
<< 24) | ((uint64_t)rt4
<< 16) |
1566 ((uint64_t)rt2
<< 8) | (uint64_t)rt0
;
1571 target_ulong
helper_precrq_qh_pw(target_ulong rs
, target_ulong rt
)
1573 uint16_t tempD
, tempC
, tempB
, tempA
;
1575 tempD
= (rs
>> 48) & MIPSDSP_LO
;
1576 tempC
= (rs
>> 16) & MIPSDSP_LO
;
1577 tempB
= (rt
>> 48) & MIPSDSP_LO
;
1578 tempA
= (rt
>> 16) & MIPSDSP_LO
;
1580 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1583 target_ulong
helper_precrq_rs_qh_pw(target_ulong rs
, target_ulong rt
,
1588 uint16_t tempD
, tempC
, tempB
, tempA
;
1590 rs2
= (rs
>> 32) & MIPSDSP_LLO
;
1591 rs0
= rs
& MIPSDSP_LLO
;
1592 rt2
= (rt
>> 32) & MIPSDSP_LLO
;
1593 rt0
= rt
& MIPSDSP_LLO
;
1595 tempD
= mipsdsp_trunc16_sat16_round(rs2
, env
);
1596 tempC
= mipsdsp_trunc16_sat16_round(rs0
, env
);
1597 tempB
= mipsdsp_trunc16_sat16_round(rt2
, env
);
1598 tempA
= mipsdsp_trunc16_sat16_round(rt0
, env
);
1600 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1603 target_ulong
helper_precrq_pw_l(target_ulong rs
, target_ulong rt
)
1605 uint32_t tempB
, tempA
;
1607 tempB
= (rs
>> 32) & MIPSDSP_LLO
;
1608 tempA
= (rt
>> 32) & MIPSDSP_LLO
;
1610 return MIPSDSP_RETURN64_32(tempB
, tempA
);
1614 target_ulong
helper_precrqu_s_qb_ph(target_ulong rs
, target_ulong rt
,
1617 uint8_t tempD
, tempC
, tempB
, tempA
;
1618 uint16_t rsh
, rsl
, rth
, rtl
;
1620 rsh
= (rs
& MIPSDSP_HI
) >> 16;
1621 rsl
= rs
& MIPSDSP_LO
;
1622 rth
= (rt
& MIPSDSP_HI
) >> 16;
1623 rtl
= rt
& MIPSDSP_LO
;
1625 tempD
= mipsdsp_sat8_reduce_precision(rsh
, env
);
1626 tempC
= mipsdsp_sat8_reduce_precision(rsl
, env
);
1627 tempB
= mipsdsp_sat8_reduce_precision(rth
, env
);
1628 tempA
= mipsdsp_sat8_reduce_precision(rtl
, env
);
1630 return MIPSDSP_RETURN32_8(tempD
, tempC
, tempB
, tempA
);
1633 #if defined(TARGET_MIPS64)
1634 target_ulong
helper_precrqu_s_ob_qh(target_ulong rs
, target_ulong rt
,
1638 uint16_t rs3
, rs2
, rs1
, rs0
;
1639 uint16_t rt3
, rt2
, rt1
, rt0
;
1645 MIPSDSP_SPLIT64_16(rs
, rs3
, rs2
, rs1
, rs0
);
1646 MIPSDSP_SPLIT64_16(rt
, rt3
, rt2
, rt1
, rt0
);
1648 temp
[7] = mipsdsp_sat8_reduce_precision(rs3
, env
);
1649 temp
[6] = mipsdsp_sat8_reduce_precision(rs2
, env
);
1650 temp
[5] = mipsdsp_sat8_reduce_precision(rs1
, env
);
1651 temp
[4] = mipsdsp_sat8_reduce_precision(rs0
, env
);
1652 temp
[3] = mipsdsp_sat8_reduce_precision(rt3
, env
);
1653 temp
[2] = mipsdsp_sat8_reduce_precision(rt2
, env
);
1654 temp
[1] = mipsdsp_sat8_reduce_precision(rt1
, env
);
1655 temp
[0] = mipsdsp_sat8_reduce_precision(rt0
, env
);
1657 for (i
= 0; i
< 8; i
++) {
1658 result
|= (uint64_t)temp
[i
] << (8 * i
);
1664 #define PRECEQ_PW(name, a, b) \
1665 target_ulong helper_preceq_pw_##name(target_ulong rt) \
1667 uint16_t tempB, tempA; \
1668 uint32_t tempBI, tempAI; \
1670 tempB = (rt >> a) & MIPSDSP_LO; \
1671 tempA = (rt >> b) & MIPSDSP_LO; \
1673 tempBI = (uint32_t)tempB << 16; \
1674 tempAI = (uint32_t)tempA << 16; \
1676 return MIPSDSP_RETURN64_32(tempBI, tempAI); \
1679 PRECEQ_PW(qhl
, 48, 32);
1680 PRECEQ_PW(qhr
, 16, 0);
1681 PRECEQ_PW(qhla
, 48, 16);
1682 PRECEQ_PW(qhra
, 32, 0);
1688 #define PRECEQU_PH(name, a, b) \
1689 target_ulong helper_precequ_ph_##name(target_ulong rt) \
1691 uint16_t tempB, tempA; \
1693 tempB = (rt >> a) & MIPSDSP_Q0; \
1694 tempA = (rt >> b) & MIPSDSP_Q0; \
1696 tempB = tempB << 7; \
1697 tempA = tempA << 7; \
1699 return MIPSDSP_RETURN32_16(tempB, tempA); \
1702 PRECEQU_PH(qbl
, 24, 16);
1703 PRECEQU_PH(qbr
, 8, 0);
1704 PRECEQU_PH(qbla
, 24, 8);
1705 PRECEQU_PH(qbra
, 16, 0);
1709 #if defined(TARGET_MIPS64)
1710 #define PRECEQU_QH(name, a, b, c, d) \
1711 target_ulong helper_precequ_qh_##name(target_ulong rt) \
1713 uint16_t tempD, tempC, tempB, tempA; \
1715 tempD = (rt >> a) & MIPSDSP_Q0; \
1716 tempC = (rt >> b) & MIPSDSP_Q0; \
1717 tempB = (rt >> c) & MIPSDSP_Q0; \
1718 tempA = (rt >> d) & MIPSDSP_Q0; \
1720 tempD = tempD << 7; \
1721 tempC = tempC << 7; \
1722 tempB = tempB << 7; \
1723 tempA = tempA << 7; \
1725 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1728 PRECEQU_QH(obl
, 56, 48, 40, 32);
1729 PRECEQU_QH(obr
, 24, 16, 8, 0);
1730 PRECEQU_QH(obla
, 56, 40, 24, 8);
1731 PRECEQU_QH(obra
, 48, 32, 16, 0);
1737 #define PRECEU_PH(name, a, b) \
1738 target_ulong helper_preceu_ph_##name(target_ulong rt) \
1740 uint16_t tempB, tempA; \
1742 tempB = (rt >> a) & MIPSDSP_Q0; \
1743 tempA = (rt >> b) & MIPSDSP_Q0; \
1745 return MIPSDSP_RETURN32_16(tempB, tempA); \
1748 PRECEU_PH(qbl
, 24, 16);
1749 PRECEU_PH(qbr
, 8, 0);
1750 PRECEU_PH(qbla
, 24, 8);
1751 PRECEU_PH(qbra
, 16, 0);
1755 #if defined(TARGET_MIPS64)
1756 #define PRECEU_QH(name, a, b, c, d) \
1757 target_ulong helper_preceu_qh_##name(target_ulong rt) \
1759 uint16_t tempD, tempC, tempB, tempA; \
1761 tempD = (rt >> a) & MIPSDSP_Q0; \
1762 tempC = (rt >> b) & MIPSDSP_Q0; \
1763 tempB = (rt >> c) & MIPSDSP_Q0; \
1764 tempA = (rt >> d) & MIPSDSP_Q0; \
1766 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1769 PRECEU_QH(obl
, 56, 48, 40, 32);
1770 PRECEU_QH(obr
, 24, 16, 8, 0);
1771 PRECEU_QH(obla
, 56, 40, 24, 8);
1772 PRECEU_QH(obra
, 48, 32, 16, 0);
1778 /** DSP GPR-Based Shift Sub-class insns **/
1779 #define SHIFT_QB(name, func) \
1780 target_ulong helper_##name##_qb(target_ulong sa, target_ulong rt) \
1782 uint8_t rt3, rt2, rt1, rt0; \
1786 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1788 rt3 = mipsdsp_##func(rt3, sa); \
1789 rt2 = mipsdsp_##func(rt2, sa); \
1790 rt1 = mipsdsp_##func(rt1, sa); \
1791 rt0 = mipsdsp_##func(rt0, sa); \
1793 return MIPSDSP_RETURN32_8(rt3, rt2, rt1, rt0); \
1796 #define SHIFT_QB_ENV(name, func) \
1797 target_ulong helper_##name##_qb(target_ulong sa, target_ulong rt,\
1798 CPUMIPSState *env) \
1800 uint8_t rt3, rt2, rt1, rt0; \
1804 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1806 rt3 = mipsdsp_##func(rt3, sa, env); \
1807 rt2 = mipsdsp_##func(rt2, sa, env); \
1808 rt1 = mipsdsp_##func(rt1, sa, env); \
1809 rt0 = mipsdsp_##func(rt0, sa, env); \
1811 return MIPSDSP_RETURN32_8(rt3, rt2, rt1, rt0); \
1814 SHIFT_QB_ENV(shll
, lshift8
);
1815 SHIFT_QB(shrl
, rshift_u8
);
1817 SHIFT_QB(shra
, rashift8
);
1818 SHIFT_QB(shra_r
, rnd8_rashift
);
1823 #if defined(TARGET_MIPS64)
1824 #define SHIFT_OB(name, func) \
1825 target_ulong helper_##name##_ob(target_ulong rt, target_ulong sa) \
1834 for (i = 0; i < 8; i++) { \
1835 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1836 rt_t[i] = mipsdsp_##func(rt_t[i], sa); \
1837 temp |= (uint64_t)rt_t[i] << (8 * i); \
1843 #define SHIFT_OB_ENV(name, func) \
1844 target_ulong helper_##name##_ob(target_ulong rt, target_ulong sa, \
1845 CPUMIPSState *env) \
1854 for (i = 0; i < 8; i++) { \
1855 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1856 rt_t[i] = mipsdsp_##func(rt_t[i], sa, env); \
1857 temp |= (uint64_t)rt_t[i] << (8 * i); \
1863 SHIFT_OB_ENV(shll
, lshift8
);
1864 SHIFT_OB(shrl
, rshift_u8
);
1866 SHIFT_OB(shra
, rashift8
);
1867 SHIFT_OB(shra_r
, rnd8_rashift
);
1874 #define SHIFT_PH(name, func) \
1875 target_ulong helper_##name##_ph(target_ulong sa, target_ulong rt, \
1876 CPUMIPSState *env) \
1878 uint16_t rth, rtl; \
1882 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
1884 rth = mipsdsp_##func(rth, sa, env); \
1885 rtl = mipsdsp_##func(rtl, sa, env); \
1887 return MIPSDSP_RETURN32_16(rth, rtl); \
1890 SHIFT_PH(shll
, lshift16
);
1891 SHIFT_PH(shll_s
, sat16_lshift
);
1895 #if defined(TARGET_MIPS64)
1896 #define SHIFT_QH(name, func) \
1897 target_ulong helper_##name##_qh(target_ulong rt, target_ulong sa) \
1899 uint16_t rt3, rt2, rt1, rt0; \
1903 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1905 rt3 = mipsdsp_##func(rt3, sa); \
1906 rt2 = mipsdsp_##func(rt2, sa); \
1907 rt1 = mipsdsp_##func(rt1, sa); \
1908 rt0 = mipsdsp_##func(rt0, sa); \
1910 return MIPSDSP_RETURN64_16(rt3, rt2, rt1, rt0); \
1913 #define SHIFT_QH_ENV(name, func) \
1914 target_ulong helper_##name##_qh(target_ulong rt, target_ulong sa, \
1915 CPUMIPSState *env) \
1917 uint16_t rt3, rt2, rt1, rt0; \
1921 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1923 rt3 = mipsdsp_##func(rt3, sa, env); \
1924 rt2 = mipsdsp_##func(rt2, sa, env); \
1925 rt1 = mipsdsp_##func(rt1, sa, env); \
1926 rt0 = mipsdsp_##func(rt0, sa, env); \
1928 return MIPSDSP_RETURN64_16(rt3, rt2, rt1, rt0); \
1931 SHIFT_QH_ENV(shll
, lshift16
);
1932 SHIFT_QH_ENV(shll_s
, sat16_lshift
);
1934 SHIFT_QH(shrl
, rshift_u16
);
1935 SHIFT_QH(shra
, rashift16
);
1936 SHIFT_QH(shra_r
, rnd16_rashift
);
1943 #define SHIFT_W(name, func) \
1944 target_ulong helper_##name##_w(target_ulong sa, target_ulong rt) \
1949 temp = mipsdsp_##func(rt, sa); \
1951 return (target_long)(int32_t)temp; \
1954 #define SHIFT_W_ENV(name, func) \
1955 target_ulong helper_##name##_w(target_ulong sa, target_ulong rt, \
1956 CPUMIPSState *env) \
1961 temp = mipsdsp_##func(rt, sa, env); \
1963 return (target_long)(int32_t)temp; \
1966 SHIFT_W_ENV(shll_s
, sat32_lshift
);
1967 SHIFT_W(shra_r
, rnd32_rashift
);
1972 #if defined(TARGET_MIPS64)
1973 #define SHIFT_PW(name, func) \
1974 target_ulong helper_##name##_pw(target_ulong rt, target_ulong sa) \
1976 uint32_t rt1, rt0; \
1979 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
1981 rt1 = mipsdsp_##func(rt1, sa); \
1982 rt0 = mipsdsp_##func(rt0, sa); \
1984 return MIPSDSP_RETURN64_32(rt1, rt0); \
1987 #define SHIFT_PW_ENV(name, func) \
1988 target_ulong helper_##name##_pw(target_ulong rt, target_ulong sa, \
1989 CPUMIPSState *env) \
1991 uint32_t rt1, rt0; \
1994 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
1996 rt1 = mipsdsp_##func(rt1, sa, env); \
1997 rt0 = mipsdsp_##func(rt0, sa, env); \
1999 return MIPSDSP_RETURN64_32(rt1, rt0); \
2002 SHIFT_PW_ENV(shll
, lshift32
);
2003 SHIFT_PW_ENV(shll_s
, sat32_lshift
);
2005 SHIFT_PW(shra
, rashift32
);
2006 SHIFT_PW(shra_r
, rnd32_rashift
);
2013 #define SHIFT_PH(name, func) \
2014 target_ulong helper_##name##_ph(target_ulong sa, target_ulong rt) \
2016 uint16_t rth, rtl; \
2020 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2022 rth = mipsdsp_##func(rth, sa); \
2023 rtl = mipsdsp_##func(rtl, sa); \
2025 return MIPSDSP_RETURN32_16(rth, rtl); \
2028 SHIFT_PH(shrl
, rshift_u16
);
2029 SHIFT_PH(shra
, rashift16
);
2030 SHIFT_PH(shra_r
, rnd16_rashift
);
2034 /** DSP Multiply Sub-class insns **/
2035 /* Return value made up by two 16bits value.
2036 * FIXME give the macro a better name.
2038 #define MUL_RETURN32_16_PH(name, func, \
2039 rsmov1, rsmov2, rsfilter, \
2040 rtmov1, rtmov2, rtfilter) \
2041 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2042 CPUMIPSState *env) \
2044 uint16_t rsB, rsA, rtB, rtA; \
2046 rsB = (rs >> rsmov1) & rsfilter; \
2047 rsA = (rs >> rsmov2) & rsfilter; \
2048 rtB = (rt >> rtmov1) & rtfilter; \
2049 rtA = (rt >> rtmov2) & rtfilter; \
2051 rsB = mipsdsp_##func(rsB, rtB, env); \
2052 rsA = mipsdsp_##func(rsA, rtA, env); \
2054 return MIPSDSP_RETURN32_16(rsB, rsA); \
2057 MUL_RETURN32_16_PH(muleu_s_ph_qbl
, mul_u8_u16
, \
2058 24, 16, MIPSDSP_Q0
, \
2060 MUL_RETURN32_16_PH(muleu_s_ph_qbr
, mul_u8_u16
, \
2063 MUL_RETURN32_16_PH(mulq_rs_ph
, rndq15_mul_q15_q15
, \
2064 16, 0, MIPSDSP_LO
, \
2066 MUL_RETURN32_16_PH(mul_ph
, mul_i16_i16
, \
2067 16, 0, MIPSDSP_LO
, \
2069 MUL_RETURN32_16_PH(mul_s_ph
, sat16_mul_i16_i16
, \
2070 16, 0, MIPSDSP_LO
, \
2072 MUL_RETURN32_16_PH(mulq_s_ph
, sat16_mul_q15_q15
, \
2073 16, 0, MIPSDSP_LO
, \
2076 #undef MUL_RETURN32_16_PH
2078 #define MUL_RETURN32_32_ph(name, func, movbits) \
2079 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2080 CPUMIPSState *env) \
2085 rsh = (rs >> movbits) & MIPSDSP_LO; \
2086 rth = (rt >> movbits) & MIPSDSP_LO; \
2087 temp = mipsdsp_##func(rsh, rth, env); \
2089 return (target_long)(int32_t)temp; \
2092 MUL_RETURN32_32_ph(muleq_s_w_phl
, mul_q15_q15_overflowflag21
, 16);
2093 MUL_RETURN32_32_ph(muleq_s_w_phr
, mul_q15_q15_overflowflag21
, 0);
2095 #undef MUL_RETURN32_32_ph
2097 #define MUL_VOID_PH(name, use_ac_env) \
2098 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2099 CPUMIPSState *env) \
2101 int16_t rsh, rsl, rth, rtl; \
2102 int32_t tempB, tempA; \
2103 int64_t acc, dotp; \
2105 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
2106 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2108 if (use_ac_env == 1) { \
2109 tempB = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2110 tempA = mipsdsp_mul_q15_q15(ac, rsl, rtl, env); \
2112 tempB = mipsdsp_mul_u16_u16(rsh, rth); \
2113 tempA = mipsdsp_mul_u16_u16(rsl, rtl); \
2116 dotp = (int64_t)tempB - (int64_t)tempA; \
2117 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2118 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2119 dotp = dotp + acc; \
2120 env->active_tc.HI[ac] = (target_long)(int32_t) \
2121 ((dotp & MIPSDSP_LHI) >> 32); \
2122 env->active_tc.LO[ac] = (target_long)(int32_t)(dotp & MIPSDSP_LLO); \
2125 MUL_VOID_PH(mulsaq_s_w_ph
, 1);
2126 MUL_VOID_PH(mulsa_w_ph
, 0);
2130 #if defined(TARGET_MIPS64)
2131 #define MUL_RETURN64_16_QH(name, func, \
2132 rsmov1, rsmov2, rsmov3, rsmov4, rsfilter, \
2133 rtmov1, rtmov2, rtmov3, rtmov4, rtfilter) \
2134 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2135 CPUMIPSState *env) \
2137 uint16_t rs3, rs2, rs1, rs0; \
2138 uint16_t rt3, rt2, rt1, rt0; \
2139 uint16_t tempD, tempC, tempB, tempA; \
2141 rs3 = (rs >> rsmov1) & rsfilter; \
2142 rs2 = (rs >> rsmov2) & rsfilter; \
2143 rs1 = (rs >> rsmov3) & rsfilter; \
2144 rs0 = (rs >> rsmov4) & rsfilter; \
2145 rt3 = (rt >> rtmov1) & rtfilter; \
2146 rt2 = (rt >> rtmov2) & rtfilter; \
2147 rt1 = (rt >> rtmov3) & rtfilter; \
2148 rt0 = (rt >> rtmov4) & rtfilter; \
2150 tempD = mipsdsp_##func(rs3, rt3, env); \
2151 tempC = mipsdsp_##func(rs2, rt2, env); \
2152 tempB = mipsdsp_##func(rs1, rt1, env); \
2153 tempA = mipsdsp_##func(rs0, rt0, env); \
2155 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
2158 MUL_RETURN64_16_QH(muleu_s_qh_obl
, mul_u8_u16
, \
2159 56, 48, 40, 32, MIPSDSP_Q0
, \
2160 48, 32, 16, 0, MIPSDSP_LO
);
2161 MUL_RETURN64_16_QH(muleu_s_qh_obr
, mul_u8_u16
, \
2162 24, 16, 8, 0, MIPSDSP_Q0
, \
2163 48, 32, 16, 0, MIPSDSP_LO
);
2164 MUL_RETURN64_16_QH(mulq_rs_qh
, rndq15_mul_q15_q15
, \
2165 48, 32, 16, 0, MIPSDSP_LO
, \
2166 48, 32, 16, 0, MIPSDSP_LO
);
2168 #undef MUL_RETURN64_16_QH
2170 #define MUL_RETURN64_32_QH(name, \
2173 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2174 CPUMIPSState *env) \
2176 uint16_t rsB, rsA; \
2177 uint16_t rtB, rtA; \
2178 uint32_t tempB, tempA; \
2180 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2181 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2182 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2183 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2185 tempB = mipsdsp_mul_q15_q15(5, rsB, rtB, env); \
2186 tempA = mipsdsp_mul_q15_q15(5, rsA, rtA, env); \
2188 return ((uint64_t)tempB << 32) | (uint64_t)tempA; \
2191 MUL_RETURN64_32_QH(muleq_s_pw_qhl
, 48, 32, 48, 32);
2192 MUL_RETURN64_32_QH(muleq_s_pw_qhr
, 16, 0, 16, 0);
2194 #undef MUL_RETURN64_32_QH
2196 void helper_mulsaq_s_w_qh(target_ulong rs
, target_ulong rt
, uint32_t ac
,
2199 int16_t rs3
, rs2
, rs1
, rs0
;
2200 int16_t rt3
, rt2
, rt1
, rt0
;
2201 int32_t tempD
, tempC
, tempB
, tempA
;
2206 MIPSDSP_SPLIT64_16(rs
, rs3
, rs2
, rs1
, rs0
);
2207 MIPSDSP_SPLIT64_16(rt
, rt3
, rt2
, rt1
, rt0
);
2209 tempD
= mipsdsp_mul_q15_q15(ac
, rs3
, rt3
, env
);
2210 tempC
= mipsdsp_mul_q15_q15(ac
, rs2
, rt2
, env
);
2211 tempB
= mipsdsp_mul_q15_q15(ac
, rs1
, rt1
, env
);
2212 tempA
= mipsdsp_mul_q15_q15(ac
, rs0
, rt0
, env
);
2214 temp
[0] = ((int32_t)tempD
- (int32_t)tempC
) +
2215 ((int32_t)tempB
- (int32_t)tempA
);
2216 temp
[0] = (int64_t)(temp
[0] << 30) >> 30;
2217 if (((temp
[0] >> 33) & 0x01) == 0) {
2223 acc
[0] = env
->active_tc
.LO
[ac
];
2224 acc
[1] = env
->active_tc
.HI
[ac
];
2226 temp_sum
= acc
[0] + temp
[0];
2227 if (((uint64_t)temp_sum
< (uint64_t)acc
[0]) &&
2228 ((uint64_t)temp_sum
< (uint64_t)temp
[0])) {
2234 env
->active_tc
.HI
[ac
] = acc
[1];
2235 env
->active_tc
.LO
[ac
] = acc
[0];
2239 #define DP_QB(name, func, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2240 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2241 CPUMIPSState *env) \
2245 uint16_t tempB, tempA; \
2246 uint64_t tempC, dotp; \
2248 rs3 = (rs >> rsmov1) & MIPSDSP_Q0; \
2249 rs2 = (rs >> rsmov2) & MIPSDSP_Q0; \
2250 rt3 = (rt >> rtmov1) & MIPSDSP_Q0; \
2251 rt2 = (rt >> rtmov2) & MIPSDSP_Q0; \
2252 tempB = mipsdsp_##func(rs3, rt3); \
2253 tempA = mipsdsp_##func(rs2, rt2); \
2254 dotp = (int64_t)tempB + (int64_t)tempA; \
2256 tempC = (((uint64_t)env->active_tc.HI[ac] << 32) | \
2257 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO)) \
2260 tempC = (((uint64_t)env->active_tc.HI[ac] << 32) | \
2261 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO)) \
2265 env->active_tc.HI[ac] = (target_long)(int32_t) \
2266 ((tempC & MIPSDSP_LHI) >> 32); \
2267 env->active_tc.LO[ac] = (target_long)(int32_t)(tempC & MIPSDSP_LLO); \
2270 DP_QB(dpau_h_qbl
, mul_u8_u8
, 1, 24, 16, 24, 16);
2271 DP_QB(dpau_h_qbr
, mul_u8_u8
, 1, 8, 0, 8, 0);
2272 DP_QB(dpsu_h_qbl
, mul_u8_u8
, 0, 24, 16, 24, 16);
2273 DP_QB(dpsu_h_qbr
, mul_u8_u8
, 0, 8, 0, 8, 0);
2277 #if defined(TARGET_MIPS64)
2278 #define DP_OB(name, add_sub, \
2279 rsmov1, rsmov2, rsmov3, rsmov4, \
2280 rtmov1, rtmov2, rtmov3, rtmov4) \
2281 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2282 CPUMIPSState *env) \
2284 uint8_t rsD, rsC, rsB, rsA; \
2285 uint8_t rtD, rtC, rtB, rtA; \
2286 uint16_t tempD, tempC, tempB, tempA; \
2289 uint64_t temp_sum; \
2294 rsD = (rs >> rsmov1) & MIPSDSP_Q0; \
2295 rsC = (rs >> rsmov2) & MIPSDSP_Q0; \
2296 rsB = (rs >> rsmov3) & MIPSDSP_Q0; \
2297 rsA = (rs >> rsmov4) & MIPSDSP_Q0; \
2298 rtD = (rt >> rtmov1) & MIPSDSP_Q0; \
2299 rtC = (rt >> rtmov2) & MIPSDSP_Q0; \
2300 rtB = (rt >> rtmov3) & MIPSDSP_Q0; \
2301 rtA = (rt >> rtmov4) & MIPSDSP_Q0; \
2303 tempD = mipsdsp_mul_u8_u8(rsD, rtD); \
2304 tempC = mipsdsp_mul_u8_u8(rsC, rtC); \
2305 tempB = mipsdsp_mul_u8_u8(rsB, rtB); \
2306 tempA = mipsdsp_mul_u8_u8(rsA, rtA); \
2308 temp[0] = (uint64_t)tempD + (uint64_t)tempC + \
2309 (uint64_t)tempB + (uint64_t)tempA; \
2311 acc[0] = env->active_tc.LO[ac]; \
2312 acc[1] = env->active_tc.HI[ac]; \
2315 temp_sum = acc[0] + temp[0]; \
2316 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2317 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2320 temp[0] = temp_sum; \
2321 temp[1] = acc[1] + temp[1]; \
2323 temp_sum = acc[0] - temp[0]; \
2324 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2327 temp[0] = temp_sum; \
2328 temp[1] = acc[1] - temp[1]; \
2331 env->active_tc.HI[ac] = temp[1]; \
2332 env->active_tc.LO[ac] = temp[0]; \
2335 DP_OB(dpau_h_obl
, 1, 56, 48, 40, 32, 56, 48, 40, 32);
2336 DP_OB(dpau_h_obr
, 1, 24, 16, 8, 0, 24, 16, 8, 0);
2337 DP_OB(dpsu_h_obl
, 0, 56, 48, 40, 32, 56, 48, 40, 32);
2338 DP_OB(dpsu_h_obr
, 0, 24, 16, 8, 0, 24, 16, 8, 0);
2343 #define DP_NOFUNC_PH(name, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2344 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2345 CPUMIPSState *env) \
2347 int16_t rsB, rsA, rtB, rtA; \
2348 int32_t tempA, tempB; \
2351 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2352 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2353 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2354 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2356 tempB = (int32_t)rsB * (int32_t)rtB; \
2357 tempA = (int32_t)rsA * (int32_t)rtA; \
2359 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2360 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2363 acc = acc + ((int64_t)tempB + (int64_t)tempA); \
2365 acc = acc - ((int64_t)tempB + (int64_t)tempA); \
2368 env->active_tc.HI[ac] = (target_long)(int32_t)((acc & MIPSDSP_LHI) >> 32); \
2369 env->active_tc.LO[ac] = (target_long)(int32_t)(acc & MIPSDSP_LLO); \
2372 DP_NOFUNC_PH(dpa_w_ph
, 1, 16, 0, 16, 0);
2373 DP_NOFUNC_PH(dpax_w_ph
, 1, 16, 0, 0, 16);
2374 DP_NOFUNC_PH(dps_w_ph
, 0, 16, 0, 16, 0);
2375 DP_NOFUNC_PH(dpsx_w_ph
, 0, 16, 0, 0, 16);
2378 #define DP_HASFUNC_PH(name, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2379 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2380 CPUMIPSState *env) \
2382 int16_t rsB, rsA, rtB, rtA; \
2383 int32_t tempB, tempA; \
2384 int64_t acc, dotp; \
2386 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2387 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2388 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2389 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2391 tempB = mipsdsp_mul_q15_q15(ac, rsB, rtB, env); \
2392 tempA = mipsdsp_mul_q15_q15(ac, rsA, rtA, env); \
2394 dotp = (int64_t)tempB + (int64_t)tempA; \
2395 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2396 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2404 env->active_tc.HI[ac] = (target_long)(int32_t) \
2405 ((acc & MIPSDSP_LHI) >> 32); \
2406 env->active_tc.LO[ac] = (target_long)(int32_t) \
2407 (acc & MIPSDSP_LLO); \
2410 DP_HASFUNC_PH(dpaq_s_w_ph
, 1, 16, 0, 16, 0);
2411 DP_HASFUNC_PH(dpaqx_s_w_ph
, 1, 16, 0, 0, 16);
2412 DP_HASFUNC_PH(dpsq_s_w_ph
, 0, 16, 0, 16, 0);
2413 DP_HASFUNC_PH(dpsqx_s_w_ph
, 0, 16, 0, 0, 16);
2415 #undef DP_HASFUNC_PH
2417 #define DP_128OPERATION_PH(name, is_add) \
2418 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2419 CPUMIPSState *env) \
2421 int16_t rsh, rsl, rth, rtl; \
2422 int32_t tempB, tempA, tempC62_31, tempC63; \
2423 int64_t acc, dotp, tempC; \
2425 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
2426 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2428 tempB = mipsdsp_mul_q15_q15(ac, rsh, rtl, env); \
2429 tempA = mipsdsp_mul_q15_q15(ac, rsl, rth, env); \
2431 dotp = (int64_t)tempB + (int64_t)tempA; \
2432 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2433 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2435 tempC = acc + dotp; \
2437 tempC = acc - dotp; \
2439 tempC63 = (tempC >> 63) & 0x01; \
2440 tempC62_31 = (tempC >> 31) & 0xFFFFFFFF; \
2442 if ((tempC63 == 0) && (tempC62_31 != 0x00000000)) { \
2443 tempC = 0x7FFFFFFF; \
2444 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2447 if ((tempC63 == 1) && (tempC62_31 != 0xFFFFFFFF)) { \
2448 tempC = (int64_t)(int32_t)0x80000000; \
2449 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2452 env->active_tc.HI[ac] = (target_long)(int32_t) \
2453 ((tempC & MIPSDSP_LHI) >> 32); \
2454 env->active_tc.LO[ac] = (target_long)(int32_t) \
2455 (tempC & MIPSDSP_LLO); \
2458 DP_128OPERATION_PH(dpaqx_sa_w_ph
, 1);
2459 DP_128OPERATION_PH(dpsqx_sa_w_ph
, 0);
2461 #undef DP_128OPERATION_HP
2463 #if defined(TARGET_MIPS64)
2464 #define DP_QH(name, is_add, use_ac_env) \
2465 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2466 CPUMIPSState *env) \
2468 int32_t rs3, rs2, rs1, rs0; \
2469 int32_t rt3, rt2, rt1, rt0; \
2470 int32_t tempD, tempC, tempB, tempA; \
2475 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
2476 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
2479 tempD = mipsdsp_mul_q15_q15(ac, rs3, rt3, env); \
2480 tempC = mipsdsp_mul_q15_q15(ac, rs2, rt2, env); \
2481 tempB = mipsdsp_mul_q15_q15(ac, rs1, rt1, env); \
2482 tempA = mipsdsp_mul_q15_q15(ac, rs0, rt0, env); \
2484 tempD = mipsdsp_mul_u16_u16(rs3, rt3); \
2485 tempC = mipsdsp_mul_u16_u16(rs2, rt2); \
2486 tempB = mipsdsp_mul_u16_u16(rs1, rt1); \
2487 tempA = mipsdsp_mul_u16_u16(rs0, rt0); \
2490 temp[0] = (int64_t)tempD + (int64_t)tempC + \
2491 (int64_t)tempB + (int64_t)tempA; \
2493 if (temp[0] >= 0) { \
2499 acc[1] = env->active_tc.HI[ac]; \
2500 acc[0] = env->active_tc.LO[ac]; \
2503 temp_sum = acc[0] + temp[0]; \
2504 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2505 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2506 acc[1] = acc[1] + 1; \
2508 temp[0] = temp_sum; \
2509 temp[1] = acc[1] + temp[1]; \
2511 temp_sum = acc[0] - temp[0]; \
2512 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2513 acc[1] = acc[1] - 1; \
2515 temp[0] = temp_sum; \
2516 temp[1] = acc[1] - temp[1]; \
2519 env->active_tc.HI[ac] = temp[1]; \
2520 env->active_tc.LO[ac] = temp[0]; \
2523 DP_QH(dpa_w_qh
, 1, 0);
2524 DP_QH(dpaq_s_w_qh
, 1, 1);
2525 DP_QH(dps_w_qh
, 0, 0);
2526 DP_QH(dpsq_s_w_qh
, 0, 1);
2532 #define DP_L_W(name, is_add) \
2533 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2534 CPUMIPSState *env) \
2537 int64_t dotp, acc; \
2540 dotp = mipsdsp_mul_q31_q31(ac, rs, rt, env); \
2541 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2542 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2547 temp = acc + dotp; \
2548 if (MIPSDSP_OVERFLOW((uint64_t)acc, (uint64_t)dotp, temp, \
2549 (0x01ull << 63))) { \
2550 temp63 = (temp >> 63) & 0x01; \
2551 if (temp63 == 1) { \
2552 temp = (0x01ull << 63) - 1; \
2554 temp = 0x01ull << 63; \
2557 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2560 env->active_tc.HI[ac] = (target_long)(int32_t) \
2561 ((temp & MIPSDSP_LHI) >> 32); \
2562 env->active_tc.LO[ac] = (target_long)(int32_t) \
2563 (temp & MIPSDSP_LLO); \
2566 DP_L_W(dpaq_sa_l_w
, 1);
2567 DP_L_W(dpsq_sa_l_w
, 0);
2571 #if defined(TARGET_MIPS64)
2572 #define DP_L_PW(name, func) \
2573 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2574 CPUMIPSState *env) \
2578 int64_t tempB[2], tempA[2]; \
2586 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
2587 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2589 tempB[0] = mipsdsp_mul_q31_q31(ac, rs1, rt1, env); \
2590 tempA[0] = mipsdsp_mul_q31_q31(ac, rs0, rt0, env); \
2592 if (tempB[0] >= 0) { \
2598 if (tempA[0] >= 0) { \
2604 temp_sum = tempB[0] + tempA[0]; \
2605 if (((uint64_t)temp_sum < (uint64_t)tempB[0]) && \
2606 ((uint64_t)temp_sum < (uint64_t)tempA[0])) { \
2609 temp[0] = temp_sum; \
2610 temp[1] += tempB[1] + tempA[1]; \
2612 mipsdsp_##func(acc, ac, temp, env); \
2614 env->active_tc.HI[ac] = acc[1]; \
2615 env->active_tc.LO[ac] = acc[0]; \
2618 DP_L_PW(dpaq_sa_l_pw
, sat64_acc_add_q63
);
2619 DP_L_PW(dpsq_sa_l_pw
, sat64_acc_sub_q63
);
2623 void helper_mulsaq_s_l_pw(target_ulong rs
, target_ulong rt
, uint32_t ac
,
2628 int64_t tempB
[2], tempA
[2];
2633 rs1
= (rs
>> 32) & MIPSDSP_LLO
;
2634 rs0
= rs
& MIPSDSP_LLO
;
2635 rt1
= (rt
>> 32) & MIPSDSP_LLO
;
2636 rt0
= rt
& MIPSDSP_LLO
;
2638 tempB
[0] = mipsdsp_mul_q31_q31(ac
, rs1
, rt1
, env
);
2639 tempA
[0] = mipsdsp_mul_q31_q31(ac
, rs0
, rt0
, env
);
2641 if (tempB
[0] >= 0) {
2647 if (tempA
[0] >= 0) {
2653 acc
[0] = env
->active_tc
.LO
[ac
];
2654 acc
[1] = env
->active_tc
.HI
[ac
];
2656 temp_sum
= tempB
[0] - tempA
[0];
2657 if ((uint64_t)temp_sum
> (uint64_t)tempB
[0]) {
2661 temp
[1] = tempB
[1] - tempA
[1];
2663 if ((temp
[1] & 0x01) == 0) {
2669 temp_sum
= acc
[0] + temp
[0];
2670 if (((uint64_t)temp_sum
< (uint64_t)acc
[0]) &&
2671 ((uint64_t)temp_sum
< (uint64_t)temp
[0])) {
2677 env
->active_tc
.HI
[ac
] = acc
[1];
2678 env
->active_tc
.LO
[ac
] = acc
[0];
2682 #define MAQ_S_W(name, mov) \
2683 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2684 CPUMIPSState *env) \
2688 int64_t tempL, acc; \
2690 rsh = (rs >> mov) & MIPSDSP_LO; \
2691 rth = (rt >> mov) & MIPSDSP_LO; \
2692 tempA = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2693 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2694 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2695 tempL = (int64_t)tempA + acc; \
2696 env->active_tc.HI[ac] = (target_long)(int32_t) \
2697 ((tempL & MIPSDSP_LHI) >> 32); \
2698 env->active_tc.LO[ac] = (target_long)(int32_t) \
2699 (tempL & MIPSDSP_LLO); \
2702 MAQ_S_W(maq_s_w_phl
, 16);
2703 MAQ_S_W(maq_s_w_phr
, 0);
2707 #define MAQ_SA_W(name, mov) \
2708 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2709 CPUMIPSState *env) \
2714 rsh = (rs >> mov) & MIPSDSP_LO; \
2715 rth = (rt >> mov) & MIPSDSP_LO; \
2716 tempA = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2717 tempA = mipsdsp_sat32_acc_q31(ac, tempA, env); \
2719 env->active_tc.HI[ac] = (target_long)(int32_t)(((int64_t)tempA & \
2720 MIPSDSP_LHI) >> 32); \
2721 env->active_tc.LO[ac] = (target_long)(int32_t)((int64_t)tempA & \
2725 MAQ_SA_W(maq_sa_w_phl
, 16);
2726 MAQ_SA_W(maq_sa_w_phr
, 0);
2730 #define MULQ_W(name, addvar) \
2731 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2732 CPUMIPSState *env) \
2734 uint32_t rs_t, rt_t; \
2738 rs_t = rs & MIPSDSP_LLO; \
2739 rt_t = rt & MIPSDSP_LLO; \
2741 if ((rs_t == 0x80000000) && (rt_t == 0x80000000)) { \
2742 tempL = 0x7FFFFFFF00000000ull; \
2743 set_DSPControl_overflow_flag(1, 21, env); \
2745 tempL = ((int64_t)rs_t * (int64_t)rt_t) << 1; \
2748 tempI = (tempL & MIPSDSP_LHI) >> 32; \
2750 return (target_long)(int32_t)tempI; \
2753 MULQ_W(mulq_s_w
, 0);
2754 MULQ_W(mulq_rs_w
, 0x80000000ull
);
2758 #if defined(TARGET_MIPS64)
2760 #define MAQ_S_W_QH(name, mov) \
2761 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2762 CPUMIPSState *env) \
2764 int16_t rs_t, rt_t; \
2773 rs_t = (rs >> mov) & MIPSDSP_LO; \
2774 rt_t = (rt >> mov) & MIPSDSP_LO; \
2775 temp_mul = mipsdsp_mul_q15_q15(ac, rs_t, rt_t, env); \
2777 temp[0] = (int64_t)temp_mul; \
2778 if (temp[0] >= 0) { \
2784 acc[0] = env->active_tc.LO[ac]; \
2785 acc[1] = env->active_tc.HI[ac]; \
2787 temp_sum = acc[0] + temp[0]; \
2788 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2789 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2792 acc[0] = temp_sum; \
2793 acc[1] += temp[1]; \
2795 env->active_tc.HI[ac] = acc[1]; \
2796 env->active_tc.LO[ac] = acc[0]; \
2799 MAQ_S_W_QH(maq_s_w_qhll
, 48);
2800 MAQ_S_W_QH(maq_s_w_qhlr
, 32);
2801 MAQ_S_W_QH(maq_s_w_qhrl
, 16);
2802 MAQ_S_W_QH(maq_s_w_qhrr
, 0);
2806 #define MAQ_SA_W(name, mov) \
2807 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2808 CPUMIPSState *env) \
2810 int16_t rs_t, rt_t; \
2814 rs_t = (rs >> mov) & MIPSDSP_LO; \
2815 rt_t = (rt >> mov) & MIPSDSP_LO; \
2816 temp = mipsdsp_mul_q15_q15(ac, rs_t, rt_t, env); \
2817 temp = mipsdsp_sat32_acc_q31(ac, temp, env); \
2819 acc[0] = (int64_t)(int32_t)temp; \
2820 if (acc[0] >= 0) { \
2826 env->active_tc.HI[ac] = acc[1]; \
2827 env->active_tc.LO[ac] = acc[0]; \
2830 MAQ_SA_W(maq_sa_w_qhll
, 48);
2831 MAQ_SA_W(maq_sa_w_qhlr
, 32);
2832 MAQ_SA_W(maq_sa_w_qhrl
, 16);
2833 MAQ_SA_W(maq_sa_w_qhrr
, 0);
2837 #define MAQ_S_L_PW(name, mov) \
2838 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2839 CPUMIPSState *env) \
2841 int32_t rs_t, rt_t; \
2849 rs_t = (rs >> mov) & MIPSDSP_LLO; \
2850 rt_t = (rt >> mov) & MIPSDSP_LLO; \
2852 temp[0] = mipsdsp_mul_q31_q31(ac, rs_t, rt_t, env); \
2853 if (temp[0] >= 0) { \
2859 acc[0] = env->active_tc.LO[ac]; \
2860 acc[1] = env->active_tc.HI[ac]; \
2862 temp_sum = acc[0] + temp[0]; \
2863 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2864 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2867 acc[0] = temp_sum; \
2868 acc[1] += temp[1]; \
2870 env->active_tc.HI[ac] = acc[1]; \
2871 env->active_tc.LO[ac] = acc[0]; \
2874 MAQ_S_L_PW(maq_s_l_pwl
, 32);
2875 MAQ_S_L_PW(maq_s_l_pwr
, 0);
2879 #define DM_OPERATE(name, func, is_add, sigext) \
2880 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2881 CPUMIPSState *env) \
2885 int64_t tempBL[2], tempAL[2]; \
2893 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
2894 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2897 tempBL[0] = (int64_t)mipsdsp_##func(rs1, rt1); \
2898 tempAL[0] = (int64_t)mipsdsp_##func(rs0, rt0); \
2900 if (tempBL[0] >= 0) { \
2903 tempBL[1] = ~0ull; \
2906 if (tempAL[0] >= 0) { \
2909 tempAL[1] = ~0ull; \
2912 tempBL[0] = mipsdsp_##func(rs1, rt1); \
2913 tempAL[0] = mipsdsp_##func(rs0, rt0); \
2918 acc[1] = env->active_tc.HI[ac]; \
2919 acc[0] = env->active_tc.LO[ac]; \
2921 temp_sum = tempBL[0] + tempAL[0]; \
2922 if (((uint64_t)temp_sum < (uint64_t)tempBL[0]) && \
2923 ((uint64_t)temp_sum < (uint64_t)tempAL[0])) { \
2926 temp[0] = temp_sum; \
2927 temp[1] += tempBL[1] + tempAL[1]; \
2930 temp_sum = acc[0] + temp[0]; \
2931 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2932 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2935 temp[0] = temp_sum; \
2936 temp[1] = acc[1] + temp[1]; \
2938 temp_sum = acc[0] - temp[0]; \
2939 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2942 temp[0] = temp_sum; \
2943 temp[1] = acc[1] - temp[1]; \
2946 env->active_tc.HI[ac] = temp[1]; \
2947 env->active_tc.LO[ac] = temp[0]; \
2950 DM_OPERATE(dmadd
, mul_i32_i32
, 1, 1);
2951 DM_OPERATE(dmaddu
, mul_u32_u32
, 1, 0);
2952 DM_OPERATE(dmsub
, mul_i32_i32
, 0, 1);
2953 DM_OPERATE(dmsubu
, mul_u32_u32
, 0, 0);
2957 /** DSP Bit/Manipulation Sub-class insns **/
2958 target_ulong
helper_bitrev(target_ulong rt
)
2964 temp
= rt
& MIPSDSP_LO
;
2966 for (i
= 0; i
< 16; i
++) {
2967 rd
= (rd
<< 1) | (temp
& 1);
2971 return (target_ulong
)rd
;
2974 #define BIT_INSV(name, posfilter, sizefilter, ret_type) \
2975 target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \
2978 uint32_t pos, size, msb, lsb; \
2979 target_ulong filter; \
2980 target_ulong temp, temprs, temprt; \
2981 target_ulong dspc; \
2983 dspc = env->active_tc.DSPControl; \
2985 pos = dspc & posfilter; \
2986 size = (dspc >> 7) & sizefilter; \
2988 msb = pos + size - 1; \
2991 if (lsb > msb || (msb > TARGET_LONG_BITS)) { \
2995 filter = ((int32_t)0x01 << size) - 1; \
2996 filter = filter << pos; \
2997 temprs = (rs << pos) & filter; \
2998 temprt = rt & ~filter; \
2999 temp = temprs | temprt; \
3001 return (target_long)(ret_type)temp; \
3004 BIT_INSV(insv
, 0x1F, 0x1F, int32_t);
3005 #ifdef TARGET_MIPS64
3006 BIT_INSV(dinsv
, 0x7F, 0x3F, target_long
);
3012 /** DSP Compare-Pick Sub-class insns **/
3013 #define CMP_HAS_RET(name, func, split_num, filter, bit_size) \
3014 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
3016 uint32_t rs_t, rt_t; \
3018 uint32_t temp = 0; \
3021 for (i = 0; i < split_num; i++) { \
3022 rs_t = (rs >> (bit_size * i)) & filter; \
3023 rt_t = (rt >> (bit_size * i)) & filter; \
3024 cc = mipsdsp_##func(rs_t, rt_t); \
3028 return (target_ulong)temp; \
3031 CMP_HAS_RET(cmpgu_eq_qb
, cmpu_eq
, 4, MIPSDSP_Q0
, 8);
3032 CMP_HAS_RET(cmpgu_lt_qb
, cmpu_lt
, 4, MIPSDSP_Q0
, 8);
3033 CMP_HAS_RET(cmpgu_le_qb
, cmpu_le
, 4, MIPSDSP_Q0
, 8);
3035 #ifdef TARGET_MIPS64
3036 CMP_HAS_RET(cmpgu_eq_ob
, cmpu_eq
, 8, MIPSDSP_Q0
, 8);
3037 CMP_HAS_RET(cmpgu_lt_ob
, cmpu_lt
, 8, MIPSDSP_Q0
, 8);
3038 CMP_HAS_RET(cmpgu_le_ob
, cmpu_le
, 8, MIPSDSP_Q0
, 8);
3044 #define CMP_NO_RET(name, func, split_num, filter, bit_size) \
3045 void helper_##name(target_ulong rs, target_ulong rt, \
3046 CPUMIPSState *env) \
3048 int##bit_size##_t rs_t, rt_t; \
3049 int##bit_size##_t flag = 0; \
3050 int##bit_size##_t cc; \
3053 for (i = 0; i < split_num; i++) { \
3054 rs_t = (rs >> (bit_size * i)) & filter; \
3055 rt_t = (rt >> (bit_size * i)) & filter; \
3057 cc = mipsdsp_##func((int32_t)rs_t, (int32_t)rt_t); \
3061 set_DSPControl_24(flag, split_num, env); \
3064 CMP_NO_RET(cmpu_eq_qb
, cmpu_eq
, 4, MIPSDSP_Q0
, 8);
3065 CMP_NO_RET(cmpu_lt_qb
, cmpu_lt
, 4, MIPSDSP_Q0
, 8);
3066 CMP_NO_RET(cmpu_le_qb
, cmpu_le
, 4, MIPSDSP_Q0
, 8);
3068 CMP_NO_RET(cmp_eq_ph
, cmp_eq
, 2, MIPSDSP_LO
, 16);
3069 CMP_NO_RET(cmp_lt_ph
, cmp_lt
, 2, MIPSDSP_LO
, 16);
3070 CMP_NO_RET(cmp_le_ph
, cmp_le
, 2, MIPSDSP_LO
, 16);
3072 #ifdef TARGET_MIPS64
3073 CMP_NO_RET(cmpu_eq_ob
, cmpu_eq
, 8, MIPSDSP_Q0
, 8);
3074 CMP_NO_RET(cmpu_lt_ob
, cmpu_lt
, 8, MIPSDSP_Q0
, 8);
3075 CMP_NO_RET(cmpu_le_ob
, cmpu_le
, 8, MIPSDSP_Q0
, 8);
3077 CMP_NO_RET(cmp_eq_qh
, cmp_eq
, 4, MIPSDSP_LO
, 16);
3078 CMP_NO_RET(cmp_lt_qh
, cmp_lt
, 4, MIPSDSP_LO
, 16);
3079 CMP_NO_RET(cmp_le_qh
, cmp_le
, 4, MIPSDSP_LO
, 16);
3081 CMP_NO_RET(cmp_eq_pw
, cmp_eq
, 2, MIPSDSP_LLO
, 32);
3082 CMP_NO_RET(cmp_lt_pw
, cmp_lt
, 2, MIPSDSP_LLO
, 32);
3083 CMP_NO_RET(cmp_le_pw
, cmp_le
, 2, MIPSDSP_LLO
, 32);
3087 #if defined(TARGET_MIPS64)
3089 #define CMPGDU_OB(name) \
3090 target_ulong helper_cmpgdu_##name##_ob(target_ulong rs, target_ulong rt, \
3091 CPUMIPSState *env) \
3094 uint8_t rs_t, rt_t; \
3099 for (i = 0; i < 8; i++) { \
3100 rs_t = (rs >> (8 * i)) & MIPSDSP_Q0; \
3101 rt_t = (rt >> (8 * i)) & MIPSDSP_Q0; \
3103 if (mipsdsp_cmpu_##name(rs_t, rt_t)) { \
3104 cond |= 0x01 << i; \
3108 set_DSPControl_24(cond, 8, env); \
3110 return (uint64_t)cond; \
3119 #define PICK_INSN(name, split_num, filter, bit_size, ret32bit) \
3120 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
3121 CPUMIPSState *env) \
3123 uint32_t rs_t, rt_t; \
3127 target_ulong result = 0; \
3129 dsp = env->active_tc.DSPControl; \
3130 for (i = 0; i < split_num; i++) { \
3131 rs_t = (rs >> (bit_size * i)) & filter; \
3132 rt_t = (rt >> (bit_size * i)) & filter; \
3133 cc = (dsp >> (24 + i)) & 0x01; \
3134 cc = cc == 1 ? rs_t : rt_t; \
3136 result |= (target_ulong)cc << (bit_size * i); \
3140 result = (target_long)(int32_t)(result & MIPSDSP_LLO); \
3146 PICK_INSN(pick_qb
, 4, MIPSDSP_Q0
, 8, 1);
3147 PICK_INSN(pick_ph
, 2, MIPSDSP_LO
, 16, 1);
3149 #ifdef TARGET_MIPS64
3150 PICK_INSN(pick_ob
, 8, MIPSDSP_Q0
, 8, 0);
3151 PICK_INSN(pick_qh
, 4, MIPSDSP_LO
, 16, 0);
3152 PICK_INSN(pick_pw
, 2, MIPSDSP_LLO
, 32, 0);
3156 #define APPEND_INSN(name, ret_32) \
3157 target_ulong helper_##name(target_ulong rt, target_ulong rs, uint32_t sa) \
3159 target_ulong temp; \
3162 temp = ((rt & MIPSDSP_LLO) << sa) | \
3163 ((rs & MIPSDSP_LLO) & ((0x01 << sa) - 1)); \
3164 temp = (target_long)(int32_t)(temp & MIPSDSP_LLO); \
3166 temp = (rt << sa) | (rs & ((0x01 << sa) - 1)); \
3172 APPEND_INSN(append
, 1);
3173 #ifdef TARGET_MIPS64
3174 APPEND_INSN(dappend
, 0);
3178 #define PREPEND_INSN(name, or_val, ret_32) \
3179 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
3185 return (target_long)(int32_t)(uint32_t) \
3186 (((rs & MIPSDSP_LLO) << (32 - sa)) | \
3187 ((rt & MIPSDSP_LLO) >> sa)); \
3189 return (rs << (64 - sa)) | (rt >> sa); \
3193 PREPEND_INSN(prepend
, 0, 1);
3194 #ifdef TARGET_MIPS64
3195 PREPEND_INSN(prependw
, 0, 0);
3196 PREPEND_INSN(prependd
, 0x20, 0);
3200 #define BALIGN_INSN(name, filter, ret32) \
3201 target_ulong helper_##name(target_ulong rs, target_ulong rt, uint32_t bp) \
3205 if ((bp & 1) == 0) { \
3209 return (target_long)(int32_t)((rt << (8 * bp)) | \
3210 (rs >> (8 * (4 - bp)))); \
3212 return (rt << (8 * bp)) | (rs >> (8 * (8 - bp))); \
3217 BALIGN_INSN(balign
, 0x03, 1);
3218 #if defined(TARGET_MIPS64)
3219 BALIGN_INSN(dbalign
, 0x07, 0);
3223 target_ulong
helper_packrl_ph(target_ulong rs
, target_ulong rt
)
3227 rsl
= rs
& MIPSDSP_LO
;
3228 rth
= (rt
& MIPSDSP_HI
) >> 16;
3230 return (target_long
)(int32_t)((rsl
<< 16) | rth
);
3233 #if defined(TARGET_MIPS64)
3234 target_ulong
helper_packrl_pw(target_ulong rs
, target_ulong rt
)
3238 rs0
= rs
& MIPSDSP_LLO
;
3239 rt1
= (rt
>> 32) & MIPSDSP_LLO
;
3241 return ((uint64_t)rs0
<< 32) | (uint64_t)rt1
;
3245 /** DSP Accumulator and DSPControl Access Sub-class insns **/
3246 target_ulong
helper_extr_w(target_ulong ac
, target_ulong shift
,
3252 shift
= shift
& 0x1F;
3254 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3255 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3256 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3257 set_DSPControl_overflow_flag(1, 23, env
);
3260 tempI
= (tempDL
[0] >> 1) & MIPSDSP_LLO
;
3263 if (tempDL
[0] == 0) {
3267 if ((!(tempDL
[1] == 0 && (tempDL
[0] & MIPSDSP_LHI
) == 0x00)) &&
3268 (!(tempDL
[1] == 1 && (tempDL
[0] & MIPSDSP_LHI
) == MIPSDSP_LHI
))) {
3269 set_DSPControl_overflow_flag(1, 23, env
);
3272 return (target_long
)tempI
;
3275 target_ulong
helper_extr_r_w(target_ulong ac
, target_ulong shift
,
3280 shift
= shift
& 0x1F;
3282 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3283 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3284 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3285 set_DSPControl_overflow_flag(1, 23, env
);
3289 if (tempDL
[0] == 0) {
3293 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3294 (tempDL
[1] != 1 && (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3295 set_DSPControl_overflow_flag(1, 23, env
);
3298 return (target_long
)(int32_t)(tempDL
[0] >> 1);
3301 target_ulong
helper_extr_rs_w(target_ulong ac
, target_ulong shift
,
3304 int32_t tempI
, temp64
;
3307 shift
= shift
& 0x1F;
3309 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3310 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3311 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3312 set_DSPControl_overflow_flag(1, 23, env
);
3315 if (tempDL
[0] == 0) {
3318 tempI
= tempDL
[0] >> 1;
3320 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3321 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3328 set_DSPControl_overflow_flag(1, 23, env
);
3331 return (target_long
)tempI
;
3334 #if defined(TARGET_MIPS64)
3335 target_ulong
helper_dextr_w(target_ulong ac
, target_ulong shift
,
3340 shift
= shift
& 0x3F;
3342 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3344 return (int64_t)(int32_t)(temp
[0] >> 1);
3347 target_ulong
helper_dextr_r_w(target_ulong ac
, target_ulong shift
,
3353 shift
= shift
& 0x3F;
3354 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3364 temp128
= temp
[2] & 0x01;
3366 if ((temp128
!= 0 || temp
[1] != 0) &&
3367 (temp128
!= 1 || temp
[1] != ~0ull)) {
3368 set_DSPControl_overflow_flag(1, 23, env
);
3371 return (int64_t)(int32_t)(temp
[0] >> 1);
3374 target_ulong
helper_dextr_rs_w(target_ulong ac
, target_ulong shift
,
3380 shift
= shift
& 0x3F;
3381 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3391 temp128
= temp
[2] & 0x01;
3393 if ((temp128
!= 0 || temp
[1] != 0) &&
3394 (temp128
!= 1 || temp
[1] != ~0ull)) {
3396 temp
[0] = 0x0FFFFFFFF;
3398 temp
[0] = 0x0100000000ULL
;
3400 set_DSPControl_overflow_flag(1, 23, env
);
3403 return (int64_t)(int32_t)(temp
[0] >> 1);
3406 target_ulong
helper_dextr_l(target_ulong ac
, target_ulong shift
,
3410 target_ulong result
;
3412 shift
= shift
& 0x3F;
3414 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3415 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3420 target_ulong
helper_dextr_r_l(target_ulong ac
, target_ulong shift
,
3425 target_ulong result
;
3427 shift
= shift
& 0x3F;
3428 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3438 temp128
= temp
[2] & 0x01;
3440 if ((temp128
!= 0 || temp
[1] != 0) &&
3441 (temp128
!= 1 || temp
[1] != ~0ull)) {
3442 set_DSPControl_overflow_flag(1, 23, env
);
3445 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3450 target_ulong
helper_dextr_rs_l(target_ulong ac
, target_ulong shift
,
3455 target_ulong result
;
3457 shift
= shift
& 0x3F;
3458 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3468 temp128
= temp
[2] & 0x01;
3470 if ((temp128
!= 0 || temp
[1] != 0) &&
3471 (temp128
!= 1 || temp
[1] != ~0ull)) {
3473 temp
[1] &= ~0x00ull
- 1;
3474 temp
[0] |= ~0x00ull
- 1;
3479 set_DSPControl_overflow_flag(1, 23, env
);
3481 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3487 target_ulong
helper_extr_s_h(target_ulong ac
, target_ulong shift
,
3492 shift
= shift
& 0x1F;
3494 acc
= ((int64_t)env
->active_tc
.HI
[ac
] << 32) |
3495 ((int64_t)env
->active_tc
.LO
[ac
] & 0xFFFFFFFF);
3497 temp
= acc
>> shift
;
3499 if (temp
> (int64_t)0x7FFF) {
3501 set_DSPControl_overflow_flag(1, 23, env
);
3502 } else if (temp
< (int64_t)0xFFFFFFFFFFFF8000ULL
) {
3504 set_DSPControl_overflow_flag(1, 23, env
);
3507 return (target_long
)(int32_t)(temp
& 0xFFFFFFFF);
3511 #if defined(TARGET_MIPS64)
3512 target_ulong
helper_dextr_s_h(target_ulong ac
, target_ulong shift
,
3518 shift
= shift
& 0x1F;
3520 mipsdsp_rashift_acc((uint64_t *)temp
, ac
, shift
, env
);
3522 temp127
= (temp
[1] >> 63) & 0x01;
3524 if ((temp127
== 0) && (temp
[1] > 0 || temp
[0] > 32767)) {
3525 temp
[0] &= 0xFFFF0000;
3526 temp
[0] |= 0x00007FFF;
3527 set_DSPControl_overflow_flag(1, 23, env
);
3528 } else if ((temp127
== 1) &&
3529 (temp
[1] < 0xFFFFFFFFFFFFFFFFll
3530 || temp
[0] < 0xFFFFFFFFFFFF1000ll
)) {
3531 temp
[0] &= 0xFFFF0000;
3532 temp
[0] |= 0x00008000;
3533 set_DSPControl_overflow_flag(1, 23, env
);
3536 return (int64_t)(int16_t)(temp
[0] & MIPSDSP_LO
);
3541 target_ulong
helper_extp(target_ulong ac
, target_ulong size
, CPUMIPSState
*env
)
3551 start_pos
= get_DSPControl_pos(env
);
3552 sub
= start_pos
- (size
+ 1);
3554 acc
= ((uint64_t)env
->active_tc
.HI
[ac
] << 32) |
3555 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3556 temp
= (acc
>> (start_pos
- size
)) &
3557 (((uint32_t)0x01 << (size
+ 1)) - 1);
3558 set_DSPControl_efi(0, env
);
3560 set_DSPControl_efi(1, env
);
3563 return (target_ulong
)temp
;
3566 target_ulong
helper_extpdp(target_ulong ac
, target_ulong size
,
3576 start_pos
= get_DSPControl_pos(env
);
3577 sub
= start_pos
- (size
+ 1);
3579 acc
= ((uint64_t)env
->active_tc
.HI
[ac
] << 32) |
3580 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3581 temp
= (acc
>> (start_pos
- size
)) &
3582 (((uint32_t)0x01 << (size
+ 1)) - 1);
3584 set_DSPControl_pos(start_pos
- (size
+ 1), env
);
3585 set_DSPControl_efi(0, env
);
3587 set_DSPControl_efi(1, env
);
3590 return (target_ulong
)temp
;
3594 #if defined(TARGET_MIPS64)
3595 target_ulong
helper_dextp(target_ulong ac
, target_ulong size
, CPUMIPSState
*env
)
3600 uint64_t tempB
, tempA
;
3606 start_pos
= get_DSPControl_pos(env
);
3607 len
= start_pos
- size
;
3608 tempB
= env
->active_tc
.HI
[ac
];
3609 tempA
= env
->active_tc
.LO
[ac
];
3611 sub
= start_pos
- (size
+ 1);
3614 temp
= (tempB
<< (64 - len
)) | (tempA
>> len
);
3615 temp
= temp
& ((0x01 << (size
+ 1)) - 1);
3616 set_DSPControl_efi(0, env
);
3618 set_DSPControl_efi(1, env
);
3624 target_ulong
helper_dextpdp(target_ulong ac
, target_ulong size
,
3630 uint64_t tempB
, tempA
;
3635 start_pos
= get_DSPControl_pos(env
);
3636 len
= start_pos
- size
;
3637 tempB
= env
->active_tc
.HI
[ac
];
3638 tempA
= env
->active_tc
.LO
[ac
];
3640 sub
= start_pos
- (size
+ 1);
3643 temp
= (tempB
<< (64 - len
)) | (tempA
>> len
);
3644 temp
= temp
& ((0x01 << (size
+ 1)) - 1);
3645 set_DSPControl_pos(sub
, env
);
3646 set_DSPControl_efi(0, env
);
3648 set_DSPControl_efi(1, env
);
3656 void helper_shilo(target_ulong ac
, target_ulong rs
, CPUMIPSState
*env
)
3662 rs5_0
= (int8_t)(rs5_0
<< 2) >> 2;
3664 if (unlikely(rs5_0
== 0)) {
3668 acc
= (((uint64_t)env
->active_tc
.HI
[ac
] << 32) & MIPSDSP_LHI
) |
3669 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3672 temp
= acc
>> rs5_0
;
3674 temp
= acc
<< -rs5_0
;
3677 env
->active_tc
.HI
[ac
] = (target_ulong
)(int32_t)((temp
& MIPSDSP_LHI
) >> 32);
3678 env
->active_tc
.LO
[ac
] = (target_ulong
)(int32_t)(temp
& MIPSDSP_LLO
);
3681 #if defined(TARGET_MIPS64)
3682 void helper_dshilo(target_ulong shift
, target_ulong ac
, CPUMIPSState
*env
)
3685 uint64_t tempB
, tempA
;
3687 shift_t
= (int8_t)(shift
<< 1) >> 1;
3689 tempB
= env
->active_tc
.HI
[ac
];
3690 tempA
= env
->active_tc
.LO
[ac
];
3694 tempA
= (tempB
<< (64 - shift_t
)) | (tempA
>> shift_t
);
3695 tempB
= tempB
>> shift_t
;
3698 tempB
= (tempB
<< shift_t
) | (tempA
>> (64 - shift_t
));
3699 tempA
= tempA
<< shift_t
;
3703 env
->active_tc
.HI
[ac
] = tempB
;
3704 env
->active_tc
.LO
[ac
] = tempA
;
3708 void helper_mthlip(target_ulong ac
, target_ulong rs
, CPUMIPSState
*env
)
3710 int32_t tempA
, tempB
, pos
;
3713 tempB
= env
->active_tc
.LO
[ac
];
3714 env
->active_tc
.HI
[ac
] = (target_long
)tempB
;
3715 env
->active_tc
.LO
[ac
] = (target_long
)tempA
;
3716 pos
= get_DSPControl_pos(env
);
3721 set_DSPControl_pos(pos
+ 32, env
);
3725 #if defined(TARGET_MIPS64)
3726 void helper_dmthlip(target_ulong rs
, target_ulong ac
, CPUMIPSState
*env
)
3730 uint64_t tempB
, tempA
;
3735 tempB
= env
->active_tc
.LO
[ac_t
];
3737 env
->active_tc
.HI
[ac_t
] = tempB
;
3738 env
->active_tc
.LO
[ac_t
] = tempA
;
3740 pos
= get_DSPControl_pos(env
);
3744 set_DSPControl_pos(pos
, env
);
3749 void helper_wrdsp(target_ulong rs
, target_ulong mask_num
, CPUMIPSState
*env
)
3753 uint32_t newbits
, overwrite
;
3757 overwrite
= 0xFFFFFFFF;
3758 dsp
= env
->active_tc
.DSPControl
;
3760 for (i
= 0; i
< 6; i
++) {
3761 mask
[i
] = (mask_num
>> i
) & 0x01;
3765 #if defined(TARGET_MIPS64)
3766 overwrite
&= 0xFFFFFF80;
3767 newbits
&= 0xFFFFFF80;
3768 newbits
|= 0x0000007F & rs
;
3770 overwrite
&= 0xFFFFFFC0;
3771 newbits
&= 0xFFFFFFC0;
3772 newbits
|= 0x0000003F & rs
;
3777 overwrite
&= 0xFFFFE07F;
3778 newbits
&= 0xFFFFE07F;
3779 newbits
|= 0x00001F80 & rs
;
3783 overwrite
&= 0xFFFFDFFF;
3784 newbits
&= 0xFFFFDFFF;
3785 newbits
|= 0x00002000 & rs
;
3789 overwrite
&= 0xFF00FFFF;
3790 newbits
&= 0xFF00FFFF;
3791 newbits
|= 0x00FF0000 & rs
;
3795 overwrite
&= 0x00FFFFFF;
3796 newbits
&= 0x00FFFFFF;
3797 #if defined(TARGET_MIPS64)
3798 newbits
|= 0xFF000000 & rs
;
3800 newbits
|= 0x0F000000 & rs
;
3805 overwrite
&= 0xFFFFBFFF;
3806 newbits
&= 0xFFFFBFFF;
3807 newbits
|= 0x00004000 & rs
;
3810 dsp
= dsp
& overwrite
;
3811 dsp
= dsp
| newbits
;
3812 env
->active_tc
.DSPControl
= dsp
;
3815 target_ulong
helper_rddsp(target_ulong masknum
, CPUMIPSState
*env
)
3823 for (i
= 0; i
< 6; i
++) {
3824 mask
[i
] = (masknum
& ruler
) >> i
;
3829 dsp
= env
->active_tc
.DSPControl
;
3832 #if defined(TARGET_MIPS64)
3840 temp
|= dsp
& 0x1F80;
3844 temp
|= dsp
& 0x2000;
3848 temp
|= dsp
& 0x00FF0000;
3852 #if defined(TARGET_MIPS64)
3853 temp
|= dsp
& 0xFF000000;
3855 temp
|= dsp
& 0x0F000000;
3860 temp
|= dsp
& 0x4000;
3876 #undef MIPSDSP_SPLIT32_8
3877 #undef MIPSDSP_SPLIT32_16
3879 #undef MIPSDSP_RETURN32_8
3880 #undef MIPSDSP_RETURN32_16
3882 #ifdef TARGET_MIPS64
3883 #undef MIPSDSP_SPLIT64_16
3884 #undef MIPSDSP_SPLIT64_32
3885 #undef MIPSDSP_RETURN64_16
3886 #undef MIPSDSP_RETURN64_32