RISC-V Memory Models: RVWMO and Ztso, with Zalasr
RVWMO and Ztso are alternative RISC-V memory models. They are mutually exclusive: a target uses either the default RVWMO model or Ztso. Zalasr is an independent extension that can be enabled on top of either model.
The same C11 atomics therefore have four possible target configurations.
1 |
|
The generated ordering instructions can be compared as follows:
| Operation | RVWMO | RVWMO + Zalasr | Ztso | Ztso + Zalasr |
|---|---|---|---|---|
| Acquire load | lw + fence r,rw |
lw.aq |
lw |
lw |
| Acquire fence | fence r,rw |
fence r,rw |
none | none |
| Release store | fence rw,w + sw |
sw.rl |
sw |
sw |
| Release fence | fence rw,w |
fence rw,w |
none | none |
| Sequentially consistent store | fence rw,w + sw + fence rw,rw |
sw.rl |
sw + fence rw,rw |
sw.rl |
RVWMO (baseline, -O2 -march=rv64g)
1 | load_acquire: |
RVWMO + Zalasr (-O2 -march=rv64g_zalasr)
1 | load_acquire: |
Ztso (-O2 -march=rv64g_ztso)
1 | load_acquire: |
Ztso + Zalasr (-O2 -march=rv64g_ztso_zalasr)
1 | load_acquire: |
Ztso already provides the ordering needed by acquire and release operations, so those operations and fences can be emitted without extra ordering instructions. A sequentially consistent store still uses the .rl annotation in this output.