AMDGPUOperandSyntax.rst 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. =====================================
  2. Syntax of AMDGPU Instruction Operands
  3. =====================================
  4. .. contents::
  5. :local:
  6. Conventions
  7. ===========
  8. The following notation is used throughout this document:
  9. =================== =============================================================================
  10. Notation Description
  11. =================== =============================================================================
  12. {0..N} Any integer value in the range from 0 to N (inclusive).
  13. <x> Syntax and meaning of *x* is explained elsewhere.
  14. =================== =============================================================================
  15. .. _amdgpu_syn_operands:
  16. Operands
  17. ========
  18. .. _amdgpu_synid_v:
  19. v
  20. -
  21. Vector registers. There are 256 32-bit vector registers.
  22. A sequence of *vector* registers may be used to operate with more than 32 bits of data.
  23. Assembler currently supports sequences of 1, 2, 3, 4, 8 and 16 *vector* registers.
  24. =================================================== ====================================================================
  25. Syntax Description
  26. =================================================== ====================================================================
  27. **v**\<N> A single 32-bit *vector* register.
  28. *N* must be a decimal integer number.
  29. **v[**\ <N>\ **]** A single 32-bit *vector* register.
  30. *N* may be specified as an
  31. :ref:`integer number<amdgpu_synid_integer_number>`
  32. or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
  33. **v[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *vector* registers.
  34. *N* and *K* may be specified as
  35. :ref:`integer numbers<amdgpu_synid_integer_number>`
  36. or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
  37. **[v**\ <N>, \ **v**\ <N+1>, ... **v**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *vector* registers.
  38. Register indices must be specified as decimal integer numbers.
  39. =================================================== ====================================================================
  40. Note. *N* and *K* must satisfy the following conditions:
  41. * *N* <= *K*.
  42. * 0 <= *N* <= 255.
  43. * 0 <= *K* <= 255.
  44. * *K-N+1* must be equal to 1, 2, 3, 4, 8 or 16.
  45. Examples:
  46. .. parsed-literal::
  47. v255
  48. v[0]
  49. v[0:1]
  50. v[1:1]
  51. v[0:3]
  52. v[2*2]
  53. v[1-1:2-1]
  54. [v252]
  55. [v252,v253,v254,v255]
  56. .. _amdgpu_synid_nsa:
  57. *Image* instructions may use special *NSA* (Non-Sequential Address) syntax for *image addresses*:
  58. =================================================== ====================================================================
  59. Syntax Description
  60. =================================================== ====================================================================
  61. **[v**\ <A>, \ **v**\ <B>, ... **v**\ <X>\ **]** A sequence of *vector* registers. At least one register
  62. must be specified.
  63. In contrast with standard syntax described above, registers in
  64. this sequence are not required to have consecutive indices.
  65. Moreover, the same register may appear in the list more than once.
  66. =================================================== ====================================================================
  67. Note. Reqister indices must be in the range 0..255. They must be specified as decimal integer numbers.
  68. Examples:
  69. .. parsed-literal::
  70. [v32,v1,v2]
  71. [v4,v4,v4,v4]
  72. .. _amdgpu_synid_s:
  73. s
  74. -
  75. Scalar 32-bit registers. The number of available *scalar* registers depends on GPU:
  76. ======= ============================
  77. GPU Number of *scalar* registers
  78. ======= ============================
  79. GFX7 104
  80. GFX8 102
  81. GFX9 102
  82. GFX10 106
  83. ======= ============================
  84. A sequence of *scalar* registers may be used to operate with more than 32 bits of data.
  85. Assembler currently supports sequences of 1, 2, 4, 8 and 16 *scalar* registers.
  86. Pairs of *scalar* registers must be even-aligned (the first register must be even).
  87. Sequences of 4 and more *scalar* registers must be quad-aligned.
  88. ======================================================== ====================================================================
  89. Syntax Description
  90. ======================================================== ====================================================================
  91. **s**\ <N> A single 32-bit *scalar* register.
  92. *N* must be a decimal integer number.
  93. **s[**\ <N>\ **]** A single 32-bit *scalar* register.
  94. *N* may be specified as an
  95. :ref:`integer number<amdgpu_synid_integer_number>`
  96. or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
  97. **s[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
  98. *N* and *K* may be specified as
  99. :ref:`integer numbers<amdgpu_synid_integer_number>`
  100. or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
  101. **[s**\ <N>, \ **s**\ <N+1>, ... **s**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *scalar* registers.
  102. Register indices must be specified as decimal integer numbers.
  103. ======================================================== ====================================================================
  104. Note. *N* and *K* must satisfy the following conditions:
  105. * *N* must be properly aligned based on sequence size.
  106. * *N* <= *K*.
  107. * 0 <= *N* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
  108. * 0 <= *K* < *SMAX*\ , where *SMAX* is the number of available *scalar* registers.
  109. * *K-N+1* must be equal to 1, 2, 4, 8 or 16.
  110. Examples:
  111. .. parsed-literal::
  112. s0
  113. s[0]
  114. s[0:1]
  115. s[1:1]
  116. s[0:3]
  117. s[2*2]
  118. s[1-1:2-1]
  119. [s4]
  120. [s4,s5,s6,s7]
  121. Examples of *scalar* registers with an invalid alignment:
  122. .. parsed-literal::
  123. s[1:2]
  124. s[2:5]
  125. .. _amdgpu_synid_trap:
  126. trap
  127. ----
  128. A set of trap handler registers:
  129. * :ref:`ttmp<amdgpu_synid_ttmp>`
  130. * :ref:`tba<amdgpu_synid_tba>`
  131. * :ref:`tma<amdgpu_synid_tma>`
  132. .. _amdgpu_synid_ttmp:
  133. ttmp
  134. ----
  135. Trap handler temporary scalar registers, 32-bits wide.
  136. The number of available *ttmp* registers depends on GPU:
  137. ======= ===========================
  138. GPU Number of *ttmp* registers
  139. ======= ===========================
  140. GFX7 12
  141. GFX8 12
  142. GFX9 16
  143. GFX10 16
  144. ======= ===========================
  145. A sequence of *ttmp* registers may be used to operate with more than 32 bits of data.
  146. Assembler currently supports sequences of 1, 2, 4, 8 and 16 *ttmp* registers.
  147. Pairs of *ttmp* registers must be even-aligned (the first register must be even).
  148. Sequences of 4 and more *ttmp* registers must be quad-aligned.
  149. ============================================================= ====================================================================
  150. Syntax Description
  151. ============================================================= ====================================================================
  152. **ttmp**\ <N> A single 32-bit *ttmp* register.
  153. *N* must be a decimal integer number.
  154. **ttmp[**\ <N>\ **]** A single 32-bit *ttmp* register.
  155. *N* may be specified as an
  156. :ref:`integer number<amdgpu_synid_integer_number>`
  157. or an :ref:`absolute expression<amdgpu_synid_absolute_expression>`.
  158. **ttmp[**\ <N>:<K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
  159. *N* and *K* may be specified as
  160. :ref:`integer numbers<amdgpu_synid_integer_number>`
  161. or :ref:`absolute expressions<amdgpu_synid_absolute_expression>`.
  162. **[ttmp**\ <N>, \ **ttmp**\ <N+1>, ... **ttmp**\ <K>\ **]** A sequence of (\ *K-N+1*\ ) *ttmp* registers.
  163. Register indices must be specified as decimal integer numbers.
  164. ============================================================= ====================================================================
  165. Note. *N* and *K* must satisfy the following conditions:
  166. * *N* must be properly aligned based on sequence size.
  167. * *N* <= *K*.
  168. * 0 <= *N* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
  169. * 0 <= *K* < *TMAX*, where *TMAX* is the number of available *ttmp* registers.
  170. * *K-N+1* must be equal to 1, 2, 4, 8 or 16.
  171. Examples:
  172. .. parsed-literal::
  173. ttmp0
  174. ttmp[0]
  175. ttmp[0:1]
  176. ttmp[1:1]
  177. ttmp[0:3]
  178. ttmp[2*2]
  179. ttmp[1-1:2-1]
  180. [ttmp4]
  181. [ttmp4,ttmp5,ttmp6,ttmp7]
  182. Examples of *ttmp* registers with an invalid alignment:
  183. .. parsed-literal::
  184. ttmp[1:2]
  185. ttmp[2:5]
  186. .. _amdgpu_synid_tba:
  187. tba
  188. ---
  189. Trap base address, 64-bits wide. Holds the pointer to the current trap handler program.
  190. ================== ======================================================================= =============
  191. Syntax Description Availability
  192. ================== ======================================================================= =============
  193. tba 64-bit *trap base address* register. GFX7, GFX8
  194. [tba] 64-bit *trap base address* register (an alternative syntax). GFX7, GFX8
  195. [tba_lo,tba_hi] 64-bit *trap base address* register (an alternative syntax). GFX7, GFX8
  196. ================== ======================================================================= =============
  197. High and low 32 bits of *trap base address* may be accessed as separate registers:
  198. ================== ======================================================================= =============
  199. Syntax Description Availability
  200. ================== ======================================================================= =============
  201. tba_lo Low 32 bits of *trap base address* register. GFX7, GFX8
  202. tba_hi High 32 bits of *trap base address* register. GFX7, GFX8
  203. [tba_lo] Low 32 bits of *trap base address* register (an alternative syntax). GFX7, GFX8
  204. [tba_hi] High 32 bits of *trap base address* register (an alternative syntax). GFX7, GFX8
  205. ================== ======================================================================= =============
  206. Note that *tba*, *tba_lo* and *tba_hi* are not accessible as assembler registers in GFX9 and GFX10,
  207. but *tba* is readable/writable with the help of *s_get_reg* and *s_set_reg* instructions.
  208. .. _amdgpu_synid_tma:
  209. tma
  210. ---
  211. Trap memory address, 64-bits wide.
  212. ================= ======================================================================= ==================
  213. Syntax Description Availability
  214. ================= ======================================================================= ==================
  215. tma 64-bit *trap memory address* register. GFX7, GFX8
  216. [tma] 64-bit *trap memory address* register (an alternative syntax). GFX7, GFX8
  217. [tma_lo,tma_hi] 64-bit *trap memory address* register (an alternative syntax). GFX7, GFX8
  218. ================= ======================================================================= ==================
  219. High and low 32 bits of *trap memory address* may be accessed as separate registers:
  220. ================= ======================================================================= ==================
  221. Syntax Description Availability
  222. ================= ======================================================================= ==================
  223. tma_lo Low 32 bits of *trap memory address* register. GFX7, GFX8
  224. tma_hi High 32 bits of *trap memory address* register. GFX7, GFX8
  225. [tma_lo] Low 32 bits of *trap memory address* register (an alternative syntax). GFX7, GFX8
  226. [tma_hi] High 32 bits of *trap memory address* register (an alternative syntax). GFX7, GFX8
  227. ================= ======================================================================= ==================
  228. Note that *tma*, *tma_lo* and *tma_hi* are not accessible as assembler registers in GFX9 and GFX10,
  229. but *tma* is readable/writable with the help of *s_get_reg* and *s_set_reg* instructions.
  230. .. _amdgpu_synid_flat_scratch:
  231. flat_scratch
  232. ------------
  233. Flat scratch address, 64-bits wide. Holds the base address of scratch memory.
  234. ================================== ================================================================
  235. Syntax Description
  236. ================================== ================================================================
  237. flat_scratch 64-bit *flat scratch* address register.
  238. [flat_scratch] 64-bit *flat scratch* address register (an alternative syntax).
  239. [flat_scratch_lo,flat_scratch_hi] 64-bit *flat scratch* address register (an alternative syntax).
  240. ================================== ================================================================
  241. High and low 32 bits of *flat scratch* address may be accessed as separate registers:
  242. ========================= =========================================================================
  243. Syntax Description
  244. ========================= =========================================================================
  245. flat_scratch_lo Low 32 bits of *flat scratch* address register.
  246. flat_scratch_hi High 32 bits of *flat scratch* address register.
  247. [flat_scratch_lo] Low 32 bits of *flat scratch* address register (an alternative syntax).
  248. [flat_scratch_hi] High 32 bits of *flat scratch* address register (an alternative syntax).
  249. ========================= =========================================================================
  250. .. _amdgpu_synid_xnack:
  251. xnack
  252. -----
  253. Xnack mask, 64-bits wide. Holds a 64-bit mask of which threads
  254. received an *XNACK* due to a vector memory operation.
  255. .. WARNING:: GFX7 does not support *xnack* feature. For availability of this feature in other GPUs, refer :ref:`this table<amdgpu-processors>`.
  256. \
  257. ============================== =====================================================
  258. Syntax Description
  259. ============================== =====================================================
  260. xnack_mask 64-bit *xnack mask* register.
  261. [xnack_mask] 64-bit *xnack mask* register (an alternative syntax).
  262. [xnack_mask_lo,xnack_mask_hi] 64-bit *xnack mask* register (an alternative syntax).
  263. ============================== =====================================================
  264. High and low 32 bits of *xnack mask* may be accessed as separate registers:
  265. ===================== ==============================================================
  266. Syntax Description
  267. ===================== ==============================================================
  268. xnack_mask_lo Low 32 bits of *xnack mask* register.
  269. xnack_mask_hi High 32 bits of *xnack mask* register.
  270. [xnack_mask_lo] Low 32 bits of *xnack mask* register (an alternative syntax).
  271. [xnack_mask_hi] High 32 bits of *xnack mask* register (an alternative syntax).
  272. ===================== ==============================================================
  273. .. _amdgpu_synid_vcc:
  274. .. _amdgpu_synid_vcc_lo:
  275. vcc
  276. ---
  277. Vector condition code, 64-bits wide. A bit mask with one bit per thread;
  278. it holds the result of a vector compare operation.
  279. Note that GFX10 H/W does not use high 32 bits of *vcc* in *wave32* mode.
  280. ================ =========================================================================
  281. Syntax Description
  282. ================ =========================================================================
  283. vcc 64-bit *vector condition code* register.
  284. [vcc] 64-bit *vector condition code* register (an alternative syntax).
  285. [vcc_lo,vcc_hi] 64-bit *vector condition code* register (an alternative syntax).
  286. ================ =========================================================================
  287. High and low 32 bits of *vector condition code* may be accessed as separate registers:
  288. ================ =========================================================================
  289. Syntax Description
  290. ================ =========================================================================
  291. vcc_lo Low 32 bits of *vector condition code* register.
  292. vcc_hi High 32 bits of *vector condition code* register.
  293. [vcc_lo] Low 32 bits of *vector condition code* register (an alternative syntax).
  294. [vcc_hi] High 32 bits of *vector condition code* register (an alternative syntax).
  295. ================ =========================================================================
  296. .. _amdgpu_synid_m0:
  297. m0
  298. --
  299. A 32-bit memory register. It has various uses,
  300. including register indexing and bounds checking.
  301. =========== ===================================================
  302. Syntax Description
  303. =========== ===================================================
  304. m0 A 32-bit *memory* register.
  305. [m0] A 32-bit *memory* register (an alternative syntax).
  306. =========== ===================================================
  307. .. _amdgpu_synid_exec:
  308. exec
  309. ----
  310. Execute mask, 64-bits wide. A bit mask with one bit per thread,
  311. which is applied to vector instructions and controls which threads execute
  312. and which ignore the instruction.
  313. Note that GFX10 H/W does not use high 32 bits of *exec* in *wave32* mode.
  314. ===================== =================================================================
  315. Syntax Description
  316. ===================== =================================================================
  317. exec 64-bit *execute mask* register.
  318. [exec] 64-bit *execute mask* register (an alternative syntax).
  319. [exec_lo,exec_hi] 64-bit *execute mask* register (an alternative syntax).
  320. ===================== =================================================================
  321. High and low 32 bits of *execute mask* may be accessed as separate registers:
  322. ===================== =================================================================
  323. Syntax Description
  324. ===================== =================================================================
  325. exec_lo Low 32 bits of *execute mask* register.
  326. exec_hi High 32 bits of *execute mask* register.
  327. [exec_lo] Low 32 bits of *execute mask* register (an alternative syntax).
  328. [exec_hi] High 32 bits of *execute mask* register (an alternative syntax).
  329. ===================== =================================================================
  330. .. _amdgpu_synid_vccz:
  331. vccz
  332. ----
  333. A single bit flag indicating that the :ref:`vcc<amdgpu_synid_vcc>` is all zeros.
  334. Note. When GFX10 operates in *wave32* mode, this register reflects state of :ref:`vcc_lo<amdgpu_synid_vcc_lo>`.
  335. .. _amdgpu_synid_execz:
  336. execz
  337. -----
  338. A single bit flag indicating that the :ref:`exec<amdgpu_synid_exec>` is all zeros.
  339. Note. When GFX10 operates in *wave32* mode, this register reflects state of :ref:`exec_lo<amdgpu_synid_exec>`.
  340. .. _amdgpu_synid_scc:
  341. scc
  342. ---
  343. A single bit flag indicating the result of a scalar compare operation.
  344. .. _amdgpu_synid_lds_direct:
  345. lds_direct
  346. ----------
  347. A special operand which supplies a 32-bit value
  348. fetched from *LDS* memory using :ref:`m0<amdgpu_synid_m0>` as an address.
  349. .. _amdgpu_synid_null:
  350. null
  351. ----
  352. This is a special operand which may be used as a source or a destination.
  353. When used as a destination, the result of the operation is discarded.
  354. When used as a source, it supplies zero value.
  355. GFX10 only.
  356. .. WARNING:: Due to a H/W bug, this operand cannot be used with VALU instructions in first generation of GFX10.
  357. .. _amdgpu_synid_constant:
  358. constant
  359. --------
  360. A set of integer and floating-point *inline* constants and values:
  361. * :ref:`iconst<amdgpu_synid_iconst>`
  362. * :ref:`fconst<amdgpu_synid_fconst>`
  363. * :ref:`ival<amdgpu_synid_ival>`
  364. In contrast with :ref:`literals<amdgpu_synid_literal>`, these operands are encoded as a part of instruction.
  365. If a number may be encoded as either
  366. a :ref:`literal<amdgpu_synid_literal>` or
  367. a :ref:`constant<amdgpu_synid_constant>`,
  368. assembler selects the latter encoding as more efficient.
  369. .. _amdgpu_synid_iconst:
  370. iconst
  371. ~~~~~~
  372. An :ref:`integer number<amdgpu_synid_integer_number>`
  373. encoded as an *inline constant*.
  374. Only a small fraction of integer numbers may be encoded as *inline constants*.
  375. They are enumerated in the table below.
  376. Other integer numbers have to be encoded as :ref:`literals<amdgpu_synid_literal>`.
  377. Integer *inline constants* are converted to
  378. :ref:`expected operand type<amdgpu_syn_instruction_type>`
  379. as described :ref:`here<amdgpu_synid_int_const_conv>`.
  380. ================================== ====================================
  381. Value Note
  382. ================================== ====================================
  383. {0..64} Positive integer inline constants.
  384. {-16..-1} Negative integer inline constants.
  385. ================================== ====================================
  386. .. WARNING:: GFX7 does not support inline constants for *f16* operands.
  387. .. _amdgpu_synid_fconst:
  388. fconst
  389. ~~~~~~
  390. A :ref:`floating-point number<amdgpu_synid_floating-point_number>`
  391. encoded as an *inline constant*.
  392. Only a small fraction of floating-point numbers may be encoded as *inline constants*.
  393. They are enumerated in the table below.
  394. Other floating-point numbers have to be encoded as :ref:`literals<amdgpu_synid_literal>`.
  395. Floating-point *inline constants* are converted to
  396. :ref:`expected operand type<amdgpu_syn_instruction_type>`
  397. as described :ref:`here<amdgpu_synid_fp_const_conv>`.
  398. ===================== ===================================================== ==================
  399. Value Note Availability
  400. ===================== ===================================================== ==================
  401. 0.0 The same as integer constant 0. All GPUs
  402. 0.5 Floating-point constant 0.5 All GPUs
  403. 1.0 Floating-point constant 1.0 All GPUs
  404. 2.0 Floating-point constant 2.0 All GPUs
  405. 4.0 Floating-point constant 4.0 All GPUs
  406. -0.5 Floating-point constant -0.5 All GPUs
  407. -1.0 Floating-point constant -1.0 All GPUs
  408. -2.0 Floating-point constant -2.0 All GPUs
  409. -4.0 Floating-point constant -4.0 All GPUs
  410. 0.1592 1.0/(2.0*pi). Use only for 16-bit operands. GFX8, GFX9, GFX10
  411. 0.15915494 1.0/(2.0*pi). Use only for 16- and 32-bit operands. GFX8, GFX9, GFX10
  412. 0.15915494309189532 1.0/(2.0*pi). GFX8, GFX9, GFX10
  413. ===================== ===================================================== ==================
  414. .. WARNING:: GFX7 does not support inline constants for *f16* operands.
  415. .. _amdgpu_synid_ival:
  416. ival
  417. ~~~~
  418. A symbolic operand encoded as an *inline constant*.
  419. These operands provide read-only access to H/W registers.
  420. ======================== ================================================ =============
  421. Syntax Note Availability
  422. ======================== ================================================ =============
  423. shared_base Base address of shared memory region. GFX9, GFX10
  424. shared_limit Address of the end of shared memory region. GFX9, GFX10
  425. private_base Base address of private memory region. GFX9, GFX10
  426. private_limit Address of the end of private memory region. GFX9, GFX10
  427. pops_exiting_wave_id A dedicated counter for POPS. GFX9, GFX10
  428. ======================== ================================================ =============
  429. .. _amdgpu_synid_literal:
  430. literal
  431. -------
  432. A literal is a 64-bit value which is encoded as a separate 32-bit dword in the instruction stream.
  433. If a number may be encoded as either
  434. a :ref:`literal<amdgpu_synid_literal>` or
  435. an :ref:`inline constant<amdgpu_synid_constant>`,
  436. assembler selects the latter encoding as more efficient.
  437. Literals may be specified as :ref:`integer numbers<amdgpu_synid_integer_number>`,
  438. :ref:`floating-point numbers<amdgpu_synid_floating-point_number>` or
  439. :ref:`expressions<amdgpu_synid_expression>`
  440. (expressions are currently supported for 32-bit operands only).
  441. A 64-bit literal value is converted by assembler
  442. to an :ref:`expected operand type<amdgpu_syn_instruction_type>`
  443. as described :ref:`here<amdgpu_synid_lit_conv>`.
  444. An instruction may use only one literal but several operands may refer the same literal.
  445. .. _amdgpu_synid_uimm8:
  446. uimm8
  447. -----
  448. A 8-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
  449. The value is encoded as part of the opcode so it is free to use.
  450. .. _amdgpu_synid_uimm32:
  451. uimm32
  452. ------
  453. A 32-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
  454. The value is stored as a separate 32-bit dword in the instruction stream.
  455. .. _amdgpu_synid_uimm20:
  456. uimm20
  457. ------
  458. A 20-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
  459. .. _amdgpu_synid_uimm21:
  460. uimm21
  461. ------
  462. A 21-bit positive :ref:`integer number<amdgpu_synid_integer_number>`.
  463. .. WARNING:: Assembler currently supports 20-bit offsets only. Use :ref:`uimm20<amdgpu_synid_uimm20>` as a replacement.
  464. .. _amdgpu_synid_simm21:
  465. simm21
  466. ------
  467. A 21-bit :ref:`integer number<amdgpu_synid_integer_number>`.
  468. .. WARNING:: Assembler currently supports 20-bit unsigned offsets only. Use :ref:`uimm20<amdgpu_synid_uimm20>` as a replacement.
  469. .. _amdgpu_synid_off:
  470. off
  471. ---
  472. A special entity which indicates that the value of this operand is not used.
  473. ================================== ===================================================
  474. Syntax Description
  475. ================================== ===================================================
  476. off Indicates an unused operand.
  477. ================================== ===================================================
  478. .. _amdgpu_synid_number:
  479. Numbers
  480. =======
  481. .. _amdgpu_synid_integer_number:
  482. Integer Numbers
  483. ---------------
  484. Integer numbers are 64 bits wide.
  485. They may be specified in binary, octal, hexadecimal and decimal formats:
  486. ============== ====================================
  487. Format Syntax
  488. ============== ====================================
  489. Decimal [-]?[1-9][0-9]*
  490. Binary [-]?0b[01]+
  491. Octal [-]?0[0-7]+
  492. Hexadecimal [-]?0x[0-9a-fA-F]+
  493. \ [-]?[0x]?[0-9][0-9a-fA-F]*[hH]
  494. ============== ====================================
  495. Examples:
  496. .. parsed-literal::
  497. -1234
  498. 0b1010
  499. 010
  500. 0xff
  501. 0ffh
  502. .. _amdgpu_synid_floating-point_number:
  503. Floating-Point Numbers
  504. ----------------------
  505. All floating-point numbers are handled as double (64 bits wide).
  506. Floating-point numbers may be specified in hexadecimal and decimal formats:
  507. ============== ======================================================== ========================================================
  508. Format Syntax Note
  509. ============== ======================================================== ========================================================
  510. Decimal [-]?[0-9]*[.][0-9]*([eE][+-]?[0-9]*)? Must include either a decimal separator or an exponent.
  511. Hexadecimal [-]0x[0-9a-fA-F]*(.[0-9a-fA-F]*)?[pP][+-]?[0-9a-fA-F]+
  512. ============== ======================================================== ========================================================
  513. Examples:
  514. .. parsed-literal::
  515. -1.234
  516. 234e2
  517. -0x1afp-10
  518. 0x.1afp10
  519. .. _amdgpu_synid_expression:
  520. Expressions
  521. ===========
  522. An expression specifies an address or a numeric value.
  523. There are two kinds of expressions:
  524. * :ref:`Absolute<amdgpu_synid_absolute_expression>`.
  525. * :ref:`Relocatable<amdgpu_synid_relocatable_expression>`.
  526. .. _amdgpu_synid_absolute_expression:
  527. Absolute Expressions
  528. --------------------
  529. The value of an absolute expression remains the same after program relocation.
  530. Absolute expressions must not include unassigned and relocatable values
  531. such as labels.
  532. Examples:
  533. .. parsed-literal::
  534. x = -1
  535. y = x + 10
  536. .. _amdgpu_synid_relocatable_expression:
  537. Relocatable Expressions
  538. -----------------------
  539. The value of a relocatable expression depends on program relocation.
  540. Note that use of relocatable expressions is limited with branch targets
  541. and 32-bit :ref:`literals<amdgpu_synid_literal>`.
  542. Addition information about relocation may be found :ref:`here<amdgpu-relocation-records>`.
  543. Examples:
  544. .. parsed-literal::
  545. y = x + 10 // x is not yet defined. Undefined symbols are assumed to be PC-relative.
  546. z = .
  547. Expression Data Type
  548. --------------------
  549. Expressions and operands of expressions are interpreted as 64-bit integers.
  550. Expressions may include 64-bit :ref:`floating-point numbers<amdgpu_synid_floating-point_number>` (double).
  551. However these operands are also handled as 64-bit integers
  552. using binary representation of specified floating-point numbers.
  553. No conversion from floating-point to integer is performed.
  554. Examples:
  555. .. parsed-literal::
  556. x = 0.1 // x is assigned an integer 4591870180066957722 which is a binary representation of 0.1.
  557. y = x + x // y is a sum of two integer values; it is not equal to 0.2!
  558. Syntax
  559. ------
  560. Expressions are composed of
  561. :ref:`symbols<amdgpu_synid_symbol>`,
  562. :ref:`integer numbers<amdgpu_synid_integer_number>`,
  563. :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`,
  564. :ref:`binary operators<amdgpu_synid_expression_bin_op>`,
  565. :ref:`unary operators<amdgpu_synid_expression_un_op>` and subexpressions.
  566. Expressions may also use "." which is a reference to the current PC (program counter).
  567. The syntax of expressions is shown below::
  568. expr ::= expr binop expr | primaryexpr ;
  569. primaryexpr ::= '(' expr ')' | symbol | number | '.' | unop primaryexpr ;
  570. binop ::= '&&'
  571. | '||'
  572. | '|'
  573. | '^'
  574. | '&'
  575. | '!'
  576. | '=='
  577. | '!='
  578. | '<>'
  579. | '<'
  580. | '<='
  581. | '>'
  582. | '>='
  583. | '<<'
  584. | '>>'
  585. | '+'
  586. | '-'
  587. | '*'
  588. | '/'
  589. | '%' ;
  590. unop ::= '~'
  591. | '+'
  592. | '-'
  593. | '!' ;
  594. .. _amdgpu_synid_expression_bin_op:
  595. Binary Operators
  596. ----------------
  597. Binary operators are described in the following table.
  598. They operate on and produce 64-bit integers.
  599. Operators with higher priority are performed first.
  600. ========== ========= ===============================================
  601. Operator Priority Meaning
  602. ========== ========= ===============================================
  603. \* 5 Integer multiplication.
  604. / 5 Integer division.
  605. % 5 Integer signed remainder.
  606. \+ 4 Integer addition.
  607. \- 4 Integer subtraction.
  608. << 3 Integer shift left.
  609. >> 3 Logical shift right.
  610. == 2 Equality comparison.
  611. != 2 Inequality comparison.
  612. <> 2 Inequality comparison.
  613. < 2 Signed less than comparison.
  614. <= 2 Signed less than or equal comparison.
  615. > 2 Signed greater than comparison.
  616. >= 2 Signed greater than or equal comparison.
  617. \| 1 Bitwise or.
  618. ^ 1 Bitwise xor.
  619. & 1 Bitwise and.
  620. && 0 Logical and.
  621. || 0 Logical or.
  622. ========== ========= ===============================================
  623. .. _amdgpu_synid_expression_un_op:
  624. Unary Operators
  625. ---------------
  626. Unary operators are described in the following table.
  627. They operate on and produce 64-bit integers.
  628. ========== ===============================================
  629. Operator Meaning
  630. ========== ===============================================
  631. ! Logical negation.
  632. ~ Bitwise negation.
  633. \+ Integer unary plus.
  634. \- Integer unary minus.
  635. ========== ===============================================
  636. .. _amdgpu_synid_symbol:
  637. Symbols
  638. -------
  639. A symbol is a named 64-bit value, representing a relocatable
  640. address or an absolute (non-relocatable) number.
  641. Symbol names have the following syntax:
  642. ``[a-zA-Z_.][a-zA-Z0-9_$.@]*``
  643. The table below provides several examples of syntax used for symbol definition.
  644. ================ ==========================================================
  645. Syntax Meaning
  646. ================ ==========================================================
  647. .globl <S> Declares a global symbol S without assigning it a value.
  648. .set <S>, <E> Assigns the value of an expression E to a symbol S.
  649. <S> = <E> Assigns the value of an expression E to a symbol S.
  650. <S>: Declares a label S and assigns it the current PC value.
  651. ================ ==========================================================
  652. A symbol may be used before it is declared or assigned;
  653. unassigned symbols are assumed to be PC-relative.
  654. Addition information about symbols may be found :ref:`here<amdgpu-symbols>`.
  655. .. _amdgpu_synid_conv:
  656. Conversions
  657. ===========
  658. This section describes what happens when a 64-bit
  659. :ref:`integer number<amdgpu_synid_integer_number>`, a
  660. :ref:`floating-point numbers<amdgpu_synid_floating-point_number>` or a
  661. :ref:`symbol<amdgpu_synid_symbol>`
  662. is used for an operand which has a different type or size.
  663. Depending on operand kind, this conversion is performed by either assembler or AMDGPU H/W:
  664. * Values encoded as :ref:`inline constants<amdgpu_synid_constant>` are handled by H/W.
  665. * Values encoded as :ref:`literals<amdgpu_synid_literal>` are converted by assembler.
  666. .. _amdgpu_synid_const_conv:
  667. Inline Constants
  668. ----------------
  669. .. _amdgpu_synid_int_const_conv:
  670. Integer Inline Constants
  671. ~~~~~~~~~~~~~~~~~~~~~~~~
  672. Integer :ref:`inline constants<amdgpu_synid_constant>`
  673. may be thought of as 64-bit
  674. :ref:`integer numbers<amdgpu_synid_integer_number>`;
  675. when used as operands they are truncated to the size of
  676. :ref:`expected operand type<amdgpu_syn_instruction_type>`.
  677. No data type conversions are performed.
  678. Examples:
  679. .. parsed-literal::
  680. // GFX9
  681. v_add_u16 v0, -1, 0 // v0 = 0xFFFF
  682. v_add_f16 v0, -1, 0 // v0 = 0xFFFF (NaN)
  683. v_add_u32 v0, -1, 0 // v0 = 0xFFFFFFFF
  684. v_add_f32 v0, -1, 0 // v0 = 0xFFFFFFFF (NaN)
  685. .. _amdgpu_synid_fp_const_conv:
  686. Floating-Point Inline Constants
  687. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  688. Floating-point :ref:`inline constants<amdgpu_synid_constant>`
  689. may be thought of as 64-bit
  690. :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`;
  691. when used as operands they are converted to a floating-point number of
  692. :ref:`expected operand size<amdgpu_syn_instruction_type>`.
  693. Examples:
  694. .. parsed-literal::
  695. // GFX9
  696. v_add_f16 v0, 1.0, 0 // v0 = 0x3C00 (1.0)
  697. v_add_u16 v0, 1.0, 0 // v0 = 0x3C00
  698. v_add_f32 v0, 1.0, 0 // v0 = 0x3F800000 (1.0)
  699. v_add_u32 v0, 1.0, 0 // v0 = 0x3F800000
  700. .. _amdgpu_synid_lit_conv:
  701. Literals
  702. --------
  703. .. _amdgpu_synid_int_lit_conv:
  704. Integer Literals
  705. ~~~~~~~~~~~~~~~~
  706. Integer :ref:`literals<amdgpu_synid_literal>`
  707. are specified as 64-bit :ref:`integer numbers<amdgpu_synid_integer_number>`.
  708. When used as operands they are converted to
  709. :ref:`expected operand type<amdgpu_syn_instruction_type>` as described below.
  710. ============== ============== =============== ====================================================================
  711. Expected type Condition Result Note
  712. ============== ============== =============== ====================================================================
  713. i16, u16, b16 cond(num,16) num.u16 Truncate to 16 bits.
  714. i32, u32, b32 cond(num,32) num.u32 Truncate to 32 bits.
  715. i64 cond(num,32) {-1,num.i32} Truncate to 32 bits and then sign-extend the result to 64 bits.
  716. u64, b64 cond(num,32) { 0,num.u32} Truncate to 32 bits and then zero-extend the result to 64 bits.
  717. f16 cond(num,16) num.u16 Use low 16 bits as an f16 value.
  718. f32 cond(num,32) num.u32 Use low 32 bits as an f32 value.
  719. f64 cond(num,32) {num.u32,0} Use low 32 bits of the number as high 32 bits
  720. of the result; low 32 bits of the result are zeroed.
  721. ============== ============== =============== ====================================================================
  722. The condition *cond(X,S)* indicates if a 64-bit number *X*
  723. can be converted to a smaller size *S* by truncation of upper bits.
  724. There are two cases when the conversion is possible:
  725. * The truncated bits are all 0.
  726. * The truncated bits are all 1 and the value after truncation has its MSB bit set.
  727. Examples of valid literals:
  728. .. parsed-literal::
  729. // GFX9
  730. // Literal value after conversion:
  731. v_add_u16 v0, 0xff00, v0 // 0xff00
  732. v_add_u16 v0, 0xffffffffffffff00, v0 // 0xff00
  733. v_add_u16 v0, -256, v0 // 0xff00
  734. // Literal value after conversion:
  735. s_bfe_i64 s[0:1], 0xffefffff, s3 // 0xffffffffffefffff
  736. s_bfe_u64 s[0:1], 0xffefffff, s3 // 0x00000000ffefffff
  737. v_ceil_f64_e32 v[0:1], 0xffefffff // 0xffefffff00000000 (-1.7976922776554302e308)
  738. Examples of invalid literals:
  739. .. parsed-literal::
  740. // GFX9
  741. v_add_u16 v0, 0x1ff00, v0 // truncated bits are not all 0 or 1
  742. v_add_u16 v0, 0xffffffffffff00ff, v0 // truncated bits do not match MSB of the result
  743. .. _amdgpu_synid_fp_lit_conv:
  744. Floating-Point Literals
  745. ~~~~~~~~~~~~~~~~~~~~~~~
  746. Floating-point :ref:`literals<amdgpu_synid_literal>` are specified as 64-bit
  747. :ref:`floating-point numbers<amdgpu_synid_floating-point_number>`.
  748. When used as operands they are converted to
  749. :ref:`expected operand type<amdgpu_syn_instruction_type>` as described below.
  750. ============== ============== ================= =================================================================
  751. Expected type Condition Result Note
  752. ============== ============== ================= =================================================================
  753. i16, u16, b16 cond(num,16) f16(num) Convert to f16 and use bits of the result as an integer value.
  754. i32, u32, b32 cond(num,32) f32(num) Convert to f32 and use bits of the result as an integer value.
  755. i64, u64, b64 false \- Conversion disabled because of an unclear semantics.
  756. f16 cond(num,16) f16(num) Convert to f16.
  757. f32 cond(num,32) f32(num) Convert to f32.
  758. f64 true {num.u32.hi,0} Use high 32 bits of the number as high 32 bits of the result;
  759. zero-fill low 32 bits of the result.
  760. Note that the result may differ from the original number.
  761. ============== ============== ================= =================================================================
  762. The condition *cond(X,S)* indicates if an f64 number *X* can be converted
  763. to a smaller *S*-bit floating-point type without overflow or underflow.
  764. Precision lost is allowed.
  765. Examples of valid literals:
  766. .. parsed-literal::
  767. // GFX9
  768. v_add_f16 v1, 65500.0, v2
  769. v_add_f32 v1, 65600.0, v2
  770. // Literal value before conversion: 1.7976931348623157e308 (0x7fefffffffffffff)
  771. // Literal value after conversion: 1.7976922776554302e308 (0x7fefffff00000000)
  772. v_ceil_f64 v[0:1], 1.7976931348623157e308
  773. Examples of invalid literals:
  774. .. parsed-literal::
  775. // GFX9
  776. v_add_f16 v1, 65600.0, v2 // overflow
  777. .. _amdgpu_synid_exp_conv:
  778. Expressions
  779. ~~~~~~~~~~~
  780. Expressions operate with and result in 64-bit integers.
  781. When used as operands they are truncated to
  782. :ref:`expected operand size<amdgpu_syn_instruction_type>`.
  783. No data type conversions are performed.
  784. Examples:
  785. .. parsed-literal::
  786. // GFX9
  787. x = 0.1
  788. v_sqrt_f32 v0, x // v0 = [low 32 bits of 0.1 (double)]
  789. v_sqrt_f32 v0, (0.1 + 0) // the same as above
  790. v_sqrt_f32 v0, 0.1 // v0 = [0.1 (double) converted to float]