Are CSR instructions memory atomics?
No. Atomic here means the CSR read-modify-write is one instruction, not an AMO to memory.
Read CSR into rd, then atomically set bits in the CSR where rs1 has 1s; supports read-only mode
CSRRS uses opcode 1110011 (0x73), funct3 010. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.
CSRRS performs an atomic read-modify-write on a CSR: reads the current CSR value (zero-extended to XLEN bits) into rd, then uses rs1 as a bit mask to set (assert to 1) the corresponding bits in the CSR where rs1 holds 1s (provided those bits are writable). If rs1=x0, the instruction writes nothing to the CSR, causing no write side effects and no illegal-instruction exceptions on read-only CSRs — effectively a pure read. The assembler pseudo-instruction CSRR(rd, csr) is encoded as CSRRS rd, csr, x0. Typical use: atomically setting bits like interrupt-enable flags.
CSRRS 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 «csrrs x5, mstatus, x6 # x5 = old mstatus; set bits in mstatus per x6».
Understand this scenario with real code like «csrrs x5, mstatus, x6 # x5 = old mstatus; set bits in mstatus per x6».
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.