3 // Simulator definition for the MIPS DSP REV 2 ASE.
4 // Copyright (C) 2007 Free Software Foundation, Inc.
5 // Contributed by MIPS Technologies, Inc.
8 // This file is part of GDB, the GNU debugger.
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2, or (at your option)
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with GAS; see the file COPYING. If not, write to the Free
22 // Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 // op: 0 = ADD, 1 = SUB
27 // sat: 0 = no saturation, 1 = saturation
28 :function:::void:do_u_ph_op:int rd, int rs, int rt, int op, int sat
33 unsigned32 v1 = GPR[rs];
34 unsigned32 v2 = GPR[rt];
35 unsigned32 result = 0;
36 for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
38 h1 = (unsigned16)(v1 & 0xffff);
39 h2 = (unsigned16)(v2 & 0xffff);
41 h0 = (unsigned32)h1 + (unsigned32)h2;
43 h0 = (unsigned32)h1 - (unsigned32)h2;
44 if (op == 0 && (h0 > (unsigned32)0x0000ffff)) // ADD SAT
46 DSPCR |= DSPCR_OUFLAG4;
50 else if (op == 1 && h1 < h2) // SUB SAT
52 DSPCR |= DSPCR_OUFLAG4;
56 result |= ((unsigned32)((unsigned16)h0) << i);
58 GPR[rd] = EXTEND32 (result);
61 // op: 0 = ADD, 1 = SUB
62 // round: 0 = no rounding, 1 = rounding
63 :function:::void:do_uh_qb_op:int rd, int rs, int rt, int op, int round
68 unsigned32 v1 = GPR[rs];
69 unsigned32 v2 = GPR[rt];
70 unsigned32 result = 0;
71 for (i = 0; i < 32; i += 8, v1 >>= 8, v2 >>= 8)
73 h1 = (unsigned8)(v1 & 0xff);
74 h2 = (unsigned8)(v2 & 0xff);
76 h0 = (unsigned32)h1 + (unsigned32)h2;
78 h0 = (unsigned32)h1 - (unsigned32)h2;
83 result |= ((unsigned32)((unsigned8)h0) << i);
85 GPR[rd] = EXTEND32 (result);
88 // op: 0 = EQ, 1 = LT, 2 = LE
89 :function:::void:do_qb_cmpgdu:int rd, int rs, int rt, int op
92 unsigned32 v1 = GPR[rs];
93 unsigned32 v2 = GPR[rt];
95 unsigned32 result = 0;
97 for (i = 0, j = 0; i < 32; i += 8, j++, v1 >>= 8, v2 >>= 8)
99 h1 = (unsigned8)(v1 & 0xff);
100 h2 = (unsigned8)(v2 & 0xff);
101 mask = ~(1 << (DSPCR_CCOND_SHIFT + j));
105 result |= ((h1 == h2) << j);
106 DSPCR |= ((h1 == h2) << (DSPCR_CCOND_SHIFT + j));
108 else if (op == 1) // LT
110 result |= ((h1 < h2) << j);
111 DSPCR |= ((h1 < h2) << (DSPCR_CCOND_SHIFT + j));
115 result |= ((h1 <= h2) << j);
116 DSPCR |= ((h1 <= h2) << (DSPCR_CCOND_SHIFT + j));
119 GPR[rd] = EXTEND32 (result);
122 // op: 0 = DPA 1 = DPS
123 :function:::void:do_w_ph_dot_product:int ac, int rs, int rt, int op
126 unsigned32 v1 = GPR[rs];
127 unsigned32 v2 = GPR[rt];
130 unsigned32 lo = DSPLO(ac);
131 unsigned32 hi = DSPHI(ac);
132 signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
133 for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
135 h1 = (signed16)(v1 & 0xffff);
136 h2 = (signed16)(v2 & 0xffff);
137 result = (signed32)h1 * (signed32)h2;
139 prod += (signed64)result;
141 prod -= (signed64)result;
143 DSPLO(ac) = EXTEND32 (prod);
144 DSPHI(ac) = EXTEND32 (prod >> 32);
147 // round: 0 = no rounding, 1 = rounding
148 :function:::void:do_w_mulq:int rd, int rs, int rt, int round
150 unsigned32 v1 = GPR[rs];
151 unsigned32 v2 = GPR[rt];
157 if (w1 == (signed32) 0x80000000 && w2 == (signed32) 0x80000000)
159 DSPCR |= DSPCR_OUFLAG5;
164 prod = ((signed64) w1 * (signed64) w2) << 1;
166 prod += 0x0000000080000000LL;
169 result = (unsigned32) prod;
170 GPR[rd] = EXTEND32 (result);
173 // round: 0 = no rounding, 1 = rounding
174 :function:::void:do_precr_sra:int rt, int rs, int sa, int round
176 unsigned32 v1 = GPR[rt];
177 unsigned32 v2 = GPR[rs];
178 signed32 w1 = (signed32) v1;
179 signed32 w2 = (signed32) v2;
183 if (round == 1 && (w1 & (1 << (sa - 1))))
188 if (round == 1 && (w2 & (1 << (sa - 1))))
193 result = (w1 << 16) | (w2 & 0xffff);
194 GPR[rt] = EXTEND32 (result);
197 // round: 0 = no rounding, 1 = rounding
198 :function:::void:do_qb_shra:int rd, int rt, int shift, int round
202 unsigned32 v1 = GPR[rt];
203 unsigned32 result = 0;
204 for (i = 0; i < 32; i += 8, v1 >>= 8)
206 q0 = (signed8)(v1 & 0xff);
209 if (round == 1 && (q0 & (1 << (shift - 1))))
210 q0 = (q0 >> shift) + 1;
214 result |= ((unsigned32)((unsigned8)q0) << i);
216 GPR[rd] = EXTEND32 (result);
219 :function:::void:do_ph_shrl:int rd, int rt, int shift
223 unsigned32 v1 = GPR[rt];
224 unsigned32 result = 0;
225 for (i = 0; i < 32; i += 16, v1 >>= 16)
227 h0 = (unsigned16)(v1 & 0xffff);
229 result |= ((unsigned32)h0 << i);
231 GPR[rd] = EXTEND32 (result);
234 // op: 0 = ADD, 1 = SUB
235 // round: 0 = no rounding, 1 = rounding
236 :function:::void:do_qh_ph_op:int rd, int rs, int rt, int op, int round
241 unsigned32 v1 = GPR[rs];
242 unsigned32 v2 = GPR[rt];
243 unsigned32 result = 0;
244 for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
246 h1 = (signed16)(v1 & 0xffff);
247 h2 = (signed16)(v2 & 0xffff);
249 h0 = (signed32)h1 + (signed32)h2;
251 h0 = (signed32)h1 - (signed32)h2;
256 result |= ((unsigned32)((unsigned16)h0) << i);
258 GPR[rd] = EXTEND32 (result);
261 // op: 0 = ADD, 1 = SUB
262 // round: 0 = no rounding, 1 = rounding
263 :function:::void:do_qh_w_op:int rd, int rs, int rt, int op, int round
267 signed32 v1 = (signed32)GPR[rs];
268 signed32 v2 = (signed32)GPR[rt];
270 v0 = (signed64)v1 + (signed64)v2;
272 v0 = (signed64)v1 - (signed64)v2;
277 GPR[rd] = EXTEND32 (v0);
280 // op: 0 = DPAX, 1 = DPSX
281 :function:::void:do_x_w_ph_dot_product:int ac, int rs, int rt, int op
284 unsigned32 v1 = GPR[rs];
285 unsigned32 v2 = GPR[rt];
288 unsigned32 lo = DSPLO(ac);
289 unsigned32 hi = DSPHI(ac);
290 signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
291 for (i = 0; i < 32; i += 16, v1 >>= 16, v2 <<= 16)
293 h1 = (signed16)(v1 & 0xffff);
294 h2 = (signed16)((v2 & 0xffff0000) >> 16);
295 result = (signed32)h1 * (signed32)h2;
297 prod += (signed64)result;
299 prod -= (signed64)result;
301 DSPLO(ac) = EXTEND32 (prod);
302 DSPHI(ac) = EXTEND32 (prod >> 32);
305 // op: 0 = DPAQX, 1 = DPSQX
306 // sat: 0 = no saturation, 1 = saturation of the accumulator
307 :function:::void:do_qx_w_ph_dot_product:int ac, int rs, int rt, int op, int sat
310 unsigned32 v1 = GPR[rs];
311 unsigned32 v2 = GPR[rt];
314 unsigned32 lo = DSPLO(ac);
315 unsigned32 hi = DSPHI(ac);
316 signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
318 for (i = 0; i < 32; i += 16, v1 >>= 16, v2 <<= 16)
320 h1 = (signed16)(v1 & 0xffff);
321 h2 = (signed16)((v2 & 0xffff0000) >> 16);
322 if (h1 == (signed16)0x8000 && h2 == (signed16)0x8000)
324 DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
328 result = ((signed32)h1 * (signed32)h2) << 1;
329 if (op == 0) // DPAQX
330 prod += (signed64)result;
332 prod -= (signed64)result;
334 // Saturation on the accumulator.
337 max = (signed64) 0x7fffffffLL;
338 min = (signed64) 0xffffffff80000000LL;
341 DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
346 DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
350 DSPLO(ac) = EXTEND32 (prod);
351 DSPHI(ac) = EXTEND32 (prod >> 32);
354 011111,00000,5.RT,5.RD,00001,010010:SPECIAL3:32::ABSQ_S.QB
355 "absq_s.qb r<RD>, r<RT>"
360 unsigned32 v1 = GPR[RT];
361 unsigned32 result = 0;
362 for (i = 0; i < 32; i += 8, v1 >>= 8)
364 q0 = (signed8)(v1 & 0xff);
365 if (q0 == (signed8)0x80)
367 DSPCR |= DSPCR_OUFLAG4;
372 result |= ((unsigned32)((unsigned8)q0) << i);
374 GPR[RD] = EXTEND32 (result);
377 011111,5.RS,5.RT,5.RD,01000,010000:SPECIAL3:32::ADDU.PH
378 "addu.ph r<RD>, r<RS>, r<RT>"
381 do_u_ph_op (SD_, RD, RS, RT, 0, 0);
384 011111,5.RS,5.RT,5.RD,01100,010000:SPECIAL3:32::ADDU_S.PH
385 "addu_s.ph r<RD>, r<RS>, r<RT>"
388 do_u_ph_op (SD_, RD, RS, RT, 0, 1);
391 011111,5.RS,5.RT,5.RD,00000,011000:SPECIAL3:32::ADDUH.QB
392 "adduh.qb r<RD>, r<RS>, r<RT>"
395 do_uh_qb_op (SD_, RD, RS, RT, 0, 0);
398 011111,5.RS,5.RT,5.RD,00010,011000:SPECIAL3:32::ADDUH_R.QB
399 "adduh_r.qb r<RD>, r<RS>, r<RT>"
402 do_uh_qb_op (SD_, RD, RS, RT, 0, 1);
405 011111,5.RS,5.RT,5.SA,00000,110001:SPECIAL3:32::APPEND
406 "append r<RT>, r<RS>, <SA>"
409 unsigned32 v0 = GPR[RS];
410 unsigned32 v1 = GPR[RT];
412 unsigned32 mask = (1 << SA) - 1;
413 result = (v1 << SA) | (v0 & mask);
414 GPR[RT] = EXTEND32 (result);
417 011111,5.RS,5.RT,000,2.BP,10000,110001:SPECIAL3:32::BALIGN
418 "balign r<RT>, r<RS>, <BP>"
421 unsigned32 v0 = GPR[RS];
422 unsigned32 v1 = GPR[RT];
427 result = (v1 << 8 * BP) | (v0 >> 8 * (4 - BP));
428 GPR[RT] = EXTEND32 (result);
431 011111,5.RS,5.RT,5.RD,11000,010001:SPECIAL3:32::CMPGDU.EQ.QB
432 "cmpgdu.eq.qb r<RD>, r<RS>, r<RT>"
435 do_qb_cmpgdu (SD_, RD, RS, RT, 0);
438 011111,5.RS,5.RT,5.RD,11001,010001:SPECIAL3:32::CMPGDU.LT.QB
439 "cmpgdu.lt.qb r<RD>, r<RS>, r<RT>"
442 do_qb_cmpgdu (SD_, RD, RS, RT, 1);
445 011111,5.RS,5.RT,5.RD,11010,010001:SPECIAL3:32::CMPGDU.LE.QB
446 "cmpgdu.le.qb r<RD>, r<RS>, r<RT>"
449 do_qb_cmpgdu (SD_, RD, RS, RT, 2);
452 011111,5.RS,5.RT,000,2.AC,00000,110000:SPECIAL3:32::DPA.W.PH
453 "dpa.w.ph ac<AC>, r<RS>, r<RT>"
456 do_w_ph_dot_product (SD_, AC, RS, RT, 0);
459 011111,5.RS,5.RT,000,2.AC,00001,110000:SPECIAL3:32::DPS.W.PH
460 "dps.w.ph ac<AC>, r<RS>, r<RT>"
463 do_w_ph_dot_product (SD_, AC, RS, RT, 1);
466 011111,5.RS,5.RT,5.RD,01100,011000:SPECIAL3:32::MUL.PH
467 "mul.ph r<RD>, r<RS>, r<RT>"
470 do_ph_op (SD_, RD, RS, RT, 2, 0);
473 011111,5.RS,5.RT,5.RD,01110,011000:SPECIAL3:32::MUL_S.PH
474 "mul_s.ph r<RD>, r<RS>, r<RT>"
477 do_ph_op (SD_, RD, RS, RT, 2, 1);
480 011111,5.RS,5.RT,5.RD,10111,011000:SPECIAL3:32::MULQ_RS.W
481 "mulq_rs.w r<RD>, r<RS>, r<RT>"
484 do_w_mulq (SD_, RD, RS, RT, 1);
487 011111,5.RS,5.RT,5.RD,11110,010000:SPECIAL3:32::MULQ_S.PH
488 "mulq_s.ph r<RD>, r<RS>, r<RT>"
491 do_ph_mulq (SD_, RD, RS, RT, 0);
494 011111,5.RS,5.RT,5.RD,10110,011000:SPECIAL3:32::MULQ_S.W
495 "mulq_s.w r<RD>, r<RS>, r<RT>"
498 do_w_mulq (SD_, RD, RS, RT, 0);
501 011111,5.RS,5.RT,000,2.AC,00010,110000:SPECIAL3:32::MULSA.W.PH
502 "mulsa.w.ph ac<AC>, r<RS>, r<RT>"
506 unsigned32 v1 = GPR[RS];
507 unsigned32 v2 = GPR[RT];
510 unsigned32 lo = DSPLO(AC);
511 unsigned32 hi = DSPHI(AC);
512 signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
513 for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
515 h1 = (signed16)(v1 & 0xffff);
516 h2 = (signed16)(v2 & 0xffff);
517 result = (signed32)h1 * (signed32)h2;
520 prod -= (signed64) result;
522 prod += (signed64) result;
524 DSPLO(AC) = EXTEND32 (prod);
525 DSPHI(AC) = EXTEND32 (prod >> 32);
528 011111,5.RS,5.RT,5.RD,01101,010001:SPECIAL3:32::PRECR.QB.PH
529 "precr.qb.ph r<RD>, r<RS>, r<RT>"
532 unsigned32 v1 = GPR[RS];
533 unsigned32 v2 = GPR[RT];
534 unsigned32 tempu = (v1 & 0xff0000) >> 16;
535 unsigned32 tempv = (v1 & 0xff);
536 unsigned32 tempw = (v2 & 0xff0000) >> 16;
537 unsigned32 tempx = (v2 & 0xff);
538 GPR[RD] = EXTEND32 ((tempu << 24) | (tempv << 16) | (tempw << 8) | tempx);
541 011111,5.RS,5.RT,5.SA,11110,010001:SPECIAL3:32::PRECR_SRA.PH.W
542 "precr_sra.ph.w r<RT>, r<RS>, <SA>"
545 do_precr_sra (SD_, RT, RS, SA, 0);
548 011111,5.RS,5.RT,5.SA,11111,010001:SPECIAL3:32::PRECR_SRA_R.PH.W
549 "precr_sra_r.ph.w r<RT>, r<RS>, <SA>"
552 do_precr_sra (SD_, RT, RS, SA, 1);
555 011111,5.RS,5.RT,5.SA,00001,110001:SPECIAL3:32::PREPEND
556 "prepend r<RT>, r<RS>, <SA>"
559 unsigned32 v0 = GPR[RS];
560 unsigned32 v1 = GPR[RT];
565 result = (v0 << (32 - SA)) | (v1 >> SA);
566 GPR[RT] = EXTEND32 (result);
569 011111,00,3.SHIFT3,5.RT,5.RD,00100,010011:SPECIAL3:32::SHRA.QB
570 "shra.qb r<RD>, r<RT>, <SHIFT3>"
573 do_qb_shra (SD_, RD, RT, SHIFT3, 0);
576 011111,00,3.SHIFT3,5.RT,5.RD,00101,010011:SPECIAL3:32::SHRA_R.QB
577 "shra_r.qb r<RD>, r<RT>, <SHIFT3>"
580 do_qb_shra (SD_, RD, RT, SHIFT3, 1);
583 011111,5.RS,5.RT,5.RD,00110,010011:SPECIAL3:32::SHRAV.QB
584 "shrav.qb r<RD>, r<RT>, r<RS>"
587 unsigned32 shift = GPR[RS] & 0x7;
588 do_qb_shra (SD_, RD, RT, shift, 0);
591 011111,5.RS,5.RT,5.RD,00111,010011:SPECIAL3:32::SHRAV_R.QB
592 "shrav_r.qb r<RD>, r<RT>, r<RS>"
595 unsigned32 shift = GPR[RS] & 0x7;
596 do_qb_shra (SD_, RD, RT, shift, 1);
599 011111,0,4.SHIFT4,5.RT,5.RD,11001,010011:SPECIAL3:32::SHRL.PH
600 "shrl.ph r<RD>, r<RT>, <SHIFT4>"
603 do_ph_shrl (SD_, RD, RT, SHIFT4);
606 011111,5.RS,5.RT,5.RD,11011,010011:SPECIAL3:32::SHRLV.PH
607 "shrlv.ph r<RD>, r<RT>, r<RS>"
610 unsigned32 shift = GPR[RS] & 0xf;
611 do_ph_shrl (SD_, RD, RT, shift);
614 011111,5.RS,5.RT,5.RD,01001,010000:SPECIAL3:32::SUBU.PH
615 "subu.ph r<RD>, r<RS>, r<RT>"
618 do_u_ph_op (SD_, RD, RS, RT, 1, 0);
621 011111,5.RS,5.RT,5.RD,01101,010000:SPECIAL3:32::SUBU_S.PH
622 "subu_s.ph r<RD>, r<RS>, r<RT>"
625 do_u_ph_op (SD_, RD, RS, RT, 1, 1);
628 011111,5.RS,5.RT,5.RD,00001,011000:SPECIAL3:32::SUBUH.QB
629 "subuh.qb r<RD>, r<RS>, r<RT>"
632 do_uh_qb_op (SD_, RD, RS, RT, 1, 0);
635 011111,5.RS,5.RT,5.RD,00011,011000:SPECIAL3:32::SUBUH_R.QB
636 "subuh_r.qb r<RD>, r<RS>, r<RT>"
639 do_uh_qb_op (SD_, RD, RS, RT, 1, 1);
642 011111,5.RS,5.RT,5.RD,01000,011000:SPECIAL3:32::ADDQH.PH
643 "addqh.ph r<RD>, r<RS>, r<RT>"
646 do_qh_ph_op (SD_, RD, RS, RT, 0, 0);
649 011111,5.RS,5.RT,5.RD,01010,011000:SPECIAL3:32::ADDQH_R.PH
650 "addqh_r.ph r<RD>, r<RS>, r<RT>"
653 do_qh_ph_op (SD_, RD, RS, RT, 0, 1);
656 011111,5.RS,5.RT,5.RD,10000,011000:SPECIAL3:32::ADDQH.W
657 "addqh.w r<RD>, r<RS>, r<RT>"
660 do_qh_w_op (SD_, RD, RS, RT, 0, 0);
663 011111,5.RS,5.RT,5.RD,10010,011000:SPECIAL3:32::ADDQH_R.W
664 "addqh_r.w r<RD>, r<RS>, r<RT>"
667 do_qh_w_op (SD_, RD, RS, RT, 0, 1);
670 011111,5.RS,5.RT,5.RD,01001,011000:SPECIAL3:32::SUBQH.PH
671 "subqh.ph r<RD>, r<RS>, r<RT>"
674 do_qh_ph_op (SD_, RD, RS, RT, 1, 0);
677 011111,5.RS,5.RT,5.RD,01011,011000:SPECIAL3:32::SUBQH_R.PH
678 "subqh_r.ph r<RD>, r<RS>, r<RT>"
681 do_qh_ph_op (SD_, RD, RS, RT, 1, 1);
684 011111,5.RS,5.RT,5.RD,10001,011000:SPECIAL3:32::SUBQH.W
685 "subqh.w r<RD>, r<RS>, r<RT>"
688 do_qh_w_op (SD_, RD, RS, RT, 1, 0);
691 011111,5.RS,5.RT,5.RD,10011,011000:SPECIAL3:32::SUBQH_R.W
692 "subqh_r.w r<RD>, r<RS>, r<RT>"
695 do_qh_w_op (SD_, RD, RS, RT, 1, 1);
698 011111,5.RS,5.RT,000,2.AC,01000,110000:SPECIAL3:32::DPAX.W.PH
699 "dpax.w.ph ac<AC>, r<RS>, r<RT>"
702 do_x_w_ph_dot_product (SD_, AC, RS, RT, 0);
705 011111,5.RS,5.RT,000,2.AC,01001,110000:SPECIAL3:32::DPSX.W.PH
706 "dpsx.w.ph ac<AC>, r<RS>, r<RT>"
709 do_x_w_ph_dot_product (SD_, AC, RS, RT, 1);
712 011111,5.RS,5.RT,000,2.AC,11000,110000:SPECIAL3:32::DPAQX_S.W.PH
713 "dpaqx_s.w.ph ac<AC>, r<RS>, r<RT>"
716 do_qx_w_ph_dot_product (SD_, AC, RS, RT, 0, 0);
719 011111,5.RS,5.RT,000,2.AC,11010,110000:SPECIAL3:32::DPAQX_SA.W.PH
720 "dpaqx_sa.w.ph ac<AC>, r<RS>, r<RT>"
723 do_qx_w_ph_dot_product (SD_, AC, RS, RT, 0, 1);
726 011111,5.RS,5.RT,000,2.AC,11001,110000:SPECIAL3:32::DPSQX_S.W.PH
727 "dpsqx_s.w.ph ac<AC>, r<RS>, r<RT>"
730 do_qx_w_ph_dot_product (SD_, AC, RS, RT, 1, 0);
733 011111,5.RS,5.RT,000,2.AC,11011,110000:SPECIAL3:32::DPSQX_SA.W.PH
734 "dpsqx_sa.w.ph ac<AC>, r<RS>, r<RT>"
737 do_qx_w_ph_dot_product (SD_, AC, RS, RT, 1, 1);