AMDGPUOperandSyntax.rst 44 KB

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