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* is 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 sequences of 1, 2, 3, 4, 8 and 16 *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 equal to 1, 2, 3, 4, 8 or 16.
82 GFX10 *Image* instructions may use special *NSA* (Non-Sequential Address) syntax for *image addresses*:
84 ===================================== =================================================
86 ===================================== =================================================
87 **[Vm**, \ **Vn**, ... **Vk**\ **]** A sequence of 32-bit *vector* registers.
88 Each register may be specified using a syntax
89 defined :ref:`above<amdgpu_synid_v>`.
91 In contrast with standard syntax, registers
92 in *NSA* sequence are not required to have
93 consecutive indices. Moreover, the same register
94 may appear in the list more than once.
95 ===================================== =================================================
110 Scalar 32-bit registers. The number of available *scalar* registers depends on GPU:
112 ======= ============================
113 GPU Number of *scalar* registers
114 ======= ============================
119 ======= ============================
121 A sequence of *scalar* registers may be used to operate with more than 32 bits of data.
122 Assembler currently supports sequences of 1, 2, 4, 8 and 16 *scalar* registers.
124 Pairs of *scalar* registers must be even-aligned (the first register must be even).
125 Sequences of 4 and more *scalar* registers must be quad-aligned.
127 ======================================================== ====================================================================
129 ======================================================== ====================================================================
130 **s**\ <N> A single 32-bit *scalar* register.
132 *N* must be a decimal
133 :ref:`integer number<amdgpu_synid_integer_number>`.
135 **s[**\ <N>\ **]** A single 32-bit *scalar* register.
137 *N* may be specified as an
138 :ref:`integer number<amdgpu_synid_integer_number>`
139 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
140 **s[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
142 *N* and *K* may be specified as
143 :ref:`integer numbers<amdgpu_synid_integer_number>`
144 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
146 **[s**\ <N>, \ **s**\ <N+1>, ... **s**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
148 Register indices must be specified as decimal
149 :ref:`integer numbers<amdgpu_synid_integer_number>`.
150 ======================================================== ====================================================================
152 Note: *N* and *K* must satisfy the following conditions:
154 * *N* must be properly aligned based on sequence size.
156 * 0 <= *N* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
157 * 0 <= *K* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
158 * *K-N+1* must be equal to 1, 2, 4, 8 or 16.
174 Examples of *scalar* registers with an invalid alignment:
181 .. _amdgpu_synid_trap:
186 A set of trap handler registers:
188 * :ref:`ttmp<amdgpu_synid_ttmp>`
189 * :ref:`tba<amdgpu_synid_tba>`
190 * :ref:`tma<amdgpu_synid_tma>`
192 .. _amdgpu_synid_ttmp:
197 Trap handler temporary scalar registers, 32-bits wide.
198 The number of available *ttmp* registers depends on GPU:
200 ======= ===========================
201 GPU Number of *ttmp* registers
202 ======= ===========================
207 ======= ===========================
209 A sequence of *ttmp* registers may be used to operate with more than 32 bits of data.
210 Assembler currently supports sequences of 1, 2, 4, 8 and 16 *ttmp* registers.
212 Pairs of *ttmp* registers must be even-aligned (the first register must be even).
213 Sequences of 4 and more *ttmp* registers must be quad-aligned.
215 ============================================================= ====================================================================
217 ============================================================= ====================================================================
218 **ttmp**\ <N> A single 32-bit *ttmp* register.
220 *N* must be a decimal
221 :ref:`integer number<amdgpu_synid_integer_number>`.
222 **ttmp[**\ <N>\ **]** A single 32-bit *ttmp* register.
224 *N* may be specified as an
225 :ref:`integer number<amdgpu_synid_integer_number>`
226 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
227 **ttmp[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
229 *N* and *K* may be specified as
230 :ref:`integer numbers<amdgpu_synid_integer_number>`
231 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
232 **[ttmp**\ <N>, \ **ttmp**\ <N+1>, ... **ttmp**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
234 Register indices must be specified as decimal
235 :ref:`integer numbers<amdgpu_synid_integer_number>`.
236 ============================================================= ====================================================================
238 Note: *N* and *K* must satisfy the following conditions:
240 * *N* must be properly aligned based on sequence size.
242 * 0 <= *N* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
243 * 0 <= *K* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
244 * *K-N+1* must be equal to 1, 2, 4, 8 or 16.
258 [ttmp4,ttmp5,ttmp6,ttmp7]
260 Examples of *ttmp* registers with an invalid alignment:
267 .. _amdgpu_synid_tba:
272 Trap base address, 64-bits wide. Holds the pointer to the current trap handler program.
274 ================== ======================================================================= =============
275 Syntax Description Availability
276 ================== ======================================================================= =============
277 tba 64-bit *trap base address* register. GFX7, GFX8
278 [tba] 64-bit *trap base address* register (an SP3 syntax). GFX7, GFX8
279 [tba_lo,tba_hi] 64-bit *trap base address* register (an SP3 syntax). GFX7, GFX8
280 ================== ======================================================================= =============
282 High and low 32 bits of *trap base address* may be accessed as separate registers:
284 ================== ======================================================================= =============
285 Syntax Description Availability
286 ================== ======================================================================= =============
287 tba_lo Low 32 bits of *trap base address* register. GFX7, GFX8
288 tba_hi High 32 bits of *trap base address* register. GFX7, GFX8
289 [tba_lo] Low 32 bits of *trap base address* register (an SP3 syntax). GFX7, GFX8
290 [tba_hi] High 32 bits of *trap base address* register (an SP3 syntax). GFX7, GFX8
291 ================== ======================================================================= =============
293 Note that *tba*, *tba_lo* and *tba_hi* are not accessible as assembler registers in GFX9 and GFX10,
294 but *tba* is readable/writable with the help of *s_get_reg* and *s_set_reg* instructions.
296 .. _amdgpu_synid_tma:
301 Trap memory address, 64-bits wide.
303 ================= ======================================================================= ==================
304 Syntax Description Availability
305 ================= ======================================================================= ==================
306 tma 64-bit *trap memory address* register. GFX7, GFX8
307 [tma] 64-bit *trap memory address* register (an SP3 syntax). GFX7, GFX8
308 [tma_lo,tma_hi] 64-bit *trap memory address* register (an SP3 syntax). GFX7, GFX8
309 ================= ======================================================================= ==================
311 High and low 32 bits of *trap memory address* may be accessed as separate registers:
313 ================= ======================================================================= ==================
314 Syntax Description Availability
315 ================= ======================================================================= ==================
316 tma_lo Low 32 bits of *trap memory address* register. GFX7, GFX8
317 tma_hi High 32 bits of *trap memory address* register. GFX7, GFX8
318 [tma_lo] Low 32 bits of *trap memory address* register (an SP3 syntax). GFX7, GFX8
319 [tma_hi] High 32 bits of *trap memory address* register (an SP3 syntax). GFX7, GFX8
320 ================= ======================================================================= ==================
322 Note that *tma*, *tma_lo* and *tma_hi* are not accessible as assembler registers in GFX9 and GFX10,
323 but *tma* is readable/writable with the help of *s_get_reg* and *s_set_reg* instructions.
325 .. _amdgpu_synid_flat_scratch:
330 Flat scratch address, 64-bits wide. Holds the base address of scratch memory.
332 ================================== ================================================================
334 ================================== ================================================================
335 flat_scratch 64-bit *flat scratch* address register.
336 [flat_scratch] 64-bit *flat scratch* address register (an SP3 syntax).
337 [flat_scratch_lo,flat_scratch_hi] 64-bit *flat scratch* address register (an SP3 syntax).
338 ================================== ================================================================
340 High and low 32 bits of *flat scratch* address may be accessed as separate registers:
342 ========================= =========================================================================
344 ========================= =========================================================================
345 flat_scratch_lo Low 32 bits of *flat scratch* address register.
346 flat_scratch_hi High 32 bits of *flat scratch* address register.
347 [flat_scratch_lo] Low 32 bits of *flat scratch* address register (an SP3 syntax).
348 [flat_scratch_hi] High 32 bits of *flat scratch* address register (an SP3 syntax).
349 ========================= =========================================================================
351 .. _amdgpu_synid_xnack:
356 Xnack mask, 64-bits wide. Holds a 64-bit mask of which threads
357 received an *XNACK* due to a vector memory operation.
359 .. WARNING:: GFX7 does not support *xnack* feature. For availability of this feature in other GPUs, refer :ref:`this table<amdgpu-processors>`.
363 ============================== =====================================================
365 ============================== =====================================================
366 xnack_mask 64-bit *xnack mask* register.
367 [xnack_mask] 64-bit *xnack mask* register (an SP3 syntax).
368 [xnack_mask_lo,xnack_mask_hi] 64-bit *xnack mask* register (an SP3 syntax).
369 ============================== =====================================================
371 High and low 32 bits of *xnack mask* may be accessed as separate registers:
373 ===================== ==============================================================
375 ===================== ==============================================================
376 xnack_mask_lo Low 32 bits of *xnack mask* register.
377 xnack_mask_hi High 32 bits of *xnack mask* register.
378 [xnack_mask_lo] Low 32 bits of *xnack mask* register (an SP3 syntax).
379 [xnack_mask_hi] High 32 bits of *xnack mask* register (an SP3 syntax).
380 ===================== ==============================================================
382 .. _amdgpu_synid_vcc:
383 .. _amdgpu_synid_vcc_lo:
388 Vector condition code, 64-bits wide. A bit mask with one bit per thread;
389 it holds the result of a vector compare operation.
391 Note that GFX10 H/W does not use high 32 bits of *vcc* in *wave32* mode.
393 ================ =========================================================================
395 ================ =========================================================================
396 vcc 64-bit *vector condition code* register.
397 [vcc] 64-bit *vector condition code* register (an SP3 syntax).
398 [vcc_lo,vcc_hi] 64-bit *vector condition code* register (an SP3 syntax).
399 ================ =========================================================================
401 High and low 32 bits of *vector condition code* may be accessed as separate registers:
403 ================ =========================================================================
405 ================ =========================================================================
406 vcc_lo Low 32 bits of *vector condition code* register.
407 vcc_hi High 32 bits of *vector condition code* register.
408 [vcc_lo] Low 32 bits of *vector condition code* register (an SP3 syntax).
409 [vcc_hi] High 32 bits of *vector condition code* register (an SP3 syntax).
410 ================ =========================================================================
417 A 32-bit memory register. It has various uses,
418 including register indexing and bounds checking.
420 =========== ===================================================
422 =========== ===================================================
423 m0 A 32-bit *memory* register.
424 [m0] A 32-bit *memory* register (an SP3 syntax).
425 =========== ===================================================
427 .. _amdgpu_synid_exec:
432 Execute mask, 64-bits wide. A bit mask with one bit per thread,
433 which is applied to vector instructions and controls which threads execute
434 and which ignore the instruction.
436 Note that GFX10 H/W does not use high 32 bits of *exec* in *wave32* mode.
438 ===================== =================================================================
440 ===================== =================================================================
441 exec 64-bit *execute mask* register.
442 [exec] 64-bit *execute mask* register (an SP3 syntax).
443 [exec_lo,exec_hi] 64-bit *execute mask* register (an SP3 syntax).
444 ===================== =================================================================
446 High and low 32 bits of *execute mask* may be accessed as separate registers:
448 ===================== =================================================================
450 ===================== =================================================================
451 exec_lo Low 32 bits of *execute mask* register.
452 exec_hi High 32 bits of *execute mask* register.
453 [exec_lo] Low 32 bits of *execute mask* register (an SP3 syntax).
454 [exec_hi] High 32 bits of *execute mask* register (an SP3 syntax).
455 ===================== =================================================================
457 .. _amdgpu_synid_vccz:
462 A single bit flag indicating that the :ref:`vcc<amdgpu_synid_vcc>` is all zeros.
464 Note: when GFX10 operates in *wave32* mode, this register reflects state of :ref:`vcc_lo<amdgpu_synid_vcc_lo>`.
466 .. _amdgpu_synid_execz:
471 A single bit flag indicating that the :ref:`exec<amdgpu_synid_exec>` is all zeros.
473 Note: when GFX10 operates in *wave32* mode, this register reflects state of :ref:`exec_lo<amdgpu_synid_exec>`.
475 .. _amdgpu_synid_scc:
480 A single bit flag indicating the result of a scalar compare operation.
482 .. _amdgpu_synid_lds_direct:
487 A special operand which supplies a 32-bit value
488 fetched from *LDS* memory using :ref:`m0<amdgpu_synid_m0>` as an address.
490 .. _amdgpu_synid_null:
495 This is a special operand which may be used as a source or a destination.
497 When used as a destination, the result of the operation is discarded.
499 When used as a source, it supplies zero value.
503 .. WARNING:: Due to a H/W bug, this operand cannot be used with VALU instructions in first generation of GFX10.
505 .. _amdgpu_synid_constant:
510 An *inline constant* is an integer or a floating-point value encoded as a part of an instruction.
511 Compare *inline constants* with :ref:`literals<amdgpu_synid_literal>`.
513 Inline constants include:
515 * :ref:`iconst<amdgpu_synid_iconst>`
516 * :ref:`fconst<amdgpu_synid_fconst>`
517 * :ref:`ival<amdgpu_synid_ival>`
519 If a number may be encoded as either
520 a :ref:`literal<amdgpu_synid_literal>` or
521 a :ref:`constant<amdgpu_synid_constant>`,
522 assembler selects the latter encoding as more efficient.
524 .. _amdgpu_synid_iconst:
529 An :ref:`integer number<amdgpu_synid_integer_number>` or
530 an :ref:`absolute expression<amdgpu_synid_absolute_expression>`
531 encoded as an *inline constant*.
533 Only a small fraction of integer numbers may be encoded as *inline constants*.
534 They are enumerated in the table below.
535 Other integer numbers have to be encoded as :ref:`literals<amdgpu_synid_literal>`.
537 ================================== ====================================
539 ================================== ====================================
540 {0..64} Positive integer inline constants.
541 {-16..-1} Negative integer inline constants.
542 ================================== ====================================
544 .. WARNING:: GFX7 does not support inline constants for *f16* operands.
546 .. _amdgpu_synid_fconst:
551 A :ref:`floating-point number<amdgpu_synid_floating-point_number>`
552 encoded as an *inline constant*.
554 Only a small fraction of floating-point numbers may be encoded as *inline constants*.
555 They are enumerated in the table below.
556 Other floating-point numbers have to be encoded as :ref:`literals<amdgpu_synid_literal>`.
558 ===================== ===================================================== ==================
559 Value Note Availability
560 ===================== ===================================================== ==================
561 0.0 The same as integer constant 0. All GPUs
562 0.5 Floating-point constant 0.5 All GPUs
563 1.0 Floating-point constant 1.0 All GPUs
564 2.0 Floating-point constant 2.0 All GPUs
565 4.0 Floating-point constant 4.0 All GPUs
566 -0.5 Floating-point constant -0.5 All GPUs
567 -1.0 Floating-point constant -1.0 All GPUs
568 -2.0 Floating-point constant -2.0 All GPUs
569 -4.0 Floating-point constant -4.0 All GPUs
570 0.1592 1.0/(2.0*pi). Use only for 16-bit operands. GFX8, GFX9, GFX10
571 0.15915494 1.0/(2.0*pi). Use only for 16- and 32-bit operands. GFX8, GFX9, GFX10
572 0.15915494309189532 1.0/(2.0*pi). GFX8, GFX9, GFX10
573 ===================== ===================================================== ==================
575 .. WARNING:: GFX7 does not support inline constants for *f16* operands.
577 .. _amdgpu_synid_ival:
582 A symbolic operand encoded as an *inline constant*.
583 These operands provide read-only access to H/W registers.
585 ======================== ================================================ =============
586 Syntax Note Availability
587 ======================== ================================================ =============
588 shared_base Base address of shared memory region. GFX9, GFX10
589 shared_limit Address of the end of shared memory region. GFX9, GFX10
590 private_base Base address of private memory region. GFX9, GFX10
591 private_limit Address of the end of private memory region. GFX9, GFX10
592 pops_exiting_wave_id A dedicated counter for POPS. GFX9, GFX10
593 ======================== ================================================ =============
595 .. _amdgpu_synid_literal:
600 A *literal* is a 64-bit value encoded as a separate 32-bit dword in the instruction stream.
601 Compare *literals* with :ref:`inline constants<amdgpu_synid_constant>`.
603 If a number may be encoded as either
604 a :ref:`literal<amdgpu_synid_literal>` or
605 an :ref:`inline constant<amdgpu_synid_constant>`,
606 assembler selects the latter encoding as more efficient.
608 Literals may be specified as :ref:`integer numbers<amdgpu_synid_integer_number>`,
609 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`,
610 :ref:`absolute expressions<amdgpu_synid_absolute_expression>` or
611 :ref:`relocatable expressions<amdgpu_synid_relocatable_expression>`.
613 An instruction may use only one literal but several operands may refer the same literal.
615 .. _amdgpu_synid_uimm8:
620 A 8-bit :ref:`integer number<amdgpu_synid_integer_number>`
621 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
622 The value must be in the range 0..0xFF.
624 .. _amdgpu_synid_uimm32:
629 A 32-bit :ref:`integer number<amdgpu_synid_integer_number>`
630 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
631 The value must be in the range 0..0xFFFFFFFF.
633 .. _amdgpu_synid_uimm20:
638 A 20-bit :ref:`integer number<amdgpu_synid_integer_number>`
639 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
641 The value must be in the range 0..0xFFFFF.
643 .. _amdgpu_synid_uimm21:
648 A 21-bit :ref:`integer number<amdgpu_synid_integer_number>`
649 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
651 The value must be in the range 0..0x1FFFFF.
653 .. WARNING:: Assembler currently supports 20-bit offsets only. Use :ref:`uimm20<amdgpu_synid_uimm20>` as a replacement.
655 .. _amdgpu_synid_simm21:
660 A 21-bit :ref:`integer number<amdgpu_synid_integer_number>`
661 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
663 The value must be in the range -0x100000..0x0FFFFF.
665 .. WARNING:: Assembler currently supports 20-bit unsigned offsets only. Use :ref:`uimm20<amdgpu_synid_uimm20>` as a replacement.
667 .. _amdgpu_synid_off:
672 A special entity which indicates that the value of this operand is not used.
674 ================================== ===================================================
676 ================================== ===================================================
677 off Indicates an unused operand.
678 ================================== ===================================================
681 .. _amdgpu_synid_number:
686 .. _amdgpu_synid_integer_number:
691 Integer numbers are 64 bits wide.
692 They are converted to :ref:`expected operand type<amdgpu_syn_instruction_type>`
693 as described :ref:`here<amdgpu_synid_int_conv>`.
695 Integer numbers may be specified in binary, octal, hexadecimal and decimal formats:
697 ============ =============================== ========
698 Format Syntax Example
699 ============ =============================== ========
700 Decimal [-]?[1-9][0-9]* -1234
701 Binary [-]?0b[01]+ 0b1010
702 Octal [-]?0[0-7]+ 010
703 Hexadecimal [-]?0x[0-9a-fA-F]+ 0xff
704 \ [-]?[0x]?[0-9][0-9a-fA-F]*[hH] 0ffh
705 ============ =============================== ========
707 .. _amdgpu_synid_floating-point_number:
709 Floating-Point Numbers
710 ----------------------
712 All floating-point numbers are handled as double (64 bits wide).
713 They are converted to
714 :ref:`expected operand type<amdgpu_syn_instruction_type>`
715 as described :ref:`here<amdgpu_synid_fp_conv>`.
717 Floating-point numbers may be specified in hexadecimal and decimal formats:
719 ============ ======================================================== ====================== ====================
720 Format Syntax Examples Note
721 ============ ======================================================== ====================== ====================
722 Decimal [-]?[0-9]*[.][0-9]*([eE][+-]?[0-9]*)? -1.234, 234e2 Must include either
725 Hexadecimal [-]0x[0-9a-fA-F]*(.[0-9a-fA-F]*)?[pP][+-]?[0-9a-fA-F]+ -0x1afp-10, 0x.1afp10
726 ============ ======================================================== ====================== ====================
728 .. _amdgpu_synid_expression:
733 An expression is evaluated to a 64-bit integer.
734 Note that floating-point expressions are not supported.
736 There are two kinds of expressions:
738 * :ref:`Absolute<amdgpu_synid_absolute_expression>`.
739 * :ref:`Relocatable<amdgpu_synid_relocatable_expression>`.
741 .. _amdgpu_synid_absolute_expression:
746 The value of an absolute expression does not change after program relocation.
747 Absolute expressions must not include unassigned and relocatable values
750 Absolute expressions are evaluated to 64-bit integer values and converted to
751 :ref:`expected operand type<amdgpu_syn_instruction_type>`
752 as described :ref:`here<amdgpu_synid_int_conv>`.
761 .. _amdgpu_synid_relocatable_expression:
763 Relocatable Expressions
764 -----------------------
766 The value of a relocatable expression depends on program relocation.
768 Note that use of relocatable expressions is limited with branch targets
769 and 32-bit integer operands.
771 A relocatable expression is evaluated to a 64-bit integer value
772 which depends on operand kind and :ref:`relocation type<amdgpu-relocation-records>`
773 of symbol(s) used in the expression. For example, if an instruction refers a label,
774 this reference is evaluated to an offset from the address after the instruction
775 to the label address:
780 v_add_co_u32_e32 v0, vcc, label, v1 // 'label' operand is evaluated to -4
782 Note that values of relocatable expressions are usually unknown at assembly time;
783 they are resolved later by a linker and converted to
784 :ref:`expected operand type<amdgpu_syn_instruction_type>`
785 as described :ref:`here<amdgpu_synid_rl_conv>`.
787 Operands and Operations
788 -----------------------
790 Expressions are composed of 64-bit integer operands and operations.
791 Operands include :ref:`integer numbers<amdgpu_synid_integer_number>`
792 and :ref:`symbols<amdgpu_synid_symbol>`.
794 Expressions may also use "." which is a reference to the current PC (program counter).
796 :ref:`Unary<amdgpu_synid_expression_un_op>` and :ref:`binary<amdgpu_synid_expression_bin_op>`
797 operations produce 64-bit integer results.
799 Syntax of Expressions
800 ---------------------
802 The syntax of expressions is shown below::
804 expr ::= expr binop expr | primaryexpr ;
806 primaryexpr ::= '(' expr ')' | symbol | number | '.' | unop primaryexpr ;
834 .. _amdgpu_synid_expression_bin_op:
839 Binary operators are described in the following table.
840 They operate on and produce 64-bit integers.
841 Operators with higher priority are performed first.
843 ========== ========= ===============================================
844 Operator Priority Meaning
845 ========== ========= ===============================================
846 \* 5 Integer multiplication.
847 / 5 Integer division.
848 % 5 Integer signed remainder.
849 \+ 4 Integer addition.
850 \- 4 Integer subtraction.
851 << 3 Integer shift left.
852 >> 3 Logical shift right.
853 == 2 Equality comparison.
854 != 2 Inequality comparison.
855 <> 2 Inequality comparison.
856 < 2 Signed less than comparison.
857 <= 2 Signed less than or equal comparison.
858 > 2 Signed greater than comparison.
859 >= 2 Signed greater than or equal comparison.
865 ========== ========= ===============================================
867 .. _amdgpu_synid_expression_un_op:
872 Unary operators are described in the following table.
873 They operate on and produce 64-bit integers.
875 ========== ===============================================
877 ========== ===============================================
880 \+ Integer unary plus.
881 \- Integer unary minus.
882 ========== ===============================================
884 .. _amdgpu_synid_symbol:
889 A symbol is a named 64-bit integer value, representing a relocatable
890 address or an absolute (non-relocatable) number.
892 Symbol names have the following syntax:
893 ``[a-zA-Z_.][a-zA-Z0-9_$.@]*``
895 The table below provides several examples of syntax used for symbol definition.
897 ================ ==========================================================
899 ================ ==========================================================
900 .globl <S> Declares a global symbol S without assigning it a value.
901 .set <S>, <E> Assigns the value of an expression E to a symbol S.
902 <S> = <E> Assigns the value of an expression E to a symbol S.
903 <S>: Declares a label S and assigns it the current PC value.
904 ================ ==========================================================
906 A symbol may be used before it is declared or assigned;
907 unassigned symbols are assumed to be PC-relative.
909 Additional information about symbols may be found :ref:`here<amdgpu-symbols>`.
911 .. _amdgpu_synid_conv:
913 Type and Size Conversion
914 ========================
916 This section describes what happens when a 64-bit
917 :ref:`integer number<amdgpu_synid_integer_number>`, a
918 :ref:`floating-point number<amdgpu_synid_floating-point_number>` or an
919 :ref:`expression<amdgpu_synid_expression>`
920 is used for an operand which has a different type or size.
922 .. _amdgpu_synid_int_conv:
924 Conversion of Integer Values
925 ----------------------------
927 Instruction operands may be specified as 64-bit :ref:`integer numbers<amdgpu_synid_integer_number>` or
928 :ref:`absolute expressions<amdgpu_synid_absolute_expression>`. These values are converted to
929 the :ref:`expected operand type<amdgpu_syn_instruction_type>` using the following steps:
931 1. *Validation*. Assembler checks if the input value may be truncated without loss to the required *truncation width*
932 (see the table below). There are two cases when this operation is enabled:
934 * The truncated bits are all 0.
935 * The truncated bits are all 1 and the value after truncation has its MSB bit set.
937 In all other cases assembler triggers an error.
939 2. *Conversion*. The input value is converted to the expected type as described in the table below.
940 Depending on operand kind, this conversion is performed by either assembler or AMDGPU H/W (or both).
942 ============== ================= =============== ====================================================================
943 Expected type Truncation Width Conversion Description
944 ============== ================= =============== ====================================================================
945 i16, u16, b16 16 num.u16 Truncate to 16 bits.
946 i32, u32, b32 32 num.u32 Truncate to 32 bits.
947 i64 32 {-1,num.i32} Truncate to 32 bits and then sign-extend the result to 64 bits.
948 u64, b64 32 {0,num.u32} Truncate to 32 bits and then zero-extend the result to 64 bits.
949 f16 16 num.u16 Use low 16 bits as an f16 value.
950 f32 32 num.u32 Use low 32 bits as an f32 value.
951 f64 32 {num.u32,0} Use low 32 bits of the number as high 32 bits
952 of the result; low 32 bits of the result are zeroed.
953 ============== ================= =============== ====================================================================
955 Examples of enabled conversions:
961 v_add_u16 v0, -1, 0 // src0 = 0xFFFF
962 v_add_f16 v0, -1, 0 // src0 = 0xFFFF (NaN)
964 v_add_u32 v0, -1, 0 // src0 = 0xFFFFFFFF
965 v_add_f32 v0, -1, 0 // src0 = 0xFFFFFFFF (NaN)
967 v_add_u16 v0, 0xff00, v0 // src0 = 0xff00
968 v_add_u16 v0, 0xffffffffffffff00, v0 // src0 = 0xff00
969 v_add_u16 v0, -256, v0 // src0 = 0xff00
971 s_bfe_i64 s[0:1], 0xffefffff, s3 // src0 = 0xffffffffffefffff
972 s_bfe_u64 s[0:1], 0xffefffff, s3 // src0 = 0x00000000ffefffff
973 v_ceil_f64_e32 v[0:1], 0xffefffff // src0 = 0xffefffff00000000 (-1.7976922776554302e308)
976 s_bfe_i64 s[0:1], x, s3 // src0 = 0xffffffffffefffff
977 s_bfe_u64 s[0:1], x, s3 // src0 = 0x00000000ffefffff
978 v_ceil_f64_e32 v[0:1], x // src0 = 0xffefffff00000000 (-1.7976922776554302e308)
980 Examples of disabled conversions:
986 v_add_u16 v0, 0x1ff00, v0 // truncated bits are not all 0 or 1
987 v_add_u16 v0, 0xffffffffffff00ff, v0 // truncated bits do not match MSB of the result
989 .. _amdgpu_synid_fp_conv:
991 Conversion of Floating-Point Values
992 -----------------------------------
994 Instruction operands may be specified as 64-bit :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`.
995 These values are converted to the :ref:`expected operand type<amdgpu_syn_instruction_type>` using the following steps:
997 1. *Validation*. Assembler checks if the input f64 number can be converted
998 to the *required floating-point type* (see the table below) without overflow or underflow.
999 Precision lost is allowed. If this conversion is not possible, assembler triggers an error.
1001 2. *Conversion*. The input value is converted to the expected type as described in the table below.
1002 Depending on operand kind, this is performed by either assembler or AMDGPU H/W (or both).
1004 ============== ================ ================= =================================================================
1005 Expected type Required FP Type Conversion Description
1006 ============== ================ ================= =================================================================
1007 i16, u16, b16 f16 f16(num) Convert to f16 and use bits of the result as an integer value.
1008 i32, u32, b32 f32 f32(num) Convert to f32 and use bits of the result as an integer value.
1009 i64, u64, b64 \- \- Conversion disabled.
1010 f16 f16 f16(num) Convert to f16.
1011 f32 f32 f32(num) Convert to f32.
1012 f64 f64 {num.u32.hi,0} Use high 32 bits of the number as high 32 bits of the result;
1013 zero-fill low 32 bits of the result.
1015 Note that the result may differ from the original number.
1016 ============== ================ ================= =================================================================
1018 Examples of enabled conversions:
1024 v_add_f16 v0, 1.0, 0 // src0 = 0x3C00 (1.0)
1025 v_add_u16 v0, 1.0, 0 // src0 = 0x3C00
1027 v_add_f32 v0, 1.0, 0 // src0 = 0x3F800000 (1.0)
1028 v_add_u32 v0, 1.0, 0 // src0 = 0x3F800000
1030 // src0 before conversion:
1031 // 1.7976931348623157e308 = 0x7fefffffffffffff
1032 // src0 after conversion:
1033 // 1.7976922776554302e308 = 0x7fefffff00000000
1034 v_ceil_f64 v[0:1], 1.7976931348623157e308
1036 v_add_f16 v1, 65500.0, v2 // ok for f16.
1037 v_add_f32 v1, 65600.0, v2 // ok for f32, but would result in overflow for f16.
1039 Examples of disabled conversions:
1045 v_add_f16 v1, 65600.0, v2 // overflow
1047 .. _amdgpu_synid_rl_conv:
1049 Conversion of Relocatable Values
1050 --------------------------------
1052 :ref:`Relocatable expressions<amdgpu_synid_relocatable_expression>`
1053 may be used with 32-bit integer operands and jump targets.
1055 When the value of a relocatable expression is resolved by a linker, it is
1056 converted as needed and truncated to the operand size. The conversion depends
1057 on :ref:`relocation type<amdgpu-relocation-records>` and operand kind.
1059 For example, when a 32-bit operand of an instruction refers a relocatable expression *expr*,
1060 this reference is evaluated to a 64-bit offset from the address after the
1061 instruction to the address being referenced, *counted in bytes*.
1062 Then the value is truncated to 32 bits and encoded as a literal:
1067 v_add_co_u32_e32 v0, vcc, expr, v1 // 'expr' operand is evaluated to -4
1068 // and then truncated to 0xFFFFFFFC
1070 As another example, when a branch instruction refers a label,
1071 this reference is evaluated to an offset from the address after the
1072 instruction to the label address, *counted in dwords*.
1073 Then the value is truncated to 16 bits:
1078 s_branch label // 'label' operand is evaluated to -1 and truncated to 0xFFFF