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

Commit 56496c8

Browse files
committed
Add syntax for SIMD instructions
1 parent 8e1bda6 commit 56496c8

File tree

2 files changed

+165
-9
lines changed

2 files changed

+165
-9
lines changed

document/core/syntax/instructions.rst

Lines changed: 143 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ The following sections group instructions into a number of different categories.
3535
.. _syntax-fbinop:
3636
.. _syntax-ftestop:
3737
.. _syntax-frelop:
38+
.. _syntax-vunop:
39+
.. _syntax-vbinop:
40+
.. _syntax-vternop:
41+
.. _syntax-vtestop:
42+
.. _syntax-vshiftop:
43+
.. _syntax-viunop:
44+
.. _syntax-vibinop:
45+
.. _syntax-vsatbinop:
46+
.. _syntax-vfunop:
47+
.. _syntax-vfbinop:
3848
.. _syntax-instr-numeric:
3949

4050
Numeric Instructions
@@ -47,15 +57,27 @@ These operations closely match respective operations available in hardware.
4757
\begin{array}{llcl}
4858
\production{width} & \X{nn}, \X{mm} &::=&
4959
\K{32} ~|~ \K{64} \\
60+
\production{simdwidth} & \X{sss} &::=&
61+
\K{128} \\
5062
\production{signedness} & \sx &::=&
5163
\K{u} ~|~ \K{s} \\
64+
\production{ishape} & \X{ixx} &::=&
65+
\K{i8x16} ~|~ \K{i16x8} ~|~ \K{i32x4} ~|~ \K{i64x2} \\
66+
\production{fshape} & \X{fxx} &::=&
67+
\K{f32x4} ~|~ \K{f64x2} \\
68+
\production{vshape} & \X{vxx} &::=&
69+
\X{ixx} ~|~ \X{fxx} \\
5270
\production{instruction} & \instr &::=&
5371
\K{i}\X{nn}\K{.}\CONST~\xref{syntax/values}{syntax-int}{\iX{\X{nn}}} ~|~
54-
\K{f}\X{nn}\K{.}\CONST~\xref{syntax/values}{syntax-float}{\fX{\X{nn}}} \\&&|&
72+
\K{f}\X{nn}\K{.}\CONST~\xref{syntax/values}{syntax-float}{\fX{\X{nn}}} ~|~
73+
\K{v}\X{sss}\K{.}\CONST~\xref{syntax/values}{syntax-simd}{\vX{\X{sss}}} \\&&|&
5574
\K{i}\X{nn}\K{.}\iunop ~|~
56-
\K{f}\X{nn}\K{.}\funop \\&&|&
75+
\K{f}\X{nn}\K{.}\funop ~|~
76+
\K{v}\X{sss}\K{.}\vunop \\&&|&
5777
\K{i}\X{nn}\K{.}\ibinop ~|~
58-
\K{f}\X{nn}\K{.}\fbinop \\&&|&
78+
\K{f}\X{nn}\K{.}\fbinop ~|~
79+
\K{v}\X{sss}\K{.}\vbinop \\&&|&
80+
\K{v}\X{sss}\K{.}\vternop \\&&|&
5981
\K{i}\X{nn}\K{.}\itestop \\&&|&
6082
\K{i}\X{nn}\K{.}\irelop ~|~
6183
\K{f}\X{nn}\K{.}\frelop \\&&|&
@@ -71,6 +93,49 @@ These operations closely match respective operations available in hardware.
7193
\K{f}\X{nn}\K{.}\CONVERT\K{\_i}\X{mm}\K{\_}\sx \\&&|&
7294
\K{i}\X{nn}\K{.}\REINTERPRET\K{\_f}\X{nn} ~|~
7395
\K{f}\X{nn}\K{.}\REINTERPRET\K{\_i}\X{nn} \\&&|&
96+
\K{v8x16.}\SHUFFLE ~|~ \K{v8x16.}\SWIZZLE \\&&|&
97+
\X{vxx}\K{.}\SPLAT \\&&|&
98+
\K{i8x16.}\EXTRACTLANE\K{\_}\sx ~|~
99+
\K{i16x8.}\EXTRACTLANE\K{\_}\sx \\&&|&
100+
\K{i32x4.}\EXTRACTLANE ~|~
101+
\K{i64x2.}\EXTRACTLANE \\&&|&
102+
\X{fxx}\K{.}\EXTRACTLANE \\&&|&
103+
\X{vxx}\K{.}\REPLACELANE \\&&|&
104+
\X{ixx}\K{.}\irelop \\&&|&
105+
\X{fxx}\K{.}\frelop \\&&|&
106+
\K{i8x16.}\viunop ~|~
107+
\K{i16x8.}\viunop ~|~
108+
\K{i32x4.}\viunop \\&&|&
109+
\K{i64x2.}\NEG \\&&|&
110+
\X{fxx.}\vfunop \\&&|&
111+
\K{i8x16.}\vtestop ~|~
112+
\K{i16x8.}\vtestop ~|~
113+
\K{i32x4.}\vtestop \\&&|&
114+
\K{i8x16.}\BITMASK ~|~
115+
\K{i16x8.}\BITMASK ~|~
116+
\K{i32x4.}\BITMASK \\&&|&
117+
\K{i8x16.}\NARROW\K{\_i16x8\_}\sx ~|~
118+
\K{i16x8.}\NARROW\K{\_i32x4\_}\sx \\&&|&
119+
\K{i16x8.}\WIDEN\K{\_low}\K{\_i8x16\_}\sx ~|~
120+
\K{i32x4.}\WIDEN\K{\_low}\K{\_i16x8\_}\sx \\&&|&
121+
\K{i16x8.}\WIDEN\K{\_high}\K{\_i8x16\_}\sx ~|~
122+
\K{i32x4.}\WIDEN\K{\_high}\K{\_i16x8\_}\sx \\&&|&
123+
\X{ixx}\K{.}\vshiftop \\&&|&
124+
\K{i8x16.}\vibinop ~|~
125+
\K{i16x8.}\vibinop ~|~
126+
\K{i32x4.}\vibinop \\&&|&
127+
\K{i64x2.}\ADD ~|~
128+
\K{i64x2.}\SUB \\&&|&
129+
\K{i8x16.}\vsatbinop ~|~
130+
\K{i16x8.}\vsatbinop \\&&|&
131+
\K{i16x8.}\K{mul} ~|~
132+
\K{i32x4.}\K{mul} ~|~
133+
\K{i64x2.}\K{mul} \\&&|&
134+
\K{i8x16.}\AVGRU ~|~
135+
\K{i16x8.}\AVGRU \\&&|&
136+
\X{fxx.}\vfbinop \\&&|&
137+
\K{i32x4.}\TRUNC\K{\_sat\_f32x4\_}\sx ~|~
138+
\K{f32x4.}\CONVERT\K{\_i32x4\_}\sx \\&&|&
74139
\dots \\
75140
\production{integer unary operator} & \iunop &::=&
76141
\K{clz} ~|~
@@ -105,8 +170,20 @@ These operations closely match respective operations available in hardware.
105170
\K{min} ~|~
106171
\K{max} ~|~
107172
\K{copysign} \\
173+
\production{SIMD unary operator} & \vunop &::=&
174+
\K{not} \\
175+
\production{SIMD binary operator} & \vbinop &::=&
176+
\K{and} ~|~
177+
\K{andnot} ~|~
178+
\K{or} ~|~
179+
\K{xor} \\
180+
\production{SIMD unary operator} & \vternop &::=&
181+
\K{bitselect} \\
108182
\production{integer test operator} & \itestop &::=&
109183
\K{eqz} \\
184+
\production{SIMD test operator} & \vtestop &::=&
185+
\K{any\_true} ~|~
186+
\K{all\_true} \\
110187
\production{integer relational operator} & \irelop &::=&
111188
\K{eq} ~|~
112189
\K{ne} ~|~
@@ -121,6 +198,32 @@ These operations closely match respective operations available in hardware.
121198
\K{gt} ~|~
122199
\K{le} ~|~
123200
\K{ge} \\
201+
\production{SIMD integer shift operator} & \vshiftop &::=&
202+
\K{shl} ~|~
203+
\K{shr\_s} ~|~
204+
\K{shr\_u} \\
205+
\production{SIMD integer unary operator} & \viunop &::=&
206+
\K{abs} ~|~
207+
\K{neg} \\
208+
\production{SIMD integer binary operator} & \vibinop &::=&
209+
\K{add} ~|~
210+
\K{sub} ~|~
211+
\K{min\_}\sx ~|~
212+
\K{max\_}\sx \\
213+
\production{SIMD integer saturating binary operator} & \vsatbinop &::=&
214+
\K{add\_sat\_}\sx ~|~
215+
\K{sub\_sat\_}\sx \\
216+
\production{SIMD floating-point unary operator} & \vfunop &::=&
217+
\K{abs} ~|~
218+
\K{neg} ~|~
219+
\K{sqrt} \\
220+
\production{SIMD floating-point binary operator} & \vfbinop &::=&
221+
\K{add} ~|~
222+
\K{sub} ~|~
223+
\K{mul} ~|~
224+
\K{div} ~|~
225+
\K{min} ~|~
226+
\K{max} \\
124227
\end{array}
125228
126229
Numeric instructions are divided by :ref:`value type <syntax-valtype>`.
@@ -134,15 +237,25 @@ For each type, several subcategories can be distinguished:
134237

