1 =====================================
2 Syntax of AMDGPU Instruction Operands
3 =====================================
11 The following notation is used throughout this document:
13 =================== =============================================================================
15 =================== =============================================================================
16 {0..N} Any integer value in the range from 0 to N (inclusive).
17 <x> Syntax and meaning of *x* are explained elsewhere.
18 =================== =============================================================================
20 .. _amdgpu_syn_operands:
30 Vector registers. There are 256 32-bit vector registers.
32 A sequence of *vector* registers may be used to operate with more than 32 bits of data.
34 Assembler currently supports tuples with 1 to 12, 16 and 32 *vector* registers.
36 =================================================== ====================================================================
38 =================================================== ====================================================================
39 **v**\<N> A single 32-bit *vector* register.
42 :ref:`integer number<amdgpu_synid_integer_number>`.
43 **v[**\ <N>\ **]** A single 32-bit *vector* register.
45 *N* may be specified as an
46 :ref:`integer number<amdgpu_synid_integer_number>`
47 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
48 **v[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *vector* registers.
50 *N* and *K* may be specified as
51 :ref:`integer numbers<amdgpu_synid_integer_number>`
52 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
53 **[v**\ <N>, \ **v**\ <N+1>, ... **v**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *vector* registers.
55 Register indices must be specified as decimal
56 :ref:`integer numbers<amdgpu_synid_integer_number>`.
57 =================================================== ====================================================================
59 Note: *N* and *K* must satisfy the following conditions:
64 * *K-N+1* must be in the range from 1 to 12 or equal to 16 or 32.
66 GFX90A and GFX940 have an additional alignment requirement:
67 pairs of *vector* registers must be even-aligned
68 (first register must be even).
86 **Non-Sequential Address (NSA) Syntax**
88 GFX10+ *image* instructions may use special *NSA* (Non-Sequential Address)
89 syntax for *image addresses*:
91 ===================================== =================================================
93 ===================================== =================================================
94 **[Vm**, \ **Vn**, ... **Vk**\ **]** A sequence of 32-bit *vector* registers.
95 Each register may be specified using the syntax
96 defined :ref:`above<amdgpu_synid_v>`.
98 In contrast with the standard syntax, registers
99 in *NSA* sequence are not required to have
100 consecutive indices. Moreover, the same register
101 may appear in the sequence more than once.
103 GFX11+ has an additional limitation: if address
104 size occupies more than 5 dwords, registers
105 starting from the 5th element must be contiguous.
106 ===================================== =================================================
116 .. _amdgpu_synid_v16:
121 16-bit vector registers. Each :ref:`32-bit vector register<amdgpu_synid_v>` is divided into two 16-bit low and high registers, so there are 512 16-bit vector registers.
123 Only VOP3, VOP3P and VINTERP instructions may access all 512 registers (using :ref:`op_sel<amdgpu_synid_op_sel>` modifier).
124 VOP1, VOP2 and VOPC instructions may currently access only 128 low 16-bit registers using the syntax described below.
126 .. WARNING:: This section is incomplete. The support of 16-bit registers in the assembler is still WIP.
129 =================================================== ====================================================================
131 =================================================== ====================================================================
132 **v**\<N> A single 16-bit *vector* register (low half).
133 =================================================== ====================================================================
135 Note: *N* must satisfy the following conditions:
150 Accumulator registers. There are 256 32-bit accumulator registers.
152 A sequence of *accumulator* registers may be used to operate with more than 32 bits of data.
154 Assembler currently supports tuples with 1 to 12, 16 and 32 *accumulator* registers.
156 =================================================== ========================================================= ====================================================================
157 Syntax Alternative Syntax (SP3) Description
158 =================================================== ========================================================= ====================================================================
159 **a**\<N> **acc**\<N> A single 32-bit *accumulator* register.
161 *N* must be a decimal
162 :ref:`integer number<amdgpu_synid_integer_number>`.
163 **a[**\ <N>\ **]** **acc[**\ <N>\ **]** A single 32-bit *accumulator* register.
165 *N* may be specified as an
166 :ref:`integer number<amdgpu_synid_integer_number>`
167 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
168 **a[**\ <N>:<K>\ **]** **acc[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *accumulator* registers.
170 *N* and *K* may be specified as
171 :ref:`integer numbers<amdgpu_synid_integer_number>`
172 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
173 **[a**\ <N>, \ **a**\ <N+1>, ... **a**\ <K>\ **]** **[acc**\ <N>, \ **acc**\ <N+1>, ... **acc**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *accumulator* registers.
175 Register indices must be specified as decimal
176 :ref:`integer numbers<amdgpu_synid_integer_number>`.
177 =================================================== ========================================================= ====================================================================
179 Note: *N* and *K* must satisfy the following conditions:
184 * *K-N+1* must be in the range from 1 to 12 or equal to 16 or 32.
186 GFX90A and GFX940 have an additional alignment requirement:
187 pairs of *accumulator* registers must be even-aligned
188 (first register must be even).
202 [a252,a253,a254,a255]
214 Scalar 32-bit registers. The number of available *scalar* registers depends on the GPU:
216 ======= ============================
217 GPU Number of *scalar* registers
218 ======= ============================
223 ======= ============================
225 A sequence of *scalar* registers may be used to operate with more than 32 bits of data.
226 Assembler currently supports tuples with 1 to 12, 16 and 32 *scalar* registers.
228 Pairs of *scalar* registers must be even-aligned (first register must be even).
229 Sequences of 4 and more *scalar* registers must be quad-aligned.
231 ======================================================== ====================================================================
233 ======================================================== ====================================================================
234 **s**\ <N> A single 32-bit *scalar* register.
236 *N* must be a decimal
237 :ref:`integer number<amdgpu_synid_integer_number>`.
239 **s[**\ <N>\ **]** A single 32-bit *scalar* register.
241 *N* may be specified as an
242 :ref:`integer number<amdgpu_synid_integer_number>`
243 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
244 **s[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
246 *N* and *K* may be specified as
247 :ref:`integer numbers<amdgpu_synid_integer_number>`
248 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
250 **[s**\ <N>, \ **s**\ <N+1>, ... **s**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
252 Register indices must be specified as decimal
253 :ref:`integer numbers<amdgpu_synid_integer_number>`.
254 ======================================================== ====================================================================
256 Note: *N* and *K* must satisfy the following conditions:
258 * *N* must be properly aligned based on the sequence size.
260 * 0 <= *N* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
261 * 0 <= *K* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
262 * *K-N+1* must be in the range from 1 to 12 or equal to 16 or 32.
278 Examples of *scalar* registers with an invalid alignment:
285 .. _amdgpu_synid_trap:
290 A set of trap handler registers:
292 * :ref:`ttmp<amdgpu_synid_ttmp>`
293 * :ref:`tba<amdgpu_synid_tba>`
294 * :ref:`tma<amdgpu_synid_tma>`
296 .. _amdgpu_synid_ttmp:
301 Trap handler temporary scalar registers, 32-bits wide.
302 The number of available *ttmp* registers depends on the GPU:
304 ======= ===========================
305 GPU Number of *ttmp* registers
306 ======= ===========================
311 ======= ===========================
313 A sequence of *ttmp* registers may be used to operate with more than 32 bits of data.
314 Assembler currently supports tuples with 1 to 12 and 16 *ttmp* registers.
316 Pairs of *ttmp* registers must be even-aligned (first register must be even).
317 Sequences of 4 and more *ttmp* registers must be quad-aligned.
319 ============================================================= ====================================================================
321 ============================================================= ====================================================================
322 **ttmp**\ <N> A single 32-bit *ttmp* register.
324 *N* must be a decimal
325 :ref:`integer number<amdgpu_synid_integer_number>`.
326 **ttmp[**\ <N>\ **]** A single 32-bit *ttmp* register.
328 *N* may be specified as an
329 :ref:`integer number<amdgpu_synid_integer_number>`
330 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
331 **ttmp[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
333 *N* and *K* may be specified as
334 :ref:`integer numbers<amdgpu_synid_integer_number>`
335 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
336 **[ttmp**\ <N>, \ **ttmp**\ <N+1>, ... **ttmp**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
338 Register indices must be specified as decimal
339 :ref:`integer numbers<amdgpu_synid_integer_number>`.
340 ============================================================= ====================================================================
342 Note: *N* and *K* must satisfy the following conditions:
344 * *N* must be properly aligned based on the sequence size.
346 * 0 <= *N* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
347 * 0 <= *K* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
348 * *K-N+1* must be in the range from 1 to 12 or equal to 16.
362 [ttmp4,ttmp5,ttmp6,ttmp7]
364 Examples of *ttmp* registers with an invalid alignment:
371 .. _amdgpu_synid_tba:
376 Trap base address, 64-bits wide. Holds the pointer to the current
377 trap handler program.
379 ================== ======================================================================= =============
380 Syntax Description Availability
381 ================== ======================================================================= =============
382 tba 64-bit *trap base address* register. GFX7, GFX8
383 [tba] 64-bit *trap base address* register (an SP3 syntax). GFX7, GFX8
384 [tba_lo,tba_hi] 64-bit *trap base address* register (an SP3 syntax). GFX7, GFX8
385 ================== ======================================================================= =============
387 High and low 32 bits of *trap base address* may be accessed as separate registers:
389 ================== ======================================================================= =============
390 Syntax Description Availability
391 ================== ======================================================================= =============
392 tba_lo Low 32 bits of *trap base address* register. GFX7, GFX8
393 tba_hi High 32 bits of *trap base address* register. GFX7, GFX8
394 [tba_lo] Low 32 bits of *trap base address* register (an SP3 syntax). GFX7, GFX8
395 [tba_hi] High 32 bits of *trap base address* register (an SP3 syntax). GFX7, GFX8
396 ================== ======================================================================= =============
398 .. _amdgpu_synid_tma:
403 Trap memory address, 64-bits wide.
405 ================= ======================================================================= ==================
406 Syntax Description Availability
407 ================= ======================================================================= ==================
408 tma 64-bit *trap memory address* register. GFX7, GFX8
409 [tma] 64-bit *trap memory address* register (an SP3 syntax). GFX7, GFX8
410 [tma_lo,tma_hi] 64-bit *trap memory address* register (an SP3 syntax). GFX7, GFX8
411 ================= ======================================================================= ==================
413 High and low 32 bits of *trap memory address* may be accessed as separate registers:
415 ================= ======================================================================= ==================
416 Syntax Description Availability
417 ================= ======================================================================= ==================
418 tma_lo Low 32 bits of *trap memory address* register. GFX7, GFX8
419 tma_hi High 32 bits of *trap memory address* register. GFX7, GFX8
420 [tma_lo] Low 32 bits of *trap memory address* register (an SP3 syntax). GFX7, GFX8
421 [tma_hi] High 32 bits of *trap memory address* register (an SP3 syntax). GFX7, GFX8
422 ================= ======================================================================= ==================
424 .. _amdgpu_synid_flat_scratch:
429 Flat scratch address, 64-bits wide. Holds the base address of scratch memory.
431 ================================== ================================================================
433 ================================== ================================================================
434 flat_scratch 64-bit *flat scratch* address register.
435 [flat_scratch] 64-bit *flat scratch* address register (an SP3 syntax).
436 [flat_scratch_lo,flat_scratch_hi] 64-bit *flat scratch* address register (an SP3 syntax).
437 ================================== ================================================================
439 High and low 32 bits of *flat scratch* address may be accessed as separate registers:
441 ========================= =========================================================================
443 ========================= =========================================================================
444 flat_scratch_lo Low 32 bits of *flat scratch* address register.
445 flat_scratch_hi High 32 bits of *flat scratch* address register.
446 [flat_scratch_lo] Low 32 bits of *flat scratch* address register (an SP3 syntax).
447 [flat_scratch_hi] High 32 bits of *flat scratch* address register (an SP3 syntax).
448 ========================= =========================================================================
450 .. _amdgpu_synid_xnack:
451 .. _amdgpu_synid_xnack_mask:
456 Xnack mask, 64-bits wide. Holds a 64-bit mask of which threads
457 received an *XNACK* due to a vector memory operation.
459 For availability of *xnack* feature, refer to :ref:`this table<amdgpu-processors>`.
461 ============================== =====================================================
463 ============================== =====================================================
464 xnack_mask 64-bit *xnack mask* register.
465 [xnack_mask] 64-bit *xnack mask* register (an SP3 syntax).
466 [xnack_mask_lo,xnack_mask_hi] 64-bit *xnack mask* register (an SP3 syntax).
467 ============================== =====================================================
469 High and low 32 bits of *xnack mask* may be accessed as separate registers:
471 ===================== ==============================================================
473 ===================== ==============================================================
474 xnack_mask_lo Low 32 bits of *xnack mask* register.
475 xnack_mask_hi High 32 bits of *xnack mask* register.
476 [xnack_mask_lo] Low 32 bits of *xnack mask* register (an SP3 syntax).
477 [xnack_mask_hi] High 32 bits of *xnack mask* register (an SP3 syntax).
478 ===================== ==============================================================
480 .. _amdgpu_synid_vcc:
481 .. _amdgpu_synid_vcc_lo:
486 Vector condition code, 64-bits wide. A bit mask with one bit per thread;
487 it holds the result of a vector compare operation.
489 Note that GFX10+ H/W does not use high 32 bits of *vcc* in *wave32* mode.
491 ================ =========================================================================
493 ================ =========================================================================
494 vcc 64-bit *vector condition code* register.
495 [vcc] 64-bit *vector condition code* register (an SP3 syntax).
496 [vcc_lo,vcc_hi] 64-bit *vector condition code* register (an SP3 syntax).
497 ================ =========================================================================
499 High and low 32 bits of *vector condition code* may be accessed as separate registers:
501 ================ =========================================================================
503 ================ =========================================================================
504 vcc_lo Low 32 bits of *vector condition code* register.
505 vcc_hi High 32 bits of *vector condition code* register.
506 [vcc_lo] Low 32 bits of *vector condition code* register (an SP3 syntax).
507 [vcc_hi] High 32 bits of *vector condition code* register (an SP3 syntax).
508 ================ =========================================================================
515 A 32-bit memory register. It has various uses,
516 including register indexing and bounds checking.
518 =========== ===================================================
520 =========== ===================================================
521 m0 A 32-bit *memory* register.
522 [m0] A 32-bit *memory* register (an SP3 syntax).
523 =========== ===================================================
525 .. _amdgpu_synid_exec:
530 Execute mask, 64-bits wide. A bit mask with one bit per thread,
531 which is applied to vector instructions and controls which threads execute
532 and which ignore the instruction.
534 Note that GFX10+ H/W does not use high 32 bits of *exec* in *wave32* mode.
536 ===================== =================================================================
538 ===================== =================================================================
539 exec 64-bit *execute mask* register.
540 [exec] 64-bit *execute mask* register (an SP3 syntax).
541 [exec_lo,exec_hi] 64-bit *execute mask* register (an SP3 syntax).
542 ===================== =================================================================
544 High and low 32 bits of *execute mask* may be accessed as separate registers:
546 ===================== =================================================================
548 ===================== =================================================================
549 exec_lo Low 32 bits of *execute mask* register.
550 exec_hi High 32 bits of *execute mask* register.
551 [exec_lo] Low 32 bits of *execute mask* register (an SP3 syntax).
552 [exec_hi] High 32 bits of *execute mask* register (an SP3 syntax).
553 ===================== =================================================================
555 .. _amdgpu_synid_vccz:
560 A single bit flag indicating that the :ref:`vcc<amdgpu_synid_vcc>`
563 Note: when GFX10+ operates in *wave32* mode, this register reflects
564 the state of :ref:`vcc_lo<amdgpu_synid_vcc_lo>`.
566 .. _amdgpu_synid_execz:
571 A single bit flag indicating that the :ref:`exec<amdgpu_synid_exec>`
574 Note: when GFX10+ operates in *wave32* mode, this register reflects
575 the state of :ref:`exec_lo<amdgpu_synid_exec>`.
577 .. _amdgpu_synid_scc:
582 A single bit flag indicating the result of a scalar compare operation.
584 .. _amdgpu_synid_lds_direct:
589 A special operand which supplies a 32-bit value
590 fetched from *LDS* memory using :ref:`m0<amdgpu_synid_m0>` as an address.
592 .. _amdgpu_synid_null:
597 This is a special operand that may be used as a source or a destination.
599 When used as a destination, the result of the operation is discarded.
601 When used as a source, it supplies zero value.
603 .. _amdgpu_synid_constant:
608 An *inline constant* is an integer or a floating-point value
609 encoded as a part of an instruction. Compare *inline constants*
610 with :ref:`literals<amdgpu_synid_literal>`.
612 Inline constants include:
614 * :ref:`Integer inline constants<amdgpu_synid_iconst>`;
615 * :ref:`Floating-point inline constants<amdgpu_synid_fconst>`;
616 * :ref:`Inline values<amdgpu_synid_ival>`.
618 If a number may be encoded as either
619 a :ref:`literal<amdgpu_synid_literal>` or
620 a :ref:`constant<amdgpu_synid_constant>`,
621 the assembler selects the latter encoding as more efficient.
623 .. _amdgpu_synid_iconst:
628 An :ref:`integer number<amdgpu_synid_integer_number>` or
629 an :ref:`absolute expression<amdgpu_synid_absolute_expression>`
630 encoded as an *inline constant*.
632 Only a small fraction of integer numbers may be encoded as *inline constants*.
633 They are enumerated in the table below.
634 Other integer numbers are encoded as :ref:`literals<amdgpu_synid_literal>`.
636 ================================== ====================================
638 ================================== ====================================
639 {0..64} Positive integer inline constants.
640 {-16..-1} Negative integer inline constants.
641 ================================== ====================================
643 .. _amdgpu_synid_fconst:
648 A :ref:`floating-point number<amdgpu_synid_floating-point_number>`
649 encoded as an *inline constant*.
651 Only a small fraction of floating-point numbers may be encoded
652 as *inline constants*. They are enumerated in the table below.
653 Other floating-point numbers are encoded as
654 :ref:`literals<amdgpu_synid_literal>`.
656 ===================== ===================================================== ==================
657 Value Note Availability
658 ===================== ===================================================== ==================
659 0.0 The same as integer constant 0. All GPUs
660 0.5 Floating-point constant 0.5 All GPUs
661 1.0 Floating-point constant 1.0 All GPUs
662 2.0 Floating-point constant 2.0 All GPUs
663 4.0 Floating-point constant 4.0 All GPUs
664 -0.5 Floating-point constant -0.5 All GPUs
665 -1.0 Floating-point constant -1.0 All GPUs
666 -2.0 Floating-point constant -2.0 All GPUs
667 -4.0 Floating-point constant -4.0 All GPUs
668 0.1592 1.0/(2.0*pi). Use only for 16-bit operands. GFX8+
669 0.15915494 1.0/(2.0*pi). Use only for 16- and 32-bit operands. GFX8+
670 0.15915494309189532 1.0/(2.0*pi). GFX8+
671 ===================== ===================================================== ==================
673 .. WARNING:: Floating-point inline constants cannot be used with *16-bit integer* operands. \
674 Assembler encodes these values as literals.
676 .. _amdgpu_synid_ival:
681 A symbolic operand encoded as an *inline constant*.
682 These operands provide read-only access to H/W registers.
684 ===================== ========================= ================================================ =============
685 Syntax Alternative Syntax (SP3) Note Availability
686 ===================== ========================= ================================================ =============
687 shared_base src_shared_base Base address of shared memory region. GFX9+
688 shared_limit src_shared_limit Address of the end of shared memory region. GFX9+
689 private_base src_private_base Base address of private memory region. GFX9+
690 private_limit src_private_limit Address of the end of private memory region. GFX9+
691 pops_exiting_wave_id src_pops_exiting_wave_id A dedicated counter for POPS. GFX9, GFX10
692 ===================== ========================= ================================================ =============
694 .. _amdgpu_synid_literal:
699 A *literal* is a 64-bit value encoded as a separate
700 32-bit dword in the instruction stream. Compare *literals*
701 with :ref:`inline constants<amdgpu_synid_constant>`.
703 If a number may be encoded as either
704 a :ref:`literal<amdgpu_synid_literal>` or
705 an :ref:`inline constant<amdgpu_synid_constant>`,
706 assembler selects the latter encoding as more efficient.
708 Literals may be specified as
709 :ref:`integer numbers<amdgpu_synid_integer_number>`,
710 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`,
711 :ref:`absolute expressions<amdgpu_synid_absolute_expression>` or
712 :ref:`relocatable expressions<amdgpu_synid_relocatable_expression>`.
714 An instruction may use only one literal,
715 but several operands may refer to the same literal.
717 .. _amdgpu_synid_uimm8:
722 An 8-bit :ref:`integer number<amdgpu_synid_integer_number>`
723 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
724 The value must be in the range 0..0xFF.
726 .. _amdgpu_synid_uimm32:
731 A 32-bit :ref:`integer number<amdgpu_synid_integer_number>`
732 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
733 The value must be in the range 0..0xFFFFFFFF.
735 .. _amdgpu_synid_uimm20:
740 A 20-bit :ref:`integer number<amdgpu_synid_integer_number>`
741 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
743 The value must be in the range 0..0xFFFFF.
745 .. _amdgpu_synid_simm21:
750 A 21-bit :ref:`integer number<amdgpu_synid_integer_number>`
751 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
753 The value must be in the range -0x100000..0x0FFFFF.
755 .. _amdgpu_synid_off:
760 A special entity which indicates that the value of this operand is not used.
762 ================================== ===================================================
764 ================================== ===================================================
765 off Indicates an unused operand.
766 ================================== ===================================================
769 .. _amdgpu_synid_number:
774 .. _amdgpu_synid_integer_number:
779 Integer numbers are 64 bits wide.
780 They are converted to :ref:`expected operand type<amdgpu_syn_instruction_type>`
781 as described :ref:`here<amdgpu_synid_int_conv>`.
783 Integer numbers may be specified in binary, octal,
784 hexadecimal and decimal formats:
786 ============ =============================== ========
787 Format Syntax Example
788 ============ =============================== ========
789 Decimal [-]?[1-9][0-9]* -1234
790 Binary [-]?0b[01]+ 0b1010
791 Octal [-]?0[0-7]+ 010
792 Hexadecimal [-]?0x[0-9a-fA-F]+ 0xff
793 \ [-]?[0x]?[0-9][0-9a-fA-F]*[hH] 0ffh
794 ============ =============================== ========
796 .. _amdgpu_synid_floating-point_number:
798 Floating-Point Numbers
799 ----------------------
801 All floating-point numbers are handled as double (64 bits wide).
802 They are converted to
803 :ref:`expected operand type<amdgpu_syn_instruction_type>`
804 as described :ref:`here<amdgpu_synid_fp_conv>`.
806 Floating-point numbers may be specified in hexadecimal and decimal formats:
808 ============ ======================================================== ====================== ====================
809 Format Syntax Examples Note
810 ============ ======================================================== ====================== ====================
811 Decimal [-]?[0-9]*[.][0-9]*([eE][+-]?[0-9]*)? -1.234, 234e2 Must include either
814 Hexadecimal [-]0x[0-9a-fA-F]*(.[0-9a-fA-F]*)?[pP][+-]?[0-9a-fA-F]+ -0x1afp-10, 0x.1afp10
815 ============ ======================================================== ====================== ====================
817 .. _amdgpu_synid_expression:
822 An expression is evaluated to a 64-bit integer.
823 Note that floating-point expressions are not supported.
825 There are two kinds of expressions:
827 * :ref:`Absolute<amdgpu_synid_absolute_expression>`.
828 * :ref:`Relocatable<amdgpu_synid_relocatable_expression>`.
830 .. _amdgpu_synid_absolute_expression:
835 The value of an absolute expression does not change after program relocation.
836 Absolute expressions must not include unassigned and relocatable values
839 Absolute expressions are evaluated to 64-bit integer values and converted to
840 :ref:`expected operand type<amdgpu_syn_instruction_type>`
841 as described :ref:`here<amdgpu_synid_int_conv>`.
850 .. _amdgpu_synid_relocatable_expression:
852 Relocatable Expressions
853 -----------------------
855 The value of a relocatable expression depends on program relocation.
857 Note that use of relocatable expressions is limited to branch targets
858 and 32-bit integer operands.
860 A relocatable expression is evaluated to a 64-bit integer value,
861 which depends on operand kind and
862 :ref:`relocation type<amdgpu-relocation-records>` of symbol(s)
863 used in the expression. For example, if an instruction refers to a label,
864 this reference is evaluated to an offset from the address after
865 the instruction to the label address:
870 v_add_co_u32_e32 v0, vcc, label, v1 // 'label' operand is evaluated to -4
872 Note that values of relocatable expressions are usually unknown
873 at assembly time; they are resolved later by a linker and converted to
874 :ref:`expected operand type<amdgpu_syn_instruction_type>`
875 as described :ref:`here<amdgpu_synid_rl_conv>`.
877 Operands and Operations
878 -----------------------
880 Expressions are composed of 64-bit integer operands and operations.
881 Operands include :ref:`integer numbers<amdgpu_synid_integer_number>`
882 and :ref:`symbols<amdgpu_synid_symbol>`.
884 Expressions may also use "." which is a reference
885 to the current PC (program counter).
887 :ref:`Unary<amdgpu_synid_expression_un_op>` and
888 :ref:`binary<amdgpu_synid_expression_bin_op>`
889 operations produce 64-bit integer results.
891 Syntax of Expressions
892 ---------------------
894 Syntax of expressions is shown below::
896 expr ::= expr binop expr | primaryexpr ;
898 primaryexpr ::= '(' expr ')' | symbol | number | '.' | unop primaryexpr ;
926 .. _amdgpu_synid_expression_bin_op:
931 Binary operators are described in the following table.
932 They operate on and produce 64-bit integers.
933 Operators with higher priority are performed first.
935 ========== ========= ===============================================
936 Operator Priority Meaning
937 ========== ========= ===============================================
938 \* 5 Integer multiplication.
939 / 5 Integer division.
940 % 5 Integer signed remainder.
941 \+ 4 Integer addition.
942 \- 4 Integer subtraction.
943 << 3 Integer shift left.
944 >> 3 Logical shift right.
945 == 2 Equality comparison.
946 != 2 Inequality comparison.
947 <> 2 Inequality comparison.
948 < 2 Signed less than comparison.
949 <= 2 Signed less than or equal comparison.
950 > 2 Signed greater than comparison.
951 >= 2 Signed greater than or equal comparison.
957 ========== ========= ===============================================
959 .. _amdgpu_synid_expression_un_op:
964 Unary operators are described in the following table.
965 They operate on and produce 64-bit integers.
967 ========== ===============================================
969 ========== ===============================================
972 \+ Integer unary plus.
973 \- Integer unary minus.
974 ========== ===============================================
976 .. _amdgpu_synid_symbol:
981 A symbol is a named 64-bit integer value, representing a relocatable
982 address or an absolute (non-relocatable) number.
984 Symbol names have the following syntax:
985 ``[a-zA-Z_.][a-zA-Z0-9_$.@]*``
987 The table below provides several examples of syntax used for symbol definition.
989 ================ ==========================================================
991 ================ ==========================================================
992 .globl <S> Declares a global symbol S without assigning it a value.
993 .set <S>, <E> Assigns the value of an expression E to a symbol S.
994 <S> = <E> Assigns the value of an expression E to a symbol S.
995 <S>: Declares a label S and assigns it the current PC value.
996 ================ ==========================================================
998 A symbol may be used before it is declared or assigned;
999 unassigned symbols are assumed to be PC-relative.
1001 Additional information about symbols may be found :ref:`here<amdgpu-symbols>`.
1003 .. _amdgpu_synid_conv:
1005 Type and Size Conversion
1006 ========================
1008 This section describes what happens when a 64-bit
1009 :ref:`integer number<amdgpu_synid_integer_number>`, a
1010 :ref:`floating-point number<amdgpu_synid_floating-point_number>` or an
1011 :ref:`expression<amdgpu_synid_expression>`
1012 is used for an operand which has a different type or size.
1014 .. _amdgpu_synid_int_conv:
1016 Conversion of Integer Values
1017 ----------------------------
1019 Instruction operands may be specified as 64-bit
1020 :ref:`integer numbers<amdgpu_synid_integer_number>` or
1021 :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
1022 These values are converted to the
1023 :ref:`expected operand type<amdgpu_syn_instruction_type>`
1024 using the following steps:
1026 1. *Validation*. Assembler checks if the input value may be truncated
1027 without loss to the required *truncation width* (see the table below).
1028 There are two cases when this operation is enabled:
1030 * The truncated bits are all 0.
1031 * The truncated bits are all 1 and the value after truncation has its MSB bit set.
1033 In all other cases, the assembler triggers an error.
1035 2. *Conversion*. The input value is converted to the expected type
1036 as described in the table below. Depending on operand kind, this conversion
1037 is performed by either assembler or AMDGPU H/W (or both).
1039 ============== ================= =============== ====================================================================
1040 Expected type Truncation Width Conversion Description
1041 ============== ================= =============== ====================================================================
1042 i16, u16, b16 16 num.u16 Truncate to 16 bits.
1043 i32, u32, b32 32 num.u32 Truncate to 32 bits.
1044 i64 32 {-1,num.i32} Truncate to 32 bits and then sign-extend the result to 64 bits.
1045 u64, b64 32 {0,num.u32} Truncate to 32 bits and then zero-extend the result to 64 bits.
1046 f16 16 num.u16 Use low 16 bits as an f16 value.
1047 f32 32 num.u32 Use low 32 bits as an f32 value.
1048 f64 32 {num.u32,0} Use low 32 bits of the number as high 32 bits
1049 of the result; low 32 bits of the result are zeroed.
1050 ============== ================= =============== ====================================================================
1052 Examples of enabled conversions:
1058 v_add_u16 v0, -1, 0 // src0 = 0xFFFF
1059 v_add_f16 v0, -1, 0 // src0 = 0xFFFF (NaN)
1061 v_add_u32 v0, -1, 0 // src0 = 0xFFFFFFFF
1062 v_add_f32 v0, -1, 0 // src0 = 0xFFFFFFFF (NaN)
1064 v_add_u16 v0, 0xff00, v0 // src0 = 0xff00
1065 v_add_u16 v0, 0xffffffffffffff00, v0 // src0 = 0xff00
1066 v_add_u16 v0, -256, v0 // src0 = 0xff00
1068 s_bfe_i64 s[0:1], 0xffefffff, s3 // src0 = 0xffffffffffefffff
1069 s_bfe_u64 s[0:1], 0xffefffff, s3 // src0 = 0x00000000ffefffff
1070 v_ceil_f64_e32 v[0:1], 0xffefffff // src0 = 0xffefffff00000000 (-1.7976922776554302e308)
1073 s_bfe_i64 s[0:1], x, s3 // src0 = 0xffffffffffefffff
1074 s_bfe_u64 s[0:1], x, s3 // src0 = 0x00000000ffefffff
1075 v_ceil_f64_e32 v[0:1], x // src0 = 0xffefffff00000000 (-1.7976922776554302e308)
1077 Examples of disabled conversions:
1083 v_add_u16 v0, 0x1ff00, v0 // truncated bits are not all 0 or 1
1084 v_add_u16 v0, 0xffffffffffff00ff, v0 // truncated bits do not match MSB of the result
1086 .. _amdgpu_synid_fp_conv:
1088 Conversion of Floating-Point Values
1089 -----------------------------------
1091 Instruction operands may be specified as 64-bit
1092 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`.
1093 These values are converted to the
1094 :ref:`expected operand type<amdgpu_syn_instruction_type>`
1095 using the following steps:
1097 1. *Validation*. Assembler checks if the input f64 number can be converted
1098 to the *required floating-point type* (see the table below) without overflow
1099 or underflow. Precision lost is allowed. If this conversion is not possible,
1100 the assembler triggers an error.
1102 2. *Conversion*. The input value is converted to the expected type
1103 as described in the table below. Depending on operand kind, this is
1104 performed by either assembler or AMDGPU H/W (or both).
1106 ============== ================ ================= =================================================================
1107 Expected type Required FP Type Conversion Description
1108 ============== ================ ================= =================================================================
1109 i16, u16, b16 f16 f16(num) Convert to f16 and use bits of the result as an integer value.
1110 The value has to be encoded as a literal, or an error occurs.
1111 Note that the value cannot be encoded as an inline constant.
1112 i32, u32, b32 f32 f32(num) Convert to f32 and use bits of the result as an integer value.
1113 i64, u64, b64 \- \- Conversion disabled.
1114 f16 f16 f16(num) Convert to f16.
1115 f32 f32 f32(num) Convert to f32.
1116 f64 f64 {num.u32.hi,0} Use high 32 bits of the number as high 32 bits of the result;
1117 zero-fill low 32 bits of the result.
1119 Note that the result may differ from the original number.
1120 ============== ================ ================= =================================================================
1122 Examples of enabled conversions:
1128 v_add_f16 v0, 1.0, 0 // src0 = 0x3C00 (1.0)
1129 v_add_u16 v0, 1.0, 0 // src0 = 0x3C00
1131 v_add_f32 v0, 1.0, 0 // src0 = 0x3F800000 (1.0)
1132 v_add_u32 v0, 1.0, 0 // src0 = 0x3F800000
1134 // src0 before conversion:
1135 // 1.7976931348623157e308 = 0x7fefffffffffffff
1136 // src0 after conversion:
1137 // 1.7976922776554302e308 = 0x7fefffff00000000
1138 v_ceil_f64 v[0:1], 1.7976931348623157e308
1140 v_add_f16 v1, 65500.0, v2 // ok for f16.
1141 v_add_f32 v1, 65600.0, v2 // ok for f32, but would result in overflow for f16.
1143 Examples of disabled conversions:
1149 v_add_f16 v1, 65600.0, v2 // overflow
1151 .. _amdgpu_synid_rl_conv:
1153 Conversion of Relocatable Values
1154 --------------------------------
1156 :ref:`Relocatable expressions<amdgpu_synid_relocatable_expression>`
1157 may be used with 32-bit integer operands and jump targets.
1159 When the value of a relocatable expression is resolved by a linker, it is
1160 converted as needed and truncated to the operand size. The conversion depends
1161 on :ref:`relocation type<amdgpu-relocation-records>` and operand kind.
1163 For example, when a 32-bit operand of an instruction refers
1164 to a relocatable expression *expr*, this reference is evaluated
1165 to a 64-bit offset from the address after the
1166 instruction to the address being referenced, *counted in bytes*.
1167 Then the value is truncated to 32 bits and encoded as a literal:
1172 v_add_co_u32_e32 v0, vcc, expr, v1 // 'expr' operand is evaluated to -4
1173 // and then truncated to 0xFFFFFFFC
1175 As another example, when a branch instruction refers to a label,
1176 this reference is evaluated to an offset from the address after the
1177 instruction to the label address, *counted in dwords*.
1178 Then the value is truncated to 16 bits:
1183 s_branch label // 'label' operand is evaluated to -1 and truncated to 0xFFFF