csrrwi
Atomic Read/Write CSR Immediate
This instruction is defined by:
Synopsis
Atomically write CSR using a 5-bit immediate, and load the previous value into 'rd'.
Read the old value of the CSR, zero-extends the value to XLEN
bits,
and then write it to integer register rd.
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
cause any of the side effects that might occur on a CSR read.
Decode Variables
Bits<12> csr = $encoding[31:20];
Bits<5> imm = $encoding[19:15];
Bits<5> rd = $encoding[11:7];
Execution
-
Pruned, XLEN == 64
-
Original
%%LINK%func;check_csr;check_csr%%(csr, true, $encoding);
if (rd != 0) {
X[rd] = CSR[csr].sw_read();
}
CSR[csr].sw_write({{59{1'b0}}, imm});
%%LINK%func;check_csr;check_csr%%(csr, true, $encoding);
if (rd != 0) {
X[rd] = CSR[csr].sw_read();
}
CSR[csr].sw_write({{MXLEN - 5{1'b0}}, imm});