← Home

csrrci

Atomic Read and Clear Bits in CSR with Immediate

The CSRRCI variant is similar to CSRRC, except this updates the CSR using an XLEN-bit value obtained by zero-extending a 5-bit unsigned immediate (imm[4:0]) field encoded in the `xs1` field instead of a value from an integer register. For CSRRCI, if the `imm[4:0]` field is zero, then this instruction will not write to the CSR, and shall not cause any of the side effects that might otherwise occur on a CSR write, nor raise illegal-instruction exceptions on accesses to read-only CSRs. The CSRRCI will always read the CSR and cause any read side effects regardless of `xd` and `xs1` fields.

Assembly format

csrrci xd, csr, imm

Encoding

313029282726252423222120191817161514131211109876543210
csrimm111xd1110011

Decode variables

VariableBitsWidth
csr[31:20]12
imm[19:15]5
xd[11:7]5

Execution

Boolean will_write = imm != 0;

Csr csr_handle = direct_csr_lookup(csr);

# permission checks
if (csr_handle.valid == false) {
  unimplemented_csr($encoding);
} else if (!compatible_mode?(csr_handle.mode, mode())) {
  raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
} else if (will_write && csr_handle.writable == false) {
  raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
}

XReg initial_csr_value = csr_sw_read(csr_handle);

if (will_write) {
  # set bits using the mask
  # performing any WARL transformations first
  XReg mask = imm;
  csr_sw_write(csr_handle, initial_csr_value & ~mask);
}

X[xd] = initial_csr_value;

Defined by

Zicsr

Access

SUVSVU
AlwaysAlwaysAlwaysAlways

Pseudoinstructions

WhenUse
xd == 0csrci csr, imm

Version af3eaf9+cheriot.f635218

Data from the RISC-V Unified Database, copyright RISC-V International and contributors.

CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.

This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.