Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arch/inst/I/addi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: (xd == 0 && xs1 == 0 && imm == 0)
to: nop
- when: imm == 0
to: mv xd,xs1
operation(): X[xd] = X[xs1] + $signed(imm);

# SPDX-SnippetBegin
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/addiw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: imm == 0
to: sext.w xd,xs1
operation(): |
XReg operand = sext(X[xs1], 31);
X[xd] = sext(operand + imm, 31);
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/andi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: imm == 255
to: zext.b
operation(): X[xd] = X[xs1] & $signed(imm);

# SPDX-SnippetBegin
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/beq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: xs2 == 0
to: beqz xs1,imm
operation(): |
XReg lhs = X[xs1];
XReg rhs = X[xs2];
Expand Down
5 changes: 5 additions & 0 deletions arch/inst/I/bge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: xs1 == 0
to: blez xs2,imm
- when: xs2 == 0
to: blez xs1,imm
operation(): |
XReg lhs = X[xs1];
XReg rhs = X[xs2];
Expand Down
5 changes: 5 additions & 0 deletions arch/inst/I/blt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: xs2 == 0
to: bltz xs1,imm
- when: xs1 == 0
to: bgtz xs2,imm
operation(): |
XReg lhs = X[xs1];
XReg rhs = X[xs2];
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/bne.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: xs2 == 0
to: bnez xs1,imm
operation(): |
XReg lhs = X[xs1];
XReg rhs = X[xs2];
Expand Down
2 changes: 2 additions & 0 deletions arch/inst/I/fence.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ hints:
pseudoinstructions:
- when: (pred == 1) && (succ == 0) && (xd == 0) && (xs1 == 0)
to: pause
- when: (pred == 4'b1111) && (succ == 4'b1111)
to: fence # fence => fence iorw,iorw

# SPDX-SnippetBegin
# SPDX-FileCopyrightText: 2017-2025 Contributors to the RISCV Sail Model <https://github.com/riscv/sail-riscv/blob/master/LICENCE>
Expand Down
5 changes: 5 additions & 0 deletions arch/inst/I/jal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: imm == 0
to: j xd
- when: xd == x1
to: jal imm
operation(): |
XReg retrun_addr = $pc + 4;

Expand Down
5 changes: 5 additions & 0 deletions arch/inst/I/jalr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: xd == 0
to: jr imm(xs1)
- when: (rd == 0 && xs1 == x1 && imm == 0)
to: ret
operation(): |
XReg returnaddr;
returnaddr = $pc + 4;
Expand Down
5 changes: 5 additions & 0 deletions arch/inst/I/slt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: xs2 == 0
to: sltz xd,xs1
- when: xs1 == 0
to: sgtz xd,xs2
operation(): |
XReg src1 = X[xs1];
XReg src2 = X[xs2];
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/sltiu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: imm == 1
to: seqz xd,xs1
operation(): |
Bits<MXLEN> sign_extend_imm = $signed(imm);
X[xd] = (X[xs1] < sign_extend_imm) ? 1 : 0;
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/sltu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: xs1 == 0
to: snez xd,xs2
operation(): |
X[xd] = (X[xs1] < X[xs2]) ? 1 : 0;

Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/sub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: xs1 == 0
to: neg xd,xs2
operation(): |
XReg t0 = X[xs1];
XReg t1 = X[xs2];
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/subw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: xs1 == 0
to: negw xd,xs2
operation(): |
Bits<32> t0 = X[xs1][31:0];
Bits<32> t1 = X[xs2][31:0];
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/I/xori.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ access:
vs: always
vu: always
data_independent_timing: true
pseudoinstructions:
- when: $signed(imm) == -1
to: not xd,xs1
operation(): X[xd] = X[xs1] ^ $signed(imm);

# SPDX-SnippetBegin
Expand Down
3 changes: 3 additions & 0 deletions arch/inst/Zicsr/csrrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ access:
vs: always
vu: always
data_independent_timing: false
pseudoinstructions:
- when: xd == 0
to: csrc csr,xs1
operation(): |
Csr csr_handle = direct_csr_lookup(csr);

Expand Down
5 changes: 4 additions & 1 deletion arch/inst/Zicsr/csrrci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ long_name: No synopsis available
description: |
No description available.
definedBy: Zicsr
assembly: rd, imm, rs1
assembly: xd, csr, uimm
encoding:
match: -----------------111-----1110011
variables:
Expand All @@ -23,6 +23,9 @@ access:
vs: always
vu: always
data_independent_timing: false
pseudoinstructions:
- when: xd == 0
to: csrci csr,uimm
operation(): |
Boolean will_write = uimm != 0;

Expand Down
21 changes: 13 additions & 8 deletions arch/inst/Zicsr/csrrs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description: |
Atomically read and set bits in a CSR.