135238
* *Tests*: consume one operand of the respective type and produce a Boolean integer result.
136239

137-
* *Comparisons*: consume two operands of the respective type and produce a Boolean integer result.
240+
* *Comparisons*: consume two operands of the respective type and produce a Boolean integer result or a result of the respective type.
138241

139242
* *Conversions*: consume a value of one type and produce a result of another
140243
(the source type of the conversion is the one after the ":math:`\K{\_}`").
141244

245+
.. todo::
246+
Do these subcategories have to cover every instruction? E.g. simd shifts don't fit anywhere here, since they take 128-bit int and a 32-bit int.
247+
142248
Some integer instructions come in two flavors,
143249
where a signedness annotation |sx| distinguishes whether the operands are to be :ref:`interpreted <aux-signed>` as :ref:`unsigned <syntax-uint>` or :ref:`signed <syntax-sint>` integers.
144250
For the other integer instructions, the use of two's complement for the signed interpretation means that they behave the same regardless of signedness.
145251

252+
Instructions that operate on |V128| operands have a naming convention that
253+
determines how those operands will be interpreted. An instruction beginning with :math:`\K{i32x4}`
254+
will interpret its operands as four |i32|, packed side-by-side into a |i128|.
255+
Similarly, and instruction beginning with :math:`\K{f64x2}` interprets its operands as two |f64|, packed side-by-side into a |i128|.
256+
257+
.. todo::
258+
write up runtime interpretation for the lane shapes
146259

