csrrs
Atomic Read and Set Bits in CSR
This instruction is defined by:
Synopsis
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
corresponding bit to be set in the CSR, if that CSR bit is writable.
Other bits in the CSR are not explicitly written.
Decode Variables
Bits<12> csr = $encoding[31:20];
Bits<5> rs1 = $encoding[19:15];
Bits<5> rd = $encoding[11:7];
Execution
-
Pruned, XLEN == 64
-
Original
XReg initial_csr_value = CSR[csr].sw_read();
XReg mask = X[rs1];
CSR[csr].sw_write(initial_csr_value | mask);
X[rd] = initial_csr_value;
XReg initial_csr_value = CSR[csr].sw_read();
XReg mask = X[rs1];
CSR[csr].sw_write(initial_csr_value | mask);
X[rd] = initial_csr_value;