Skip to content

Commit 00464f4

Browse files
authored
Rename atomic.notify and *.atomic.wait (#149)
The new names are memory.atomic.notify, memory.atomic.wait32, and memory.atomic.wait64. See #145.
1 parent cbb6edc commit 00464f4

18 files changed

Lines changed: 120 additions & 109 deletions

File tree

document/core/appendix/index-instructions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ Instruction Binary Opcode
200200
:math:`\F32.\REINTERPRET\K{\_}\I32` :math:`\hex{BE}` :math:`[\I32] \to [\F32]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
201201
:math:`\F64.\REINTERPRET\K{\_}\I64` :math:`\hex{BF}` :math:`[\I64] \to [\F64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
202202
:math:`\ATOMICNOTIFY~\memarg` :math:`\hex{FE}~\hex{00}` :math:`[\I32~\I64] \to [\I64]` :ref:`validation <valid-atomic-notify>`
203-
:math:`\I32.\ATOMICWAIT~\memarg` :math:`\hex{FE}~\hex{01}` :math:`[\I32~\I32~\I64] \to [\I32]` :ref:`validation <valid-atomic-wait>`
204-
:math:`\I64.\ATOMICWAIT~\memarg` :math:`\hex{FE}~\hex{02}` :math:`[\I32~\I64~\I64] \to [\I32]` :ref:`validation <valid-atomic-wait>`
203+
:math:`\MEMORYATOMICWAIT32~\memarg` :math:`\hex{FE}~\hex{01}` :math:`[\I32~\I32~\I64] \to [\I32]` :ref:`validation <valid-atomic-wait>`
204+
:math:`\MEMORYATOMICWAIT64~\memarg` :math:`\hex{FE}~\hex{02}` :math:`[\I32~\I64~\I64] \to [\I32]` :ref:`validation <valid-atomic-wait>`
205205
:math:`\I32.\ATOMICLOAD~\memarg` :math:`\hex{FE}~\hex{10}` :math:`[\I32] \to [\I32]` :ref:`validation <valid-atomic-load>` :ref:`execution <exec-atomic-load>`
206206
:math:`\I64.\ATOMICLOAD~\memarg` :math:`\hex{FE}~\hex{11}` :math:`[\I32] \to [\I64]` :ref:`validation <valid-atomic-load>` :ref:`execution <exec-atomic-load>`
207207
:math:`\I32.\ATOMICLOAD\K{8\_u}~\memarg` :math:`\hex{FE}~\hex{12}` :math:`[\I32] \to [\I32]` :ref:`validation <valid-atomic-loadn>` :ref:`execution <exec-atomic-loadn>`

document/core/binary/instructions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ Each variant of :ref:`atomic memory instruction <syntax-instr-atomic-memory>` is
184184
.. math::
185185
\begin{array}{llclll}
186186
\production{instruction} & \Binstr &::=& \dots && \phantom{thisshouldbeenough} \\ &&|&
187-
\hex{FE}~\hex{00}~~m{:}\Bmemarg &\Rightarrow& \ATOMICNOTIFY~m \\ &&|&
188-
\hex{FE}~\hex{01}~~m{:}\Bmemarg &\Rightarrow& \I32.\ATOMICWAIT~m \\ &&|&
189-
\hex{FE}~\hex{02}~~m{:}\Bmemarg &\Rightarrow& \I64.\ATOMICWAIT~m \\
187+
\hex{FE}~\hex{00}~~m{:}\Bmemarg &\Rightarrow& \MEMORYATOMICNOTIFY~m \\ &&|&
188+
\hex{FE}~\hex{01}~~m{:}\Bmemarg &\Rightarrow& \MEMORYATOMICWAIT\K{32}~m \\ &&|&
189+
\hex{FE}~\hex{02}~~m{:}\Bmemarg &\Rightarrow& \MEMORYATOMICWAIT\K{64}~m \\
190190
\end{array}
191191
192192

document/core/exec/instructions.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -966,46 +966,46 @@ See :ref:`above <exec-atomic-store>`.
966966
967967
.. _exec-wait:
968968

969-
:math:`t\K{.}\ATOMICWAIT`
970-
.........................
969+
:math:`\MEMORYATOMICWAIT{N}`
970+
............................
971971

972972
.. todo:: update to new rules
973973
.. todo:: add text
974974

975975
.. math::
976976
\begin{array}{l}
977977
\begin{array}{lcl@{\qquad}l}
978-
F; (\I64.\CONST~k)~(t.\CONST~c)~(\I32.\CONST~i)~t.\ATOMICWAIT
979-
&\stepto^{(\ARD~a.\LLEN~n)~(\ARD~a.\LDATA[i]~b^{|t|})}&
978+
F; (\I64.\CONST~k)~(\iN.\CONST~c)~(\I32.\CONST~i)~\MEMORYATOMICWAIT{N}
979+
&\stepto^{(\ARD~a.\LLEN~n)~(\ARD~a.\LDATA[i]~b^{N})}&
980980
F; (\WAITX~a.\LDATA[i])
981981
\end{array}
982982
\\ \qquad
983983
\begin{array}[t]{@{}r@{~}l@{}}
984-
(\iff & \X{ea} + |t|/8 \leq n \\
985-
\wedge & \X{ea} \mod |t|/8 = 0 \\
986-
\wedge & b^{|t|} = \bytes_t(c) \\
984+
(\iff & \X{ea} + N/8 \leq n \\
985+
\wedge & \X{ea} \mod N/8 = 0 \\
986+
\wedge & b^{N} = \bytes_t(c) \\
987987
\end{array}
988988
\\[1ex]
989989
\begin{array}{lcl@{\qquad}l}
990-
F; (\I64.\CONST~k)~(t.\CONST~c)~(\I32.\CONST~i)~t.\ATOMICWAIT
991-
&\stepto^{(\ARD~a.\LLEN~n)~(\ARD~a.\LDATA[i]~b^{|t|})}&
990+
F; (\I64.\CONST~k)~(\iN.\CONST~c)~(\I32.\CONST~i)~\MEMORYATOMICWAIT{N}
991+
&\stepto^{(\ARD~a.\LLEN~n)~(\ARD~a.\LDATA[i]~b^{N})}&
992992
F; (\I32.\CONST~1)
993993
\end{array}
994994
\\ \qquad
995995
\begin{array}[t]{@{}r@{~}l@{}}
996-
(\iff & \X{ea} + |t|/8 \leq n \\
997-
\wedge & \X{ea} \mod |t|/8 = 0 \\
998-
\wedge & b^{|t|} \neq \bytes_t(c) \\
996+
(\iff & \X{ea} + N/8 \leq n \\
997+
\wedge & \X{ea} \mod N/8 = 0 \\
998+
\wedge & b^{N} \neq \bytes_t(c) \\
999999
\end{array}
10001000
\\[1ex]
10011001
\begin{array}{lcl@{\qquad}l}
1002-
F; (\I64.\CONST~k)~(t.\CONST~c)~(\I32.\CONST~i)~t.\ATOMICWAIT
1002+
F; (\I64.\CONST~k)~(\iN.\CONST~c)~(\I32.\CONST~i)~\MEMORYATOMICWAIT{N}
10031003
&\stepto^{(\ARD~a.\LLEN~n)}&
10041004
F; \TRAP
10051005
\end{array}
10061006
\\ \qquad
10071007
\begin{array}[t]{@{}r@{~}l@{}}
1008-
(\iff i + |t|/8 > n \vee i \mod |t|/8 \neq 0) \\
1008+
(\iff i + N/8 > n \vee i \mod N/8 \neq 0) \\
10091009
\end{array}
10101010
\\[2ex]
10111011
\begin{array}[t]{@{}r@{~}l@{}}
@@ -1017,8 +1017,8 @@ See :ref:`above <exec-atomic-store>`.
10171017
10181018
.. _exec-notify:
10191019

1020-
:math:`\ATOMICNOTIFY`
1021-
.....................
1020+
:math:`\MEMORYATOMICNOTIFY`
1021+
...........................
10221022

10231023
.. todo:: update to new rules
10241024
.. todo:: add text; operand order? is the trap case correct (issue #105)?

document/core/syntax/instructions.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ Instructions in this group are concerned with accessing :ref:`linear memory <syn
287287
\ATOMICXCHG \\
288288
\production{instruction} & \instr &::=&
289289
\dots ~|~ \\&&&
290-
\ATOMICNOTIFY~\memarg ~|~ \\&&&
291-
\K{i}\X{nn}\K{.}\ATOMICWAIT~\memarg ~|~ \\&&&
290+
\MEMORYATOMICNOTIFY~\memarg ~|~ \\&&&
291+
\MEMORYATOMICWAIT\X{nn}~\memarg ~|~ \\&&&
292292
\K{i}\X{nn}\K{.}\ATOMICLOAD~\memarg ~|~ \\&&&
293293
\K{i}\X{nn}\K{.}\ATOMICSTORE~\memarg ~|~ \\&&&
294294
\K{i}\X{nn}\K{.}\ATOMICLOAD\K{8\_u}~\memarg ~|~
@@ -324,13 +324,13 @@ this action conditionally, if the read value is equal to a provided comparison
324324
argument. All other :ref:`atomicops <syntax-atomicop>` have behavior of the
325325
:ref:`ibinop <syntax-ibinop>` of the same name.
326326

327-
The |ATOMICWAIT| and |ATOMICNOTIFY| instructions provide primitive
328-
synchronization between :ref:`threads <syntax-thread>`. The |ATOMICWAIT|
327+
The |MEMORYATOMICWAIT| and |MEMORYATOMICNOTIFY| instructions provide primitive
328+
synchronization between :ref:`threads <syntax-thread>`. The |MEMORYATOMICWAIT|
329329
instructions atomically load a value from the calculated effective address and
330330
compare it to an expected value. If they are equal, the thread is then
331331
suspended until a given timeout expires or another thread wakes it. The
332-
|ATOMICNOTIFY| instruction wakes threads that are waiting on a given address, up
333-
to a given maximum.
332+
|MEMORYATOMICNOTIFY| instruction wakes threads that are waiting on a given
333+
address, up to a given maximum.
334334

335335

336336
.. index:: ! control instruction, ! structured control, ! label, ! block, ! branch, ! unwinding, result type, label index, function index, type index, vector, trap, function, table, function type

document/core/text/instructions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ The offset immediate to atomic memory instructions is optional, and defaults to
241241
.. math::
242242
\begin{array}{llclll}
243243
\production{instruction} & \Tplaininstr_I &::=& \dots \phantom{thisshouldbeenoughnowitissee} && \phantom{thisshouldbeenough} \\ &&|&
244-
\text{atomic.notify}~~m{:}\Tmemarg_4 &\Rightarrow& \ATOMICNOTIFY~m \\ &&|&
245-
\text{i32.atomic.wait}~~m{:}\Tmemarg_4 &\Rightarrow& \I32.\ATOMICWAIT~m \\ &&|&
246-
\text{i64.atomic.wait}~~m{:}\Tmemarg_8 &\Rightarrow& \I64.\ATOMICWAIT~m \\
244+
\text{memory.atomic.notify}~~m{:}\Tmemarg_4 &\Rightarrow& \MEMORYATOMICNOTIFY~m \\ &&|&
245+
\text{memory.atomic.wait32}~~m{:}\Tmemarg_4 &\Rightarrow& \MEMORYATOMICWAIT{32}~m \\ &&|&
246+
\text{memory.atomic.wait64}~~m{:}\Tmemarg_8 &\Rightarrow& \MEMORYATOMICWAIT{64}~m \\
247247
\end{array}
248248
249249
.. math::

document/core/util/macros.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@
379379
.. |REINTERPRET| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{reinterpret}}
380380

381381
.. |ATOMIC| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{atomic}}
382-
.. |ATOMICWAIT| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{atomic.wait}}
383-
.. |ATOMICNOTIFY| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{atomic.notify}}
382+
.. |MEMORYATOMICWAIT| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{memory.atomic.wait}}
383+
.. |MEMORYATOMICNOTIFY| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{memory.atomic.notify}}
384384
.. |ATOMICADD| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{add}}
385385
.. |ATOMICSUB| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{sub}}
386386
.. |ATOMICAND| mathdef:: \xref{syntax/instructions}{syntax-instr-atomic-memory}{\K{and}}

document/core/valid/instructions.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ Atomic Memory Instructions
433433

434434
.. _valid-atomic-notify:
435435

436-
:math:`\ATOMICNOTIFY~\memarg`
437-
.............................
436+
:math:`\MEMORYATOMICNOTIFY~\memarg`
437+
...................................
438438

439439
* The memory :math:`C.\CMEMS[0]` must be defined in the context.
440440

@@ -450,29 +450,29 @@ Atomic Memory Instructions
450450
\qquad
451451
2^{\memarg.\ALIGN} = 4
452452
}{
453-
C \vdash \ATOMICNOTIFY~\memarg : [\I32~\I64] \to [\I64]
453+
C \vdash \MEMORYATOMICNOTIFY~\memarg : [\I32~\I64] \to [\I64]
454454
}
455455
456456
.. _valid-atomic-wait:
457457

458-
:math:`t\K{.}\ATOMICWAIT~\memarg`
459-
.................................
458+
:math:`\MEMORYATOMICWAIT{N}~\memarg`
459+
....................................
460460

461461
* The memory :math:`C.\CMEMS[0]` must be defined in the context.
462462

463463
* Let :math:`\limits~\share` be the :ref:`memory type <syntax-memtype>` :math:`C.\CMEMS[0]`.
464464

465-
* The alignment :math:`2^{\memarg.\ALIGN}` must be equal to the :ref:`width <syntax-valtype>` of :math:`t` divided by :math:`8`.
465+
* The alignment :math:`2^{\memarg.\ALIGN}` must be equal to :math:`N` divided by :math:`8`.
466466

467-
* Then the instruction is valid with type :math:`[\I32~t~\I64] \to [\I32]`.
467+
* Then the instruction is valid with type :math:`[\I32~\K{i}{N}~\I64] \to [\I32]`.
468468

469469
.. math::
470470
\frac{
471471
C.\CMEMS[0] = \memtype
472472
\qquad
473-
2^{\memarg.\ALIGN} = |t|/8
473+
2^{\memarg.\ALIGN} = N/8
474474
}{
475-
C \vdash t\K{.}\ATOMICWAIT~\memarg : [\I32~t~\I64] \to [\I32]
475+
C \vdash \MEMORYATOMICWAIT{N}~\memarg : [\I32~\K{i}{N}~\I64] \to [\I32]
476476
}
477477
478478
.. _valid-atomic-load:

interpreter/binary/decode.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ let memop s =
209209
let atomic_instr s =
210210
let pos = pos s in
211211
match op s with
212-
| 0x00 -> let a, o = memop s in atomic_notify a o
213-
| 0x01 -> let a, o = memop s in i32_atomic_wait a o
214-
| 0x02 -> let a, o = memop s in i64_atomic_wait a o
212+
| 0x00 -> let a, o = memop s in memory_atomic_notify a o
213+
| 0x01 -> let a, o = memop s in memory_atomic_wait32 a o
214+
| 0x02 -> let a, o = memop s in memory_atomic_wait64 a o
215215

216216
| 0x10 -> let a, o = memop s in i32_atomic_load a o
217217
| 0x11 -> let a, o = memop s in i64_atomic_load a o

interpreter/binary/encode.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,18 @@ let encode m =
207207
| Store ({ty = I64Type; sz = Some Pack32; _} as mo) -> op 0x3e; memop mo
208208
| Store {ty = F32Type | F64Type; sz = Some _; _} -> assert false
209209

210-
| AtomicNotify ({ty = I32Type; sz = None; _} as mo) ->
210+
| MemoryAtomicNotify ({ty = I32Type; sz = None; _} as mo) ->
211211
op 0xfe; op 0x00; memop mo
212-
| AtomicNotify {ty = I32Type; sz = Some _; _} -> assert false
213-
| AtomicNotify {ty = I64Type | F32Type | F64Type; _} -> assert false
212+
| MemoryAtomicNotify {ty = I32Type; sz = Some _; _} -> assert false
213+
| MemoryAtomicNotify {ty = I64Type | F32Type | F64Type; _} -> assert false
214214

215-
| AtomicWait ({ty = I32Type; sz = None; _} as mo) ->
215+
| MemoryAtomicWait ({ty = I32Type; sz = None; _} as mo) ->
216216
op 0xfe; op 0x01; memop mo
217-
| AtomicWait ({ty = I64Type; sz = None; _} as mo) ->
217+
| MemoryAtomicWait ({ty = I64Type; sz = None; _} as mo) ->
218218
op 0xfe; op 0x02; memop mo
219-
| AtomicWait {ty = I32Type | I64Type; sz = Some _; _} -> assert false
220-
| AtomicWait {ty = F32Type | F64Type; _} -> assert false
219+
| MemoryAtomicWait {ty = I32Type | I64Type; sz = Some _; _} ->
220+
assert false
221+
| MemoryAtomicWait {ty = F32Type | F64Type; _} -> assert false
221222

222223
| AtomicLoad ({ty = I32Type; sz = None; _} as mo) ->
223224
op 0xfe; op 0x10; memop mo

interpreter/exec/eval.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ let rec step (c : config) : config =
276276
v1 :: vs', []
277277
with exn -> vs', [Trapping (memory_error e.at exn) @@ e.at]);
278278

279-
| AtomicWait {offset; ty; sz; _}, I64 timeout :: ve :: I32 i :: vs' ->
280-
(* TODO: Trap if memory is not shared *)
279+
| MemoryAtomicWait {offset; ty; sz; _}, I64 timeout :: ve :: I32 i :: vs' ->
281280
let mem = memory frame.inst (0l @@ e.at) in
282281
let addr = I64_convert.extend_i32_u i in
283282
(try
@@ -290,7 +289,7 @@ let rec step (c : config) : config =
290289
I32 1l :: vs', [] (* Not equal *)
291290
with exn -> vs', [Trapping (memory_error e.at exn) @@ e.at])
292291

293-
| AtomicNotify x, I32 count :: I32 i :: vs' ->
292+
| MemoryAtomicNotify x, I32 count :: I32 i :: vs' ->
294293
if count = 0l then
295294
I32 0l :: vs', [] (* Trivial case waking 0 waiters *)
296295
else

0 commit comments

Comments
 (0)