Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

[spectext] Load lane and store lane validation and semantics #445

Merged
merged 2 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions document/core/exec/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,68 @@ Memory Instructions
\end{array}


.. _exec-load-lane:

:math:`\V128\K{.}\LOAD{N}\K{\_lane}~\memarg~x`
.....................................................

1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`.

2. Assert: due to :ref:`validation <valid-load-extend>`, :math:`F.\AMODULE.\MIMEMS[0]` exists.

3. Let :math:`a` be the :ref:`memory address <syntax-memaddr>` :math:`F.\AMODULE.\MIMEMS[0]`.

4. Assert: due to :ref:`validation <valid-load-extend>`, :math:`S.\SMEMS[a]` exists.

5. Let :math:`\X{mem}` be the :ref:`memory instance <syntax-meminst>` :math:`S.\SMEMS[a]`.

6. Assert: due to :ref:`validation <valid-load-extend>`, a value of :ref:`value type <syntax-valtype>` |V128| is on the top of the stack.

7. Pop the value :math:`\V128.\CONST~v` from the stack.

8. Assert: due to :ref:`validation <valid-load-extend>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.

9. Pop the value :math:`\I32.\CONST~i` from the stack.

10. Let :math:`\X{ea}` be the integer :math:`i + \memarg.\OFFSET`.

11. If :math:`\X{ea} + N/8` is larger than the length of :math:`\X{mem}.\MIDATA`, then:

a. Trap.

12. Let :math:`b^\ast` be the byte sequence :math:`\X{mem}.\MIDATA[\X{ea} \slice N/8]`.

13. Let :math:`r` be the constant for which :math:`\bytes_{\iN}(r) = b^\ast`.

14. Let :math:`L` be :math:`128 / N`.

15. Let :math:`c` be the result of computing :math:`\lanes^{-1}_{\K{i}N\K{x}L}(\lanes_{\K{i}N\K{x}L}(v) \with [x] = r)`.

16. Push the value :math:`\V128.\CONST~c` to the stack.

.. math::
~\\[-1ex]
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~i)~(\V128.\CONST~v)~(\V128\K{.}\LOAD{N}\K{\_lane}~\memarg~x) &\stepto& S; F; (\V128.\CONST~c)
\end{array}
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
(\iff & \X{ea} = i + \memarg.\OFFSET \\
\wedge & \X{ea} + N/8 \leq |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA| \\
\wedge & \bytes_{\iN}(r) = S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA[\X{ea} \slice N/8]) \\
\wedge & L = 128/N \\
\wedge & c = \lanes^{-1}_{\K{i}N\K{x}L}(\lanes_{\K{i}N\K{x}L}(v) \with [x] = r)
\end{array}
\\[1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~k)~(\V128.\CONST~v)~(\V128.\LOAD{N}\K{\_lane}~\memarg~x) &\stepto& S; F; \TRAP
\end{array}
\\ \qquad
(\otherwise) \\
\end{array}


.. _exec-store:
.. _exec-storen:

Expand Down Expand Up @@ -1257,6 +1319,63 @@ Memory Instructions
\end{array}


.. _exec-store-lane:

:math:`\V128\K{.}\STORE{N}\K{\_lane}~\memarg~x`
......................................................

1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`.

2. Assert: due to :ref:`validation <valid-storen>`, :math:`F.\AMODULE.\MIMEMS[0]` exists.

3. Let :math:`a` be the :ref:`memory address <syntax-memaddr>` :math:`F.\AMODULE.\MIMEMS[0]`.

4. Assert: due to :ref:`validation <valid-storen>`, :math:`S.\SMEMS[a]` exists.

5. Let :math:`\X{mem}` be the :ref:`memory instance <syntax-meminst>` :math:`S.\SMEMS[a]`.

6. Assert: due to :ref:`validation <valid-storen>`, a value of :ref:`value type <syntax-valtype>` :math:`\V128` is on the top of the stack.

7. Pop the value :math:`\V128.\CONST~c` from the stack.

8. Assert: due to :ref:`validation <valid-storen>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.

9. Pop the value :math:`\I32.\CONST~i` from the stack.

10. Let :math:`\X{ea}` be the integer :math:`i + \memarg.\OFFSET`.

11. If :math:`\X{ea} + N/8` is larger than the length of :math:`\X{mem}.\MIDATA`, then:

a. Trap.

12. Let :math:`L` be :math:`128/N`.

13. Let :math:`b^\ast` be the byte sequence :math:`\bytes_{\iN}(\lanes_{\K{i}N\K{x}L}(c)[x])`.

14. Replace the bytes :math:`\X{mem}.\MIDATA[\X{ea} \slice N/8]` with :math:`b^\ast`.

