Are CSR instructions memory atomics?
No. Atomic here means the CSR read-modify-write is one instruction, not an AMO to memory.
Atomically swap CSR and zero-extended 5-bit immediate: read old CSR value into rd, write uimm to the CSR
CSRRWI uses opcode 1110011 (0x73), funct3 101. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.
CSRRWI is the immediate variant of CSRRW: it reads the old CSR value, zero-extends it to XLEN, writes it to rd, then writes the 5-bit unsigned immediate uimm[4:0], zero-extended to XLEN, into the CSR. If rd=x0, the instruction does not read the CSR and does not trigger CSR read side effects. The immediate can encode only 0..31; larger values require CSRRW with an integer register. The assembler pseudo-instruction CSRWI(csr, uimm) is encoded as CSRRWI x0, csr, uimm.
CSRRWI is a Zicsr atomic CSR read-modify-write instruction. CSR addresses are 12 bits, and whether read/write side effects occur depends on rd and on rs1 or uimm being x0/0.
Understand this scenario with real code like «csrrwi x5, fflags, 3 # x5 = old fflags; fflags = 3».
Understand this scenario with real code like «csrrwi x5, fflags, 3 # x5 = old fflags; fflags = 3».
No. Atomic here means the CSR read-modify-write is one instruction, not an AMO to memory.
For CSRRW it suppresses the CSR read and read side effects; CSRRS/CSRRC still read the CSR.