3 // NEC specific instructions
21 // Simulate the various kinds of multiply and multiply-accumulate instructions.
22 // Perform an operation of the form:
24 // LHS (+/-) GPR[RS] * GPR[RT]
26 // and store it in the 64-bit accumulator. Optionally copy either LO or
27 // HI into a general purpose register.
29 // - RD is the destination register of the LO or HI move
30 // - RS are RT are the multiplication source registers
31 // - ACCUMULATE_P is true if LHS should be the value of the 64-bit accumulator,
32 // false if it should be 0.
33 // - STORE_HI_P is true if HI should be stored in RD, false if LO should be.
34 // - UNSIGNED_P is true if the operation should be unsigned.
35 // - SATURATE_P is true if the result should be saturated to a 32-bit value.
36 // - SUBTRACT_P is true if the right hand side should be subtraced from LHS,
37 // false if it should be added.
38 // - SHORT_P is true if RS and RT must be 16-bit numbers.
39 // - DOUBLE_P is true if the 64-bit accumulator is in LO, false it is a
40 // concatenation of the low 32 bits of HI and LO.
41 :function:::void:do_vr_mul_op:int rd, int rs, int rt, int accumulate_p, int store_hi_p, int unsigned_p, int saturate_p, int subtract_p, int short_p, int double_p
43 unsigned64 lhs, x, y, xcut, ycut, product, result;
45 check_mult_hilo (SD_, HIHISTORY, LOHISTORY);
47 lhs = (!accumulate_p ? 0 : double_p ? LO : U8_4 (HI, LO));
51 /* Work out the canonical form of X and Y from their significant bits. */
54 /* Normal sign-extension rule for 32-bit operands. */
60 /* Operands must be zero-extended 16-bit numbers. */
66 /* Likewise but sign-extended. */
70 if (x != xcut || y != ycut)
71 sim_engine_abort (SD, CPU, CIA,
72 "invalid multiplication operand at 0x%08lx\n",
75 TRACE_ALU_INPUT2 (x, y);
76 product = (unsigned_p ? x * y : EXTEND32 (x) * EXTEND32 (y));
77 result = (subtract_p ? lhs - product : lhs + product);
80 /* Saturate the result to 32 bits. An unsigned, unsaturated
81 result is zero-extended to 64 bits, but unsigned overflow
82 causes all 64 bits to be set. */
83 if (!unsigned_p && (unsigned64) EXTEND32 (result) != result)
84 result = ((signed64) result < 0 ? -0x7fffffff - 1 : 0x7fffffff);
85 else if (unsigned_p && (result >> 32) != 0)
86 result = (unsigned64) 0 - 1;
88 TRACE_ALU_RESULT (result);
94 LO = EXTEND32 (result);
95 HI = EXTEND32 (VH4_8 (result));
98 GPR[rd] = store_hi_p ? HI : LO;
101 // 32-bit rotate right of X by Y bits.
102 :function:::unsigned64:do_ror:unsigned32 x,unsigned32 y
109 TRACE_ALU_INPUT2 (x, y);
110 result = EXTEND32 (ROTR32 (x, y));
111 TRACE_ALU_RESULT (result);
116 :function:::unsigned64:do_dror:unsigned64 x,unsigned64 y
123 TRACE_ALU_INPUT2 (x, y);
124 result = ROTR64 (x, y);
125 TRACE_ALU_RESULT (result);
130 // VR4100 instructions.
132 000000,5.RS,5.RT,00000,00000,101000::32::MADD16
133 "madd16 r<RS>, r<RT>"
136 do_vr_mul_op (SD_, 0, RS, RT,
139 0 /* signed arithmetic */,
140 0 /* don't saturate */,
141 0 /* don't subtract */,
146 000000,5.RS,5.RT,00000,00000,101001::64::DMADD16
147 "dmadd16 r<RS>, r<RT>"
150 do_vr_mul_op (SD_, 0, RS, RT,
153 0 /* signed arithmetic */,
154 0 /* don't saturate */,
155 0 /* don't subtract */,
162 // VR4120 and VR4130 instructions.
164 000000,5.RS,5.RT,5.RD,1.SAT,1.MFHI,00,1.UNS,101001::64::DMACC
165 "dmacc%s<MFHI>%s<UNS>%s<SAT> r<RD>, r<RS>, r<RT>"
168 do_vr_mul_op (SD_, RD, RS, RT,
171 0 /* don't subtract */,
176 000000,5.RS,5.RT,5.RD,1.SAT,1.MFHI,00,1.UNS,101000::32::MACC_4120
177 "macc%s<MFHI>%s<UNS>%s<SAT> r<RD>, r<RS>, r<RT>"
180 do_vr_mul_op (SD_, RD, RS, RT,
183 0 /* don't subtract */,
189 // VR5400 and VR5500 instructions.
191 000000,5.RS,5.RT,5.RD,0,1.MFHI,001,01100,1.UNS::32::MUL
192 "mul%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
196 do_vr_mul_op (SD_, RD, RS, RT,
197 0 /* don't accumulate */,
199 0 /* don't saturate */,
200 0 /* don't subtract */,
205 000000,5.RS,5.RT,5.RD,0,1.MFHI,011,01100,1.UNS::32::MULS
206 "muls%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
210 do_vr_mul_op (SD_, RD, RS, RT,
211 0 /* don't accumulate */,
213 0 /* don't saturate */,
219 000000,5.RS,5.RT,5.RD,0,1.MFHI,101,01100,1.UNS::32::MACC_5xxx
220 "macc%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
224 do_vr_mul_op (SD_, RD, RS, RT,
227 0 /* don't saturate */,
228 0 /* don't subtract */,
233 000000,5.RS,5.RT,5.RD,0,1.MFHI,111,01100,1.UNS::32::MSAC
234 "msac%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
238 do_vr_mul_op (SD_, RD, RS, RT,
241 0 /* don't saturate */,
247 000000,00001,5.RT,5.RD,5.SHIFT,000010::32::ROR
248 "ror r<RD>, r<RT>, <SHIFT>"
252 GPR[RD] = do_ror (SD_, GPR[RT], SHIFT);
255 000000,5.RS,5.RT,5.RD,00001,000110::32::RORV
256 "rorv r<RD>, r<RT>, r<RS>"
260 GPR[RD] = do_ror (SD_, GPR[RT], GPR[RS]);
263 000000,00001,5.RT,5.RD,5.SHIFT,111010::64::DROR
264 "dror r<RD>, r<RT>, <SHIFT>"
268 GPR[RD] = do_dror (SD_, GPR[RT], SHIFT);
271 000000,00001,5.RT,5.RD,5.SHIFT,111110::64::DROR32
272 "dror32 r<RD>, r<RT>, <SHIFT>"
276 GPR[RD] = do_dror (SD_, GPR[RT], SHIFT + 32);
279 000000,5.RS,5.RT,5.RD,00001,010110::64::DRORV
280 "drorv r<RD>, r<RT>, r<RS>"
284 GPR[RD] = do_dror (SD_, GPR[RT], GPR[RS]);
287 010011,5.BASE,5.INDEX,5.0,5.FD,000101:COP1X:64::LUXC1
288 "luxc1 f<FD>, r<INDEX>(r<BASE>)"
292 COP_LD (1, FD, do_load (SD_, AccessLength_DOUBLEWORD,
293 (GPR[BASE] + GPR[INDEX]) & ~MASK64 (2, 0), 0));
296 010011,5.BASE,5.INDEX,5.FS,00000,001101:COP1X:64::SUXC1
297 "suxc1 f<FS>, r<INDEX>(r<BASE>)"
301 do_store (SD_, AccessLength_DOUBLEWORD,
302 (GPR[BASE] + GPR[INDEX]) & ~MASK64 (2, 0), 0,
306 010000,1,19.*,100000:COP0:32::WAIT
310 011100,00000,5.RT,5.DR,00000,111101:SPECIAL:64::MFDR
315 011100,00100,5.RT,5.DR,00000,111101:SPECIAL:64::MTDR
320 011100,00000,00000,00000,00000,111110:SPECIAL:64::DRET