147260
Conventions
148261
...........
@@ -154,9 +267,22 @@ Occasionally, it is convenient to group operators together according to the foll
154267
\production{unary operator} & \unop &::=&
155268
\iunop ~|~
156269
\funop ~|~
270+
\vunop ~|~
271+
\viunop ~|~
272+
\vfunop ~|~
157273
\EXTEND{N}\K{\_s} \\
158-
\production{binary operator} & \binop &::=& \ibinop ~|~ \fbinop \\
159-
\production{test operator} & \testop &::=& \itestop \\
274+
\production{binary operator} & \binop &::=&
275+
\ibinop ~|~
276+
\fbinop ~|~
277+
\vbinop ~|~
278+
\vibinop ~|~
279+
\vsatbinop ~|~
280+
\vfbinop ~|~
281+
\AVGRU
282+
\\
283+
\production{test operator} & \testop &::=&
284+
\itestop ~|~
285+
\vtestop \\
160286
\production{relational operator} & \relop &::=& \irelop ~|~ \frelop \\
161287
\production{conversion operator} & \cvtop &::=&
162288
\WRAP ~|~
@@ -166,7 +292,9 @@ Occasionally, it is convenient to group operators together according to the foll
166292
\CONVERT ~|~
167293
\DEMOTE ~|~
168294
\PROMOTE ~|~
169-
\REINTERPRET \\
295+
\REINTERPRET ~|~
296+
\NARROW ~|~
297+
\WIDEN \\
170298
\end{array}
171299
172300
@@ -235,15 +363,21 @@ Instructions in this group are concerned with linear :ref:`memory <syntax-mem>`.
235363
\production{instruction} & \instr &::=&
236364
\dots \\&&|&
237365
\K{i}\X{nn}\K{.}\LOAD~\memarg ~|~
238-
\K{f}\X{nn}\K{.}\LOAD~\memarg \\&&|&
366+
\K{f}\X{nn}\K{.}\LOAD~\memarg ~|~
367+
\K{v}\X{sss}\K{.}\LOAD~\memarg \\&&|&
239368
\K{i}\X{nn}\K{.}\STORE~\memarg ~|~
240-
\K{f}\X{nn}\K{.}\STORE~\memarg \\&&|&
369+
\K{f}\X{nn}\K{.}\STORE~\memarg ~|~
370+
\K{v}\X{sss}\K{.}\STORE~\memarg \\&&|&
241371
\K{i}\X{nn}\K{.}\LOAD\K{8\_}\sx~\memarg ~|~
242372
\K{i}\X{nn}\K{.}\LOAD\K{16\_}\sx~\memarg ~|~
243373
\K{i64.}\LOAD\K{32\_}\sx~\memarg \\&&|&
244374
\K{i}\X{nn}\K{.}\STORE\K{8}~\memarg ~|~
245375
\K{i}\X{nn}\K{.}\STORE\K{16}~\memarg ~|~
246376
\K{i64.}\STORE\K{32}~\memarg \\&&|&
377+
\K{i16x8.}\LOAD\K{8x8}\_\sx ~|~
378+
\K{i32x4.}\LOAD\K{16x4}\_\sx ~|~
379+
\K{i64x2.}\LOAD\K{32x2}\_\sx \\&&|&
380+
\K{v}\X{ixx}\K{.}\LOAD\K{\_splat} \\&&|&
247381
\MEMORYSIZE \\&&|&
248382
\MEMORYGROW \\
249383
\end{array}

