Skip to content

Commit

Permalink
Remove duplicate shift definitions
Browse files Browse the repository at this point in the history
SHIFTW and SHIFTIWOP were duplicated. This did not cause any harm except that the disassembly for the SHIFTW version was incorrect. Therefore I removed that version.

The `execute()` functions were identical but the SHIFTW version is slightly neater (only one `[31..0]`) so I applied that to the SHIFTIWOP version.

This should cause no functional changes to the model except that the disassembly will have the extra `w` which is correct.
  • Loading branch information
Timmmm committed Sep 18, 2023
1 parent 4c77f62 commit 0c63bbe
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions model/riscv_insts_base.sail
Original file line number Diff line number Diff line change
Expand Up @@ -504,39 +504,6 @@ mapping clause assembly = ADDIW(imm, rs1, rd)
<-> "addiw" ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ hex_bits_12(imm)
if sizeof(xlen) == 64

/* ****************************************************************** */
union clause ast = SHIFTW : (bits(5), regidx, regidx, sop)

mapping clause encdec = SHIFTW(shamt, rs1, rd, RISCV_SLLI)
if sizeof(xlen) == 64
<-> 0b0000000 @ shamt @ rs1 @ 0b001 @ rd @ 0b0011011
if sizeof(xlen) == 64
mapping clause encdec = SHIFTW(shamt, rs1, rd, RISCV_SRLI)
if sizeof(xlen) == 64
<-> 0b0000000 @ shamt @ rs1 @ 0b101 @ rd @ 0b0011011
if sizeof(xlen) == 64
mapping clause encdec = SHIFTW(shamt, rs1, rd, RISCV_SRAI)
if sizeof(xlen) == 64
<-> 0b0100000 @ shamt @ rs1 @ 0b101 @ rd @ 0b0011011
if sizeof(xlen) == 64

function clause execute (SHIFTW(shamt, rs1, rd, op)) = {
let rs1_val = (X(rs1))[31..0];
let result : bits(32) = match op {
RISCV_SLLI => rs1_val << shamt,
RISCV_SRLI => rs1_val >> shamt,
RISCV_SRAI => shift_right_arith32(rs1_val, shamt)
};
X(rd) = sign_extend(result);
RETIRE_SUCCESS
}

mapping shiftw_mnemonic : sop <-> string = {
RISCV_SLLI <-> "slli",
RISCV_SRLI <-> "srli",
RISCV_SRAI <-> "srai"
}

mapping clause assembly = SHIFTW(shamt, rs1, rd, op)
if sizeof(xlen) == 64
<-> shiftw_mnemonic(op) ^ spc() ^ reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ hex_bits_5(shamt)
Expand Down Expand Up @@ -610,11 +577,11 @@ mapping clause encdec = SHIFTIWOP(shamt, rs1, rd, RISCV_SRAIW)
if sizeof(xlen) == 64

function clause execute (SHIFTIWOP(shamt, rs1, rd, op)) = {
let rs1_val = X(rs1);
let rs1_val = (X(rs1))[31..0];
let result : bits(32) = match op {
RISCV_SLLIW => rs1_val[31..0] << shamt,
RISCV_SRLIW => rs1_val[31..0] >> shamt,
RISCV_SRAIW => shift_right_arith32(rs1_val[31..0], shamt)
RISCV_SLLIW => rs1_val << shamt,
RISCV_SRLIW => rs1_val >> shamt,
RISCV_SRAIW => shift_right_arith32(rs1_val, shamt)
};
X(rd) = sign_extend(result);
RETIRE_SUCCESS
Expand Down

0 comments on commit 0c63bbe

Please sign in to comment.