Skip to content

Commit da2ed14

Browse files
committed
Strengthen atomic_compare_exchange seq_cst failure mapping
The Zacas extension defines different ordering behavior when an amocas fails: > The memory operation performed by an AMOCAS.W/D/Q, when not successful, has > acquire semantics if aq bit is 1 but does not have release semantics, > regardless of rl. This requires a leading fence to maintain A6C compatability for both the RVWMO and Ztso memory models. The A7 mappings can use the non-fenced versions. See issue riscv-non-isa#444 for more context and litmus tests. Resolves riscv-non-isa#444.
1 parent 6b692f8 commit da2ed14

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

riscv-atomic.adoc

+28-17
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ the `lr` and `sc` instructions.
107107

108108
|`atomic_<op>(memory_order_acq_rel)` |`amo<op>.{w\|d}.aqrl` |4
109109

110-
|`atomic_<op>(memory_order_seq_cst)` |`amo<op>.{w\|d}.aqrl` |4
110+
|`atomic_<op>(memory_order_seq_cst)` |`amo<op>.{w\|d}.aqrl` |4, 5
111111

112112
|===
113113

@@ -148,6 +148,11 @@ mappings with code generated by a compiler using those older mappings.
148148

149149
4) Currently only directly possible for 32- and 64-bit operands.
150150

151+
5) atomic_compare_exchange operations with a memory_order_seq_cst failure
152+
ordering are considered to have a note 3 annotation.
153+
To remove the note 3 annotation the amocas operation must be prepended with a
154+
leading fence (`fence rw,rw; amocas.{w\|d}.aqrl`).
155+
151156
== Ztso atomics mappings
152157

153158
This specifies additional mappings of C and {Cpp} atomic operations to RISC-V
@@ -157,7 +162,8 @@ For each construct, we provide a mapping that assumes only the A and Ztso
157162
extension.
158163

159164
All mappings interoperate correctly with the RVWMO mappings, and with the
160-
original "Table A.6" mappings.
165+
original "Table A.6" mappings, _except_ that mappings marked with note 3 do not
166+
interoperate with the original "Table A.6" mappings.
161167

162168
We present the mappings as a table in 3 sections, as above.
163169

@@ -167,32 +173,32 @@ We present the mappings as a table in 3 sections, as above.
167173
|===
168174
|C/{Cpp} Construct |Ztso Mapping |Notes
169175

170-
|`atomic_load(memory_order_acquire)` |`l{b\|h\|w\|d}` | 5
176+
|`atomic_load(memory_order_acquire)` |`l{b\|h\|w\|d}` | 6
171177

172-
|`atomic_load(memory_order_seq_cst)` |`fence rw,rw; l{b\|h\|w\|d}` | 5
178+
|`atomic_load(memory_order_seq_cst)` |`fence rw,rw; l{b\|h\|w\|d}` | 6
173179

174-
|`atomic_store(memory_order_release)` |`s{b\|h\|w\|d}` | 5
180+
|`atomic_store(memory_order_release)` |`s{b\|h\|w\|d}` | 6
175181

176-
|`atomic_store(memory_order_seq_cst)` |`s{b\|h\|w\|d}; fence rw, rw` | 5
182+
|`atomic_store(memory_order_seq_cst)` |`s{b\|h\|w\|d}; fence rw, rw` | 6
177183

178-
|`atomic_thread_fence(memory_order_acquire)` |`nop` | 5
184+
|`atomic_thread_fence(memory_order_acquire)` |`nop` | 6
179185

180-
|`atomic_thread_fence(memory_order_release)` |`nop` | 5
186+
|`atomic_thread_fence(memory_order_release)` |`nop` | 6
181187

182-
|`atomic_thread_fence(memory_order_acq_rel)` |`nop` | 5
188+
|`atomic_thread_fence(memory_order_acq_rel)` |`nop` | 6
183189
|===
184190

185191
[cols="<20,<20,<4",options="header",]
186192
|===
187193
|C/{Cpp} Construct |Ztso AMO Mapping |Notes
188194

189-
|`atomic_<op>(memory_order_acquire)` |`amo<op>.{w\|d}` |4, 5
195+
|`atomic_<op>(memory_order_acquire)` |`amo<op>.{w\|d}` |4, 6
190196

191-
|`atomic_<op>(memory_order_release)` |`amo<op>.{w\|d}` |4, 5
197+
|`atomic_<op>(memory_order_release)` |`amo<op>.{w\|d}` |4, 6
192198

193-
|`atomic_<op>(memory_order_acq_rel)` |`amo<op>.{w\|d}` |4, 5
199+
|`atomic_<op>(memory_order_acq_rel)` |`amo<op>.{w\|d}` |4, 6
194200

195-
|`atomic_<op>(memory_order_seq_cst)` |`amo<op>.{w\|d}` |4, 5
201+
|`atomic_<op>(memory_order_seq_cst)` |`amo<op>.{w\|d}` |4, 5, 6
196202

197203
|===
198204

@@ -201,21 +207,26 @@ We present the mappings as a table in 3 sections, as above.
201207
|C/{Cpp} Construct |Ztso LR/SC Mapping |Notes
202208

203209
|`atomic_<op>(memory_order_acquire)`
204-
|`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 5
210+
|`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 6
205211

206212
|`atomic_<op>(memory_order_release)`
207-
|`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 5
213+
|`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 6
208214

209215
|`atomic_<op>(memory_order_acq_rel)`
210-
|`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 5
216+
|`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 6
211217

212218
|===
213219

214220
=== Meaning of notes in table
215221

216222
4) Currently only directly possible for 32- and 64-bit operands.
217223

218-
5) Requires the Ztso extension.
224+
5) atomic_compare_exchange operations with a memory_order_seq_cst failure
225+
ordering are considered to have a note 3 annotation.
226+
To remove the note 3 annotation the amocas operation must be prepended with a
227+
leading fence (`fence rw,rw; amocas.{w\|d}`).
228+
229+
6) Requires the Ztso extension.
219230

220231
== Other conventions
221232

0 commit comments

Comments
 (0)