Skip to content

Commit 3be4c2f

Browse files
authored
[spec] Fix definition of lane ops + better xrefs (#1700)
1 parent 92fbea7 commit 3be4c2f

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

document/core/appendix/index-instructions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def RefWrap(s, kind):
5454

5555
def Instruction(name, opcode, type=None, validation=None, execution=None, operator=None):
5656
if operator:
57-
execution_str = ', '.join([RefWrap(execution, 'execution'),
58-
RefWrap(operator, 'operator')])
57+
execution_str = RefWrap(execution, 'execution') + ' (' + RefWrap(operator, 'operator') + ')'
5958
else:
6059
execution_str = RefWrap(execution, 'execution')
6160

document/core/exec/instructions.rst

+29-23
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ The mapping of numeric instructions to their underlying operators is expressed b
2020

2121
.. math::
2222
\begin{array}{lll@{\qquad}l}
23-
\X{op}_{\IN}(i_1,\dots,i_k) &=& \F{i}\X{op}_N(i_1,\dots,i_k) \\
24-
\X{op}_{\FN}(z_1,\dots,z_k) &=& \F{f}\X{op}_N(z_1,\dots,z_k) \\
25-
\X{op}_{\VN}(i_1,\dots,i_k) &=& \F{i}\X{op}_N(i_1,\dots,i_k) \\
23+
\X{op}_{\IN}(i_1,\dots,i_k) &=& \xref{exec/numerics}{int-ops}{\F{i}\X{op}}_N(i_1,\dots,i_k) \\
24+
\X{op}_{\FN}(z_1,\dots,z_k) &=& \xref{exec/numerics}{float-ops}{\F{f}\X{op}}_N(z_1,\dots,z_k) \\
2625
\end{array}
2726
2827
And for :ref:`conversion operators <exec-cvtop>`:
2928

3029
.. math::
3130
\begin{array}{lll@{\qquad}l}
32-
\X{cvtop}^{\sx^?}_{t_1,t_2}(c) &=& \X{cvtop}^{\sx^?}_{|t_1|,|t_2|}(c) \\
31+
\cvtop^{\sx^?}_{t_1,t_2}(c) &=& \xref{exec/numerics}{convert-ops}{\X{cvtop}}^{\sx^?}_{|t_1|,|t_2|}(c) \\
3332
\end{array}
3433
3534
Where the underlying operators are partial, the corresponding instruction will :ref:`trap <trap>` when the result is not defined.
@@ -64,9 +63,9 @@ Where the underlying operators are non-deterministic, because they may return on
6463

6564
2. Pop the value :math:`t.\CONST~c_1` from the stack.
6665

67-
3. If :math:`\unop_t(c_1)` is defined, then:
66+
3. If :math:`\unopF_t(c_1)` is defined, then:
6867

69-
a. Let :math:`c` be a possible result of computing :math:`\unop_t(c_1)`.
68+
a. Let :math:`c` be a possible result of computing :math:`\unopF_t(c_1)`.
7069

7170
b. Push the value :math:`t.\CONST~c` to the stack.
7271

@@ -77,9 +76,9 @@ Where the underlying operators are non-deterministic, because they may return on
7776
.. math::
7877
\begin{array}{lcl@{\qquad}l}
7978
(t\K{.}\CONST~c_1)~t\K{.}\unop &\stepto& (t\K{.}\CONST~c)
80-
& (\iff c \in \unop_t(c_1)) \\
79+
& (\iff c \in \unopF_t(c_1)) \\
8180
(t\K{.}\CONST~c_1)~t\K{.}\unop &\stepto& \TRAP
82-
& (\iff \unop_{t}(c_1) = \{\})
81+
& (\iff \unopF_{t}(c_1) = \{\})
8382
\end{array}
8483
8584
@@ -94,9 +93,9 @@ Where the underlying operators are non-deterministic, because they may return on
9493

9594
3. Pop the value :math:`t.\CONST~c_1` from the stack.
9695

97-
4. If :math:`\binop_t(c_1, c_2)` is defined, then:
96+
4. If :math:`\binopF_t(c_1, c_2)` is defined, then:
9897

99-
a. Let :math:`c` be a possible result of computing :math:`\binop_t(c_1, c_2)`.
98+
a. Let :math:`c` be a possible result of computing :math:`\binopF_t(c_1, c_2)`.
10099

101100
b. Push the value :math:`t.\CONST~c` to the stack.
102101

@@ -107,9 +106,9 @@ Where the underlying operators are non-deterministic, because they may return on
107106
.. math::
108107
\begin{array}{lcl@{\qquad}l}
109108
(t\K{.}\CONST~c_1)~(t\K{.}\CONST~c_2)~t\K{.}\binop &\stepto& (t\K{.}\CONST~c)
110-
& (\iff c \in \binop_t(c_1,c_2)) \\
109+
& (\iff c \in \binopF_t(c_1,c_2)) \\
111110
(t\K{.}\CONST~c_1)~(t\K{.}\CONST~c_2)~t\K{.}\binop &\stepto& \TRAP
112-
& (\iff \binop_{t}(c_1,c_2) = \{\})
111+
& (\iff \binopF_{t}(c_1,c_2) = \{\})
113112
\end{array}
114113
115114
@@ -122,14 +121,14 @@ Where the underlying operators are non-deterministic, because they may return on
122121

123122
2. Pop the value :math:`t.\CONST~c_1` from the stack.
124123

125-
3. Let :math:`c` be the result of computing :math:`\testop_t(c_1)`.
124+
3. Let :math:`c` be the result of computing :math:`\testopF_t(c_1)`.
126125

127126
4. Push the value :math:`\I32.\CONST~c` to the stack.
128127

129128
.. math::
130129
\begin{array}{lcl@{\qquad}l}
131130
(t\K{.}\CONST~c_1)~t\K{.}\testop &\stepto& (\I32\K{.}\CONST~c)
132-
& (\iff c = \testop_t(c_1)) \\
131+
& (\iff c = \testopF_t(c_1)) \\
133132
\end{array}
134133
135134
@@ -144,14 +143,14 @@ Where the underlying operators are non-deterministic, because they may return on
144143

145144
3. Pop the value :math:`t.\CONST~c_1` from the stack.
146145

147-
4. Let :math:`c` be the result of computing :math:`\relop_t(c_1, c_2)`.
146+
4. Let :math:`c` be the result of computing :math:`\relopF_t(c_1, c_2)`.
148147

149148
5. Push the value :math:`\I32.\CONST~c` to the stack.
150149

151150
.. math::
152151
\begin{array}{lcl@{\qquad}l}
153152
(t\K{.}\CONST~c_1)~(t\K{.}\CONST~c_2)~t\K{.}\relop &\stepto& (\I32\K{.}\CONST~c)
154-
& (\iff c = \relop_t(c_1,c_2)) \\
153+
& (\iff c = \relopF_t(c_1,c_2)) \\
155154
\end{array}
156155
157156
@@ -256,20 +255,27 @@ Reference Instructions
256255
Vector Instructions
257256
~~~~~~~~~~~~~~~~~~~
258257

259-
Most vector instructions are defined in terms of generic numeric operators applied lane-wise based on the :ref:`shape <syntax-vec-shape>`.
258+
Vector instructions that operate bitwise are handled as integer operations of respective width.
260259

261260
.. math::
262261
\begin{array}{lll@{\qquad}l}
262+
\X{op}_{\VN}(i_1,\dots,i_k) &=& \xref{exec/numerics}{int-ops}{\F{i}\X{op}}_N(i_1,\dots,i_k) \\
263+
\end{array}
264+
265+
Most other vector instructions are defined in terms of numeric operators that are applied lane-wise according to the given :ref:`shape <syntax-vec-shape>`.
266+
267+
.. math::
268+
\begin{array}{llll}
263269
\X{op}_{t\K{x}N}(n_1,\dots,n_k) &=&
264-
\lanes^{-1}_{t\K{x}N}(op_t(\lanes_{t\K{x}N}(n_1) ~\dots~ \lanes_{t\K{x}N}(n_k))
270+
\lanes^{-1}_{t\K{x}N}(\xref{exec/instructions}{exec-instr-numeric}{\X{op}}_t(i_1,\dots,i_k)^\ast) & \qquad(\iff i_1^\ast = \lanes_{t\K{x}N}(n_1) \land \dots \land i_k^\ast = \lanes_{t\K{x}N}(n_k) \\
265271
\end{array}
266272
267273
.. note::
268-
For example, the result of instruction :math:`\K{i32x4}.\ADD` applied to operands :math:`i_1, i_2`
269-
invokes :math:`\ADD_{\K{i32x4}}(i_1, i_2)`, which maps to
270-
:math:`\lanes^{-1}_{\K{i32x4}}(\ADD_{\I32}(i_1^+, i_2^+))`,
271-
where :math:`i_1^+` and :math:`i_2^+` are sequences resulting from invoking
272-
:math:`\lanes_{\K{i32x4}}(i_1)` and :math:`\lanes_{\K{i32x4}}(i_2)`
274+
For example, the result of instruction :math:`\K{i32x4}.\ADD` applied to operands :math:`v_1, v_2`
275+
invokes :math:`\ADD_{\K{i32x4}}(v_1, v_2)`, which maps to
276+
:math:`\lanes^{-1}_{\K{i32x4}}(\ADD_{\I32}(i_1, i_2)^\ast)`,
277+
where :math:`i_1^\ast` and :math:`i_2^\ast` are sequences resulting from invoking
278+
:math:`\lanes_{\K{i32x4}}(v_1)` and :math:`\lanes_{\K{i32x4}}(v_2)`
273279
respectively.
274280

275281

document/core/exec/numerics.rst

+9-8
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,25 @@ where :math:`M = \significand(N)` and :math:`E = \exponent(N)`.
169169
Vectors
170170
.......
171171

172-
Numeric vectors have the same underlying representation as an |i128|.
173-
They can also be interpreted as a sequence of numeric values packed into a |V128| with a particular |shape|.
172+
Numeric vectors of type |VN| have the same underlying representation as an |IN|.
173+
They can also be interpreted as a sequence of numeric values packed into a |VN| with a particular |shape| :math:`t\K{x}M`,
174+
provided that :math:`N = |t|\cdot M`.
174175

175176
.. math::
176177
\begin{array}{l}
177178
\begin{array}{lll@{\qquad}l}
178-
\lanes_{t\K{x}N}(c) &=&
179-
c_0~\dots~c_{N-1} \\
179+
\lanes_{t\K{x}M}(c) &=&
180+
c_0~\dots~c_{M-1} \\
180181
\end{array}
181182
\\ \qquad
182183
\begin{array}[t]{@{}r@{~}l@{}l@{~}l@{~}l}
183-
(\where & B &=& |t| / 8 \\
184-
\wedge & b^{16} &=& \bytes_{\i128}(c) \\
185-
\wedge & c_i &=& \bytes_{t}^{-1}(b^{16}[i \cdot B \slice B]))
184+
(\where & w &=& |t| / 8 \\
185+
\wedge & b^\ast &=& \bytes_{\IN}(c) \\
186+
\wedge & c_i &=& \bytes_{t}^{-1}(b^\ast[i \cdot w \slice w]))
186187
\end{array}
187188
\end{array}
188189
189-
These functions are bijections, so they are invertible.
190+
This function is a bijection on |IN|, hence it is invertible.
190191

191192

192193
.. index:: byte, little endian, memory

document/core/util/macros.def

+6
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@
500500
.. |relop| mathdef:: \xref{syntax/instructions}{syntax-relop}{\X{relop}}
501501
.. |cvtop| mathdef:: \xref{syntax/instructions}{syntax-cvtop}{\X{cvtop}}
502502

503+
.. |unopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{unop}}
504+
.. |binopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{binop}}
505+
.. |testopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{testop}}
506+
.. |relopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{relop}}
507+
.. |cvtopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{cvtop}}
508+
503509
.. |iunop| mathdef:: \xref{syntax/instructions}{syntax-iunop}{\X{iunop}}
504510
.. |ibinop| mathdef:: \xref{syntax/instructions}{syntax-ibinop}{\X{ibinop}}
505511
.. |itestop| mathdef:: \xref{syntax/instructions}{syntax-itestop}{\X{itestop}}

0 commit comments

Comments
 (0)