blob: 1ae73f51d45ef2910998a691f096cae627b88374 [file] [log] [blame]
Alexey Frunze00b53b72016-02-02 20:25:45 -08001%default {"preinstr":"", "result":"a0", "chkzero":"0"}
2 /*
3 * Generic 32-bit "/2addr" binary operation. Provide an "instr" line
4 * that specifies an instruction that performs "result = a0 op a1".
5 * This could be a MIPS instruction or a function call. (If the result
6 * comes back in a register other than a0, you can override "result".)
7 *
8 * If "chkzero" is set to 1, we perform a divide-by-zero check on
9 * vB (a1). Useful for integer division and modulus. Note that we
10 * *don't* check for (INT_MIN / -1) here, because the CPU handles it
11 * correctly.
12 *
13 * For: add-int/2addr, sub-int/2addr, mul-int/2addr, div-int/2addr,
14 * rem-int/2addr, and-int/2addr, or-int/2addr, xor-int/2addr,
15 * shl-int/2addr, shr-int/2addr, ushr-int/2addr
16 */
17 /* binop/2addr vA, vB */
18 ext a2, rINST, 8, 4 # a2 <- A
19 ext a3, rINST, 12, 4 # a3 <- B
20 GET_VREG a0, a2 # a0 <- vA
21 GET_VREG a1, a3 # a1 <- vB
22 .if $chkzero
23 beqz a1, common_errDivideByZero # is second operand zero?
24 .endif
25 FETCH_ADVANCE_INST 1 # advance rPC, load rINST
26 $preinstr # optional op
27 $instr # $result <- op, a0-a3 changed
28 GET_INST_OPCODE v0 # extract opcode from rINST
29 SET_VREG $result, a2 # vA <- $result
30 GOTO_OPCODE v0 # jump to next instruction