document/core/util/macros.def

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
.. |sX#1| mathdef:: {\X{s#1}}
130130
.. |iX#1| mathdef:: {\X{i#1}}
131131
.. |fX#1| mathdef:: {\X{f#1}}
132+
.. |vX#1| mathdef:: {\X{v#1}}
132133

133134
.. |uN| mathdef:: \xref{syntax/values}{syntax-int}{\X{u}N}
134135
.. |uM| mathdef:: \xref{syntax/values}{syntax-int}{\X{u}M}
@@ -378,6 +379,16 @@
378379
.. |DEMOTE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{demote}}
379380
.. |REINTERPRET| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{reinterpret}}
380381

382+
.. |SHUFFLE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{shuffle}}
383+
.. |SWIZZLE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{swizzle}}
384+
.. |SPLAT| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{splat}}
385+
.. |EXTRACTLANE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{extract\_lane}}
386+
.. |REPLACELANE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{replace\_lane}}
387+
.. |BITMASK| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{bitmask}}
388+
.. |NARROW| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{narrow}}
389+
.. |WIDEN| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{widen}}
390+
.. |AVGRU| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{avgr\_u}}
391+
381392

382393
.. Instructions, non-terminals
383394

@@ -397,6 +408,17 @@
397408
.. |ftestop| mathdef:: \xref{syntax/instructions}{syntax-ftestop}{\X{ftestop}}
398409
.. |frelop| mathdef:: \xref{syntax/instructions}{syntax-frelop}{\X{frelop}}
399410

411+
.. |vunop| mathdef:: \xref{syntax/instructions}{syntax-vunop}{\X{vunop}}
412+
.. |vbinop| mathdef:: \xref{syntax/instructions}{syntax-vbinop}{\X{vbinop}}
413+
.. |vternop| mathdef:: \xref{syntax/instructions}{syntax-vternop}{\X{vternop}}
414+
.. |vtestop| mathdef:: \xref{syntax/instructions}{syntax-vtestop}{\X{vtestop}}
415+
.. |vshiftop| mathdef:: \xref{syntax/instructions}{syntax-vshiftop}{\X{vshiftop}}
416+
.. |viunop| mathdef:: \xref{syntax/instructions}{syntax-viunop}{\X{viunop}}
417+
.. |vibinop| mathdef:: \xref{syntax/instructions}{syntax-vibinop}{\X{vibinop}}
418+
.. |vsatbinop| mathdef:: \xref{syntax/instructions}{syntax-vsatbinop}{\X{vsatbinop}}
419+
.. |vfunop| mathdef:: \xref{syntax/instructions}{syntax-vfunop}{\X{vfunop}}
420+
.. |vfbinop| mathdef:: \xref{syntax/instructions}{syntax-vfbinop}{\X{vfbinop}}
421+
400422
.. |sx| mathdef:: \xref{syntax/instructions}{syntax-sx}{\X{sx}}
401423
.. |memarg| mathdef:: \xref{syntax/instructions}{syntax-memarg}{\X{memarg}}
402424

0 commit comments

Comments
 (0)