.. math::
~\\[-1ex]
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~i)~(\V128.\CONST~c)~(\V128.\STORE{N}\K{\_lane}~\memarg~x) &\stepto& S'; F; \epsilon
\end{array}
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
(\iff & \X{ea} = i + \memarg.\OFFSET \\
\wedge & \X{ea} + N \leq |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA| \\
\wedge & L = 128/N \\
\wedge & S' = S \with \SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA[\X{ea} \slice N/8] = \bytes_{\iN}(\lanes_{\K{i}N\K{x}L}(c)[x])
\end{array}
\\[1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~k)~(\V128.\CONST~c)~(\V128.\STORE{N}\K{\_lane}~\memarg~x) &\stepto& S; F; \TRAP
\end{array}
\\ \qquad
(\otherwise) \\
\end{array}


.. _exec-memory.size:

:math:`\MEMORYSIZE`
Expand Down
10 changes: 6 additions & 4 deletions document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ The |LOCALTEE| instruction is like |LOCALSET| but also returns its argument.
.. _syntax-loadn:
.. _syntax-storen:
.. _syntax-memarg:
.. _syntax-lanewidth:
.. _syntax-instr-memory:

Memory Instructions
Expand All @@ -444,6 +445,8 @@ Instructions in this group are concerned with linear :ref:`memory <syntax-mem>`.
\begin{array}{llcl}
\production{memory immediate} & \memarg &::=&
\{ \OFFSET~\u32, \ALIGN~\u32 \} \\
\production{lane width} & \lanewidth &::=&
8 ~|~ 16 ~|~ 32 ~|~ 64 \\
\production{instruction} & \instr &::=&
\dots \\&&|&
\K{i}\X{nn}\K{.}\LOAD~\memarg ~|~
Expand All @@ -461,12 +464,11 @@ Instructions in this group are concerned with linear :ref:`memory <syntax-mem>`.
\K{v128.}\LOAD\K{8x8}\_\sx~\memarg ~|~
\K{v128.}\LOAD\K{16x4}\_\sx~\memarg ~|~
\K{v128.}\LOAD\K{32x2}\_\sx~\memarg \\&&|&
\K{v128.}\LOAD\K{8\_splat}~\memarg ~|~
\K{v128.}\LOAD\K{16\_splat}~\memarg \\&&|&
\K{v128.}\LOAD\K{32\_splat}~\memarg ~|~
\K{v128.}\LOAD\K{64\_splat}~\memarg \\&&|&
\K{v128.}\LOAD\lanewidth\K{\_splat}~\memarg \\&&|&
\K{v128.}\LOAD\K{32\_zero}~\memarg ~|~
\K{v128.}\LOAD\K{64\_zero}~\memarg \\&&|&
\K{v128.}\LOAD\lanewidth\K{\_lane}~\memarg~\laneidx ~|~
\K{v128.}\STORE\lanewidth\K{\_lane}~\memarg~\laneidx \\&&|&
\MEMORYSIZE \\&&|&
\MEMORYGROW \\
\end{array}
Expand Down
1 change: 1 addition & 0 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@

.. |sx| mathdef:: \xref{syntax/instructions}{syntax-sx}{\X{sx}}
.. |memarg| mathdef:: \xref{syntax/instructions}{syntax-memarg}{\X{memarg}}
.. |lanewidth| mathdef:: \xref{syntax/instructions}{syntax-lanewidth}{\X{lanewidth}}

.. |blocktype| mathdef:: \xref{syntax/instructions}{syntax-blocktype}{\X{blocktype}}

Expand Down
51 changes: 50 additions & 1 deletion document/core/valid/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ Memory Instructions
.. _valid-load-zero:

:math:`\K{v128.}\LOAD{N}\K{\_zero}~\memarg`
...............................................
...........................................

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

Expand All @@ -748,6 +748,55 @@ Memory Instructions
}


.. _valid-load-lane:

:math:`\K{v128.}\LOAD{N}\K{\_lane}~\memarg~\laneidx`
....................................................

* The lane index :math:`\laneidx` must be smaller than :math:`128/N`.

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

* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.

* Then the instruction is valid with type :math:`[\I32~\V128] \to [\V128]`.

.. math::
\frac{
\laneidx < 128/N
\qquad
C.\CMEMS[0] = \memtype
\qquad
2^{\memarg.\ALIGN} < N/8
}{
C \vdashinstr \K{v128.}\LOAD{N}\K{\_lane}~\memarg~\laneidx : [\I32~\V128] \to [\V128]
}

.. _valid-store-lane:

:math:`\K{v128.}\STORE{N}\K{\_lane}~\memarg~\laneidx`
.....................................................

* The lane index :math:`\laneidx` must be smaller than :math:`128/N`.

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

* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than :math:`N/8`.

* Then the instruction is valid with type :math:`[\I32~\V128] \to [\V128]`.

.. math::
\frac{
\laneidx < 128/N
\qquad
C.\CMEMS[0] = \memtype
\qquad
2^{\memarg.\ALIGN} < N/8
}{
C \vdashinstr \K{v128.}\STORE{N}\K{\_lane}~\memarg~\laneidx : [\I32~\V128] \to []
}


.. _valid-memory.size:

:math:`\MEMORYSIZE`
Expand Down