xref: /llvm-project/llvm/docs/AMDGPUInstructionSyntax.rst (revision b8e1071a29035f5f7314bccfc1259a5a4935a8bc)
147eb6368SDmitry Preobrazhensky=========================
247eb6368SDmitry PreobrazhenskyAMDGPU Instruction Syntax
347eb6368SDmitry Preobrazhensky=========================
447eb6368SDmitry Preobrazhensky
547eb6368SDmitry Preobrazhensky.. contents::
647eb6368SDmitry Preobrazhensky   :local:
747eb6368SDmitry Preobrazhensky
847eb6368SDmitry Preobrazhensky.. _amdgpu_syn_instructions:
947eb6368SDmitry Preobrazhensky
1047eb6368SDmitry PreobrazhenskyInstructions
1147eb6368SDmitry Preobrazhensky============
1247eb6368SDmitry Preobrazhensky
1347eb6368SDmitry PreobrazhenskySyntax
1447eb6368SDmitry Preobrazhensky~~~~~~
1547eb6368SDmitry Preobrazhensky
16*b8e1071aSDmitry PreobrazhenskySyntax of Regular Instructions
17*b8e1071aSDmitry Preobrazhensky------------------------------
18*b8e1071aSDmitry Preobrazhensky
1947eb6368SDmitry PreobrazhenskyAn instruction has the following syntax:
2047eb6368SDmitry Preobrazhensky
21d9daee5aSDmitry Preobrazhensky  | ``<``\ *opcode mnemonic*\ ``>    <``\ *operand0*\ ``>,
22d9daee5aSDmitry Preobrazhensky      <``\ *operand1*\ ``>,...    <``\ *modifier0*\ ``> <``\ *modifier1*\ ``>...``
2347eb6368SDmitry Preobrazhensky
24d9daee5aSDmitry Preobrazhensky:doc:`Operands<AMDGPUOperandSyntax>` are normally comma-separated, while
2547eb6368SDmitry Preobrazhensky:doc:`modifiers<AMDGPUModifierSyntax>` are space-separated.
2647eb6368SDmitry Preobrazhensky
2747eb6368SDmitry PreobrazhenskyThe order of *operands* and *modifiers* is fixed.
2847eb6368SDmitry PreobrazhenskyMost *modifiers* are optional and may be omitted.
2947eb6368SDmitry Preobrazhensky
30*b8e1071aSDmitry PreobrazhenskySyntax of VOPD Instructions
31*b8e1071aSDmitry Preobrazhensky---------------------------
32*b8e1071aSDmitry Preobrazhensky
33*b8e1071aSDmitry Preobrazhensky*VOPDX* and *VOPDY* instructions must be concatenated with the :: operator to form a single *VOPD* instruction:
34*b8e1071aSDmitry Preobrazhensky
35*b8e1071aSDmitry Preobrazhensky    ``<``\ *VOPDX instruction*\ ``>  ::  <``\ *VOPDY instruction*\ ``>``
36*b8e1071aSDmitry Preobrazhensky
37*b8e1071aSDmitry PreobrazhenskyAn example:
38*b8e1071aSDmitry Preobrazhensky
39*b8e1071aSDmitry Preobrazhensky.. parsed-literal::
40*b8e1071aSDmitry Preobrazhensky
41*b8e1071aSDmitry Preobrazhensky    v_dual_add_f32 v255, v255, v2 :: v_dual_fmaak_f32 v6, v2, v3, 1.0
42*b8e1071aSDmitry Preobrazhensky
43*b8e1071aSDmitry PreobrazhenskyNote that *VOPDX* and *VOPDY* instructions cannot be used as separate opcodes.
44*b8e1071aSDmitry Preobrazhensky
4547eb6368SDmitry Preobrazhensky.. _amdgpu_syn_instruction_mnemo:
4647eb6368SDmitry Preobrazhensky
4747eb6368SDmitry PreobrazhenskyOpcode Mnemonic
4847eb6368SDmitry Preobrazhensky~~~~~~~~~~~~~~~
4947eb6368SDmitry Preobrazhensky
50d9daee5aSDmitry PreobrazhenskyOpcode mnemonic describes opcode semantics
51d9daee5aSDmitry Preobrazhenskyand may include one or more suffices in this order:
5247eb6368SDmitry Preobrazhensky
538ea3e9d9SDmitry Preobrazhensky* :ref:`Packing suffix<amdgpu_syn_instruction_pk>`.
5447eb6368SDmitry Preobrazhensky* :ref:`Destination operand type suffix<amdgpu_syn_instruction_type>`.
5547eb6368SDmitry Preobrazhensky* :ref:`Source operand type suffix<amdgpu_syn_instruction_type>`.
5647eb6368SDmitry Preobrazhensky* :ref:`Encoding suffix<amdgpu_syn_instruction_enc>`.
5747eb6368SDmitry Preobrazhensky
588ea3e9d9SDmitry Preobrazhensky.. _amdgpu_syn_instruction_pk:
598ea3e9d9SDmitry Preobrazhensky
608ea3e9d9SDmitry PreobrazhenskyPacking Suffix
618ea3e9d9SDmitry Preobrazhensky~~~~~~~~~~~~~~
628ea3e9d9SDmitry Preobrazhensky
638ea3e9d9SDmitry PreobrazhenskyMost instructions which operate on packed data have a *_pk* suffix.
648ea3e9d9SDmitry PreobrazhenskyUnless otherwise :ref:`noted<amdgpu_syn_instruction_operand_tags>`,
658ea3e9d9SDmitry Preobrazhenskythese instructions operate on and produce packed data composed of
668ea3e9d9SDmitry Preobrazhenskytwo values. The type of values is indicated by
678ea3e9d9SDmitry Preobrazhensky:ref:`type suffices<amdgpu_syn_instruction_type>`.
688ea3e9d9SDmitry Preobrazhensky
698ea3e9d9SDmitry PreobrazhenskyFor example, the following instruction sums up two pairs of f16 values
708ea3e9d9SDmitry Preobrazhenskyand produces a pair of f16 values:
718ea3e9d9SDmitry Preobrazhensky
728ea3e9d9SDmitry Preobrazhensky.. parsed-literal::
738ea3e9d9SDmitry Preobrazhensky
748ea3e9d9SDmitry Preobrazhensky    v_pk_add_f16 v1, v2, v3     // Each operand has f16x2 type
758ea3e9d9SDmitry Preobrazhensky
7647eb6368SDmitry Preobrazhensky.. _amdgpu_syn_instruction_type:
7747eb6368SDmitry Preobrazhensky
7847eb6368SDmitry PreobrazhenskyType and Size Suffices
7947eb6368SDmitry Preobrazhensky~~~~~~~~~~~~~~~~~~~~~~
8047eb6368SDmitry Preobrazhensky
8147eb6368SDmitry PreobrazhenskyInstructions which operate with data have an implied type of *data* operands.
8247eb6368SDmitry PreobrazhenskyThis data type is specified as a suffix of instruction mnemonic.
8347eb6368SDmitry Preobrazhensky
8447eb6368SDmitry PreobrazhenskyThere are instructions which have 2 type suffices:
8547eb6368SDmitry Preobrazhenskythe first is the data type of the destination operand,
8647eb6368SDmitry Preobrazhenskythe second is the data type of source *data* operand(s).
8747eb6368SDmitry Preobrazhensky
8847eb6368SDmitry PreobrazhenskyNote that data type specified by an instruction does not apply
8947eb6368SDmitry Preobrazhenskyto other kinds of operands such as *addresses*, *offsets* and so on.
9047eb6368SDmitry Preobrazhensky
9147eb6368SDmitry PreobrazhenskyThe following table enumerates the most frequently used type suffices.
9247eb6368SDmitry Preobrazhensky
938ea3e9d9SDmitry Preobrazhensky    ============================================ ======================= ============================
9447eb6368SDmitry Preobrazhensky    Type Suffices                                Packed instruction?     Data Type
958ea3e9d9SDmitry Preobrazhensky    ============================================ ======================= ============================
9647eb6368SDmitry Preobrazhensky    _b512, _b256, _b128, _b64, _b32, _b16, _b8   No                      Bits.
9747eb6368SDmitry Preobrazhensky    _u64, _u32, _u16, _u8                        No                      Unsigned integer.
9847eb6368SDmitry Preobrazhensky    _i64, _i32, _i16, _i8                        No                      Signed integer.
9947eb6368SDmitry Preobrazhensky    _f64, _f32, _f16                             No                      Floating-point.
1008ea3e9d9SDmitry Preobrazhensky    _b16, _u16, _i16, _f16                       Yes                     Packed (b16x2, u16x2, etc).
1018ea3e9d9SDmitry Preobrazhensky    ============================================ ======================= ============================
10247eb6368SDmitry Preobrazhensky
10347eb6368SDmitry PreobrazhenskyInstructions which have no type suffices are assumed to operate with typeless data.
104d9daee5aSDmitry PreobrazhenskyThe size of typeless data is specified by size suffices:
10547eb6368SDmitry Preobrazhensky
10647eb6368SDmitry Preobrazhensky    ================= =================== =====================================
10747eb6368SDmitry Preobrazhensky    Size Suffix       Implied data type   Required register size in dwords
10847eb6368SDmitry Preobrazhensky    ================= =================== =====================================
10947eb6368SDmitry Preobrazhensky    \-                b32                 1
11047eb6368SDmitry Preobrazhensky    x2                b64                 2
11147eb6368SDmitry Preobrazhensky    x3                b96                 3
11247eb6368SDmitry Preobrazhensky    x4                b128                4
11347eb6368SDmitry Preobrazhensky    x8                b256                8
11447eb6368SDmitry Preobrazhensky    x16               b512                16
11547eb6368SDmitry Preobrazhensky    x                 b32                 1
11647eb6368SDmitry Preobrazhensky    xy                b64                 2
11747eb6368SDmitry Preobrazhensky    xyz               b96                 3
11847eb6368SDmitry Preobrazhensky    xyzw              b128                4
11947eb6368SDmitry Preobrazhensky    d16_x             b16                 1
1203f7985e6SDmitry Preobrazhensky    d16_xy            b16x2               2 for GFX8.0, 1 for GFX8.1 and GFX9+
1213f7985e6SDmitry Preobrazhensky    d16_xyz           b16x3               3 for GFX8.0, 2 for GFX8.1 and GFX9+
1223f7985e6SDmitry Preobrazhensky    d16_xyzw          b16x4               4 for GFX8.0, 2 for GFX8.1 and GFX9+
123*b8e1071aSDmitry Preobrazhensky    d16_format_x      b16                 1
124*b8e1071aSDmitry Preobrazhensky    d16_format_xy     b16x2               1
125*b8e1071aSDmitry Preobrazhensky    d16_format_xyz    b16x3               2
126*b8e1071aSDmitry Preobrazhensky    d16_format_xyzw   b16x4               2
12747eb6368SDmitry Preobrazhensky    ================= =================== =====================================
12847eb6368SDmitry Preobrazhensky
12947eb6368SDmitry Preobrazhensky.. WARNING::
130d9daee5aSDmitry Preobrazhensky    There are exceptions to the rules described above.
131d9daee5aSDmitry Preobrazhensky    Operands which have a type different from the type specified by the opcode are
13247eb6368SDmitry Preobrazhensky    :ref:`tagged<amdgpu_syn_instruction_operand_tags>` in the description.
13347eb6368SDmitry Preobrazhensky
13447eb6368SDmitry PreobrazhenskyExamples of instructions with different types of source and destination operands:
13547eb6368SDmitry Preobrazhensky
1361fa7aaf5SDmitry Preobrazhensky.. parsed-literal::
13747eb6368SDmitry Preobrazhensky
13847eb6368SDmitry Preobrazhensky    s_bcnt0_i32_b64
13947eb6368SDmitry Preobrazhensky    v_cvt_f32_u32
14047eb6368SDmitry Preobrazhensky
14147eb6368SDmitry PreobrazhenskyExamples of instructions with one data type:
14247eb6368SDmitry Preobrazhensky
1431fa7aaf5SDmitry Preobrazhensky.. parsed-literal::
14447eb6368SDmitry Preobrazhensky
14547eb6368SDmitry Preobrazhensky    v_max3_f32
14647eb6368SDmitry Preobrazhensky    v_max3_i16
14747eb6368SDmitry Preobrazhensky
14847eb6368SDmitry PreobrazhenskyExamples of instructions which operate with packed data:
14947eb6368SDmitry Preobrazhensky
1501fa7aaf5SDmitry Preobrazhensky.. parsed-literal::
15147eb6368SDmitry Preobrazhensky
15247eb6368SDmitry Preobrazhensky    v_pk_add_u16
15347eb6368SDmitry Preobrazhensky    v_pk_add_i16
15447eb6368SDmitry Preobrazhensky    v_pk_add_f16
15547eb6368SDmitry Preobrazhensky
15647eb6368SDmitry PreobrazhenskyExamples of typeless instructions which operate on b128 data:
15747eb6368SDmitry Preobrazhensky
1581fa7aaf5SDmitry Preobrazhensky.. parsed-literal::
15947eb6368SDmitry Preobrazhensky
16047eb6368SDmitry Preobrazhensky    buffer_store_dwordx4
16147eb6368SDmitry Preobrazhensky    flat_load_dwordx4
16247eb6368SDmitry Preobrazhensky
16347eb6368SDmitry Preobrazhensky.. _amdgpu_syn_instruction_enc:
16447eb6368SDmitry Preobrazhensky
16547eb6368SDmitry PreobrazhenskyEncoding Suffices
16647eb6368SDmitry Preobrazhensky~~~~~~~~~~~~~~~~~
16747eb6368SDmitry Preobrazhensky
16847eb6368SDmitry PreobrazhenskyMost *VOP1*, *VOP2* and *VOPC* instructions have several variants:
16947eb6368SDmitry Preobrazhenskythey may also be encoded in *VOP3*, *DPP* and *SDWA* formats.
17047eb6368SDmitry Preobrazhensky
171d9daee5aSDmitry PreobrazhenskyThe assembler selects an optimal encoding automatically
172d9daee5aSDmitry Preobrazhenskybased on instruction operands and modifiers,
173d9daee5aSDmitry Preobrazhenskyunless a specific encoding is explicitly requested.
17447eb6368SDmitry PreobrazhenskyTo force specific encoding, one can add a suffix to the opcode of the instruction:
17547eb6368SDmitry Preobrazhensky
17647eb6368SDmitry Preobrazhensky    =================================================== =================
17747eb6368SDmitry Preobrazhensky    Encoding                                            Encoding Suffix
17847eb6368SDmitry Preobrazhensky    =================================================== =================
1798ea3e9d9SDmitry Preobrazhensky    *VOP1*, *VOP2* and *VOPC* (32-bit) encoding         _e32
18047eb6368SDmitry Preobrazhensky    *VOP3* (64-bit) encoding                            _e64
18147eb6368SDmitry Preobrazhensky    *DPP* encoding                                      _dpp
18247eb6368SDmitry Preobrazhensky    *SDWA* encoding                                     _sdwa
183*b8e1071aSDmitry Preobrazhensky    *VOP3 DPP* encoding                                 _e64_dpp
18447eb6368SDmitry Preobrazhensky    =================================================== =================
18547eb6368SDmitry Preobrazhensky
186d9daee5aSDmitry PreobrazhenskyThis reference uses encoding suffices to specify which encoding is implied.
187d9daee5aSDmitry PreobrazhenskyWhen no suffix is specified, native instruction encoding is assumed.
18847eb6368SDmitry Preobrazhensky
18947eb6368SDmitry PreobrazhenskyOperands
19047eb6368SDmitry Preobrazhensky========
19147eb6368SDmitry Preobrazhensky
19247eb6368SDmitry PreobrazhenskySyntax
19347eb6368SDmitry Preobrazhensky~~~~~~
19447eb6368SDmitry Preobrazhensky
195d9daee5aSDmitry PreobrazhenskyThe syntax of generic operands is described :doc:`in this document<AMDGPUOperandSyntax>`.
19647eb6368SDmitry Preobrazhensky
197d9daee5aSDmitry PreobrazhenskyFor detailed information about operands, follow *operand links* in GPU-specific documents.
19847eb6368SDmitry Preobrazhensky
19947eb6368SDmitry PreobrazhenskyModifiers
20047eb6368SDmitry Preobrazhensky=========
20147eb6368SDmitry Preobrazhensky
20247eb6368SDmitry PreobrazhenskySyntax
20347eb6368SDmitry Preobrazhensky~~~~~~
20447eb6368SDmitry Preobrazhensky
205d9daee5aSDmitry PreobrazhenskyThe syntax of modifiers is described :doc:`in this document<AMDGPUModifierSyntax>`.
20647eb6368SDmitry Preobrazhensky
207d9daee5aSDmitry PreobrazhenskyInformation about modifiers supported for individual instructions
208d9daee5aSDmitry Preobrazhenskymay be found in GPU-specific documents.
209