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 uint64_t 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);
77 ? V8_4 (x, 1) * V8_4 (y, 1)
78 : EXTEND32 (x) * EXTEND32 (y));
79 result = (subtract_p ? lhs - product : lhs + product);
82 /* Saturate the result to 32 bits. An unsigned, unsaturated
83 result is zero-extended to 64 bits, but unsigned overflow
84 causes all 64 bits to be set. */
85 if (!unsigned_p && (uint64_t) EXTEND32 (result) != result)
86 result = ((int64_t) result < 0 ? -0x7fffffff - 1 : 0x7fffffff);
87 else if (unsigned_p && (result >> 32) != 0)
88 result = (uint64_t) 0 - 1;
90 TRACE_ALU_RESULT (result);
96 LO = EXTEND32 (result);
97 HI = EXTEND32 (VH4_8 (result));
100 GPR[rd] = store_hi_p ? HI : LO;
103 // VR4100 instructions.
105 000000,5.RS,5.RT,00000,00000,101000::32::MADD16
106 "madd16 r<RS>, r<RT>"
109 do_vr_mul_op (SD_, 0, RS, RT,
112 0 /* signed arithmetic */,
113 0 /* don't saturate */,
114 0 /* don't subtract */,
119 000000,5.RS,5.RT,00000,00000,101001::64::DMADD16
120 "dmadd16 r<RS>, r<RT>"
123 do_vr_mul_op (SD_, 0, RS, RT,
126 0 /* signed arithmetic */,
127 0 /* don't saturate */,
128 0 /* don't subtract */,
135 // VR4120 and VR4130 instructions.
137 000000,5.RS,5.RT,5.RD,1.SAT,1.MFHI,00,1.UNS,101001::64::DMACC
138 "dmacc%s<MFHI>%s<UNS>%s<SAT> r<RD>, r<RS>, r<RT>"
141 do_vr_mul_op (SD_, RD, RS, RT,
144 0 /* don't subtract */,
149 000000,5.RS,5.RT,5.RD,1.SAT,1.MFHI,00,1.UNS,101000::32::MACC_4120
150 "macc%s<MFHI>%s<UNS>%s<SAT> r<RD>, r<RS>, r<RT>"
153 do_vr_mul_op (SD_, RD, RS, RT,
156 0 /* don't subtract */,
162 // VR5400 and VR5500 instructions.
164 000000,5.RS,5.RT,5.RD,0,1.MFHI,001,01100,1.UNS::32::MUL
165 "mul%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
169 do_vr_mul_op (SD_, RD, RS, RT,
170 0 /* don't accumulate */,
172 0 /* don't saturate */,
173 0 /* don't subtract */,
178 000000,5.RS,5.RT,5.RD,0,1.MFHI,011,01100,1.UNS::32::MULS
179 "muls%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
183 do_vr_mul_op (SD_, RD, RS, RT,
184 0 /* don't accumulate */,
186 0 /* don't saturate */,
192 000000,5.RS,5.RT,5.RD,0,1.MFHI,101,01100,1.UNS::32::MACC_5xxx
193 "macc%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
197 do_vr_mul_op (SD_, RD, RS, RT,
200 0 /* don't saturate */,
201 0 /* don't subtract */,
206 000000,5.RS,5.RT,5.RD,0,1.MFHI,111,01100,1.UNS::32::MSAC
207 "msac%s<MFHI>%s<UNS> r<RD>, r<RS>, r<RT>"
211 do_vr_mul_op (SD_, RD, RS, RT,
214 0 /* don't saturate */,
221 010011,5.BASE,5.INDEX,5.0,5.FD,000101:COP1X:64::LUXC1
222 "luxc1 f<FD>, r<INDEX>(r<BASE>)"
226 COP_LD (1, FD, do_load (SD_, AccessLength_DOUBLEWORD,
227 (GPR[BASE] + GPR[INDEX]) & ~MASK64 (2, 0), 0));
230 010011,5.BASE,5.INDEX,5.FS,00000,001101:COP1X:64::SUXC1
231 "suxc1 f<FS>, r<INDEX>(r<BASE>)"
235 do_store (SD_, AccessLength_DOUBLEWORD,
236 (GPR[BASE] + GPR[INDEX]) & ~MASK64 (2, 0), 0,
240 010000,1,19.*,100000:COP0:32::WAIT
244 011100,00000,5.RT,5.DR,00000,111101:SPECIAL:64::MFDR
249 011100,00100,5.RT,5.DR,00000,111101:SPECIAL:64::MTDR
254 011100,00000,00000,00000,00000,111110:SPECIAL:64::DRET