|
| 1 | +# yaml-language-server: $schema=../../../schemas/inst_schema.json |
| 2 | + |
| 3 | +c.and: |
| 4 | + long_name: And |
| 5 | + description: | |
| 6 | + And rd with rs2, and store the result in rd |
| 7 | + The rd and rs2 register indexes should be used as rd+8 and rs2+8 (registers x8-x15). |
| 8 | + C.AND expands into `and rd, rd, rs2`. |
| 9 | + definedBy: |
| 10 | + anyOf: |
| 11 | + - C |
| 12 | + - Zca |
| 13 | + assembly: xd, rs2 |
| 14 | + encoding: |
| 15 | + match: 100011---11---01 |
| 16 | + variables: |
| 17 | + - name: rs2 |
| 18 | + location: 4-2 |
| 19 | + - name: rd |
| 20 | + location: 9-7 |
| 21 | + access: |
| 22 | + s: always |
| 23 | + u: always |
| 24 | + vs: always |
| 25 | + vu: always |
| 26 | + operation(): | |
| 27 | + XReg t0 = X[rd+8]; |
| 28 | + XReg t1 = X[rs2+8]; |
| 29 | + X[rd+8] = t0 & t1; |
| 30 | +
|
| 31 | + sail(): | |
| 32 | + { |
| 33 | + let rs1_val = X(rd+8); |
| 34 | + let rs2_val = X(rs2+8); |
| 35 | + let result : xlenbits = match op { |
| 36 | + RISCV_ADD => rs1_val + rs2_val, |
| 37 | + RISCV_SLT => zero_extend(bool_to_bits(rs1_val <_s rs2_val)), |
| 38 | + RISCV_SLTU => zero_extend(bool_to_bits(rs1_val <_u rs2_val)), |
| 39 | + RISCV_AND => rs1_val & rs2_val, |
| 40 | + RISCV_OR => rs1_val | rs2_val, |
| 41 | + RISCV_XOR => rs1_val ^ rs2_val, |
| 42 | + RISCV_SLL => if sizeof(xlen) == 32 |
| 43 | + then rs1_val << (rs2_val[4..0]) |
| 44 | + else rs1_val << (rs2_val[5..0]), |
| 45 | + RISCV_SRL => if sizeof(xlen) == 32 |
| 46 | + then rs1_val >> (rs2_val[4..0]) |
| 47 | + else rs1_val >> (rs2_val[5..0]), |
| 48 | + RISCV_SUB => rs1_val - rs2_val, |
| 49 | + RISCV_SRA => if sizeof(xlen) == 32 |
| 50 | + then shift_right_arith32(rs1_val, rs2_val[4..0]) |
| 51 | + else shift_right_arith64(rs1_val, rs2_val[5..0]) |
| 52 | + }; |
| 53 | + X(rd+8) = result; |
| 54 | + RETIRE_SUCCESS |
| 55 | + } |
0 commit comments