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

[spec] Add table.copy exec text #105

Merged
merged 5 commits into from Jul 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 90 additions & 0 deletions document/core/exec/instructions.rst
Expand Up @@ -810,6 +810,96 @@ Memory Instructions
Table Instructions
~~~~~~~~~~~~~~~~~~

.. _exec-table.copy:

:math:`\TABLECOPY`
...................

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

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

3. Let :math:`\X{ta}` be the :ref:`table address <syntax-tableaddr>` :math:`F.\AMODULE.\MITABLES[0]`.

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

5. Pop the value :math:`\I32.\CONST~cnt` from the stack.

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

7. Pop the value :math:`\I32.\CONST~src` from the stack.

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

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

10. If :math:`cnt = 0`, then:

a. Return.

11. If :math:`dst < src`, then:

a. Push the value :math:`\I32.\CONST~dst` to the stack.

b. Push the value :math:`\I32.\CONST~src` to the stack.

c. Execute the instruction :math:`\TABLEGET`.

d. Execute the instruction :math:`\TABLESET`.

e. Push the value :math:`\I32.\CONST~(dst+1)` to the stack.

f. Push the value :math:`\I32.\CONST~(src+1)` to the stack.

12. Else:

a. Push the value :math:`\I32.\CONST~(dst+cnt-1)` to the stack.

b. Push the value :math:`\I32.\CONST~(src+cnt-1)` to the stack.

c. Execute the instruction :math:`\TABLEGET`.

d. Execute the instruction :math:`\TABLESET`.

e. Push the value :math:`\I32.\CONST~dst` to the stack.

f. Push the value :math:`\I32.\CONST~src` to the stack.

13. Push the value :math:`\I32.\CONST~(cnt-1)` to the stack.

14. Execute the instruction :math:`\TABLECOPY`.

.. math::
~\\[-1ex]
\begin{array}{l}
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~dst)~(\I32.\CONST~(src)~(\I32.\CONST~0)~(\TABLECOPY) &\stepto& S'; F; \epsilon
gahaas marked this conversation as resolved.
Show resolved Hide resolved
\end{array}
\\[1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~(cnt+1))~(\TABLECOPY) &\stepto& S; F;
gahaas marked this conversation as resolved.
Show resolved Hide resolved
\begin{array}[t]{@{}l@{}}
(\I32.\CONST~dst)~((\I32.\CONST~src)~\TABLEGET)~\TABLESET \\
(\I32.\CONST~(dst+1))~(\I32.\CONST~(src+1))~(\I32.\CONST~cnt)~(\TABLECOPY~x) \\
gahaas marked this conversation as resolved.
Show resolved Hide resolved
\end{array} \\
\end{array} \\
\\ \qquad
\begin{array}[t]{@{}r@{~}l@{}}
(\iff & dst < src)
\end{array}
\\[1ex]
\begin{array}{lcl@{\qquad}l}
S; F; (\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~(cnt+1))~(\TABLECOPY) &\stepto& S; F;
gahaas marked this conversation as resolved.
Show resolved Hide resolved
\begin{array}[t]{@{}l@{}}
(\I32.\CONST~(dst+cnt-1))~((\I32.\CONST~(src+cnt-1))~\TABLEGET)~\TABLESET \\
(\I32.\CONST~dst)~(\I32.\CONST~src)~(\I32.\CONST~cnt)~(\TABLECOPY) \\
gahaas marked this conversation as resolved.
Show resolved Hide resolved
\end{array} \\
\end{array} \\
\\ \qquad
(\otherwise) \\
\end{array}


.. _exec-table.init:

:math:`\TABLEINIT~x`
Expand Down