@@ -6,10 +6,10 @@ endif::[]
6
6
7
7
== RISC-V atomics mappings
8
8
9
- This specifies mappings of C and C\++ atomic operations to RISC-V
9
+ This specifies mappings of C and {Cpp} atomic operations to RISC-V
10
10
machine instructions. Other languages, for example Java, provide similar
11
11
facilities that should be implemented in a consistent manner, usually
12
- by applying the mapping for the corresponding C++ primitive.
12
+ by applying the mapping for the corresponding {Cpp} primitive.
13
13
14
14
NOTE: Because different programming languages may be used within the same
15
15
process, these mappings must be compatible across programming languages. For
19
19
20
20
NOTE: Though many mappings are possible, not all of them will interoperate
21
21
correctly. In particular, many mapping combinations will not
22
- correctly enforce ordering between a C++ `memory_order_seq_cst`
22
+ correctly enforce ordering between a {Cpp} `memory_order_seq_cst`
23
23
store and a subsequent `memory_order_seq_cst` load.
24
24
25
25
NOTE: These mappings are very similar to those that originally appeared in the
26
26
appendix of the RISC-V "unprivileged" architecture specification as
27
- "Mappings from C/C++ primitives to RISC-V Primitives", which we will
27
+ "Mappings from C/{Cpp} primitives to RISC-V Primitives", which we will
28
28
refer to by their 2019 historical label of "Table A.6". That mapping may
29
29
be used, _except_ that `atomic_store(memory_order_seq_cst)` must have an
30
30
an extra trailing fence for compatibility with the "Hypothetical mappings ..."
@@ -55,10 +55,10 @@ section deals with other read-modify-write operations that require
55
55
the `lr` and `sc` instructions.
56
56
57
57
[[tab:c11mappings]]
58
- .Mappings from C/C++ primitives to RISC-V primitives
58
+ .Mappings from C/{Cpp} primitives to RISC-V primitives
59
59
[cols="<22,<18,<4",options="header",]
60
60
|===
61
- |C/C++ Construct |RVWMO Mapping |Notes
61
+ |C/{Cpp} Construct |RVWMO Mapping |Notes
62
62
63
63
|Non-atomic load |`l{b\|h\|w\|d}` |
64
64
@@ -97,7 +97,7 @@ the `lr` and `sc` instructions.
97
97
98
98
[cols="<20,<20,<4",options="header",]
99
99
|===
100
- |C/C++ Construct |RVWMO AMO Mapping |Notes
100
+ |C/{Cpp} Construct |RVWMO AMO Mapping |Notes
101
101
102
102
|`atomic_<op>(memory_order_relaxed)` |`amo<op>.{w\|d}` |4
103
103
@@ -113,7 +113,7 @@ the `lr` and `sc` instructions.
113
113
114
114
[cols="<16,<24,<4",options="header",]
115
115
|===
116
- |C/C++ Construct |RVWMO LR/SC Mapping |Notes
116
+ |C/{Cpp} Construct |RVWMO LR/SC Mapping |Notes
117
117
118
118
|`atomic_<op>(memory_order_relaxed)` |`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4
119
119
@@ -136,7 +136,7 @@ the `lr` and `sc` instructions.
136
136
=== Meaning of notes in table
137
137
138
138
1) Depends on a load instruction with an RCsc aquire annotation,
139
- or a store instruction with an RCsc release annotation. These are curently
139
+ or a store instruction with an RCsc release annotation. These are currently
140
140
under discussion, but the specification has not yet been approved.
141
141
142
142
2) An RCpc load or store would also suffice, if it were to be introduced
@@ -148,11 +148,80 @@ mappings with code generated by a compiler using those older mappings.
148
148
149
149
4) Currently only directly possible for 32- and 64-bit operands.
150
150
151
- === Other conventions
151
+ == Ztso atomics mappings
152
152
153
- It is expected that the RVWMO AMO Mappings will be used for atomic read-modify-write
154
- operations that are directly supported by corresponding AMO instructions,
155
- and that LR/SC mappings will be used for the remainder, currently
153
+ This specifies additional mappings of C and {Cpp} atomic operations to RISC-V
154
+ machine instructions.
155
+
156
+ For each construct, we provide a mapping that assumes only the A and Ztso
157
+ extension.
158
+
159
+ All mappings interoperate correctly with the RVWMO mappings, and with the
160
+ original "Table A.6" mappings.
161
+
162
+ We present the mappings as a table in 3 sections, as above.
163
+
164
+ [[tab:c11mappingsztso]]
165
+ .Mappings with Ztso extension from C/{Cpp} primitives to RISC-V primitives
166
+ [cols="<22,<18,<4",options="header",]
167
+ |===
168
+ |C/{Cpp} Construct |Ztso Mapping |Notes
169
+
170
+ |`atomic_load(memory_order_acquire)` |`l{b\|h\|w\|d}` | 5
171
+
172
+ |`atomic_load(memory_order_seq_cst)` |`fence rw,rw; l{b\|h\|w\|d}` | 5
173
+
174
+ |`atomic_store(memory_order_release)` |`s{b\|h\|w\|d}` | 5
175
+
176
+ |`atomic_store(memory_order_seq_cst)` |`s{b\|h\|w\|d}; fence rw, rw` | 5
177
+
178
+ |`atomic_thread_fence(memory_order_acquire)` |`nop` | 5
179
+
180
+ |`atomic_thread_fence(memory_order_release)` |`nop` | 5
181
+
182
+ |`atomic_thread_fence(memory_order_acq_rel)` |`nop` | 5
183
+ |===
184
+
185
+ [cols="<20,<20,<4",options="header",]
186
+ |===
187
+ |C/{Cpp} Construct |Ztso AMO Mapping |Notes
188
+
189
+ |`atomic_<op>(memory_order_acquire)` |`amo<op>.{w\|d}` |4, 5
190
+
191
+ |`atomic_<op>(memory_order_release)` |`amo<op>.{w\|d}` |4, 5
192
+
193
+ |`atomic_<op>(memory_order_acq_rel)` |`amo<op>.{w\|d}` |4, 5
194
+
195
+ |`atomic_<op>(memory_order_seq_cst)` |`amo<op>.{w\|d}` |4, 5
196
+
197
+ |===
198
+
199
+ [cols="<16,<24,<4",options="header",]
200
+ |===
201
+ |C/{Cpp} Construct |Ztso LR/SC Mapping |Notes
202
+
203
+ |`atomic_<op>(memory_order_acquire)`
204
+ |`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 5
205
+
206
+ |`atomic_<op>(memory_order_release)`
207
+ |`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 5
208
+
209
+ |`atomic_<op>(memory_order_acq_rel)`
210
+ |`loop:lr.{w\|d}; <op>; sc.{w\|d}; bnez loop` |4, 5
211
+
212
+ |===
213
+
214
+ === Meaning of notes in table
215
+
216
+ 4) Currently only directly possible for 32- and 64-bit operands.
217
+
218
+ 5) Requires the Ztso extension.
219
+
220
+ == Other conventions
221
+
222
+ It is expected that the RVWMO and Ztso AMO Mappings will be used for atomic
223
+ read-modify-write operations that are directly supported by corresponding AMO
224
+ instructions, and that LR/SC mappings will be used for the remainder, currently
156
225
including compare-exchange operations. Compare-exchange LR/SC sequences
157
226
on the containing 32-bit word should be used for shorter operands. Thus,
158
227
a `fetch_add` operation on a 16-bit quantity would use a 32-bit LR/SC sequence.
0 commit comments