Reads the value of the CSR, zero-extends the value to `XLEN` bits,
and writes it to integer register `rd`. The initial value in integer
register `rs1` is treated as a bit mask that specifies bit positions
to be set in the CSR. Any bit that is high in `rs1` will cause the
and writes it to integer register `xd`. The initial value in integer
register `xs1` is treated as a bit mask that specifies bit positions
to be set in the CSR. Any bit that is high in `xs1` will cause the
corresponding bit to be set in the CSR, if that CSR bit is writable.
Other bits in the CSR are not explicitly written.
definedBy: Zicsr
Expand All @@ -20,17 +20,22 @@ encoding:
variables:
- name: csr
location: 31-20
- name: rs1
- name: xs1
location: 19-15
- name: rd
- name: xd
location: 11-7
access:
s: always
u: always
vs: always
vu: always
pseudoinstructions:
- when: xs1 == 0
to: csrr xd,csr
- when: xd == 0
to: csrs csr,xs1
operation(): |
Boolean will_write = rs1 != 0;
Boolean will_write = xs1 != 0;

Csr csr_handle = direct_csr_lookup(csr);

Expand All @@ -48,11 +53,11 @@ operation(): |
if (will_write) {
# set bits using the mask
# performing any WARL transformations first
XReg mask = X[rs1];
XReg mask = X[xs1];
csr_sw_write(csr_handle, initial_csr_value | mask);
}

X[rd] = initial_csr_value;
X[xd] = initial_csr_value;

# SPDX-SnippetBegin
# SPDX-FileCopyrightText: 2017-2025 Contributors to the RISCV Sail Model <https://github.com/riscv/sail-riscv/blob/master/LICENCE>
Expand Down
5 changes: 4 additions & 1 deletion arch/inst/Zicsr/csrrsi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ long_name: No synopsis available
description: |
No description available.
definedBy: Zicsr
assembly: rd, imm, rs1
assembly: xd, csr, uimm
encoding:
match: -----------------110-----1110011
variables:
Expand All @@ -23,6 +23,9 @@ access:
vs: always
vu: always
data_independent_timing: false
pseudoinstructions:
- when: xd == 0
to: csrsi csr,uimm
operation(): |
Boolean will_write = uimm != 0;

Expand Down
9 changes: 6 additions & 3 deletions arch/inst/Zicsr/csrrw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ description: |
Atomically swap values in the CSRs and integer registers.

Read the old value of the CSR, zero-extends the value to `XLEN` bits,
and then write it to integer register rd.
The initial value in rs1 is written to the CSR.
If `rd=x0`, then the instruction shall not read the CSR and shall not
and then write it to integer register xd.
The initial value in xs1 is written to the CSR.
If `xd=x0`, then the instruction shall not read the CSR and shall not
cause any of the side effects that might occur on a CSR read.
definedBy: Zicsr
assembly: xd, imm, xs1
Expand All @@ -28,6 +28,9 @@ access:
u: always
vs: always
vu: always
pseudoinstructions:
- when: xd == 0
to: csrw csr,xs1
operation(): |
Csr csr_handle = direct_csr_lookup(csr);

Expand Down
17 changes: 10 additions & 7 deletions arch/inst/Zicsr/csrrwi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@ kind: instruction
name: csrrwi
long_name: Atomic Read/Write CSR Immediate
description: |
Atomically write CSR using a 5-bit immediate, and load the previous value into 'rd'.
Atomically write CSR using a 5-bit immediate, and load the previous value into 'xd'.

Read the old value of the CSR, zero-extends the value to `XLEN` bits,
and then write it to integer register rd.
and then write it to integer register xd.
The 5-bit uimm field is zero-extended and written to the CSR.
If `rd=x0`, then the instruction shall not read the CSR and shall not
If `xd=x0`, then the instruction shall not read the CSR and shall not
cause any of the side effects that might occur on a CSR read.
definedBy: Zicsr
assembly: rd, imm, rs1
assembly: xd, imm, xs1
encoding:
match: -----------------101-----1110011
variables:
- name: csr
location: 31-20
- name: imm
location: 19-15
- name: rd
- name: xd
location: 11-7
access:
s: always
u: always
vs: always
vu: always
pseudoinstructions:
- when: xd == 0
to: csrwi csr,imm
operation(): |
Csr csr_handle = direct_csr_lookup(csr);

Expand All @@ -40,8 +43,8 @@ operation(): |
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

if (rd != 0) {
X[rd] = csr_sw_read(csr_handle);
if (xd != 0) {
X[xd] = csr_sw_read(csr_handle);
}

# writes the zero-extended immediate to the CSR,
Expand Down
Loading