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 /*** MIPS DSP internal functions begin ***/
24 #define MIPSDSP_ABS(x) (((x) >= 0) ? x : -x)
25 #define MIPSDSP_OVERFLOW(a, b, c, d) (!(!((a ^ b ^ -1) & (a ^ c) & d)))
27 static inline void set_DSPControl_overflow_flag(uint32_t flag
, int position
,
30 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< position
;
33 static inline void set_DSPControl_carryflag(uint32_t flag
, CPUMIPSState
*env
)
35 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 13;
38 static inline uint32_t get_DSPControl_carryflag(CPUMIPSState
*env
)
40 return (env
->active_tc
.DSPControl
>> 13) & 0x01;
43 static inline void set_DSPControl_24(uint32_t flag
, int len
, CPUMIPSState
*env
)
47 filter
= ((0x01 << len
) - 1) << 24;
50 env
->active_tc
.DSPControl
&= filter
;
51 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 24;
54 static inline uint32_t get_DSPControl_24(int len
, CPUMIPSState
*env
)
58 filter
= (0x01 << len
) - 1;
60 return (env
->active_tc
.DSPControl
>> 24) & filter
;
63 static inline void set_DSPControl_pos(uint32_t pos
, CPUMIPSState
*env
)
67 dspc
= env
->active_tc
.DSPControl
;
69 dspc
= dspc
& 0xFFFFFFC0;
72 dspc
= dspc
& 0xFFFFFF80;
75 env
->active_tc
.DSPControl
= dspc
;
78 static inline uint32_t get_DSPControl_pos(CPUMIPSState
*env
)
83 dspc
= env
->active_tc
.DSPControl
;
94 static inline void set_DSPControl_efi(uint32_t flag
, CPUMIPSState
*env
)
96 env
->active_tc
.DSPControl
&= 0xFFFFBFFF;
97 env
->active_tc
.DSPControl
|= (target_ulong
)flag
<< 14;
100 #define DO_MIPS_SAT_ABS(size) \
101 static inline int##size##_t mipsdsp_sat_abs##size(int##size##_t a, \
104 if (a == INT##size##_MIN) { \
105 set_DSPControl_overflow_flag(1, 20, env); \
106 return INT##size##_MAX; \
108 return MIPSDSP_ABS(a); \
114 #undef DO_MIPS_SAT_ABS
117 static inline int16_t mipsdsp_add_i16(int16_t a
, int16_t b
, CPUMIPSState
*env
)
123 if (MIPSDSP_OVERFLOW(a
, b
, tempI
, 0x8000)) {
124 set_DSPControl_overflow_flag(1, 20, env
);
130 static inline int16_t mipsdsp_sat_add_i16(int16_t a
, int16_t b
,
137 if (MIPSDSP_OVERFLOW(a
, b
, tempS
, 0x8000)) {
143 set_DSPControl_overflow_flag(1, 20, env
);
149 static inline int32_t mipsdsp_sat_add_i32(int32_t a
, int32_t b
,
156 if (MIPSDSP_OVERFLOW(a
, b
, tempI
, 0x80000000)) {
162 set_DSPControl_overflow_flag(1, 20, env
);
168 static inline uint8_t mipsdsp_add_u8(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
172 temp
= (uint16_t)a
+ (uint16_t)b
;
175 set_DSPControl_overflow_flag(1, 20, env
);
181 static inline uint16_t mipsdsp_add_u16(uint16_t a
, uint16_t b
,
186 temp
= (uint32_t)a
+ (uint32_t)b
;
188 if (temp
& 0x00010000) {
189 set_DSPControl_overflow_flag(1, 20, env
);
192 return temp
& 0xFFFF;
195 static inline uint8_t mipsdsp_sat_add_u8(uint8_t a
, uint8_t b
,
201 temp
= (uint16_t)a
+ (uint16_t)b
;
202 result
= temp
& 0xFF;
206 set_DSPControl_overflow_flag(1, 20, env
);
212 static inline uint16_t mipsdsp_sat_add_u16(uint16_t a
, uint16_t b
,
218 temp
= (uint32_t)a
+ (uint32_t)b
;
219 result
= temp
& 0xFFFF;
221 if (0x00010000 & temp
) {
223 set_DSPControl_overflow_flag(1, 20, env
);
229 static inline int32_t mipsdsp_sat32_acc_q31(int32_t acc
, int32_t a
,
233 int32_t temp32
, temp31
, result
;
236 #ifndef TARGET_MIPS64
237 temp
= ((uint64_t)env
->active_tc
.HI
[acc
] << 32) |
238 (uint64_t)env
->active_tc
.LO
[acc
];
240 temp
= (uint64_t)env
->active_tc
.LO
[acc
];
243 temp_sum
= (int64_t)a
+ temp
;
245 temp32
= (temp_sum
>> 32) & 0x01;
246 temp31
= (temp_sum
>> 31) & 0x01;
247 result
= temp_sum
& 0xFFFFFFFF;
250 This sat function may wrong, because user manual wrote:
251 temp127..0 ← temp + ( (signA) || a31..0
252 if ( temp32 ≠ temp31 ) then
253 if ( temp32 = 0 ) then
254 temp31..0 ← 0x80000000
256 temp31..0 ← 0x7FFFFFFF
258 DSPControlouflag:16+acc ← 1
261 if (temp32
!= temp31
) {
267 set_DSPControl_overflow_flag(1, 16 + acc
, env
);
273 /* a[0] is LO, a[1] is HI. */
274 static inline void mipsdsp_sat64_acc_add_q63(int64_t *ret
,
281 ret
[0] = env
->active_tc
.LO
[ac
] + a
[0];
282 ret
[1] = env
->active_tc
.HI
[ac
] + a
[1];
284 if (((uint64_t)ret
[0] < (uint64_t)env
->active_tc
.LO
[ac
]) &&
285 ((uint64_t)ret
[0] < (uint64_t)a
[0])) {
289 if (temp64
!= ((ret
[0] >> 63) & 0x01)) {
291 ret
[0] = (0x01ull
<< 63);
294 ret
[0] = (0x01ull
<< 63) - 1;
297 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
301 static inline void mipsdsp_sat64_acc_sub_q63(int64_t *ret
,
308 ret
[0] = env
->active_tc
.LO
[ac
] - a
[0];
309 ret
[1] = env
->active_tc
.HI
[ac
] - a
[1];
311 if ((uint64_t)ret
[0] > (uint64_t)env
->active_tc
.LO
[ac
]) {
315 if (temp64
!= ((ret
[0] >> 63) & 0x01)) {
317 ret
[0] = (0x01ull
<< 63);
320 ret
[0] = (0x01ull
<< 63) - 1;
323 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
327 static inline int32_t mipsdsp_mul_i16_i16(int16_t a
, int16_t b
,
332 temp
= (int32_t)a
* (int32_t)b
;
334 if ((temp
> (int)0x7FFF) || (temp
< (int)0xFFFF8000)) {
335 set_DSPControl_overflow_flag(1, 21, env
);
342 static inline int32_t mipsdsp_mul_u16_u16(int32_t a
, int32_t b
)
347 static inline int32_t mipsdsp_mul_i32_i32(int32_t a
, int32_t b
)
352 static inline int32_t mipsdsp_sat16_mul_i16_i16(int16_t a
, int16_t b
,
357 temp
= (int32_t)a
* (int32_t)b
;
359 if (temp
> (int)0x7FFF) {
361 set_DSPControl_overflow_flag(1, 21, env
);
362 } else if (temp
< (int)0xffff8000) {
364 set_DSPControl_overflow_flag(1, 21, env
);
371 static inline int32_t mipsdsp_mul_q15_q15_overflowflag21(uint16_t a
, uint16_t b
,
376 if ((a
== 0x8000) && (b
== 0x8000)) {
378 set_DSPControl_overflow_flag(1, 21, env
);
380 temp
= ((int32_t)(int16_t)a
* (int32_t)(int16_t)b
) << 1;
387 static inline uint8_t mipsdsp_rshift_u8(uint8_t a
, target_ulong mov
)
392 static inline uint16_t mipsdsp_rshift_u16(uint16_t a
, target_ulong mov
)
397 static inline int8_t mipsdsp_rashift8(int8_t a
, target_ulong mov
)
402 static inline int16_t mipsdsp_rashift16(int16_t a
, target_ulong mov
)
407 static inline int32_t mipsdsp_rashift32(int32_t a
, target_ulong mov
)
412 static inline int16_t mipsdsp_rshift1_add_q16(int16_t a
, int16_t b
)
416 temp
= (int32_t)a
+ (int32_t)b
;
418 return (temp
>> 1) & 0xFFFF;
421 /* round right shift */
422 static inline int16_t mipsdsp_rrshift1_add_q16(int16_t a
, int16_t b
)
426 temp
= (int32_t)a
+ (int32_t)b
;
429 return (temp
>> 1) & 0xFFFF;
432 static inline int32_t mipsdsp_rshift1_add_q32(int32_t a
, int32_t b
)
436 temp
= (int64_t)a
+ (int64_t)b
;
438 return (temp
>> 1) & 0xFFFFFFFF;
441 static inline int32_t mipsdsp_rrshift1_add_q32(int32_t a
, int32_t b
)
445 temp
= (int64_t)a
+ (int64_t)b
;
448 return (temp
>> 1) & 0xFFFFFFFF;
451 static inline uint8_t mipsdsp_rshift1_add_u8(uint8_t a
, uint8_t b
)
455 temp
= (uint16_t)a
+ (uint16_t)b
;
457 return (temp
>> 1) & 0x00FF;
460 static inline uint8_t mipsdsp_rrshift1_add_u8(uint8_t a
, uint8_t b
)
464 temp
= (uint16_t)a
+ (uint16_t)b
+ 1;
466 return (temp
>> 1) & 0x00FF;
469 static inline uint8_t mipsdsp_rshift1_sub_u8(uint8_t a
, uint8_t b
)
473 temp
= (uint16_t)a
- (uint16_t)b
;
475 return (temp
>> 1) & 0x00FF;
478 static inline uint8_t mipsdsp_rrshift1_sub_u8(uint8_t a
, uint8_t b
)
482 temp
= (uint16_t)a
- (uint16_t)b
+ 1;
484 return (temp
>> 1) & 0x00FF;
487 /* 128 bits long. p[0] is LO, p[1] is HI. */
488 static inline void mipsdsp_rndrashift_short_acc(int64_t *p
,
495 acc
= ((int64_t)env
->active_tc
.HI
[ac
] << 32) |
496 ((int64_t)env
->active_tc
.LO
[ac
] & 0xFFFFFFFF);
499 p
[1] = (acc
>> 63) & 0x01;
501 p
[0] = acc
>> (shift
- 1);
506 /* 128 bits long. p[0] is LO, p[1] is HI */
507 static inline void mipsdsp_rashift_acc(uint64_t *p
,
512 uint64_t tempB
, tempA
;
514 tempB
= env
->active_tc
.HI
[ac
];
515 tempA
= env
->active_tc
.LO
[ac
];
516 shift
= shift
& 0x1F;
522 p
[0] = (tempB
<< (64 - shift
)) | (tempA
>> shift
);
523 p
[1] = (int64_t)tempB
>> shift
;
527 /* 128 bits long. p[0] is LO, p[1] is HI , p[2] is sign of HI.*/
528 static inline void mipsdsp_rndrashift_acc(uint64_t *p
,
533 int64_t tempB
, tempA
;
535 tempB
= env
->active_tc
.HI
[ac
];
536 tempA
= env
->active_tc
.LO
[ac
];
537 shift
= shift
& 0x3F;
541 p
[1] = (tempB
<< 1) | (tempA
>> 63);
544 p
[0] = (tempB
<< (65 - shift
)) | (tempA
>> (shift
- 1));
545 p
[1] = (int64_t)tempB
>> (shift
- 1);
554 static inline int32_t mipsdsp_mul_q15_q15(int32_t ac
, uint16_t a
, uint16_t b
,
559 if ((a
== 0x8000) && (b
== 0x8000)) {
561 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
563 temp
= ((uint32_t)a
* (uint32_t)b
) << 1;
569 static inline int64_t mipsdsp_mul_q31_q31(int32_t ac
, uint32_t a
, uint32_t b
,
574 if ((a
== 0x80000000) && (b
== 0x80000000)) {
575 temp
= (0x01ull
<< 63) - 1;
576 set_DSPControl_overflow_flag(1, 16 + ac
, env
);
578 temp
= ((uint64_t)a
* (uint64_t)b
) << 1;
584 static inline uint16_t mipsdsp_mul_u8_u8(uint8_t a
, uint8_t b
)
586 return (uint16_t)a
* (uint16_t)b
;
589 static inline uint16_t mipsdsp_mul_u8_u16(uint8_t a
, uint16_t b
,
594 tempI
= (uint32_t)a
* (uint32_t)b
;
595 if (tempI
> 0x0000FFFF) {
597 set_DSPControl_overflow_flag(1, 21, env
);
600 return tempI
& 0x0000FFFF;
603 static inline uint64_t mipsdsp_mul_u32_u32(uint32_t a
, uint32_t b
)
605 return (uint64_t)a
* (uint64_t)b
;
608 static inline int16_t mipsdsp_rndq15_mul_q15_q15(uint16_t a
, uint16_t b
,
613 if ((a
== 0x8000) && (b
== 0x8000)) {
615 set_DSPControl_overflow_flag(1, 21, env
);
618 temp
= temp
+ 0x00008000;
621 return (temp
& 0xFFFF0000) >> 16;
624 static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a
, uint16_t b
,
629 if ((a
== 0x8000) && (b
== 0x8000)) {
631 set_DSPControl_overflow_flag(1, 21, env
);
633 temp
= ((uint32_t)a
* (uint32_t)b
);
637 return (temp
>> 16) & 0x0000FFFF;
640 static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a
,
645 temp
= (int32_t)a
+ 0x00008000;
647 if (a
> (int)0x7fff8000) {
649 set_DSPControl_overflow_flag(1, 22, env
);
652 return (temp
>> 16) & 0xFFFF;
655 static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a
,
661 sign
= (a
>> 15) & 0x01;
666 set_DSPControl_overflow_flag(1, 22, env
);
669 return (mag
>> 7) & 0xFFFF;
672 set_DSPControl_overflow_flag(1, 22, env
);
677 static inline uint8_t mipsdsp_lshift8(uint8_t a
, uint8_t s
, CPUMIPSState
*env
)
685 sign
= (a
>> 7) & 0x01;
687 discard
= (((0x01 << (8 - s
)) - 1) << s
) |
688 ((a
>> (6 - (s
- 1))) & ((0x01 << s
) - 1));
690 discard
= a
>> (6 - (s
- 1));
693 if (discard
!= 0x00) {
694 set_DSPControl_overflow_flag(1, 22, env
);
700 static inline uint16_t mipsdsp_lshift16(uint16_t a
, uint8_t s
,
709 sign
= (a
>> 15) & 0x01;
711 discard
= (((0x01 << (16 - s
)) - 1) << s
) |
712 ((a
>> (14 - (s
- 1))) & ((0x01 << s
) - 1));
714 discard
= a
>> (14 - (s
- 1));
717 if ((discard
!= 0x0000) && (discard
!= 0xFFFF)) {
718 set_DSPControl_overflow_flag(1, 22, env
);
725 static inline uint32_t mipsdsp_lshift32(uint32_t a
, uint8_t s
,
733 discard
= (int32_t)a
>> (31 - (s
- 1));
735 if ((discard
!= 0x00000000) && (discard
!= 0xFFFFFFFF)) {
736 set_DSPControl_overflow_flag(1, 22, env
);
742 static inline uint16_t mipsdsp_sat16_lshift(uint16_t a
, uint8_t s
,
751 sign
= (a
>> 15) & 0x01;
753 discard
= (((0x01 << (16 - s
)) - 1) << s
) |
754 ((a
>> (14 - (s
- 1))) & ((0x01 << s
) - 1));
756 discard
= a
>> (14 - (s
- 1));
759 if ((discard
!= 0x0000) && (discard
!= 0xFFFF)) {
760 set_DSPControl_overflow_flag(1, 22, env
);
761 return (sign
== 0) ? 0x7FFF : 0x8000;
768 static inline uint32_t mipsdsp_sat32_lshift(uint32_t a
, uint8_t s
,
777 sign
= (a
>> 31) & 0x01;
779 discard
= (((0x01 << (32 - s
)) - 1) << s
) |
780 ((a
>> (30 - (s
- 1))) & ((0x01 << s
) - 1));
782 discard
= a
>> (30 - (s
- 1));
785 if ((discard
!= 0x00000000) && (discard
!= 0xFFFFFFFF)) {
786 set_DSPControl_overflow_flag(1, 22, env
);
787 return (sign
== 0) ? 0x7FFFFFFF : 0x80000000;
794 static inline uint8_t mipsdsp_rnd8_rashift(uint8_t a
, uint8_t s
)
799 temp
= (uint32_t)a
<< 1;
801 temp
= (int32_t)(int8_t)a
>> (s
- 1);
804 return (temp
+ 1) >> 1;
807 static inline uint16_t mipsdsp_rnd16_rashift(uint16_t a
, uint8_t s
)
812 temp
= (uint32_t)a
<< 1;
814 temp
= (int32_t)(int16_t)a
>> (s
- 1);
817 return (temp
+ 1) >> 1;
820 static inline uint32_t mipsdsp_rnd32_rashift(uint32_t a
, uint8_t s
)
825 temp
= (uint64_t)a
<< 1;
827 temp
= (int64_t)(int32_t)a
>> (s
- 1);
831 return (temp
>> 1) & 0xFFFFFFFFull
;
834 static inline uint16_t mipsdsp_sub_i16(int16_t a
, int16_t b
, CPUMIPSState
*env
)
839 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x8000)) {
840 set_DSPControl_overflow_flag(1, 20, env
);
846 static inline uint16_t mipsdsp_sat16_sub(int16_t a
, int16_t b
,
852 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x8000)) {
858 set_DSPControl_overflow_flag(1, 20, env
);
864 static inline uint32_t mipsdsp_sat32_sub(int32_t a
, int32_t b
,
870 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x80000000)) {
876 set_DSPControl_overflow_flag(1, 20, env
);
879 return temp
& 0xFFFFFFFFull
;
882 static inline uint16_t mipsdsp_rshift1_sub_q16(int16_t a
, int16_t b
)
886 temp
= (int32_t)a
- (int32_t)b
;
888 return (temp
>> 1) & 0x0000FFFF;
891 static inline uint16_t mipsdsp_rrshift1_sub_q16(int16_t a
, int16_t b
)
895 temp
= (int32_t)a
- (int32_t)b
;
898 return (temp
>> 1) & 0x0000FFFF;
901 static inline uint32_t mipsdsp_rshift1_sub_q32(int32_t a
, int32_t b
)
905 temp
= (int64_t)a
- (int64_t)b
;
907 return (temp
>> 1) & 0xFFFFFFFFull
;
910 static inline uint32_t mipsdsp_rrshift1_sub_q32(int32_t a
, int32_t b
)
914 temp
= (int64_t)a
- (int64_t)b
;
917 return (temp
>> 1) & 0xFFFFFFFFull
;
920 static inline uint16_t mipsdsp_sub_u16_u16(uint16_t a
, uint16_t b
,
926 temp
= (uint32_t)a
- (uint32_t)b
;
927 temp16
= (temp
>> 16) & 0x01;
929 set_DSPControl_overflow_flag(1, 20, env
);
931 return temp
& 0x0000FFFF;
934 static inline uint16_t mipsdsp_satu16_sub_u16_u16(uint16_t a
, uint16_t b
,
940 temp
= (uint32_t)a
- (uint32_t)b
;
941 temp16
= (temp
>> 16) & 0x01;
945 set_DSPControl_overflow_flag(1, 20, env
);
948 return temp
& 0x0000FFFF;
951 static inline uint8_t mipsdsp_sub_u8(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
956 temp
= (uint16_t)a
- (uint16_t)b
;
957 temp8
= (temp
>> 8) & 0x01;
959 set_DSPControl_overflow_flag(1, 20, env
);
962 return temp
& 0x00FF;
965 static inline uint8_t mipsdsp_satu8_sub(uint8_t a
, uint8_t b
, CPUMIPSState
*env
)
970 temp
= (uint16_t)a
- (uint16_t)b
;
971 temp8
= (temp
>> 8) & 0x01;
974 set_DSPControl_overflow_flag(1, 20, env
);
977 return temp
& 0x00FF;
980 static inline uint32_t mipsdsp_sub32(int32_t a
, int32_t b
, CPUMIPSState
*env
)
985 if (MIPSDSP_OVERFLOW(a
, -b
, temp
, 0x80000000)) {
986 set_DSPControl_overflow_flag(1, 20, env
);
992 static inline int32_t mipsdsp_add_i32(int32_t a
, int32_t b
, CPUMIPSState
*env
)
998 if (MIPSDSP_OVERFLOW(a
, b
, temp
, 0x80000000)) {
999 set_DSPControl_overflow_flag(1, 20, env
);
1005 static inline int32_t mipsdsp_cmp_eq(int32_t a
, int32_t b
)
1010 static inline int32_t mipsdsp_cmp_le(int32_t a
, int32_t b
)
1015 static inline int32_t mipsdsp_cmp_lt(int32_t a
, int32_t b
)
1020 static inline int32_t mipsdsp_cmpu_eq(uint32_t a
, uint32_t b
)
1025 static inline int32_t mipsdsp_cmpu_le(uint32_t a
, uint32_t b
)
1030 static inline int32_t mipsdsp_cmpu_lt(uint32_t a
, uint32_t b
)
1034 /*** MIPS DSP internal functions end ***/
1036 #define MIPSDSP_LHI 0xFFFFFFFF00000000ull
1037 #define MIPSDSP_LLO 0x00000000FFFFFFFFull
1038 #define MIPSDSP_HI 0xFFFF0000
1039 #define MIPSDSP_LO 0x0000FFFF
1040 #define MIPSDSP_Q3 0xFF000000
1041 #define MIPSDSP_Q2 0x00FF0000
1042 #define MIPSDSP_Q1 0x0000FF00
1043 #define MIPSDSP_Q0 0x000000FF
1045 #define MIPSDSP_SPLIT32_8(num, a, b, c, d) \
1047 a = (num >> 24) & MIPSDSP_Q0; \
1048 b = (num >> 16) & MIPSDSP_Q0; \
1049 c = (num >> 8) & MIPSDSP_Q0; \
1050 d = num & MIPSDSP_Q0; \
1053 #define MIPSDSP_SPLIT32_16(num, a, b) \
1055 a = (num >> 16) & MIPSDSP_LO; \
1056 b = num & MIPSDSP_LO; \
1059 #define MIPSDSP_RETURN32(a) ((target_long)(int32_t)a)
1060 #define MIPSDSP_RETURN32_8(a, b, c, d) ((target_long)(int32_t) \
1061 (((uint32_t)a << 24) | \
1062 (((uint32_t)b << 16) | \
1063 (((uint32_t)c << 8) | \
1064 ((uint32_t)d & 0xFF)))))
1065 #define MIPSDSP_RETURN32_16(a, b) ((target_long)(int32_t) \
1066 (((uint32_t)a << 16) | \
1067 ((uint32_t)b & 0xFFFF)))
1069 #ifdef TARGET_MIPS64
1070 #define MIPSDSP_SPLIT64_16(num, a, b, c, d) \
1072 a = (num >> 48) & MIPSDSP_LO; \
1073 b = (num >> 32) & MIPSDSP_LO; \
1074 c = (num >> 16) & MIPSDSP_LO; \
1075 d = num & MIPSDSP_LO; \
1078 #define MIPSDSP_SPLIT64_32(num, a, b) \
1080 a = (num >> 32) & MIPSDSP_LLO; \
1081 b = num & MIPSDSP_LLO; \
1084 #define MIPSDSP_RETURN64_16(a, b, c, d) (((uint64_t)a << 48) | \
1085 ((uint64_t)b << 32) | \
1086 ((uint64_t)c << 16) | \
1088 #define MIPSDSP_RETURN64_32(a, b) (((uint64_t)a << 32) | (uint64_t)b)
1091 /** DSP Arithmetic Sub-class insns **/
1092 #define ARITH_PH(name, func) \
1093 target_ulong helper_##name##_ph(target_ulong rs, target_ulong rt) \
1095 uint16_t rsh, rsl, rth, rtl, temph, templ; \
1097 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
1098 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
1100 temph = mipsdsp_##func(rsh, rth); \
1101 templ = mipsdsp_##func(rsl, rtl); \
1103 return MIPSDSP_RETURN32_16(temph, templ); \
1106 #define ARITH_PH_ENV(name, func) \
1107 target_ulong helper_##name##_ph(target_ulong rs, target_ulong rt, \
1108 CPUMIPSState *env) \
1110 uint16_t rsh, rsl, rth, rtl, temph, templ; \
1112 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
1113 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
1115 temph = mipsdsp_##func(rsh, rth, env); \
1116 templ = mipsdsp_##func(rsl, rtl, env); \
1118 return MIPSDSP_RETURN32_16(temph, templ); \
1122 ARITH_PH_ENV(addq
, add_i16
);
1123 ARITH_PH_ENV(addq_s
, sat_add_i16
);
1124 ARITH_PH_ENV(addu
, add_u16
);
1125 ARITH_PH_ENV(addu_s
, sat_add_u16
);
1127 ARITH_PH(addqh
, rshift1_add_q16
);
1128 ARITH_PH(addqh_r
, rrshift1_add_q16
);
1130 ARITH_PH_ENV(subq
, sub_i16
);
1131 ARITH_PH_ENV(subq_s
, sat16_sub
);
1132 ARITH_PH_ENV(subu
, sub_u16_u16
);
1133 ARITH_PH_ENV(subu_s
, satu16_sub_u16_u16
);
1135 ARITH_PH(subqh
, rshift1_sub_q16
);
1136 ARITH_PH(subqh_r
, rrshift1_sub_q16
);
1141 #ifdef TARGET_MIPS64
1142 #define ARITH_QH_ENV(name, func) \
1143 target_ulong helper_##name##_qh(target_ulong rs, target_ulong rt, \
1144 CPUMIPSState *env) \
1146 uint16_t rs3, rs2, rs1, rs0; \
1147 uint16_t rt3, rt2, rt1, rt0; \
1148 uint16_t tempD, tempC, tempB, tempA; \
1150 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
1151 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1153 tempD = mipsdsp_##func(rs3, rt3, env); \
1154 tempC = mipsdsp_##func(rs2, rt2, env); \
1155 tempB = mipsdsp_##func(rs1, rt1, env); \
1156 tempA = mipsdsp_##func(rs0, rt0, env); \
1158 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1161 ARITH_QH_ENV(addq
, add_i16
);
1162 ARITH_QH_ENV(addq_s
, sat_add_i16
);
1163 ARITH_QH_ENV(addu
, add_u16
);
1164 ARITH_QH_ENV(addu_s
, sat_add_u16
);
1166 ARITH_QH_ENV(subq
, sub_i16
);
1167 ARITH_QH_ENV(subq_s
, sat16_sub
);
1168 ARITH_QH_ENV(subu
, sub_u16_u16
);
1169 ARITH_QH_ENV(subu_s
, satu16_sub_u16_u16
);
1175 #define ARITH_W(name, func) \
1176 target_ulong helper_##name##_w(target_ulong rs, target_ulong rt) \
1179 rd = mipsdsp_##func(rs, rt); \
1180 return MIPSDSP_RETURN32(rd); \
1183 #define ARITH_W_ENV(name, func) \
1184 target_ulong helper_##name##_w(target_ulong rs, target_ulong rt, \
1185 CPUMIPSState *env) \
1188 rd = mipsdsp_##func(rs, rt, env); \
1189 return MIPSDSP_RETURN32(rd); \
1192 ARITH_W_ENV(addq_s
, sat_add_i32
);
1194 ARITH_W(addqh
, rshift1_add_q32
);
1195 ARITH_W(addqh_r
, rrshift1_add_q32
);
1197 ARITH_W_ENV(subq_s
, sat32_sub
);
1199 ARITH_W(subqh
, rshift1_sub_q32
);
1200 ARITH_W(subqh_r
, rrshift1_sub_q32
);
1205 target_ulong
helper_absq_s_w(target_ulong rt
, CPUMIPSState
*env
)
1209 rd
= mipsdsp_sat_abs32(rt
, env
);
1211 return (target_ulong
)rd
;
1215 #if defined(TARGET_MIPS64)
1217 #define ARITH_PW_ENV(name, func) \
1218 target_ulong helper_##name##_pw(target_ulong rs, target_ulong rt, \
1219 CPUMIPSState *env) \
1221 uint32_t rs1, rs0; \
1222 uint32_t rt1, rt0; \
1223 uint32_t tempB, tempA; \
1225 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
1226 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
1228 tempB = mipsdsp_##func(rs1, rt1, env); \
1229 tempA = mipsdsp_##func(rs0, rt0, env); \
1231 return MIPSDSP_RETURN64_32(tempB, tempA); \
1234 ARITH_PW_ENV(addq
, add_i32
);
1235 ARITH_PW_ENV(addq_s
, sat_add_i32
);
1236 ARITH_PW_ENV(subq
, sub32
);
1237 ARITH_PW_ENV(subq_s
, sat32_sub
);
1243 #define ARITH_QB(name, func) \
1244 target_ulong helper_##name##_qb(target_ulong rs, target_ulong rt) \
1246 uint8_t rs0, rs1, rs2, rs3; \
1247 uint8_t rt0, rt1, rt2, rt3; \
1248 uint8_t temp0, temp1, temp2, temp3; \
1250 MIPSDSP_SPLIT32_8(rs, rs3, rs2, rs1, rs0); \
1251 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1253 temp0 = mipsdsp_##func(rs0, rt0); \
1254 temp1 = mipsdsp_##func(rs1, rt1); \
1255 temp2 = mipsdsp_##func(rs2, rt2); \
1256 temp3 = mipsdsp_##func(rs3, rt3); \
1258 return MIPSDSP_RETURN32_8(temp3, temp2, temp1, temp0); \
1261 #define ARITH_QB_ENV(name, func) \
1262 target_ulong helper_##name##_qb(target_ulong rs, target_ulong rt, \
1263 CPUMIPSState *env) \
1265 uint8_t rs0, rs1, rs2, rs3; \
1266 uint8_t rt0, rt1, rt2, rt3; \
1267 uint8_t temp0, temp1, temp2, temp3; \
1269 MIPSDSP_SPLIT32_8(rs, rs3, rs2, rs1, rs0); \
1270 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1272 temp0 = mipsdsp_##func(rs0, rt0, env); \
1273 temp1 = mipsdsp_##func(rs1, rt1, env); \
1274 temp2 = mipsdsp_##func(rs2, rt2, env); \
1275 temp3 = mipsdsp_##func(rs3, rt3, env); \
1277 return MIPSDSP_RETURN32_8(temp3, temp2, temp1, temp0); \
1280 ARITH_QB(adduh
, rshift1_add_u8
);
1281 ARITH_QB(adduh_r
, rrshift1_add_u8
);
1283 ARITH_QB_ENV(addu
, add_u8
);
1284 ARITH_QB_ENV(addu_s
, sat_add_u8
);
1289 #if defined(TARGET_MIPS64)
1290 #define ARITH_OB(name, func) \
1291 target_ulong helper_##name##_ob(target_ulong rs, target_ulong rt) \
1294 uint8_t rs_t[8], rt_t[8]; \
1300 for (i = 0; i < 8; i++) { \
1301 rs_t[i] = (rs >> (8 * i)) & MIPSDSP_Q0; \
1302 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1303 temp[i] = mipsdsp_##func(rs_t[i], rt_t[i]); \
1304 result |= (uint64_t)temp[i] << (8 * i); \
1310 #define ARITH_OB_ENV(name, func) \
1311 target_ulong helper_##name##_ob(target_ulong rs, target_ulong rt, \
1312 CPUMIPSState *env) \
1315 uint8_t rs_t[8], rt_t[8]; \
1321 for (i = 0; i < 8; i++) { \
1322 rs_t[i] = (rs >> (8 * i)) & MIPSDSP_Q0; \
1323 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1324 temp[i] = mipsdsp_##func(rs_t[i], rt_t[i], env); \
1325 result |= (uint64_t)temp[i] << (8 * i); \
1331 ARITH_OB_ENV(addu
, add_u8
);
1332 ARITH_OB_ENV(addu_s
, sat_add_u8
);
1334 ARITH_OB(adduh
, rshift1_add_u8
);
1335 ARITH_OB(adduh_r
, rrshift1_add_u8
);
1337 ARITH_OB_ENV(subu
, sub_u8
);
1338 ARITH_OB_ENV(subu_s
, satu8_sub
);
1340 ARITH_OB(subuh
, rshift1_sub_u8
);
1341 ARITH_OB(subuh_r
, rrshift1_sub_u8
);
1348 #define SUBU_QB(name, func) \
1349 target_ulong helper_##name##_qb(target_ulong rs, \
1351 CPUMIPSState *env) \
1353 uint8_t rs3, rs2, rs1, rs0; \
1354 uint8_t rt3, rt2, rt1, rt0; \
1355 uint8_t tempD, tempC, tempB, tempA; \
1357 MIPSDSP_SPLIT32_8(rs, rs3, rs2, rs1, rs0); \
1358 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1360 tempD = mipsdsp_##func(rs3, rt3, env); \
1361 tempC = mipsdsp_##func(rs2, rt2, env); \
1362 tempB = mipsdsp_##func(rs1, rt1, env); \
1363 tempA = mipsdsp_##func(rs0, rt0, env); \
1365 return MIPSDSP_RETURN32_8(tempD, tempC, tempB, tempA); \
1368 SUBU_QB(subu
, sub_u8
);
1369 SUBU_QB(subu_s
, satu8_sub
);
1373 #define SUBUH_QB(name, var) \
1374 target_ulong helper_##name##_qb(target_ulong rs, target_ulong rt) \
1376 uint8_t rs3, rs2, rs1, rs0; \
1377 uint8_t rt3, rt2, rt1, rt0; \
1378 uint8_t tempD, tempC, tempB, tempA; \
1380 MIPSDSP_SPLIT32_8(rs, rs3, rs2, rs1, rs0); \
1381 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1383 tempD = ((uint16_t)rs3 - (uint16_t)rt3 + var) >> 1; \
1384 tempC = ((uint16_t)rs2 - (uint16_t)rt2 + var) >> 1; \
1385 tempB = ((uint16_t)rs1 - (uint16_t)rt1 + var) >> 1; \
1386 tempA = ((uint16_t)rs0 - (uint16_t)rt0 + var) >> 1; \
1388 return ((uint32_t)tempD << 24) | ((uint32_t)tempC << 16) | \
1389 ((uint32_t)tempB << 8) | ((uint32_t)tempA); \
1393 SUBUH_QB(subuh_r
, 1);
1397 target_ulong
helper_addsc(target_ulong rs
, target_ulong rt
, CPUMIPSState
*env
)
1399 uint64_t temp
, tempRs
, tempRt
;
1402 tempRs
= (uint64_t)rs
& MIPSDSP_LLO
;
1403 tempRt
= (uint64_t)rt
& MIPSDSP_LLO
;
1405 temp
= tempRs
+ tempRt
;
1406 flag
= (temp
& 0x0100000000ull
) >> 32;
1407 set_DSPControl_carryflag(flag
, env
);
1409 return (target_long
)(int32_t)(temp
& MIPSDSP_LLO
);
1412 target_ulong
helper_addwc(target_ulong rs
, target_ulong rt
, CPUMIPSState
*env
)
1415 int32_t temp32
, temp31
;
1418 tempL
= (int64_t)(int32_t)rs
+ (int64_t)(int32_t)rt
+
1419 get_DSPControl_carryflag(env
);
1420 temp31
= (tempL
>> 31) & 0x01;
1421 temp32
= (tempL
>> 32) & 0x01;
1423 if (temp31
!= temp32
) {
1424 set_DSPControl_overflow_flag(1, 20, env
);
1427 rd
= tempL
& MIPSDSP_LLO
;
1429 return (target_long
)(int32_t)rd
;
1432 target_ulong
helper_modsub(target_ulong rs
, target_ulong rt
)
1438 decr
= rt
& MIPSDSP_Q0
;
1439 lastindex
= (rt
>> 8) & MIPSDSP_LO
;
1441 if ((rs
& MIPSDSP_LLO
) == 0x00000000) {
1442 rd
= (target_ulong
)lastindex
;
1450 target_ulong
helper_raddu_w_qb(target_ulong rs
)
1452 uint8_t rs3
, rs2
, rs1
, rs0
;
1455 MIPSDSP_SPLIT32_8(rs
, rs3
, rs2
, rs1
, rs0
);
1457 temp
= (uint16_t)rs3
+ (uint16_t)rs2
+ (uint16_t)rs1
+ (uint16_t)rs0
;
1459 return (target_ulong
)temp
;
1462 #if defined(TARGET_MIPS64)
1463 target_ulong
helper_raddu_l_ob(target_ulong rs
)
1471 for (i
= 0; i
< 8; i
++) {
1472 rs_t
[i
] = (rs
>> (8 * i
)) & MIPSDSP_Q0
;
1473 temp
+= (uint64_t)rs_t
[i
];
1480 target_ulong
helper_absq_s_qb(target_ulong rt
, CPUMIPSState
*env
)
1482 uint8_t tempD
, tempC
, tempB
, tempA
;
1484 MIPSDSP_SPLIT32_8(rt
, tempD
, tempC
, tempB
, tempA
);
1486 tempD
= mipsdsp_sat_abs8(tempD
, env
);
1487 tempC
= mipsdsp_sat_abs8(tempC
, env
);
1488 tempB
= mipsdsp_sat_abs8(tempB
, env
);
1489 tempA
= mipsdsp_sat_abs8(tempA
, env
);
1491 return MIPSDSP_RETURN32_8(tempD
, tempC
, tempB
, tempA
);
1494 target_ulong
helper_absq_s_ph(target_ulong rt
, CPUMIPSState
*env
)
1496 uint16_t tempB
, tempA
;
1498 MIPSDSP_SPLIT32_16(rt
, tempB
, tempA
);
1500 tempB
= mipsdsp_sat_abs16 (tempB
, env
);
1501 tempA
= mipsdsp_sat_abs16 (tempA
, env
);
1503 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1506 #if defined(TARGET_MIPS64)
1507 target_ulong
helper_absq_s_ob(target_ulong rt
, CPUMIPSState
*env
)
1513 for (i
= 0; i
< 8; i
++) {
1514 temp
[i
] = (rt
>> (8 * i
)) & MIPSDSP_Q0
;
1515 temp
[i
] = mipsdsp_sat_abs8(temp
[i
], env
);
1518 for (i
= 0; i
< 8; i
++) {
1519 result
= (uint64_t)(uint8_t)temp
[i
] << (8 * i
);
1525 target_ulong
helper_absq_s_qh(target_ulong rt
, CPUMIPSState
*env
)
1527 int16_t tempD
, tempC
, tempB
, tempA
;
1529 MIPSDSP_SPLIT64_16(rt
, tempD
, tempC
, tempB
, tempA
);
1531 tempD
= mipsdsp_sat_abs16(tempD
, env
);
1532 tempC
= mipsdsp_sat_abs16(tempC
, env
);
1533 tempB
= mipsdsp_sat_abs16(tempB
, env
);
1534 tempA
= mipsdsp_sat_abs16(tempA
, env
);
1536 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1539 target_ulong
helper_absq_s_pw(target_ulong rt
, CPUMIPSState
*env
)
1541 int32_t tempB
, tempA
;
1543 MIPSDSP_SPLIT64_32(rt
, tempB
, tempA
);
1545 tempB
= mipsdsp_sat_abs32(tempB
, env
);
1546 tempA
= mipsdsp_sat_abs32(tempA
, env
);
1548 return MIPSDSP_RETURN64_32(tempB
, tempA
);
1552 #define PRECR_QB_PH(name, a, b)\
1553 target_ulong helper_##name##_qb_ph(target_ulong rs, target_ulong rt) \
1555 uint8_t tempD, tempC, tempB, tempA; \
1557 tempD = (rs >> a) & MIPSDSP_Q0; \
1558 tempC = (rs >> b) & MIPSDSP_Q0; \
1559 tempB = (rt >> a) & MIPSDSP_Q0; \
1560 tempA = (rt >> b) & MIPSDSP_Q0; \
1562 return MIPSDSP_RETURN32_8(tempD, tempC, tempB, tempA); \
1565 PRECR_QB_PH(precr
, 16, 0);
1566 PRECR_QB_PH(precrq
, 24, 8);
1570 target_ulong
helper_precr_sra_ph_w(uint32_t sa
, target_ulong rs
,
1573 uint16_t tempB
, tempA
;
1575 tempB
= ((int32_t)rt
>> sa
) & MIPSDSP_LO
;
1576 tempA
= ((int32_t)rs
>> sa
) & MIPSDSP_LO
;
1578 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1581 target_ulong
helper_precr_sra_r_ph_w(uint32_t sa
,
1582 target_ulong rs
, target_ulong rt
)
1584 uint64_t tempB
, tempA
;
1586 /* If sa = 0, then (sa - 1) = -1 will case shift error, so we need else. */
1588 tempB
= (rt
& MIPSDSP_LO
) << 1;
1589 tempA
= (rs
& MIPSDSP_LO
) << 1;
1591 tempB
= ((int32_t)rt
>> (sa
- 1)) + 1;
1592 tempA
= ((int32_t)rs
>> (sa
- 1)) + 1;
1594 rt
= (((tempB
>> 1) & MIPSDSP_LO
) << 16) | ((tempA
>> 1) & MIPSDSP_LO
);
1596 return (target_long
)(int32_t)rt
;
1599 target_ulong
helper_precrq_ph_w(target_ulong rs
, target_ulong rt
)
1601 uint16_t tempB
, tempA
;
1603 tempB
= (rs
& MIPSDSP_HI
) >> 16;
1604 tempA
= (rt
& MIPSDSP_HI
) >> 16;
1606 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1609 target_ulong
helper_precrq_rs_ph_w(target_ulong rs
, target_ulong rt
,
1612 uint16_t tempB
, tempA
;
1614 tempB
= mipsdsp_trunc16_sat16_round(rs
, env
);
1615 tempA
= mipsdsp_trunc16_sat16_round(rt
, env
);
1617 return MIPSDSP_RETURN32_16(tempB
, tempA
);
1620 #if defined(TARGET_MIPS64)
1621 target_ulong
helper_precr_ob_qh(target_ulong rs
, target_ulong rt
)
1623 uint8_t rs6
, rs4
, rs2
, rs0
;
1624 uint8_t rt6
, rt4
, rt2
, rt0
;
1627 rs6
= (rs
>> 48) & MIPSDSP_Q0
;
1628 rs4
= (rs
>> 32) & MIPSDSP_Q0
;
1629 rs2
= (rs
>> 16) & MIPSDSP_Q0
;
1630 rs0
= rs
& MIPSDSP_Q0
;
1631 rt6
= (rt
>> 48) & MIPSDSP_Q0
;
1632 rt4
= (rt
>> 32) & MIPSDSP_Q0
;
1633 rt2
= (rt
>> 16) & MIPSDSP_Q0
;
1634 rt0
= rt
& MIPSDSP_Q0
;
1636 temp
= ((uint64_t)rs6
<< 56) | ((uint64_t)rs4
<< 48) |
1637 ((uint64_t)rs2
<< 40) | ((uint64_t)rs0
<< 32) |
1638 ((uint64_t)rt6
<< 24) | ((uint64_t)rt4
<< 16) |
1639 ((uint64_t)rt2
<< 8) | (uint64_t)rt0
;
1644 #define PRECR_QH_PW(name, var) \
1645 target_ulong helper_precr_##name##_qh_pw(target_ulong rs, target_ulong rt, \
1648 uint16_t rs3, rs2, rs1, rs0; \
1649 uint16_t rt3, rt2, rt1, rt0; \
1650 uint16_t tempD, tempC, tempB, tempA; \
1652 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
1653 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
1655 /* When sa = 0, we use rt2, rt0, rs2, rs0; \
1656 * when sa != 0, we use rt3, rt1, rs3, rs1. */ \
1658 tempD = rt2 << var; \
1659 tempC = rt0 << var; \
1660 tempB = rs2 << var; \
1661 tempA = rs0 << var; \
1663 tempD = (((int16_t)rt3 >> sa) + var) >> var; \
1664 tempC = (((int16_t)rt1 >> sa) + var) >> var; \
1665 tempB = (((int16_t)rs3 >> sa) + var) >> var; \
1666 tempA = (((int16_t)rs1 >> sa) + var) >> var; \
1669 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1672 PRECR_QH_PW(sra
, 0);
1673 PRECR_QH_PW(sra_r
, 1);
1677 target_ulong
helper_precrq_ob_qh(target_ulong rs
, target_ulong rt
)
1679 uint8_t rs6
, rs4
, rs2
, rs0
;
1680 uint8_t rt6
, rt4
, rt2
, rt0
;
1683 rs6
= (rs
>> 56) & MIPSDSP_Q0
;
1684 rs4
= (rs
>> 40) & MIPSDSP_Q0
;
1685 rs2
= (rs
>> 24) & MIPSDSP_Q0
;
1686 rs0
= (rs
>> 8) & MIPSDSP_Q0
;
1687 rt6
= (rt
>> 56) & MIPSDSP_Q0
;
1688 rt4
= (rt
>> 40) & MIPSDSP_Q0
;
1689 rt2
= (rt
>> 24) & MIPSDSP_Q0
;
1690 rt0
= (rt
>> 8) & MIPSDSP_Q0
;
1692 temp
= ((uint64_t)rs6
<< 56) | ((uint64_t)rs4
<< 48) |
1693 ((uint64_t)rs2
<< 40) | ((uint64_t)rs0
<< 32) |
1694 ((uint64_t)rt6
<< 24) | ((uint64_t)rt4
<< 16) |
1695 ((uint64_t)rt2
<< 8) | (uint64_t)rt0
;
1700 target_ulong
helper_precrq_qh_pw(target_ulong rs
, target_ulong rt
)
1702 uint16_t tempD
, tempC
, tempB
, tempA
;
1704 tempD
= (rs
>> 48) & MIPSDSP_LO
;
1705 tempC
= (rs
>> 16) & MIPSDSP_LO
;
1706 tempB
= (rt
>> 48) & MIPSDSP_LO
;
1707 tempA
= (rt
>> 16) & MIPSDSP_LO
;
1709 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1712 target_ulong
helper_precrq_rs_qh_pw(target_ulong rs
, target_ulong rt
,
1717 uint16_t tempD
, tempC
, tempB
, tempA
;
1719 rs2
= (rs
>> 32) & MIPSDSP_LLO
;
1720 rs0
= rs
& MIPSDSP_LLO
;
1721 rt2
= (rt
>> 32) & MIPSDSP_LLO
;
1722 rt0
= rt
& MIPSDSP_LLO
;
1724 tempD
= mipsdsp_trunc16_sat16_round(rs2
, env
);
1725 tempC
= mipsdsp_trunc16_sat16_round(rs0
, env
);
1726 tempB
= mipsdsp_trunc16_sat16_round(rt2
, env
);
1727 tempA
= mipsdsp_trunc16_sat16_round(rt0
, env
);
1729 return MIPSDSP_RETURN64_16(tempD
, tempC
, tempB
, tempA
);
1732 target_ulong
helper_precrq_pw_l(target_ulong rs
, target_ulong rt
)
1734 uint32_t tempB
, tempA
;
1736 tempB
= (rs
>> 32) & MIPSDSP_LLO
;
1737 tempA
= (rt
>> 32) & MIPSDSP_LLO
;
1739 return MIPSDSP_RETURN64_32(tempB
, tempA
);
1743 target_ulong
helper_precrqu_s_qb_ph(target_ulong rs
, target_ulong rt
,
1746 uint8_t tempD
, tempC
, tempB
, tempA
;
1747 uint16_t rsh
, rsl
, rth
, rtl
;
1749 rsh
= (rs
& MIPSDSP_HI
) >> 16;
1750 rsl
= rs
& MIPSDSP_LO
;
1751 rth
= (rt
& MIPSDSP_HI
) >> 16;
1752 rtl
= rt
& MIPSDSP_LO
;
1754 tempD
= mipsdsp_sat8_reduce_precision(rsh
, env
);
1755 tempC
= mipsdsp_sat8_reduce_precision(rsl
, env
);
1756 tempB
= mipsdsp_sat8_reduce_precision(rth
, env
);
1757 tempA
= mipsdsp_sat8_reduce_precision(rtl
, env
);
1759 return MIPSDSP_RETURN32_8(tempD
, tempC
, tempB
, tempA
);
1762 #if defined(TARGET_MIPS64)
1763 target_ulong
helper_precrqu_s_ob_qh(target_ulong rs
, target_ulong rt
,
1767 uint16_t rs3
, rs2
, rs1
, rs0
;
1768 uint16_t rt3
, rt2
, rt1
, rt0
;
1774 MIPSDSP_SPLIT64_16(rs
, rs3
, rs2
, rs1
, rs0
);
1775 MIPSDSP_SPLIT64_16(rt
, rt3
, rt2
, rt1
, rt0
);
1777 temp
[7] = mipsdsp_sat8_reduce_precision(rs3
, env
);
1778 temp
[6] = mipsdsp_sat8_reduce_precision(rs2
, env
);
1779 temp
[5] = mipsdsp_sat8_reduce_precision(rs1
, env
);
1780 temp
[4] = mipsdsp_sat8_reduce_precision(rs0
, env
);
1781 temp
[3] = mipsdsp_sat8_reduce_precision(rt3
, env
);
1782 temp
[2] = mipsdsp_sat8_reduce_precision(rt2
, env
);
1783 temp
[1] = mipsdsp_sat8_reduce_precision(rt1
, env
);
1784 temp
[0] = mipsdsp_sat8_reduce_precision(rt0
, env
);
1786 for (i
= 0; i
< 8; i
++) {
1787 result
|= (uint64_t)temp
[i
] << (8 * i
);
1793 #define PRECEQ_PW(name, a, b) \
1794 target_ulong helper_preceq_pw_##name(target_ulong rt) \
1796 uint16_t tempB, tempA; \
1797 uint32_t tempBI, tempAI; \
1799 tempB = (rt >> a) & MIPSDSP_LO; \
1800 tempA = (rt >> b) & MIPSDSP_LO; \
1802 tempBI = (uint32_t)tempB << 16; \
1803 tempAI = (uint32_t)tempA << 16; \
1805 return MIPSDSP_RETURN64_32(tempBI, tempAI); \
1808 PRECEQ_PW(qhl
, 48, 32);
1809 PRECEQ_PW(qhr
, 16, 0);
1810 PRECEQ_PW(qhla
, 48, 16);
1811 PRECEQ_PW(qhra
, 32, 0);
1817 #define PRECEQU_PH(name, a, b) \
1818 target_ulong helper_precequ_ph_##name(target_ulong rt) \
1820 uint16_t tempB, tempA; \
1822 tempB = (rt >> a) & MIPSDSP_Q0; \
1823 tempA = (rt >> b) & MIPSDSP_Q0; \
1825 tempB = tempB << 7; \
1826 tempA = tempA << 7; \
1828 return MIPSDSP_RETURN32_16(tempB, tempA); \
1831 PRECEQU_PH(qbl
, 24, 16);
1832 PRECEQU_PH(qbr
, 8, 0);
1833 PRECEQU_PH(qbla
, 24, 8);
1834 PRECEQU_PH(qbra
, 16, 0);
1838 #if defined(TARGET_MIPS64)
1839 #define PRECEQU_QH(name, a, b, c, d) \
1840 target_ulong helper_precequ_qh_##name(target_ulong rt) \
1842 uint16_t tempD, tempC, tempB, tempA; \
1844 tempD = (rt >> a) & MIPSDSP_Q0; \
1845 tempC = (rt >> b) & MIPSDSP_Q0; \
1846 tempB = (rt >> c) & MIPSDSP_Q0; \
1847 tempA = (rt >> d) & MIPSDSP_Q0; \
1849 tempD = tempD << 7; \
1850 tempC = tempC << 7; \
1851 tempB = tempB << 7; \
1852 tempA = tempA << 7; \
1854 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1857 PRECEQU_QH(obl
, 56, 48, 40, 32);
1858 PRECEQU_QH(obr
, 24, 16, 8, 0);
1859 PRECEQU_QH(obla
, 56, 40, 24, 8);
1860 PRECEQU_QH(obra
, 48, 32, 16, 0);
1866 #define PRECEU_PH(name, a, b) \
1867 target_ulong helper_preceu_ph_##name(target_ulong rt) \
1869 uint16_t tempB, tempA; \
1871 tempB = (rt >> a) & MIPSDSP_Q0; \
1872 tempA = (rt >> b) & MIPSDSP_Q0; \
1874 return MIPSDSP_RETURN32_16(tempB, tempA); \
1877 PRECEU_PH(qbl
, 24, 16);
1878 PRECEU_PH(qbr
, 8, 0);
1879 PRECEU_PH(qbla
, 24, 8);
1880 PRECEU_PH(qbra
, 16, 0);
1884 #if defined(TARGET_MIPS64)
1885 #define PRECEU_QH(name, a, b, c, d) \
1886 target_ulong helper_preceu_qh_##name(target_ulong rt) \
1888 uint16_t tempD, tempC, tempB, tempA; \
1890 tempD = (rt >> a) & MIPSDSP_Q0; \
1891 tempC = (rt >> b) & MIPSDSP_Q0; \
1892 tempB = (rt >> c) & MIPSDSP_Q0; \
1893 tempA = (rt >> d) & MIPSDSP_Q0; \
1895 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
1898 PRECEU_QH(obl
, 56, 48, 40, 32);
1899 PRECEU_QH(obr
, 24, 16, 8, 0);
1900 PRECEU_QH(obla
, 56, 40, 24, 8);
1901 PRECEU_QH(obra
, 48, 32, 16, 0);
1907 /** DSP GPR-Based Shift Sub-class insns **/
1908 #define SHIFT_QB(name, func) \
1909 target_ulong helper_##name##_qb(target_ulong sa, target_ulong rt) \
1911 uint8_t rt3, rt2, rt1, rt0; \
1915 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1917 rt3 = mipsdsp_##func(rt3, sa); \
1918 rt2 = mipsdsp_##func(rt2, sa); \
1919 rt1 = mipsdsp_##func(rt1, sa); \
1920 rt0 = mipsdsp_##func(rt0, sa); \
1922 return MIPSDSP_RETURN32_8(rt3, rt2, rt1, rt0); \
1925 #define SHIFT_QB_ENV(name, func) \
1926 target_ulong helper_##name##_qb(target_ulong sa, target_ulong rt,\
1927 CPUMIPSState *env) \
1929 uint8_t rt3, rt2, rt1, rt0; \
1933 MIPSDSP_SPLIT32_8(rt, rt3, rt2, rt1, rt0); \
1935 rt3 = mipsdsp_##func(rt3, sa, env); \
1936 rt2 = mipsdsp_##func(rt2, sa, env); \
1937 rt1 = mipsdsp_##func(rt1, sa, env); \
1938 rt0 = mipsdsp_##func(rt0, sa, env); \
1940 return MIPSDSP_RETURN32_8(rt3, rt2, rt1, rt0); \
1943 SHIFT_QB_ENV(shll
, lshift8
);
1944 SHIFT_QB(shrl
, rshift_u8
);
1946 SHIFT_QB(shra
, rashift8
);
1947 SHIFT_QB(shra_r
, rnd8_rashift
);
1952 #if defined(TARGET_MIPS64)
1953 #define SHIFT_OB(name, func) \
1954 target_ulong helper_##name##_ob(target_ulong rt, target_ulong sa) \
1963 for (i = 0; i < 8; i++) { \
1964 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1965 rt_t[i] = mipsdsp_##func(rt_t[i], sa); \
1966 temp |= (uint64_t)rt_t[i] << (8 * i); \
1972 #define SHIFT_OB_ENV(name, func) \
1973 target_ulong helper_##name##_ob(target_ulong rt, target_ulong sa, \
1974 CPUMIPSState *env) \
1983 for (i = 0; i < 8; i++) { \
1984 rt_t[i] = (rt >> (8 * i)) & MIPSDSP_Q0; \
1985 rt_t[i] = mipsdsp_##func(rt_t[i], sa, env); \
1986 temp |= (uint64_t)rt_t[i] << (8 * i); \
1992 SHIFT_OB_ENV(shll
, lshift8
);
1993 SHIFT_OB(shrl
, rshift_u8
);
1995 SHIFT_OB(shra
, rashift8
);
1996 SHIFT_OB(shra_r
, rnd8_rashift
);
2003 #define SHIFT_PH(name, func) \
2004 target_ulong helper_##name##_ph(target_ulong sa, target_ulong rt, \
2005 CPUMIPSState *env) \
2007 uint16_t rth, rtl; \
2011 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2013 rth = mipsdsp_##func(rth, sa, env); \
2014 rtl = mipsdsp_##func(rtl, sa, env); \
2016 return MIPSDSP_RETURN32_16(rth, rtl); \
2019 SHIFT_PH(shll
, lshift16
);
2020 SHIFT_PH(shll_s
, sat16_lshift
);
2024 #if defined(TARGET_MIPS64)
2025 #define SHIFT_QH(name, func) \
2026 target_ulong helper_##name##_qh(target_ulong rt, target_ulong sa) \
2028 uint16_t rt3, rt2, rt1, rt0; \
2032 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
2034 rt3 = mipsdsp_##func(rt3, sa); \
2035 rt2 = mipsdsp_##func(rt2, sa); \
2036 rt1 = mipsdsp_##func(rt1, sa); \
2037 rt0 = mipsdsp_##func(rt0, sa); \
2039 return MIPSDSP_RETURN64_16(rt3, rt2, rt1, rt0); \
2042 #define SHIFT_QH_ENV(name, func) \
2043 target_ulong helper_##name##_qh(target_ulong rt, target_ulong sa, \
2044 CPUMIPSState *env) \
2046 uint16_t rt3, rt2, rt1, rt0; \
2050 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
2052 rt3 = mipsdsp_##func(rt3, sa, env); \
2053 rt2 = mipsdsp_##func(rt2, sa, env); \
2054 rt1 = mipsdsp_##func(rt1, sa, env); \
2055 rt0 = mipsdsp_##func(rt0, sa, env); \
2057 return MIPSDSP_RETURN64_16(rt3, rt2, rt1, rt0); \
2060 SHIFT_QH_ENV(shll
, lshift16
);
2061 SHIFT_QH_ENV(shll_s
, sat16_lshift
);
2063 SHIFT_QH(shrl
, rshift_u16
);
2064 SHIFT_QH(shra
, rashift16
);
2065 SHIFT_QH(shra_r
, rnd16_rashift
);
2072 #define SHIFT_W(name, func) \
2073 target_ulong helper_##name##_w(target_ulong sa, target_ulong rt) \
2078 temp = mipsdsp_##func(rt, sa); \
2080 return (target_long)(int32_t)temp; \
2083 #define SHIFT_W_ENV(name, func) \
2084 target_ulong helper_##name##_w(target_ulong sa, target_ulong rt, \
2085 CPUMIPSState *env) \
2090 temp = mipsdsp_##func(rt, sa, env); \
2092 return (target_long)(int32_t)temp; \
2095 SHIFT_W_ENV(shll_s
, sat32_lshift
);
2096 SHIFT_W(shra_r
, rnd32_rashift
);
2101 #if defined(TARGET_MIPS64)
2102 #define SHIFT_PW(name, func) \
2103 target_ulong helper_##name##_pw(target_ulong rt, target_ulong sa) \
2105 uint32_t rt1, rt0; \
2108 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2110 rt1 = mipsdsp_##func(rt1, sa); \
2111 rt0 = mipsdsp_##func(rt0, sa); \
2113 return MIPSDSP_RETURN64_32(rt1, rt0); \
2116 #define SHIFT_PW_ENV(name, func) \
2117 target_ulong helper_##name##_pw(target_ulong rt, target_ulong sa, \
2118 CPUMIPSState *env) \
2120 uint32_t rt1, rt0; \
2123 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2125 rt1 = mipsdsp_##func(rt1, sa, env); \
2126 rt0 = mipsdsp_##func(rt0, sa, env); \
2128 return MIPSDSP_RETURN64_32(rt1, rt0); \
2131 SHIFT_PW_ENV(shll
, lshift32
);
2132 SHIFT_PW_ENV(shll_s
, sat32_lshift
);
2134 SHIFT_PW(shra
, rashift32
);
2135 SHIFT_PW(shra_r
, rnd32_rashift
);
2142 #define SHIFT_PH(name, func) \
2143 target_ulong helper_##name##_ph(target_ulong sa, target_ulong rt) \
2145 uint16_t rth, rtl; \
2149 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2151 rth = mipsdsp_##func(rth, sa); \
2152 rtl = mipsdsp_##func(rtl, sa); \
2154 return MIPSDSP_RETURN32_16(rth, rtl); \
2157 SHIFT_PH(shrl
, rshift_u16
);
2158 SHIFT_PH(shra
, rashift16
);
2159 SHIFT_PH(shra_r
, rnd16_rashift
);
2163 /** DSP Multiply Sub-class insns **/
2164 /* Return value made up by two 16bits value.
2165 * FIXME give the macro a better name.
2167 #define MUL_RETURN32_16_PH(name, func, \
2168 rsmov1, rsmov2, rsfilter, \
2169 rtmov1, rtmov2, rtfilter) \
2170 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2171 CPUMIPSState *env) \
2173 uint16_t rsB, rsA, rtB, rtA; \
2175 rsB = (rs >> rsmov1) & rsfilter; \
2176 rsA = (rs >> rsmov2) & rsfilter; \
2177 rtB = (rt >> rtmov1) & rtfilter; \
2178 rtA = (rt >> rtmov2) & rtfilter; \
2180 rsB = mipsdsp_##func(rsB, rtB, env); \
2181 rsA = mipsdsp_##func(rsA, rtA, env); \
2183 return MIPSDSP_RETURN32_16(rsB, rsA); \
2186 MUL_RETURN32_16_PH(muleu_s_ph_qbl
, mul_u8_u16
, \
2187 24, 16, MIPSDSP_Q0
, \
2189 MUL_RETURN32_16_PH(muleu_s_ph_qbr
, mul_u8_u16
, \
2192 MUL_RETURN32_16_PH(mulq_rs_ph
, rndq15_mul_q15_q15
, \
2193 16, 0, MIPSDSP_LO
, \
2195 MUL_RETURN32_16_PH(mul_ph
, mul_i16_i16
, \
2196 16, 0, MIPSDSP_LO
, \
2198 MUL_RETURN32_16_PH(mul_s_ph
, sat16_mul_i16_i16
, \
2199 16, 0, MIPSDSP_LO
, \
2201 MUL_RETURN32_16_PH(mulq_s_ph
, sat16_mul_q15_q15
, \
2202 16, 0, MIPSDSP_LO
, \
2205 #undef MUL_RETURN32_16_PH
2207 #define MUL_RETURN32_32_ph(name, func, movbits) \
2208 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2209 CPUMIPSState *env) \
2214 rsh = (rs >> movbits) & MIPSDSP_LO; \
2215 rth = (rt >> movbits) & MIPSDSP_LO; \
2216 temp = mipsdsp_##func(rsh, rth, env); \
2218 return (target_long)(int32_t)temp; \
2221 MUL_RETURN32_32_ph(muleq_s_w_phl
, mul_q15_q15_overflowflag21
, 16);
2222 MUL_RETURN32_32_ph(muleq_s_w_phr
, mul_q15_q15_overflowflag21
, 0);
2224 #undef MUL_RETURN32_32_ph
2226 #define MUL_VOID_PH(name, use_ac_env) \
2227 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2228 CPUMIPSState *env) \
2230 int16_t rsh, rsl, rth, rtl; \
2231 int32_t tempB, tempA; \
2232 int64_t acc, dotp; \
2234 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
2235 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2237 if (use_ac_env == 1) { \
2238 tempB = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2239 tempA = mipsdsp_mul_q15_q15(ac, rsl, rtl, env); \
2241 tempB = mipsdsp_mul_u16_u16(rsh, rth); \
2242 tempA = mipsdsp_mul_u16_u16(rsl, rtl); \
2245 dotp = (int64_t)tempB - (int64_t)tempA; \
2246 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2247 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2248 dotp = dotp + acc; \
2249 env->active_tc.HI[ac] = (target_long)(int32_t) \
2250 ((dotp & MIPSDSP_LHI) >> 32); \
2251 env->active_tc.LO[ac] = (target_long)(int32_t)(dotp & MIPSDSP_LLO); \
2254 MUL_VOID_PH(mulsaq_s_w_ph
, 1);
2255 MUL_VOID_PH(mulsa_w_ph
, 0);
2259 #if defined(TARGET_MIPS64)
2260 #define MUL_RETURN64_16_QH(name, func, \
2261 rsmov1, rsmov2, rsmov3, rsmov4, rsfilter, \
2262 rtmov1, rtmov2, rtmov3, rtmov4, rtfilter) \
2263 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2264 CPUMIPSState *env) \
2266 uint16_t rs3, rs2, rs1, rs0; \
2267 uint16_t rt3, rt2, rt1, rt0; \
2268 uint16_t tempD, tempC, tempB, tempA; \
2270 rs3 = (rs >> rsmov1) & rsfilter; \
2271 rs2 = (rs >> rsmov2) & rsfilter; \
2272 rs1 = (rs >> rsmov3) & rsfilter; \
2273 rs0 = (rs >> rsmov4) & rsfilter; \
2274 rt3 = (rt >> rtmov1) & rtfilter; \
2275 rt2 = (rt >> rtmov2) & rtfilter; \
2276 rt1 = (rt >> rtmov3) & rtfilter; \
2277 rt0 = (rt >> rtmov4) & rtfilter; \
2279 tempD = mipsdsp_##func(rs3, rt3, env); \
2280 tempC = mipsdsp_##func(rs2, rt2, env); \
2281 tempB = mipsdsp_##func(rs1, rt1, env); \
2282 tempA = mipsdsp_##func(rs0, rt0, env); \
2284 return MIPSDSP_RETURN64_16(tempD, tempC, tempB, tempA); \
2287 MUL_RETURN64_16_QH(muleu_s_qh_obl
, mul_u8_u16
, \
2288 56, 48, 40, 32, MIPSDSP_Q0
, \
2289 48, 32, 16, 0, MIPSDSP_LO
);
2290 MUL_RETURN64_16_QH(muleu_s_qh_obr
, mul_u8_u16
, \
2291 24, 16, 8, 0, MIPSDSP_Q0
, \
2292 48, 32, 16, 0, MIPSDSP_LO
);
2293 MUL_RETURN64_16_QH(mulq_rs_qh
, rndq15_mul_q15_q15
, \
2294 48, 32, 16, 0, MIPSDSP_LO
, \
2295 48, 32, 16, 0, MIPSDSP_LO
);
2297 #undef MUL_RETURN64_16_QH
2299 #define MUL_RETURN64_32_QH(name, \
2302 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2303 CPUMIPSState *env) \
2305 uint16_t rsB, rsA; \
2306 uint16_t rtB, rtA; \
2307 uint32_t tempB, tempA; \
2309 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2310 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2311 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2312 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2314 tempB = mipsdsp_mul_q15_q15(5, rsB, rtB, env); \
2315 tempA = mipsdsp_mul_q15_q15(5, rsA, rtA, env); \
2317 return ((uint64_t)tempB << 32) | (uint64_t)tempA; \
2320 MUL_RETURN64_32_QH(muleq_s_pw_qhl
, 48, 32, 48, 32);
2321 MUL_RETURN64_32_QH(muleq_s_pw_qhr
, 16, 0, 16, 0);
2323 #undef MUL_RETURN64_32_QH
2325 void helper_mulsaq_s_w_qh(target_ulong rs
, target_ulong rt
, uint32_t ac
,
2328 int16_t rs3
, rs2
, rs1
, rs0
;
2329 int16_t rt3
, rt2
, rt1
, rt0
;
2330 int32_t tempD
, tempC
, tempB
, tempA
;
2335 MIPSDSP_SPLIT64_16(rs
, rs3
, rs2
, rs1
, rs0
);
2336 MIPSDSP_SPLIT64_16(rt
, rt3
, rt2
, rt1
, rt0
);
2338 tempD
= mipsdsp_mul_q15_q15(ac
, rs3
, rt3
, env
);
2339 tempC
= mipsdsp_mul_q15_q15(ac
, rs2
, rt2
, env
);
2340 tempB
= mipsdsp_mul_q15_q15(ac
, rs1
, rt1
, env
);
2341 tempA
= mipsdsp_mul_q15_q15(ac
, rs0
, rt0
, env
);
2343 temp
[0] = ((int32_t)tempD
- (int32_t)tempC
) +
2344 ((int32_t)tempB
- (int32_t)tempA
);
2345 temp
[0] = (int64_t)(temp
[0] << 30) >> 30;
2346 if (((temp
[0] >> 33) & 0x01) == 0) {
2352 acc
[0] = env
->active_tc
.LO
[ac
];
2353 acc
[1] = env
->active_tc
.HI
[ac
];
2355 temp_sum
= acc
[0] + temp
[0];
2356 if (((uint64_t)temp_sum
< (uint64_t)acc
[0]) &&
2357 ((uint64_t)temp_sum
< (uint64_t)temp
[0])) {
2363 env
->active_tc
.HI
[ac
] = acc
[1];
2364 env
->active_tc
.LO
[ac
] = acc
[0];
2368 #define DP_QB(name, func, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2369 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2370 CPUMIPSState *env) \
2374 uint16_t tempB, tempA; \
2375 uint64_t tempC, dotp; \
2377 rs3 = (rs >> rsmov1) & MIPSDSP_Q0; \
2378 rs2 = (rs >> rsmov2) & MIPSDSP_Q0; \
2379 rt3 = (rt >> rtmov1) & MIPSDSP_Q0; \
2380 rt2 = (rt >> rtmov2) & MIPSDSP_Q0; \
2381 tempB = mipsdsp_##func(rs3, rt3); \
2382 tempA = mipsdsp_##func(rs2, rt2); \
2383 dotp = (int64_t)tempB + (int64_t)tempA; \
2385 tempC = (((uint64_t)env->active_tc.HI[ac] << 32) | \
2386 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO)) \
2389 tempC = (((uint64_t)env->active_tc.HI[ac] << 32) | \
2390 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO)) \
2394 env->active_tc.HI[ac] = (target_long)(int32_t) \
2395 ((tempC & MIPSDSP_LHI) >> 32); \
2396 env->active_tc.LO[ac] = (target_long)(int32_t)(tempC & MIPSDSP_LLO); \
2399 DP_QB(dpau_h_qbl
, mul_u8_u8
, 1, 24, 16, 24, 16);
2400 DP_QB(dpau_h_qbr
, mul_u8_u8
, 1, 8, 0, 8, 0);
2401 DP_QB(dpsu_h_qbl
, mul_u8_u8
, 0, 24, 16, 24, 16);
2402 DP_QB(dpsu_h_qbr
, mul_u8_u8
, 0, 8, 0, 8, 0);
2406 #if defined(TARGET_MIPS64)
2407 #define DP_OB(name, add_sub, \
2408 rsmov1, rsmov2, rsmov3, rsmov4, \
2409 rtmov1, rtmov2, rtmov3, rtmov4) \
2410 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2411 CPUMIPSState *env) \
2413 uint8_t rsD, rsC, rsB, rsA; \
2414 uint8_t rtD, rtC, rtB, rtA; \
2415 uint16_t tempD, tempC, tempB, tempA; \
2418 uint64_t temp_sum; \
2423 rsD = (rs >> rsmov1) & MIPSDSP_Q0; \
2424 rsC = (rs >> rsmov2) & MIPSDSP_Q0; \
2425 rsB = (rs >> rsmov3) & MIPSDSP_Q0; \
2426 rsA = (rs >> rsmov4) & MIPSDSP_Q0; \
2427 rtD = (rt >> rtmov1) & MIPSDSP_Q0; \
2428 rtC = (rt >> rtmov2) & MIPSDSP_Q0; \
2429 rtB = (rt >> rtmov3) & MIPSDSP_Q0; \
2430 rtA = (rt >> rtmov4) & MIPSDSP_Q0; \
2432 tempD = mipsdsp_mul_u8_u8(rsD, rtD); \
2433 tempC = mipsdsp_mul_u8_u8(rsC, rtC); \
2434 tempB = mipsdsp_mul_u8_u8(rsB, rtB); \
2435 tempA = mipsdsp_mul_u8_u8(rsA, rtA); \
2437 temp[0] = (uint64_t)tempD + (uint64_t)tempC + \
2438 (uint64_t)tempB + (uint64_t)tempA; \
2440 acc[0] = env->active_tc.LO[ac]; \
2441 acc[1] = env->active_tc.HI[ac]; \
2444 temp_sum = acc[0] + temp[0]; \
2445 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2446 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2449 temp[0] = temp_sum; \
2450 temp[1] = acc[1] + temp[1]; \
2452 temp_sum = acc[0] - temp[0]; \
2453 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2456 temp[0] = temp_sum; \
2457 temp[1] = acc[1] - temp[1]; \
2460 env->active_tc.HI[ac] = temp[1]; \
2461 env->active_tc.LO[ac] = temp[0]; \
2464 DP_OB(dpau_h_obl
, 1, 56, 48, 40, 32, 56, 48, 40, 32);
2465 DP_OB(dpau_h_obr
, 1, 24, 16, 8, 0, 24, 16, 8, 0);
2466 DP_OB(dpsu_h_obl
, 0, 56, 48, 40, 32, 56, 48, 40, 32);
2467 DP_OB(dpsu_h_obr
, 0, 24, 16, 8, 0, 24, 16, 8, 0);
2472 #define DP_NOFUNC_PH(name, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2473 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2474 CPUMIPSState *env) \
2476 int16_t rsB, rsA, rtB, rtA; \
2477 int32_t tempA, tempB; \
2480 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2481 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2482 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2483 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2485 tempB = (int32_t)rsB * (int32_t)rtB; \
2486 tempA = (int32_t)rsA * (int32_t)rtA; \
2488 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2489 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2492 acc = acc + ((int64_t)tempB + (int64_t)tempA); \
2494 acc = acc - ((int64_t)tempB + (int64_t)tempA); \
2497 env->active_tc.HI[ac] = (target_long)(int32_t)((acc & MIPSDSP_LHI) >> 32); \
2498 env->active_tc.LO[ac] = (target_long)(int32_t)(acc & MIPSDSP_LLO); \
2501 DP_NOFUNC_PH(dpa_w_ph
, 1, 16, 0, 16, 0);
2502 DP_NOFUNC_PH(dpax_w_ph
, 1, 16, 0, 0, 16);
2503 DP_NOFUNC_PH(dps_w_ph
, 0, 16, 0, 16, 0);
2504 DP_NOFUNC_PH(dpsx_w_ph
, 0, 16, 0, 0, 16);
2507 #define DP_HASFUNC_PH(name, is_add, rsmov1, rsmov2, rtmov1, rtmov2) \
2508 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2509 CPUMIPSState *env) \
2511 int16_t rsB, rsA, rtB, rtA; \
2512 int32_t tempB, tempA; \
2513 int64_t acc, dotp; \
2515 rsB = (rs >> rsmov1) & MIPSDSP_LO; \
2516 rsA = (rs >> rsmov2) & MIPSDSP_LO; \
2517 rtB = (rt >> rtmov1) & MIPSDSP_LO; \
2518 rtA = (rt >> rtmov2) & MIPSDSP_LO; \
2520 tempB = mipsdsp_mul_q15_q15(ac, rsB, rtB, env); \
2521 tempA = mipsdsp_mul_q15_q15(ac, rsA, rtA, env); \
2523 dotp = (int64_t)tempB + (int64_t)tempA; \
2524 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2525 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2533 env->active_tc.HI[ac] = (target_long)(int32_t) \
2534 ((acc & MIPSDSP_LHI) >> 32); \
2535 env->active_tc.LO[ac] = (target_long)(int32_t) \
2536 (acc & MIPSDSP_LLO); \
2539 DP_HASFUNC_PH(dpaq_s_w_ph
, 1, 16, 0, 16, 0);
2540 DP_HASFUNC_PH(dpaqx_s_w_ph
, 1, 16, 0, 0, 16);
2541 DP_HASFUNC_PH(dpsq_s_w_ph
, 0, 16, 0, 16, 0);
2542 DP_HASFUNC_PH(dpsqx_s_w_ph
, 0, 16, 0, 0, 16);
2544 #undef DP_HASFUNC_PH
2546 #define DP_128OPERATION_PH(name, is_add) \
2547 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2548 CPUMIPSState *env) \
2550 int16_t rsh, rsl, rth, rtl; \
2551 int32_t tempB, tempA, tempC62_31, tempC63; \
2552 int64_t acc, dotp, tempC; \
2554 MIPSDSP_SPLIT32_16(rs, rsh, rsl); \
2555 MIPSDSP_SPLIT32_16(rt, rth, rtl); \
2557 tempB = mipsdsp_mul_q15_q15(ac, rsh, rtl, env); \
2558 tempA = mipsdsp_mul_q15_q15(ac, rsl, rth, env); \
2560 dotp = (int64_t)tempB + (int64_t)tempA; \
2561 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2562 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2564 tempC = acc + dotp; \
2566 tempC = acc - dotp; \
2568 tempC63 = (tempC >> 63) & 0x01; \
2569 tempC62_31 = (tempC >> 31) & 0xFFFFFFFF; \
2571 if ((tempC63 == 0) && (tempC62_31 != 0x00000000)) { \
2572 tempC = 0x7FFFFFFF; \
2573 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2576 if ((tempC63 == 1) && (tempC62_31 != 0xFFFFFFFF)) { \
2577 tempC = (int64_t)(int32_t)0x80000000; \
2578 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2581 env->active_tc.HI[ac] = (target_long)(int32_t) \
2582 ((tempC & MIPSDSP_LHI) >> 32); \
2583 env->active_tc.LO[ac] = (target_long)(int32_t) \
2584 (tempC & MIPSDSP_LLO); \
2587 DP_128OPERATION_PH(dpaqx_sa_w_ph
, 1);
2588 DP_128OPERATION_PH(dpsqx_sa_w_ph
, 0);
2590 #undef DP_128OPERATION_HP
2592 #if defined(TARGET_MIPS64)
2593 #define DP_QH(name, is_add, use_ac_env) \
2594 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2595 CPUMIPSState *env) \
2597 int32_t rs3, rs2, rs1, rs0; \
2598 int32_t rt3, rt2, rt1, rt0; \
2599 int32_t tempD, tempC, tempB, tempA; \
2604 MIPSDSP_SPLIT64_16(rs, rs3, rs2, rs1, rs0); \
2605 MIPSDSP_SPLIT64_16(rt, rt3, rt2, rt1, rt0); \
2608 tempD = mipsdsp_mul_q15_q15(ac, rs3, rt3, env); \
2609 tempC = mipsdsp_mul_q15_q15(ac, rs2, rt2, env); \
2610 tempB = mipsdsp_mul_q15_q15(ac, rs1, rt1, env); \
2611 tempA = mipsdsp_mul_q15_q15(ac, rs0, rt0, env); \
2613 tempD = mipsdsp_mul_u16_u16(rs3, rt3); \
2614 tempC = mipsdsp_mul_u16_u16(rs2, rt2); \
2615 tempB = mipsdsp_mul_u16_u16(rs1, rt1); \
2616 tempA = mipsdsp_mul_u16_u16(rs0, rt0); \
2619 temp[0] = (int64_t)tempD + (int64_t)tempC + \
2620 (int64_t)tempB + (int64_t)tempA; \
2622 if (temp[0] >= 0) { \
2628 acc[1] = env->active_tc.HI[ac]; \
2629 acc[0] = env->active_tc.LO[ac]; \
2632 temp_sum = acc[0] + temp[0]; \
2633 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2634 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2635 acc[1] = acc[1] + 1; \
2637 temp[0] = temp_sum; \
2638 temp[1] = acc[1] + temp[1]; \
2640 temp_sum = acc[0] - temp[0]; \
2641 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
2642 acc[1] = acc[1] - 1; \
2644 temp[0] = temp_sum; \
2645 temp[1] = acc[1] - temp[1]; \
2648 env->active_tc.HI[ac] = temp[1]; \
2649 env->active_tc.LO[ac] = temp[0]; \
2652 DP_QH(dpa_w_qh
, 1, 0);
2653 DP_QH(dpaq_s_w_qh
, 1, 1);
2654 DP_QH(dps_w_qh
, 0, 0);
2655 DP_QH(dpsq_s_w_qh
, 0, 1);
2661 #define DP_L_W(name, is_add) \
2662 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2663 CPUMIPSState *env) \
2666 int64_t dotp, acc; \
2669 dotp = mipsdsp_mul_q31_q31(ac, rs, rt, env); \
2670 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2671 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2676 temp = acc + dotp; \
2677 if (MIPSDSP_OVERFLOW((uint64_t)acc, (uint64_t)dotp, temp, \
2678 (0x01ull << 63))) { \
2679 temp63 = (temp >> 63) & 0x01; \
2680 if (temp63 == 1) { \
2681 temp = (0x01ull << 63) - 1; \
2683 temp = 0x01ull << 63; \
2686 set_DSPControl_overflow_flag(1, 16 + ac, env); \
2689 env->active_tc.HI[ac] = (target_long)(int32_t) \
2690 ((temp & MIPSDSP_LHI) >> 32); \
2691 env->active_tc.LO[ac] = (target_long)(int32_t) \
2692 (temp & MIPSDSP_LLO); \
2695 DP_L_W(dpaq_sa_l_w
, 1);
2696 DP_L_W(dpsq_sa_l_w
, 0);
2700 #if defined(TARGET_MIPS64)
2701 #define DP_L_PW(name, func) \
2702 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2703 CPUMIPSState *env) \
2707 int64_t tempB[2], tempA[2]; \
2715 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
2716 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
2718 tempB[0] = mipsdsp_mul_q31_q31(ac, rs1, rt1, env); \
2719 tempA[0] = mipsdsp_mul_q31_q31(ac, rs0, rt0, env); \
2721 if (tempB[0] >= 0) { \
2727 if (tempA[0] >= 0) { \
2733 temp_sum = tempB[0] + tempA[0]; \
2734 if (((uint64_t)temp_sum < (uint64_t)tempB[0]) && \
2735 ((uint64_t)temp_sum < (uint64_t)tempA[0])) { \
2738 temp[0] = temp_sum; \
2739 temp[1] += tempB[1] + tempA[1]; \
2741 mipsdsp_##func(acc, ac, temp, env); \
2743 env->active_tc.HI[ac] = acc[1]; \
2744 env->active_tc.LO[ac] = acc[0]; \
2747 DP_L_PW(dpaq_sa_l_pw
, sat64_acc_add_q63
);
2748 DP_L_PW(dpsq_sa_l_pw
, sat64_acc_sub_q63
);
2752 void helper_mulsaq_s_l_pw(target_ulong rs
, target_ulong rt
, uint32_t ac
,
2757 int64_t tempB
[2], tempA
[2];
2762 rs1
= (rs
>> 32) & MIPSDSP_LLO
;
2763 rs0
= rs
& MIPSDSP_LLO
;
2764 rt1
= (rt
>> 32) & MIPSDSP_LLO
;
2765 rt0
= rt
& MIPSDSP_LLO
;
2767 tempB
[0] = mipsdsp_mul_q31_q31(ac
, rs1
, rt1
, env
);
2768 tempA
[0] = mipsdsp_mul_q31_q31(ac
, rs0
, rt0
, env
);
2770 if (tempB
[0] >= 0) {
2776 if (tempA
[0] >= 0) {
2782 acc
[0] = env
->active_tc
.LO
[ac
];
2783 acc
[1] = env
->active_tc
.HI
[ac
];
2785 temp_sum
= tempB
[0] - tempA
[0];
2786 if ((uint64_t)temp_sum
> (uint64_t)tempB
[0]) {
2790 temp
[1] = tempB
[1] - tempA
[1];
2792 if ((temp
[1] & 0x01) == 0) {
2798 temp_sum
= acc
[0] + temp
[0];
2799 if (((uint64_t)temp_sum
< (uint64_t)acc
[0]) &&
2800 ((uint64_t)temp_sum
< (uint64_t)temp
[0])) {
2806 env
->active_tc
.HI
[ac
] = acc
[1];
2807 env
->active_tc
.LO
[ac
] = acc
[0];
2811 #define MAQ_S_W(name, mov) \
2812 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2813 CPUMIPSState *env) \
2817 int64_t tempL, acc; \
2819 rsh = (rs >> mov) & MIPSDSP_LO; \
2820 rth = (rt >> mov) & MIPSDSP_LO; \
2821 tempA = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2822 acc = ((uint64_t)env->active_tc.HI[ac] << 32) | \
2823 ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); \
2824 tempL = (int64_t)tempA + acc; \
2825 env->active_tc.HI[ac] = (target_long)(int32_t) \
2826 ((tempL & MIPSDSP_LHI) >> 32); \
2827 env->active_tc.LO[ac] = (target_long)(int32_t) \
2828 (tempL & MIPSDSP_LLO); \
2831 MAQ_S_W(maq_s_w_phl
, 16);
2832 MAQ_S_W(maq_s_w_phr
, 0);
2836 #define MAQ_SA_W(name, mov) \
2837 void helper_##name(uint32_t ac, target_ulong rs, target_ulong rt, \
2838 CPUMIPSState *env) \
2843 rsh = (rs >> mov) & MIPSDSP_LO; \
2844 rth = (rt >> mov) & MIPSDSP_LO; \
2845 tempA = mipsdsp_mul_q15_q15(ac, rsh, rth, env); \
2846 tempA = mipsdsp_sat32_acc_q31(ac, tempA, env); \
2848 env->active_tc.HI[ac] = (target_long)(int32_t)(((int64_t)tempA & \
2849 MIPSDSP_LHI) >> 32); \
2850 env->active_tc.LO[ac] = (target_long)(int32_t)((int64_t)tempA & \
2854 MAQ_SA_W(maq_sa_w_phl
, 16);
2855 MAQ_SA_W(maq_sa_w_phr
, 0);
2859 #define MULQ_W(name, addvar) \
2860 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
2861 CPUMIPSState *env) \
2863 uint32_t rs_t, rt_t; \
2867 rs_t = rs & MIPSDSP_LLO; \
2868 rt_t = rt & MIPSDSP_LLO; \
2870 if ((rs_t == 0x80000000) && (rt_t == 0x80000000)) { \
2871 tempL = 0x7FFFFFFF00000000ull; \
2872 set_DSPControl_overflow_flag(1, 21, env); \
2874 tempL = ((int64_t)rs_t * (int64_t)rt_t) << 1; \
2877 tempI = (tempL & MIPSDSP_LHI) >> 32; \
2879 return (target_long)(int32_t)tempI; \
2882 MULQ_W(mulq_s_w
, 0);
2883 MULQ_W(mulq_rs_w
, 0x80000000ull
);
2887 #if defined(TARGET_MIPS64)
2889 #define MAQ_S_W_QH(name, mov) \
2890 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2891 CPUMIPSState *env) \
2893 int16_t rs_t, rt_t; \
2902 rs_t = (rs >> mov) & MIPSDSP_LO; \
2903 rt_t = (rt >> mov) & MIPSDSP_LO; \
2904 temp_mul = mipsdsp_mul_q15_q15(ac, rs_t, rt_t, env); \
2906 temp[0] = (int64_t)temp_mul; \
2907 if (temp[0] >= 0) { \
2913 acc[0] = env->active_tc.LO[ac]; \
2914 acc[1] = env->active_tc.HI[ac]; \
2916 temp_sum = acc[0] + temp[0]; \
2917 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2918 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2921 acc[0] = temp_sum; \
2922 acc[1] += temp[1]; \
2924 env->active_tc.HI[ac] = acc[1]; \
2925 env->active_tc.LO[ac] = acc[0]; \
2928 MAQ_S_W_QH(maq_s_w_qhll
, 48);
2929 MAQ_S_W_QH(maq_s_w_qhlr
, 32);
2930 MAQ_S_W_QH(maq_s_w_qhrl
, 16);
2931 MAQ_S_W_QH(maq_s_w_qhrr
, 0);
2935 #define MAQ_SA_W(name, mov) \
2936 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2937 CPUMIPSState *env) \
2939 int16_t rs_t, rt_t; \
2943 rs_t = (rs >> mov) & MIPSDSP_LO; \
2944 rt_t = (rt >> mov) & MIPSDSP_LO; \
2945 temp = mipsdsp_mul_q15_q15(ac, rs_t, rt_t, env); \
2946 temp = mipsdsp_sat32_acc_q31(ac, temp, env); \
2948 acc[0] = (int64_t)(int32_t)temp; \
2949 if (acc[0] >= 0) { \
2955 env->active_tc.HI[ac] = acc[1]; \
2956 env->active_tc.LO[ac] = acc[0]; \
2959 MAQ_SA_W(maq_sa_w_qhll
, 48);
2960 MAQ_SA_W(maq_sa_w_qhlr
, 32);
2961 MAQ_SA_W(maq_sa_w_qhrl
, 16);
2962 MAQ_SA_W(maq_sa_w_qhrr
, 0);
2966 #define MAQ_S_L_PW(name, mov) \
2967 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
2968 CPUMIPSState *env) \
2970 int32_t rs_t, rt_t; \
2978 rs_t = (rs >> mov) & MIPSDSP_LLO; \
2979 rt_t = (rt >> mov) & MIPSDSP_LLO; \
2981 temp[0] = mipsdsp_mul_q31_q31(ac, rs_t, rt_t, env); \
2982 if (temp[0] >= 0) { \
2988 acc[0] = env->active_tc.LO[ac]; \
2989 acc[1] = env->active_tc.HI[ac]; \
2991 temp_sum = acc[0] + temp[0]; \
2992 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
2993 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
2996 acc[0] = temp_sum; \
2997 acc[1] += temp[1]; \
2999 env->active_tc.HI[ac] = acc[1]; \
3000 env->active_tc.LO[ac] = acc[0]; \
3003 MAQ_S_L_PW(maq_s_l_pwl
, 32);
3004 MAQ_S_L_PW(maq_s_l_pwr
, 0);
3008 #define DM_OPERATE(name, func, is_add, sigext) \
3009 void helper_##name(target_ulong rs, target_ulong rt, uint32_t ac, \
3010 CPUMIPSState *env) \
3014 int64_t tempBL[2], tempAL[2]; \
3022 MIPSDSP_SPLIT64_32(rs, rs1, rs0); \
3023 MIPSDSP_SPLIT64_32(rt, rt1, rt0); \
3026 tempBL[0] = (int64_t)mipsdsp_##func(rs1, rt1); \
3027 tempAL[0] = (int64_t)mipsdsp_##func(rs0, rt0); \
3029 if (tempBL[0] >= 0) { \
3032 tempBL[1] = ~0ull; \
3035 if (tempAL[0] >= 0) { \
3038 tempAL[1] = ~0ull; \
3041 tempBL[0] = mipsdsp_##func(rs1, rt1); \
3042 tempAL[0] = mipsdsp_##func(rs0, rt0); \
3047 acc[1] = env->active_tc.HI[ac]; \
3048 acc[0] = env->active_tc.LO[ac]; \
3050 temp_sum = tempBL[0] + tempAL[0]; \
3051 if (((uint64_t)temp_sum < (uint64_t)tempBL[0]) && \
3052 ((uint64_t)temp_sum < (uint64_t)tempAL[0])) { \
3055 temp[0] = temp_sum; \
3056 temp[1] += tempBL[1] + tempAL[1]; \
3059 temp_sum = acc[0] + temp[0]; \
3060 if (((uint64_t)temp_sum < (uint64_t)acc[0]) && \
3061 ((uint64_t)temp_sum < (uint64_t)temp[0])) { \
3064 temp[0] = temp_sum; \
3065 temp[1] = acc[1] + temp[1]; \
3067 temp_sum = acc[0] - temp[0]; \
3068 if ((uint64_t)temp_sum > (uint64_t)acc[0]) { \
3071 temp[0] = temp_sum; \
3072 temp[1] = acc[1] - temp[1]; \
3075 env->active_tc.HI[ac] = temp[1]; \
3076 env->active_tc.LO[ac] = temp[0]; \
3079 DM_OPERATE(dmadd
, mul_i32_i32
, 1, 1);
3080 DM_OPERATE(dmaddu
, mul_u32_u32
, 1, 0);
3081 DM_OPERATE(dmsub
, mul_i32_i32
, 0, 1);
3082 DM_OPERATE(dmsubu
, mul_u32_u32
, 0, 0);
3086 /** DSP Bit/Manipulation Sub-class insns **/
3087 target_ulong
helper_bitrev(target_ulong rt
)
3093 temp
= rt
& MIPSDSP_LO
;
3095 for (i
= 0; i
< 16; i
++) {
3096 rd
= (rd
<< 1) | (temp
& 1);
3100 return (target_ulong
)rd
;
3103 #define BIT_INSV(name, posfilter, sizefilter, ret_type) \
3104 target_ulong helper_##name(CPUMIPSState *env, target_ulong rs, \
3107 uint32_t pos, size, msb, lsb; \
3108 target_ulong filter; \
3109 target_ulong temp, temprs, temprt; \
3110 target_ulong dspc; \
3112 dspc = env->active_tc.DSPControl; \
3114 pos = dspc & posfilter; \
3115 size = (dspc >> 7) & sizefilter; \
3117 msb = pos + size - 1; \
3120 if (lsb > msb || (msb > TARGET_LONG_BITS)) { \
3124 filter = ((int32_t)0x01 << size) - 1; \
3125 filter = filter << pos; \
3126 temprs = (rs << pos) & filter; \
3127 temprt = rt & ~filter; \
3128 temp = temprs | temprt; \
3130 return (target_long)(ret_type)temp; \
3133 BIT_INSV(insv
, 0x1F, 0x1F, int32_t);
3134 #ifdef TARGET_MIPS64
3135 BIT_INSV(dinsv
, 0x7F, 0x3F, target_long
);
3141 /** DSP Compare-Pick Sub-class insns **/
3142 #define CMP_HAS_RET(name, func, split_num, filter, bit_size) \
3143 target_ulong helper_##name(target_ulong rs, target_ulong rt) \
3145 uint32_t rs_t, rt_t; \
3147 uint32_t temp = 0; \
3150 for (i = 0; i < split_num; i++) { \
3151 rs_t = (rs >> (bit_size * i)) & filter; \
3152 rt_t = (rt >> (bit_size * i)) & filter; \
3153 cc = mipsdsp_##func(rs_t, rt_t); \
3157 return (target_ulong)temp; \
3160 CMP_HAS_RET(cmpgu_eq_qb
, cmpu_eq
, 4, MIPSDSP_Q0
, 8);
3161 CMP_HAS_RET(cmpgu_lt_qb
, cmpu_lt
, 4, MIPSDSP_Q0
, 8);
3162 CMP_HAS_RET(cmpgu_le_qb
, cmpu_le
, 4, MIPSDSP_Q0
, 8);
3164 #ifdef TARGET_MIPS64
3165 CMP_HAS_RET(cmpgu_eq_ob
, cmpu_eq
, 8, MIPSDSP_Q0
, 8);
3166 CMP_HAS_RET(cmpgu_lt_ob
, cmpu_lt
, 8, MIPSDSP_Q0
, 8);
3167 CMP_HAS_RET(cmpgu_le_ob
, cmpu_le
, 8, MIPSDSP_Q0
, 8);
3173 #define CMP_NO_RET(name, func, split_num, filter, bit_size) \
3174 void helper_##name(target_ulong rs, target_ulong rt, \
3175 CPUMIPSState *env) \
3177 int##bit_size##_t rs_t, rt_t; \
3178 int##bit_size##_t flag = 0; \
3179 int##bit_size##_t cc; \
3182 for (i = 0; i < split_num; i++) { \
3183 rs_t = (rs >> (bit_size * i)) & filter; \
3184 rt_t = (rt >> (bit_size * i)) & filter; \
3186 cc = mipsdsp_##func((int32_t)rs_t, (int32_t)rt_t); \
3190 set_DSPControl_24(flag, split_num, env); \
3193 CMP_NO_RET(cmpu_eq_qb
, cmpu_eq
, 4, MIPSDSP_Q0
, 8);
3194 CMP_NO_RET(cmpu_lt_qb
, cmpu_lt
, 4, MIPSDSP_Q0
, 8);
3195 CMP_NO_RET(cmpu_le_qb
, cmpu_le
, 4, MIPSDSP_Q0
, 8);
3197 CMP_NO_RET(cmp_eq_ph
, cmp_eq
, 2, MIPSDSP_LO
, 16);
3198 CMP_NO_RET(cmp_lt_ph
, cmp_lt
, 2, MIPSDSP_LO
, 16);
3199 CMP_NO_RET(cmp_le_ph
, cmp_le
, 2, MIPSDSP_LO
, 16);
3201 #ifdef TARGET_MIPS64
3202 CMP_NO_RET(cmpu_eq_ob
, cmpu_eq
, 8, MIPSDSP_Q0
, 8);
3203 CMP_NO_RET(cmpu_lt_ob
, cmpu_lt
, 8, MIPSDSP_Q0
, 8);
3204 CMP_NO_RET(cmpu_le_ob
, cmpu_le
, 8, MIPSDSP_Q0
, 8);
3206 CMP_NO_RET(cmp_eq_qh
, cmp_eq
, 4, MIPSDSP_LO
, 16);
3207 CMP_NO_RET(cmp_lt_qh
, cmp_lt
, 4, MIPSDSP_LO
, 16);
3208 CMP_NO_RET(cmp_le_qh
, cmp_le
, 4, MIPSDSP_LO
, 16);
3210 CMP_NO_RET(cmp_eq_pw
, cmp_eq
, 2, MIPSDSP_LLO
, 32);
3211 CMP_NO_RET(cmp_lt_pw
, cmp_lt
, 2, MIPSDSP_LLO
, 32);
3212 CMP_NO_RET(cmp_le_pw
, cmp_le
, 2, MIPSDSP_LLO
, 32);
3216 #if defined(TARGET_MIPS64)
3218 #define CMPGDU_OB(name) \
3219 target_ulong helper_cmpgdu_##name##_ob(target_ulong rs, target_ulong rt, \
3220 CPUMIPSState *env) \
3223 uint8_t rs_t, rt_t; \
3228 for (i = 0; i < 8; i++) { \
3229 rs_t = (rs >> (8 * i)) & MIPSDSP_Q0; \
3230 rt_t = (rt >> (8 * i)) & MIPSDSP_Q0; \
3232 if (mipsdsp_cmpu_##name(rs_t, rt_t)) { \
3233 cond |= 0x01 << i; \
3237 set_DSPControl_24(cond, 8, env); \
3239 return (uint64_t)cond; \
3248 #define PICK_INSN(name, split_num, filter, bit_size, ret32bit) \
3249 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
3250 CPUMIPSState *env) \
3252 uint32_t rs_t, rt_t; \
3256 target_ulong result = 0; \
3258 dsp = env->active_tc.DSPControl; \
3259 for (i = 0; i < split_num; i++) { \
3260 rs_t = (rs >> (bit_size * i)) & filter; \
3261 rt_t = (rt >> (bit_size * i)) & filter; \
3262 cc = (dsp >> (24 + i)) & 0x01; \
3263 cc = cc == 1 ? rs_t : rt_t; \
3265 result |= (target_ulong)cc << (bit_size * i); \
3269 result = (target_long)(int32_t)(result & MIPSDSP_LLO); \
3275 PICK_INSN(pick_qb
, 4, MIPSDSP_Q0
, 8, 1);
3276 PICK_INSN(pick_ph
, 2, MIPSDSP_LO
, 16, 1);
3278 #ifdef TARGET_MIPS64
3279 PICK_INSN(pick_ob
, 8, MIPSDSP_Q0
, 8, 0);
3280 PICK_INSN(pick_qh
, 4, MIPSDSP_LO
, 16, 0);
3281 PICK_INSN(pick_pw
, 2, MIPSDSP_LLO
, 32, 0);
3285 #define APPEND_INSN(name, ret_32) \
3286 target_ulong helper_##name(target_ulong rt, target_ulong rs, uint32_t sa) \
3288 target_ulong temp; \
3291 temp = ((rt & MIPSDSP_LLO) << sa) | \
3292 ((rs & MIPSDSP_LLO) & ((0x01 << sa) - 1)); \
3293 temp = (target_long)(int32_t)(temp & MIPSDSP_LLO); \
3295 temp = (rt << sa) | (rs & ((0x01 << sa) - 1)); \
3301 APPEND_INSN(append
, 1);
3302 #ifdef TARGET_MIPS64
3303 APPEND_INSN(dappend
, 0);
3307 #define PREPEND_INSN(name, or_val, ret_32) \
3308 target_ulong helper_##name(target_ulong rs, target_ulong rt, \
3314 return (target_long)(int32_t)(uint32_t) \
3315 (((rs & MIPSDSP_LLO) << (32 - sa)) | \
3316 ((rt & MIPSDSP_LLO) >> sa)); \
3318 return (rs << (64 - sa)) | (rt >> sa); \
3322 PREPEND_INSN(prepend
, 0, 1);
3323 #ifdef TARGET_MIPS64
3324 PREPEND_INSN(prependw
, 0, 0);
3325 PREPEND_INSN(prependd
, 0x20, 0);
3329 #define BALIGN_INSN(name, filter, ret32) \
3330 target_ulong helper_##name(target_ulong rs, target_ulong rt, uint32_t bp) \
3334 if ((bp & 1) == 0) { \
3338 return (target_long)(int32_t)((rt << (8 * bp)) | \
3339 (rs >> (8 * (4 - bp)))); \
3341 return (rt << (8 * bp)) | (rs >> (8 * (8 - bp))); \
3346 BALIGN_INSN(balign
, 0x03, 1);
3347 #if defined(TARGET_MIPS64)
3348 BALIGN_INSN(dbalign
, 0x07, 0);
3352 target_ulong
helper_packrl_ph(target_ulong rs
, target_ulong rt
)
3356 rsl
= rs
& MIPSDSP_LO
;
3357 rth
= (rt
& MIPSDSP_HI
) >> 16;
3359 return (target_long
)(int32_t)((rsl
<< 16) | rth
);
3362 #if defined(TARGET_MIPS64)
3363 target_ulong
helper_packrl_pw(target_ulong rs
, target_ulong rt
)
3367 rs0
= rs
& MIPSDSP_LLO
;
3368 rt1
= (rt
>> 32) & MIPSDSP_LLO
;
3370 return ((uint64_t)rs0
<< 32) | (uint64_t)rt1
;
3374 /** DSP Accumulator and DSPControl Access Sub-class insns **/
3375 target_ulong
helper_extr_w(target_ulong ac
, target_ulong shift
,
3381 shift
= shift
& 0x1F;
3383 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3384 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3385 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3386 set_DSPControl_overflow_flag(1, 23, env
);
3389 tempI
= (tempDL
[0] >> 1) & MIPSDSP_LLO
;
3392 if (tempDL
[0] == 0) {
3396 if ((!(tempDL
[1] == 0 && (tempDL
[0] & MIPSDSP_LHI
) == 0x00)) &&
3397 (!(tempDL
[1] == 1 && (tempDL
[0] & MIPSDSP_LHI
) == MIPSDSP_LHI
))) {
3398 set_DSPControl_overflow_flag(1, 23, env
);
3401 return (target_long
)tempI
;
3404 target_ulong
helper_extr_r_w(target_ulong ac
, target_ulong shift
,
3409 shift
= shift
& 0x1F;
3411 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3412 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3413 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3414 set_DSPControl_overflow_flag(1, 23, env
);
3418 if (tempDL
[0] == 0) {
3422 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3423 (tempDL
[1] != 1 && (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3424 set_DSPControl_overflow_flag(1, 23, env
);
3427 return (target_long
)(int32_t)(tempDL
[0] >> 1);
3430 target_ulong
helper_extr_rs_w(target_ulong ac
, target_ulong shift
,
3433 int32_t tempI
, temp64
;
3436 shift
= shift
& 0x1F;
3438 mipsdsp_rndrashift_short_acc(tempDL
, ac
, shift
, env
);
3439 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3440 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3441 set_DSPControl_overflow_flag(1, 23, env
);
3444 if (tempDL
[0] == 0) {
3447 tempI
= tempDL
[0] >> 1;
3449 if ((tempDL
[1] != 0 || (tempDL
[0] & MIPSDSP_LHI
) != 0) &&
3450 (tempDL
[1] != 1 || (tempDL
[0] & MIPSDSP_LHI
) != MIPSDSP_LHI
)) {
3457 set_DSPControl_overflow_flag(1, 23, env
);
3460 return (target_long
)tempI
;
3463 #if defined(TARGET_MIPS64)
3464 target_ulong
helper_dextr_w(target_ulong ac
, target_ulong shift
,
3469 shift
= shift
& 0x3F;
3471 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3473 return (int64_t)(int32_t)(temp
[0] >> 1);
3476 target_ulong
helper_dextr_r_w(target_ulong ac
, target_ulong shift
,
3482 shift
= shift
& 0x3F;
3483 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3493 temp128
= temp
[2] & 0x01;
3495 if ((temp128
!= 0 || temp
[1] != 0) &&
3496 (temp128
!= 1 || temp
[1] != ~0ull)) {
3497 set_DSPControl_overflow_flag(1, 23, env
);
3500 return (int64_t)(int32_t)(temp
[0] >> 1);
3503 target_ulong
helper_dextr_rs_w(target_ulong ac
, target_ulong shift
,
3509 shift
= shift
& 0x3F;
3510 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3520 temp128
= temp
[2] & 0x01;
3522 if ((temp128
!= 0 || temp
[1] != 0) &&
3523 (temp128
!= 1 || temp
[1] != ~0ull)) {
3525 temp
[0] = 0x0FFFFFFFF;
3527 temp
[0] = 0x0100000000ULL
;
3529 set_DSPControl_overflow_flag(1, 23, env
);
3532 return (int64_t)(int32_t)(temp
[0] >> 1);
3535 target_ulong
helper_dextr_l(target_ulong ac
, target_ulong shift
,
3539 target_ulong result
;
3541 shift
= shift
& 0x3F;
3543 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3544 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3549 target_ulong
helper_dextr_r_l(target_ulong ac
, target_ulong shift
,
3554 target_ulong result
;
3556 shift
= shift
& 0x3F;
3557 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3567 temp128
= temp
[2] & 0x01;
3569 if ((temp128
!= 0 || temp
[1] != 0) &&
3570 (temp128
!= 1 || temp
[1] != ~0ull)) {
3571 set_DSPControl_overflow_flag(1, 23, env
);
3574 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3579 target_ulong
helper_dextr_rs_l(target_ulong ac
, target_ulong shift
,
3584 target_ulong result
;
3586 shift
= shift
& 0x3F;
3587 mipsdsp_rndrashift_acc(temp
, ac
, shift
, env
);
3597 temp128
= temp
[2] & 0x01;
3599 if ((temp128
!= 0 || temp
[1] != 0) &&
3600 (temp128
!= 1 || temp
[1] != ~0ull)) {
3602 temp
[1] &= ~0x00ull
- 1;
3603 temp
[0] |= ~0x00ull
- 1;
3608 set_DSPControl_overflow_flag(1, 23, env
);
3610 result
= (temp
[1] << 63) | (temp
[0] >> 1);
3616 target_ulong
helper_extr_s_h(target_ulong ac
, target_ulong shift
,
3621 shift
= shift
& 0x1F;
3623 acc
= ((int64_t)env
->active_tc
.HI
[ac
] << 32) |
3624 ((int64_t)env
->active_tc
.LO
[ac
] & 0xFFFFFFFF);
3626 temp
= acc
>> shift
;
3628 if (temp
> (int64_t)0x7FFF) {
3630 set_DSPControl_overflow_flag(1, 23, env
);
3631 } else if (temp
< (int64_t)0xFFFFFFFFFFFF8000ULL
) {
3633 set_DSPControl_overflow_flag(1, 23, env
);
3636 return (target_long
)(int32_t)(temp
& 0xFFFFFFFF);
3640 #if defined(TARGET_MIPS64)
3641 target_ulong
helper_dextr_s_h(target_ulong ac
, target_ulong shift
,
3647 shift
= shift
& 0x1F;
3649 mipsdsp_rashift_acc((uint64_t *)temp
, ac
, shift
, env
);
3651 temp127
= (temp
[1] >> 63) & 0x01;
3653 if ((temp127
== 0) && (temp
[1] > 0 || temp
[0] > 32767)) {
3654 temp
[0] &= 0xFFFF0000;
3655 temp
[0] |= 0x00007FFF;
3656 set_DSPControl_overflow_flag(1, 23, env
);
3657 } else if ((temp127
== 1) &&
3658 (temp
[1] < 0xFFFFFFFFFFFFFFFFll
3659 || temp
[0] < 0xFFFFFFFFFFFF1000ll
)) {
3660 temp
[0] &= 0xFFFF0000;
3661 temp
[0] |= 0x00008000;
3662 set_DSPControl_overflow_flag(1, 23, env
);
3665 return (int64_t)(int16_t)(temp
[0] & MIPSDSP_LO
);
3670 target_ulong
helper_extp(target_ulong ac
, target_ulong size
, CPUMIPSState
*env
)
3680 start_pos
= get_DSPControl_pos(env
);
3681 sub
= start_pos
- (size
+ 1);
3683 acc
= ((uint64_t)env
->active_tc
.HI
[ac
] << 32) |
3684 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3685 temp
= (acc
>> (start_pos
- size
)) &
3686 (((uint32_t)0x01 << (size
+ 1)) - 1);
3687 set_DSPControl_efi(0, env
);
3689 set_DSPControl_efi(1, env
);
3692 return (target_ulong
)temp
;
3695 target_ulong
helper_extpdp(target_ulong ac
, target_ulong size
,
3705 start_pos
= get_DSPControl_pos(env
);
3706 sub
= start_pos
- (size
+ 1);
3708 acc
= ((uint64_t)env
->active_tc
.HI
[ac
] << 32) |
3709 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3710 temp
= (acc
>> (start_pos
- size
)) &
3711 (((uint32_t)0x01 << (size
+ 1)) - 1);
3713 set_DSPControl_pos(start_pos
- (size
+ 1), env
);
3714 set_DSPControl_efi(0, env
);
3716 set_DSPControl_efi(1, env
);
3719 return (target_ulong
)temp
;
3723 #if defined(TARGET_MIPS64)
3724 target_ulong
helper_dextp(target_ulong ac
, target_ulong size
, CPUMIPSState
*env
)
3729 uint64_t tempB
, tempA
;
3735 start_pos
= get_DSPControl_pos(env
);
3736 len
= start_pos
- size
;
3737 tempB
= env
->active_tc
.HI
[ac
];
3738 tempA
= env
->active_tc
.LO
[ac
];
3740 sub
= start_pos
- (size
+ 1);
3743 temp
= (tempB
<< (64 - len
)) | (tempA
>> len
);
3744 temp
= temp
& ((0x01 << (size
+ 1)) - 1);
3745 set_DSPControl_efi(0, env
);
3747 set_DSPControl_efi(1, env
);
3753 target_ulong
helper_dextpdp(target_ulong ac
, target_ulong size
,
3759 uint64_t tempB
, tempA
;
3764 start_pos
= get_DSPControl_pos(env
);
3765 len
= start_pos
- size
;
3766 tempB
= env
->active_tc
.HI
[ac
];
3767 tempA
= env
->active_tc
.LO
[ac
];
3769 sub
= start_pos
- (size
+ 1);
3772 temp
= (tempB
<< (64 - len
)) | (tempA
>> len
);
3773 temp
= temp
& ((0x01 << (size
+ 1)) - 1);
3774 set_DSPControl_pos(sub
, env
);
3775 set_DSPControl_efi(0, env
);
3777 set_DSPControl_efi(1, env
);
3785 void helper_shilo(target_ulong ac
, target_ulong rs
, CPUMIPSState
*env
)
3791 rs5_0
= (int8_t)(rs5_0
<< 2) >> 2;
3793 if (unlikely(rs5_0
== 0)) {
3797 acc
= (((uint64_t)env
->active_tc
.HI
[ac
] << 32) & MIPSDSP_LHI
) |
3798 ((uint64_t)env
->active_tc
.LO
[ac
] & MIPSDSP_LLO
);
3801 temp
= acc
>> rs5_0
;
3803 temp
= acc
<< -rs5_0
;
3806 env
->active_tc
.HI
[ac
] = (target_ulong
)(int32_t)((temp
& MIPSDSP_LHI
) >> 32);
3807 env
->active_tc
.LO
[ac
] = (target_ulong
)(int32_t)(temp
& MIPSDSP_LLO
);
3810 #if defined(TARGET_MIPS64)
3811 void helper_dshilo(target_ulong shift
, target_ulong ac
, CPUMIPSState
*env
)
3814 uint64_t tempB
, tempA
;
3816 shift_t
= (int8_t)(shift
<< 1) >> 1;
3818 tempB
= env
->active_tc
.HI
[ac
];
3819 tempA
= env
->active_tc
.LO
[ac
];
3823 tempA
= (tempB
<< (64 - shift_t
)) | (tempA
>> shift_t
);
3824 tempB
= tempB
>> shift_t
;
3827 tempB
= (tempB
<< shift_t
) | (tempA
>> (64 - shift_t
));
3828 tempA
= tempA
<< shift_t
;
3832 env
->active_tc
.HI
[ac
] = tempB
;
3833 env
->active_tc
.LO
[ac
] = tempA
;
3837 void helper_mthlip(target_ulong ac
, target_ulong rs
, CPUMIPSState
*env
)
3839 int32_t tempA
, tempB
, pos
;
3842 tempB
= env
->active_tc
.LO
[ac
];
3843 env
->active_tc
.HI
[ac
] = (target_long
)tempB
;
3844 env
->active_tc
.LO
[ac
] = (target_long
)tempA
;
3845 pos
= get_DSPControl_pos(env
);
3850 set_DSPControl_pos(pos
+ 32, env
);
3854 #if defined(TARGET_MIPS64)
3855 void helper_dmthlip(target_ulong rs
, target_ulong ac
, CPUMIPSState
*env
)
3859 uint64_t tempB
, tempA
;
3864 tempB
= env
->active_tc
.LO
[ac_t
];
3866 env
->active_tc
.HI
[ac_t
] = tempB
;
3867 env
->active_tc
.LO
[ac_t
] = tempA
;
3869 pos
= get_DSPControl_pos(env
);
3873 set_DSPControl_pos(pos
, env
);
3878 void helper_wrdsp(target_ulong rs
, target_ulong mask_num
, CPUMIPSState
*env
)
3882 uint32_t newbits
, overwrite
;
3886 overwrite
= 0xFFFFFFFF;
3887 dsp
= env
->active_tc
.DSPControl
;
3889 for (i
= 0; i
< 6; i
++) {
3890 mask
[i
] = (mask_num
>> i
) & 0x01;
3894 #if defined(TARGET_MIPS64)
3895 overwrite
&= 0xFFFFFF80;
3896 newbits
&= 0xFFFFFF80;
3897 newbits
|= 0x0000007F & rs
;
3899 overwrite
&= 0xFFFFFFC0;
3900 newbits
&= 0xFFFFFFC0;
3901 newbits
|= 0x0000003F & rs
;
3906 overwrite
&= 0xFFFFE07F;
3907 newbits
&= 0xFFFFE07F;
3908 newbits
|= 0x00001F80 & rs
;
3912 overwrite
&= 0xFFFFDFFF;
3913 newbits
&= 0xFFFFDFFF;
3914 newbits
|= 0x00002000 & rs
;
3918 overwrite
&= 0xFF00FFFF;
3919 newbits
&= 0xFF00FFFF;
3920 newbits
|= 0x00FF0000 & rs
;
3924 overwrite
&= 0x00FFFFFF;
3925 newbits
&= 0x00FFFFFF;
3926 #if defined(TARGET_MIPS64)
3927 newbits
|= 0xFF000000 & rs
;
3929 newbits
|= 0x0F000000 & rs
;
3934 overwrite
&= 0xFFFFBFFF;
3935 newbits
&= 0xFFFFBFFF;
3936 newbits
|= 0x00004000 & rs
;
3939 dsp
= dsp
& overwrite
;
3940 dsp
= dsp
| newbits
;
3941 env
->active_tc
.DSPControl
= dsp
;
3944 target_ulong
helper_rddsp(target_ulong masknum
, CPUMIPSState
*env
)
3952 for (i
= 0; i
< 6; i
++) {
3953 mask
[i
] = (masknum
& ruler
) >> i
;
3958 dsp
= env
->active_tc
.DSPControl
;
3961 #if defined(TARGET_MIPS64)
3969 temp
|= dsp
& 0x1F80;
3973 temp
|= dsp
& 0x2000;
3977 temp
|= dsp
& 0x00FF0000;
3981 #if defined(TARGET_MIPS64)
3982 temp
|= dsp
& 0xFF000000;
3984 temp
|= dsp
& 0x0F000000;
3989 temp
|= dsp
& 0x4000;
4005 #undef MIPSDSP_SPLIT32_8
4006 #undef MIPSDSP_SPLIT32_16
4008 #undef MIPSDSP_RETURN32
4009 #undef MIPSDSP_RETURN32_8
4010 #undef MIPSDSP_RETURN32_16
4012 #ifdef TARGET_MIPS64
4013 #undef MIPSDSP_SPLIT64_16
4014 #undef MIPSDSP_SPLIT64_32
4015 #undef MIPSDSP_RETURN64_16
4016 #undef MIPSDSP_RETURN64_32