AMDGPUInstructionSyntax.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. =========================
  2. AMDGPU Instruction Syntax
  3. =========================
  4. .. contents::
  5. :local:
  6. .. _amdgpu_syn_instructions:
  7. Instructions
  8. ============
  9. Syntax
  10. ~~~~~~
  11. An instruction has the following syntax:
  12. ``<``\ *opcode mnemonic*\ ``> <``\ *operand0*\ ``>, <``\ *operand1*\ ``>,... <``\ *modifier0*\ ``> <``\ *modifier1*\ ``>...``
  13. :doc:`Operands<AMDGPUOperandSyntax>` are normally comma-separated while
  14. :doc:`modifiers<AMDGPUModifierSyntax>` are space-separated.
  15. The order of *operands* and *modifiers* is fixed.
  16. Most *modifiers* are optional and may be omitted.
  17. .. _amdgpu_syn_instruction_mnemo:
  18. Opcode Mnemonic
  19. ~~~~~~~~~~~~~~~
  20. Opcode mnemonic describes opcode semantics and may include one or more suffices in this order:
  21. * :ref:`Destination operand type suffix<amdgpu_syn_instruction_type>`.
  22. * :ref:`Source operand type suffix<amdgpu_syn_instruction_type>`.
  23. * :ref:`Encoding suffix<amdgpu_syn_instruction_enc>`.
  24. .. _amdgpu_syn_instruction_type:
  25. Type and Size Suffices
  26. ~~~~~~~~~~~~~~~~~~~~~~
  27. Instructions which operate with data have an implied type of *data* operands.
  28. This data type is specified as a suffix of instruction mnemonic.
  29. There are instructions which have 2 type suffices:
  30. the first is the data type of the destination operand,
  31. the second is the data type of source *data* operand(s).
  32. Note that data type specified by an instruction does not apply
  33. to other kinds of operands such as *addresses*, *offsets* and so on.
  34. The following table enumerates the most frequently used type suffices.
  35. ============================================ ======================= =================
  36. Type Suffices Packed instruction? Data Type
  37. ============================================ ======================= =================
  38. _b512, _b256, _b128, _b64, _b32, _b16, _b8 No Bits.
  39. _u64, _u32, _u16, _u8 No Unsigned integer.
  40. _i64, _i32, _i16, _i8 No Signed integer.
  41. _f64, _f32, _f16 No Floating-point.
  42. _b16, _u16, _i16, _f16 Yes Packed.
  43. ============================================ ======================= =================
  44. Instructions which have no type suffices are assumed to operate with typeless data.
  45. The size of data is specified by size suffices:
  46. ================= =================== =====================================
  47. Size Suffix Implied data type Required register size in dwords
  48. ================= =================== =====================================
  49. \- b32 1
  50. x2 b64 2
  51. x3 b96 3
  52. x4 b128 4
  53. x8 b256 8
  54. x16 b512 16
  55. x b32 1
  56. xy b64 2
  57. xyz b96 3
  58. xyzw b128 4
  59. d16_x b16 1
  60. d16_xy b16x2 2 for GFX8.0, 1 for GFX8.1 and GFX9
  61. d16_xyz b16x3 3 for GFX8.0, 2 for GFX8.1 and GFX9
  62. d16_xyzw b16x4 4 for GFX8.0, 2 for GFX8.1 and GFX9
  63. ================= =================== =====================================
  64. .. WARNING::
  65. There are exceptions from rules described above.
  66. Operands which have type different from type specified by the opcode are
  67. :ref:`tagged<amdgpu_syn_instruction_operand_tags>` in the description.
  68. Examples of instructions with different types of source and destination operands:
  69. .. parsed-literal::
  70. s_bcnt0_i32_b64
  71. v_cvt_f32_u32
  72. Examples of instructions with one data type:
  73. .. parsed-literal::
  74. v_max3_f32
  75. v_max3_i16
  76. Examples of instructions which operate with packed data:
  77. .. parsed-literal::
  78. v_pk_add_u16
  79. v_pk_add_i16
  80. v_pk_add_f16
  81. Examples of typeless instructions which operate on b128 data:
  82. .. parsed-literal::
  83. buffer_store_dwordx4
  84. flat_load_dwordx4
  85. .. _amdgpu_syn_instruction_enc:
  86. Encoding Suffices
  87. ~~~~~~~~~~~~~~~~~
  88. Most *VOP1*, *VOP2* and *VOPC* instructions have several variants:
  89. they may also be encoded in *VOP3*, *DPP* and *SDWA* formats.
  90. The assembler will automatically use optimal encoding based on instruction operands.
  91. To force specific encoding, one can add a suffix to the opcode of the instruction:
  92. =================================================== =================
  93. Encoding Encoding Suffix
  94. =================================================== =================
  95. Native 32-bit encoding (*VOP1*, *VOP2* or *VOPC*) _e32
  96. *VOP3* (64-bit) encoding _e64
  97. *DPP* encoding _dpp
  98. *SDWA* encoding _sdwa
  99. =================================================== =================
  100. These suffices are used in this reference to indicate the assumed encoding.
  101. When no suffix is specified, a native encoding is implied.
  102. Operands
  103. ========
  104. Syntax
  105. ~~~~~~
  106. Syntax of most operands is described :doc:`in this document<AMDGPUOperandSyntax>`.
  107. For detailed information about operands follow *operand links* in GPU-specific documents:
  108. * :doc:`GFX7<AMDGPU/AMDGPUAsmGFX7>`
  109. * :doc:`GFX8<AMDGPU/AMDGPUAsmGFX8>`
  110. * :doc:`GFX9<AMDGPU/AMDGPUAsmGFX9>`
  111. * :doc:`GFX10<AMDGPU/AMDGPUAsmGFX10>`
  112. Modifiers
  113. =========
  114. Syntax
  115. ~~~~~~
  116. Syntax of modifiers is described :doc:`in this document<AMDGPUModifierSyntax>`.
  117. Information about modifiers supported for individual instructions may be found in GPU-specific documents:
  118. * :doc:`GFX7<AMDGPU/AMDGPUAsmGFX7>`
  119. * :doc:`GFX8<AMDGPU/AMDGPUAsmGFX8>`
  120. * :doc:`GFX9<AMDGPU/AMDGPUAsmGFX9>`
  121. * :doc:`GFX10<AMDGPU/AMDGPUAsmGFX10>`