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.
41 *N* must be a decimal integer number.
42 **v[**\ <N>\ **]** A single 32-bit *vector* register.
44 *N* may be specified as an
45 :ref:`integer number<amdgpu_synid_integer_number>`
46 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
47 **v[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *vector* registers.
49 *N* and *K* may be specified as
50 :ref:`integer numbers<amdgpu_synid_integer_number>`
51 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
52 **[v**\ <N>, \ **v**\ <N+1>, ... **v**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *vector* registers.
54 Register indices must be specified as decimal integer numbers.
55 =================================================== ====================================================================
57 Note. *N* and *K* must satisfy the following conditions:
62 * *K-N+1* must be equal to 1, 2, 3, 4, 8 or 16.
80 *Image* instructions may use special *NSA* (Non-Sequential Address) syntax for *image addresses*:
82 =================================================== ====================================================================
84 =================================================== ====================================================================
85 **[v**\ <A>, \ **v**\ <B>, ... **v**\ <X>\ **]** A sequence of *vector* registers. At least one register
88 In contrast with standard syntax described above, registers in
89 this sequence are not required to have consecutive indices.
90 Moreover, the same register may appear in the list more than once.
91 =================================================== ====================================================================
93 Note. Reqister indices must be in the range 0..255. They must be specified as decimal integer numbers.
107 Scalar 32-bit registers. The number of available *scalar* registers depends on GPU:
109 ======= ============================
110 GPU Number of *scalar* registers
111 ======= ============================
116 ======= ============================
118 A sequence of *scalar* registers may be used to operate with more than 32 bits of data.
119 Assembler currently supports sequences of 1, 2, 4, 8 and 16 *scalar* registers.
121 Pairs of *scalar* registers must be even-aligned (the first register must be even).
122 Sequences of 4 and more *scalar* registers must be quad-aligned.
124 ======================================================== ====================================================================
126 ======================================================== ====================================================================
127 **s**\ <N> A single 32-bit *scalar* register.
129 *N* must be a decimal integer number.
130 **s[**\ <N>\ **]** A single 32-bit *scalar* register.
132 *N* may be specified as an
133 :ref:`integer number<amdgpu_synid_integer_number>`
134 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
135 **s[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
137 *N* and *K* may be specified as
138 :ref:`integer numbers<amdgpu_synid_integer_number>`
139 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
140 **[s**\ <N>, \ **s**\ <N+1>, ... **s**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
142 Register indices must be specified as decimal integer numbers.
143 ======================================================== ====================================================================
145 Note. *N* and *K* must satisfy the following conditions:
147 * *N* must be properly aligned based on sequence size.
149 * 0 <= *N* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
150 * 0 <= *K* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
151 * *K-N+1* must be equal to 1, 2, 4, 8 or 16.
167 Examples of *scalar* registers with an invalid alignment:
174 .. _amdgpu_synid_trap:
179 A set of trap handler registers:
181 * :ref:`ttmp<amdgpu_synid_ttmp>`
182 * :ref:`tba<amdgpu_synid_tba>`
183 * :ref:`tma<amdgpu_synid_tma>`
185 .. _amdgpu_synid_ttmp:
190 Trap handler temporary scalar registers, 32-bits wide.
191 The number of available *ttmp* registers depends on GPU:
193 ======= ===========================
194 GPU Number of *ttmp* registers
195 ======= ===========================
200 ======= ===========================
202 A sequence of *ttmp* registers may be used to operate with more than 32 bits of data.
203 Assembler currently supports sequences of 1, 2, 4, 8 and 16 *ttmp* registers.
205 Pairs of *ttmp* registers must be even-aligned (the first register must be even).
206 Sequences of 4 and more *ttmp* registers must be quad-aligned.
208 ============================================================= ====================================================================
210 ============================================================= ====================================================================
211 **ttmp**\ <N> A single 32-bit *ttmp* register.
213 *N* must be a decimal integer number.
214 **ttmp[**\ <N>\ **]** A single 32-bit *ttmp* register.
216 *N* may be specified as an
217 :ref:`integer number<amdgpu_synid_integer_number>`
218 or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
219 **ttmp[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
221 *N* and *K* may be specified as
222 :ref:`integer numbers<amdgpu_synid_integer_number>`
223 or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
224 **[ttmp**\ <N>, \ **ttmp**\ <N+1>, ... **ttmp**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
226 Register indices must be specified as decimal integer numbers.
227 ============================================================= ====================================================================
229 Note. *N* and *K* must satisfy the following conditions:
231 * *N* must be properly aligned based on sequence size.
233 * 0 <= *N* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
234 * 0 <= *K* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
235 * *K-N+1* must be equal to 1, 2, 4, 8 or 16.
249 [ttmp4,ttmp5,ttmp6,ttmp7]
251 Examples of *ttmp* registers with an invalid alignment:
258 .. _amdgpu_synid_tba:
263 Trap base address, 64-bits wide. Holds the pointer to the current trap handler program.
265 ================== ======================================================================= =============
266 Syntax Description Availability
267 ================== ======================================================================= =============
268 tba 64-bit *trap base address* register. GFX7, GFX8
269 [tba] 64-bit *trap base address* register (an alternative syntax). GFX7, GFX8
270 [tba_lo,tba_hi] 64-bit *trap base address* register (an alternative syntax). GFX7, GFX8
271 ================== ======================================================================= =============
273 High and low 32 bits of *trap base address* may be accessed as separate registers:
275 ================== ======================================================================= =============
276 Syntax Description Availability
277 ================== ======================================================================= =============
278 tba_lo Low 32 bits of *trap base address* register. GFX7, GFX8
279 tba_hi High 32 bits of *trap base address* register. GFX7, GFX8
280 [tba_lo] Low 32 bits of *trap base address* register (an alternative syntax). GFX7, GFX8
281 [tba_hi] High 32 bits of *trap base address* register (an alternative syntax). GFX7, GFX8
282 ================== ======================================================================= =============
284 Note that *tba*, *tba_lo* and *tba_hi* are not accessible as assembler registers in GFX9 and GFX10,
285 but *tba* is readable/writable with the help of *s_get_reg* and *s_set_reg* instructions.
287 .. _amdgpu_synid_tma:
292 Trap memory address, 64-bits wide.
294 ================= ======================================================================= ==================
295 Syntax Description Availability
296 ================= ======================================================================= ==================
297 tma 64-bit *trap memory address* register. GFX7, GFX8
298 [tma] 64-bit *trap memory address* register (an alternative syntax). GFX7, GFX8
299 [tma_lo,tma_hi] 64-bit *trap memory address* register (an alternative syntax). GFX7, GFX8
300 ================= ======================================================================= ==================
302 High and low 32 bits of *trap memory address* may be accessed as separate registers:
304 ================= ======================================================================= ==================
305 Syntax Description Availability
306 ================= ======================================================================= ==================
307 tma_lo Low 32 bits of *trap memory address* register. GFX7, GFX8
308 tma_hi High 32 bits of *trap memory address* register. GFX7, GFX8
309 [tma_lo] Low 32 bits of *trap memory address* register (an alternative syntax). GFX7, GFX8
310 [tma_hi] High 32 bits of *trap memory address* register (an alternative syntax). GFX7, GFX8
311 ================= ======================================================================= ==================
313 Note that *tma*, *tma_lo* and *tma_hi* are not accessible as assembler registers in GFX9 and GFX10,
314 but *tma* is readable/writable with the help of *s_get_reg* and *s_set_reg* instructions.
316 .. _amdgpu_synid_flat_scratch:
321 Flat scratch address, 64-bits wide. Holds the base address of scratch memory.
323 ================================== ================================================================
325 ================================== ================================================================
326 flat_scratch 64-bit *flat scratch* address register.
327 [flat_scratch] 64-bit *flat scratch* address register (an alternative syntax).
328 [flat_scratch_lo,flat_scratch_hi] 64-bit *flat scratch* address register (an alternative syntax).
329 ================================== ================================================================
331 High and low 32 bits of *flat scratch* address may be accessed as separate registers:
333 ========================= =========================================================================
335 ========================= =========================================================================
336 flat_scratch_lo Low 32 bits of *flat scratch* address register.
337 flat_scratch_hi High 32 bits of *flat scratch* address register.
338 [flat_scratch_lo] Low 32 bits of *flat scratch* address register (an alternative syntax).
339 [flat_scratch_hi] High 32 bits of *flat scratch* address register (an alternative syntax).
340 ========================= =========================================================================
342 .. _amdgpu_synid_xnack:
347 Xnack mask, 64-bits wide. Holds a 64-bit mask of which threads
348 received an *XNACK* due to a vector memory operation.
350 .. WARNING:: GFX7 does not support *xnack* feature. For availability of this feature in other GPUs, refer :ref:`this table<amdgpu-processors>`.
354 ============================== =====================================================
356 ============================== =====================================================
357 xnack_mask 64-bit *xnack mask* register.
358 [xnack_mask] 64-bit *xnack mask* register (an alternative syntax).
359 [xnack_mask_lo,xnack_mask_hi] 64-bit *xnack mask* register (an alternative syntax).
360 ============================== =====================================================
362 High and low 32 bits of *xnack mask* may be accessed as separate registers:
364 ===================== ==============================================================
366 ===================== ==============================================================
367 xnack_mask_lo Low 32 bits of *xnack mask* register.
368 xnack_mask_hi High 32 bits of *xnack mask* register.
369 [xnack_mask_lo] Low 32 bits of *xnack mask* register (an alternative syntax).
370 [xnack_mask_hi] High 32 bits of *xnack mask* register (an alternative syntax).
371 ===================== ==============================================================
373 .. _amdgpu_synid_vcc:
374 .. _amdgpu_synid_vcc_lo:
379 Vector condition code, 64-bits wide. A bit mask with one bit per thread;
380 it holds the result of a vector compare operation.
382 Note that GFX10 H/W does not use high 32 bits of *vcc* in *wave32* mode.
384 ================ =========================================================================
386 ================ =========================================================================
387 vcc 64-bit *vector condition code* register.
388 [vcc] 64-bit *vector condition code* register (an alternative syntax).
389 [vcc_lo,vcc_hi] 64-bit *vector condition code* register (an alternative syntax).
390 ================ =========================================================================
392 High and low 32 bits of *vector condition code* may be accessed as separate registers:
394 ================ =========================================================================
396 ================ =========================================================================
397 vcc_lo Low 32 bits of *vector condition code* register.
398 vcc_hi High 32 bits of *vector condition code* register.
399 [vcc_lo] Low 32 bits of *vector condition code* register (an alternative syntax).
400 [vcc_hi] High 32 bits of *vector condition code* register (an alternative syntax).
401 ================ =========================================================================
408 A 32-bit memory register. It has various uses,
409 including register indexing and bounds checking.
411 =========== ===================================================
413 =========== ===================================================
414 m0 A 32-bit *memory* register.
415 [m0] A 32-bit *memory* register (an alternative syntax).
416 =========== ===================================================
418 .. _amdgpu_synid_exec:
423 Execute mask, 64-bits wide. A bit mask with one bit per thread,
424 which is applied to vector instructions and controls which threads execute
425 and which ignore the instruction.
427 Note that GFX10 H/W does not use high 32 bits of *exec* in *wave32* mode.
429 ===================== =================================================================
431 ===================== =================================================================
432 exec 64-bit *execute mask* register.
433 [exec] 64-bit *execute mask* register (an alternative syntax).
434 [exec_lo,exec_hi] 64-bit *execute mask* register (an alternative syntax).
435 ===================== =================================================================
437 High and low 32 bits of *execute mask* may be accessed as separate registers:
439 ===================== =================================================================
441 ===================== =================================================================
442 exec_lo Low 32 bits of *execute mask* register.
443 exec_hi High 32 bits of *execute mask* register.
444 [exec_lo] Low 32 bits of *execute mask* register (an alternative syntax).
445 [exec_hi] High 32 bits of *execute mask* register (an alternative syntax).
446 ===================== =================================================================
448 .. _amdgpu_synid_vccz:
453 A single bit flag indicating that the :ref:`vcc<amdgpu_synid_vcc>` is all zeros.
455 Note. When GFX10 operates in *wave32* mode, this register reflects state of :ref:`vcc_lo<amdgpu_synid_vcc_lo>`.
457 .. _amdgpu_synid_execz:
462 A single bit flag indicating that the :ref:`exec<amdgpu_synid_exec>` is all zeros.
464 Note. When GFX10 operates in *wave32* mode, this register reflects state of :ref:`exec_lo<amdgpu_synid_exec>`.
466 .. _amdgpu_synid_scc:
471 A single bit flag indicating the result of a scalar compare operation.
473 .. _amdgpu_synid_lds_direct:
478 A special operand which supplies a 32-bit value
479 fetched from *LDS* memory using :ref:`m0<amdgpu_synid_m0>` as an address.
481 .. _amdgpu_synid_null:
486 This is a special operand which may be used as a source or a destination.
488 When used as a destination, the result of the operation is discarded.
490 When used as a source, it supplies zero value.
494 .. WARNING:: Due to a H/W bug, this operand cannot be used with VALU instructions in first generation of GFX10.
496 .. _amdgpu_synid_constant:
501 A set of integer and floating-point *inline* constants and values:
503 * :ref:`iconst<amdgpu_synid_iconst>`
504 * :ref:`fconst<amdgpu_synid_fconst>`
505 * :ref:`ival<amdgpu_synid_ival>`
507 In contrast with :ref:`literals<amdgpu_synid_literal>`, these operands are encoded as a part of instruction.
509 If a number may be encoded as either
510 a :ref:`literal<amdgpu_synid_literal>` or
511 a :ref:`constant<amdgpu_synid_constant>`,
512 assembler selects the latter encoding as more efficient.
514 .. _amdgpu_synid_iconst:
519 An :ref:`integer number<amdgpu_synid_integer_number>`
520 encoded as an *inline constant*.
522 Only a small fraction of integer numbers may be encoded as *inline constants*.
523 They are enumerated in the table below.
524 Other integer numbers have to be encoded as :ref:`literals<amdgpu_synid_literal>`.
526 Integer *inline constants* are converted to
527 :ref:`expected operand type<amdgpu_syn_instruction_type>`
528 as described :ref:`here<amdgpu_synid_int_const_conv>`.
530 ================================== ====================================
532 ================================== ====================================
533 {0..64} Positive integer inline constants.
534 {-16..-1} Negative integer inline constants.
535 ================================== ====================================
537 .. WARNING:: GFX7 does not support inline constants for *f16* operands.
539 .. _amdgpu_synid_fconst:
544 A :ref:`floating-point number<amdgpu_synid_floating-point_number>`
545 encoded as an *inline constant*.
547 Only a small fraction of floating-point numbers may be encoded as *inline constants*.
548 They are enumerated in the table below.
549 Other floating-point numbers have to be encoded as :ref:`literals<amdgpu_synid_literal>`.
551 Floating-point *inline constants* are converted to
552 :ref:`expected operand type<amdgpu_syn_instruction_type>`
553 as described :ref:`here<amdgpu_synid_fp_const_conv>`.
555 ===================== ===================================================== ==================
556 Value Note Availability
557 ===================== ===================================================== ==================
558 0.0 The same as integer constant 0. All GPUs
559 0.5 Floating-point constant 0.5 All GPUs
560 1.0 Floating-point constant 1.0 All GPUs
561 2.0 Floating-point constant 2.0 All GPUs
562 4.0 Floating-point constant 4.0 All GPUs
563 -0.5 Floating-point constant -0.5 All GPUs
564 -1.0 Floating-point constant -1.0 All GPUs
565 -2.0 Floating-point constant -2.0 All GPUs
566 -4.0 Floating-point constant -4.0 All GPUs
567 0.1592 1.0/(2.0*pi). Use only for 16-bit operands. GFX8, GFX9, GFX10
568 0.15915494 1.0/(2.0*pi). Use only for 16- and 32-bit operands. GFX8, GFX9, GFX10
569 0.15915494309189532 1.0/(2.0*pi). GFX8, GFX9, GFX10
570 ===================== ===================================================== ==================
572 .. WARNING:: GFX7 does not support inline constants for *f16* operands.
574 .. _amdgpu_synid_ival:
579 A symbolic operand encoded as an *inline constant*.
580 These operands provide read-only access to H/W registers.
582 ======================== ================================================ =============
583 Syntax Note Availability
584 ======================== ================================================ =============
585 shared_base Base address of shared memory region. GFX9, GFX10
586 shared_limit Address of the end of shared memory region. GFX9, GFX10
587 private_base Base address of private memory region. GFX9, GFX10
588 private_limit Address of the end of private memory region. GFX9, GFX10
589 pops_exiting_wave_id A dedicated counter for POPS. GFX9, GFX10
590 ======================== ================================================ =============
592 .. _amdgpu_synid_literal:
597 A literal is a 64-bit value which is encoded as a separate 32-bit dword in the instruction stream.
599 If a number may be encoded as either
600 a :ref:`literal<amdgpu_synid_literal>` or
601 an :ref:`inline constant<amdgpu_synid_constant>`,
602 assembler selects the latter encoding as more efficient.
604 Literals may be specified as :ref:`integer numbers<amdgpu_synid_integer_number>`,
605 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>` or
606 :ref:`expressions<amdgpu_synid_expression>`
607 (expressions are currently supported for 32-bit operands only).
609 A 64-bit literal value is converted by assembler
610 to an :ref:`expected operand type<amdgpu_syn_instruction_type>`
611 as described :ref:`here<amdgpu_synid_lit_conv>`.
613 An instruction may use only one literal but several operands may refer the same literal.
615 .. _amdgpu_synid_uimm8:
620 A 8-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
621 The value is encoded as part of the opcode so it is free to use.
623 .. _amdgpu_synid_uimm32:
628 A 32-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
629 The value is stored as a separate 32-bit dword in the instruction stream.
631 .. _amdgpu_synid_uimm20:
636 A 20-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
638 .. _amdgpu_synid_uimm21:
643 A 21-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
645 .. WARNING:: Assembler currently supports 20-bit offsets only. Use :ref:`uimm20<amdgpu_synid_uimm20>` as a replacement.
647 .. _amdgpu_synid_simm21:
652 A 21-bit :ref:`integer number<amdgpu_synid_integer_number>`.
654 .. WARNING:: Assembler currently supports 20-bit unsigned offsets only. Use :ref:`uimm20<amdgpu_synid_uimm20>` as a replacement.
656 .. _amdgpu_synid_off:
661 A special entity which indicates that the value of this operand is not used.
663 ================================== ===================================================
665 ================================== ===================================================
666 off Indicates an unused operand.
667 ================================== ===================================================
670 .. _amdgpu_synid_number:
675 .. _amdgpu_synid_integer_number:
680 Integer numbers are 64 bits wide.
681 They may be specified in binary, octal, hexadecimal and decimal formats:
683 ============== ====================================
685 ============== ====================================
686 Decimal [-]?[1-9][0-9]*
689 Hexadecimal [-]?0x[0-9a-fA-F]+
690 \ [-]?[0x]?[0-9][0-9a-fA-F]*[hH]
691 ============== ====================================
703 .. _amdgpu_synid_floating-point_number:
705 Floating-Point Numbers
706 ----------------------
708 All floating-point numbers are handled as double (64 bits wide).
710 Floating-point numbers may be specified in hexadecimal and decimal formats:
712 ============== ======================================================== ========================================================
714 ============== ======================================================== ========================================================
715 Decimal [-]?[0-9]*[.][0-9]*([eE][+-]?[0-9]*)? Must include either a decimal separator or an exponent.
716 Hexadecimal [-]0x[0-9a-fA-F]*(.[0-9a-fA-F]*)?[pP][+-]?[0-9a-fA-F]+
717 ============== ======================================================== ========================================================
728 .. _amdgpu_synid_expression:
733 An expression specifies an address or a numeric value.
734 There are two kinds of expressions:
736 * :ref:`Absolute<amdgpu_synid_absolute_expression>`.
737 * :ref:`Relocatable<amdgpu_synid_relocatable_expression>`.
739 .. _amdgpu_synid_absolute_expression:
744 The value of an absolute expression remains the same after program relocation.
745 Absolute expressions must not include unassigned and relocatable values
755 .. _amdgpu_synid_relocatable_expression:
757 Relocatable Expressions
758 -----------------------
760 The value of a relocatable expression depends on program relocation.
762 Note that use of relocatable expressions is limited with branch targets
763 and 32-bit :ref:`literals<amdgpu_synid_literal>`.
765 Addition information about relocation may be found :ref:`here<amdgpu-relocation-records>`.
771 y = x + 10 // x is not yet defined. Undefined symbols are assumed to be PC-relative.
777 Expressions and operands of expressions are interpreted as 64-bit integers.
779 Expressions may include 64-bit :ref:`floating-point numbers<amdgpu_synid_floating-point_number>` (double).
780 However these operands are also handled as 64-bit integers
781 using binary representation of specified floating-point numbers.
782 No conversion from floating-point to integer is performed.
788 x = 0.1 // x is assigned an integer 4591870180066957722 which is a binary representation of 0.1.
789 y = x + x // y is a sum of two integer values; it is not equal to 0.2!
794 Expressions are composed of
795 :ref:`symbols<amdgpu_synid_symbol>`,
796 :ref:`integer numbers<amdgpu_synid_integer_number>`,
797 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`,
798 :ref:`binary operators<amdgpu_synid_expression_bin_op>`,
799 :ref:`unary operators<amdgpu_synid_expression_un_op>` and subexpressions.
801 Expressions may also use "." which is a reference to the current PC (program counter).
803 The syntax of expressions is shown below::
805 expr ::= expr binop expr | primaryexpr ;
807 primaryexpr ::= '(' expr ')' | symbol | number | '.' | unop primaryexpr ;
835 .. _amdgpu_synid_expression_bin_op:
840 Binary operators are described in the following table.
841 They operate on and produce 64-bit integers.
842 Operators with higher priority are performed first.
844 ========== ========= ===============================================
845 Operator Priority Meaning
846 ========== ========= ===============================================
847 \* 5 Integer multiplication.
848 / 5 Integer division.
849 % 5 Integer signed remainder.
850 \+ 4 Integer addition.
851 \- 4 Integer subtraction.
852 << 3 Integer shift left.
853 >> 3 Logical shift right.
854 == 2 Equality comparison.
855 != 2 Inequality comparison.
856 <> 2 Inequality comparison.
857 < 2 Signed less than comparison.
858 <= 2 Signed less than or equal comparison.
859 > 2 Signed greater than comparison.
860 >= 2 Signed greater than or equal comparison.
866 ========== ========= ===============================================
868 .. _amdgpu_synid_expression_un_op:
873 Unary operators are described in the following table.
874 They operate on and produce 64-bit integers.
876 ========== ===============================================
878 ========== ===============================================
881 \+ Integer unary plus.
882 \- Integer unary minus.
883 ========== ===============================================
885 .. _amdgpu_synid_symbol:
890 A symbol is a named 64-bit value, representing a relocatable
891 address or an absolute (non-relocatable) number.
893 Symbol names have the following syntax:
894 ``[a-zA-Z_.][a-zA-Z0-9_$.@]*``
896 The table below provides several examples of syntax used for symbol definition.
898 ================ ==========================================================
900 ================ ==========================================================
901 .globl <S> Declares a global symbol S without assigning it a value.
902 .set <S>, <E> Assigns the value of an expression E to a symbol S.
903 <S> = <E> Assigns the value of an expression E to a symbol S.
904 <S>: Declares a label S and assigns it the current PC value.
905 ================ ==========================================================
907 A symbol may be used before it is declared or assigned;
908 unassigned symbols are assumed to be PC-relative.
910 Addition information about symbols may be found :ref:`here<amdgpu-symbols>`.
912 .. _amdgpu_synid_conv:
917 This section describes what happens when a 64-bit
918 :ref:`integer number<amdgpu_synid_integer_number>`, a
919 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>` or a
920 :ref:`symbol<amdgpu_synid_symbol>`
921 is used for an operand which has a different type or size.
923 Depending on operand kind, this conversion is performed by either assembler or AMDGPU H/W:
925 * Values encoded as :ref:`inline constants<amdgpu_synid_constant>` are handled by H/W.
926 * Values encoded as :ref:`literals<amdgpu_synid_literal>` are converted by assembler.
928 .. _amdgpu_synid_const_conv:
933 .. _amdgpu_synid_int_const_conv:
935 Integer Inline Constants
936 ~~~~~~~~~~~~~~~~~~~~~~~~
938 Integer :ref:`inline constants<amdgpu_synid_constant>`
939 may be thought of as 64-bit
940 :ref:`integer numbers<amdgpu_synid_integer_number>`;
941 when used as operands they are truncated to the size of
942 :ref:`expected operand type<amdgpu_syn_instruction_type>`.
943 No data type conversions are performed.
951 v_add_u16 v0, -1, 0 // v0 = 0xFFFF
952 v_add_f16 v0, -1, 0 // v0 = 0xFFFF (NaN)
954 v_add_u32 v0, -1, 0 // v0 = 0xFFFFFFFF
955 v_add_f32 v0, -1, 0 // v0 = 0xFFFFFFFF (NaN)
957 .. _amdgpu_synid_fp_const_conv:
959 Floating-Point Inline Constants
960 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
962 Floating-point :ref:`inline constants<amdgpu_synid_constant>`
963 may be thought of as 64-bit
964 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`;
965 when used as operands they are converted to a floating-point number of
966 :ref:`expected operand size<amdgpu_syn_instruction_type>`.
974 v_add_f16 v0, 1.0, 0 // v0 = 0x3C00 (1.0)
975 v_add_u16 v0, 1.0, 0 // v0 = 0x3C00
977 v_add_f32 v0, 1.0, 0 // v0 = 0x3F800000 (1.0)
978 v_add_u32 v0, 1.0, 0 // v0 = 0x3F800000
981 .. _amdgpu_synid_lit_conv:
986 .. _amdgpu_synid_int_lit_conv:
991 Integer :ref:`literals<amdgpu_synid_literal>`
992 are specified as 64-bit :ref:`integer numbers<amdgpu_synid_integer_number>`.
994 When used as operands they are converted to
995 :ref:`expected operand type<amdgpu_syn_instruction_type>` as described below.
997 ============== ============== =============== ====================================================================
998 Expected type Condition Result Note
999 ============== ============== =============== ====================================================================
1000 i16, u16, b16 cond(num,16) num.u16 Truncate to 16 bits.
1001 i32, u32, b32 cond(num,32) num.u32 Truncate to 32 bits.
1002 i64 cond(num,32) {-1,num.i32} Truncate to 32 bits and then sign-extend the result to 64 bits.
1003 u64, b64 cond(num,32) { 0,num.u32} Truncate to 32 bits and then zero-extend the result to 64 bits.
1004 f16 cond(num,16) num.u16 Use low 16 bits as an f16 value.
1005 f32 cond(num,32) num.u32 Use low 32 bits as an f32 value.
1006 f64 cond(num,32) {num.u32,0} Use low 32 bits of the number as high 32 bits
1007 of the result; low 32 bits of the result are zeroed.
1008 ============== ============== =============== ====================================================================
1010 The condition *cond(X,S)* indicates if a 64-bit number *X*
1011 can be converted to a smaller size *S* by truncation of upper bits.
1012 There are two cases when the conversion is possible:
1014 * The truncated bits are all 0.
1015 * The truncated bits are all 1 and the value after truncation has its MSB bit set.
1017 Examples of valid literals:
1022 // Literal value after conversion:
1023 v_add_u16 v0, 0xff00, v0 // 0xff00
1024 v_add_u16 v0, 0xffffffffffffff00, v0 // 0xff00
1025 v_add_u16 v0, -256, v0 // 0xff00
1026 // Literal value after conversion:
1027 s_bfe_i64 s[0:1], 0xffefffff, s3 // 0xffffffffffefffff
1028 s_bfe_u64 s[0:1], 0xffefffff, s3 // 0x00000000ffefffff
1029 v_ceil_f64_e32 v[0:1], 0xffefffff // 0xffefffff00000000 (-1.7976922776554302e308)
1031 Examples of invalid literals:
1037 v_add_u16 v0, 0x1ff00, v0 // truncated bits are not all 0 or 1
1038 v_add_u16 v0, 0xffffffffffff00ff, v0 // truncated bits do not match MSB of the result
1040 .. _amdgpu_synid_fp_lit_conv:
1042 Floating-Point Literals
1043 ~~~~~~~~~~~~~~~~~~~~~~~
1045 Floating-point :ref:`literals<amdgpu_synid_literal>` are specified as 64-bit
1046 :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`.
1048 When used as operands they are converted to
1049 :ref:`expected operand type<amdgpu_syn_instruction_type>` as described below.
1051 ============== ============== ================= =================================================================
1052 Expected type Condition Result Note
1053 ============== ============== ================= =================================================================
1054 i16, u16, b16 cond(num,16) f16(num) Convert to f16 and use bits of the result as an integer value.
1055 i32, u32, b32 cond(num,32) f32(num) Convert to f32 and use bits of the result as an integer value.
1056 i64, u64, b64 false \- Conversion disabled because of an unclear semantics.
1057 f16 cond(num,16) f16(num) Convert to f16.
1058 f32 cond(num,32) f32(num) Convert to f32.
1059 f64 true {num.u32.hi,0} Use high 32 bits of the number as high 32 bits of the result;
1060 zero-fill low 32 bits of the result.
1062 Note that the result may differ from the original number.
1063 ============== ============== ================= =================================================================
1065 The condition *cond(X,S)* indicates if an f64 number *X* can be converted
1066 to a smaller *S*-bit floating-point type without overflow or underflow.
1067 Precision lost is allowed.
1069 Examples of valid literals:
1075 v_add_f16 v1, 65500.0, v2
1076 v_add_f32 v1, 65600.0, v2
1078 // Literal value before conversion: 1.7976931348623157e308 (0x7fefffffffffffff)
1079 // Literal value after conversion: 1.7976922776554302e308 (0x7fefffff00000000)
1080 v_ceil_f64 v[0:1], 1.7976931348623157e308
1082 Examples of invalid literals:
1088 v_add_f16 v1, 65600.0, v2 // overflow
1090 .. _amdgpu_synid_exp_conv:
1095 Expressions operate with and result in 64-bit integers.
1097 When used as operands they are truncated to
1098 :ref:`expected operand size<amdgpu_syn_instruction_type>`.
1099 No data type conversions are performed.
1108 v_sqrt_f32 v0, x // v0 = [low 32 bits of 0.1 (double)]
1109 v_sqrt_f32 v0, (0.1 + 0) // the same as above
1110 v_sqrt_f32 v0, 0.1 // v0 = [0.1 (double) converted to float]