shader_bytecode.h 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <bitset>
  7. #include <optional>
  8. #include <tuple>
  9. #include <vector>
  10. #include "common/assert.h"
  11. #include "common/bit_field.h"
  12. #include "common/common_types.h"
  13. namespace Tegra::Shader {
  14. struct Register {
  15. /// Number of registers
  16. static constexpr std::size_t NumRegisters = 256;
  17. /// Register 255 is special cased to always be 0
  18. static constexpr std::size_t ZeroIndex = 255;
  19. enum class Size : u64 {
  20. Byte = 0,
  21. Short = 1,
  22. Word = 2,
  23. Long = 3,
  24. };
  25. constexpr Register() = default;
  26. constexpr Register(u64 value) : value(value) {}
  27. constexpr operator u64() const {
  28. return value;
  29. }
  30. template <typename T>
  31. constexpr u64 operator-(const T& oth) const {
  32. return value - oth;
  33. }
  34. template <typename T>
  35. constexpr u64 operator&(const T& oth) const {
  36. return value & oth;
  37. }
  38. constexpr u64 operator&(const Register& oth) const {
  39. return value & oth.value;
  40. }
  41. constexpr u64 operator~() const {
  42. return ~value;
  43. }
  44. u64 GetSwizzledIndex(u64 elem) const {
  45. elem = (value + elem) & 3;
  46. return (value & ~3) + elem;
  47. }
  48. private:
  49. u64 value{};
  50. };
  51. enum class AttributeSize : u64 {
  52. Word = 0,
  53. DoubleWord = 1,
  54. TripleWord = 2,
  55. QuadWord = 3,
  56. };
  57. union Attribute {
  58. Attribute() = default;
  59. constexpr explicit Attribute(u64 value) : value(value) {}
  60. enum class Index : u64 {
  61. LayerViewportPointSize = 6,
  62. Position = 7,
  63. Attribute_0 = 8,
  64. Attribute_31 = 39,
  65. ClipDistances0123 = 44,
  66. ClipDistances4567 = 45,
  67. PointCoord = 46,
  68. // This attribute contains a tuple of (~, ~, InstanceId, VertexId) when inside a vertex
  69. // shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
  70. // shader.
  71. TessCoordInstanceIDVertexID = 47,
  72. // This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment
  73. // shader. It is unknown what the other values contain.
  74. FrontFacing = 63,
  75. };
  76. union {
  77. BitField<20, 10, u64> immediate;
  78. BitField<22, 2, u64> element;
  79. BitField<24, 6, Index> index;
  80. BitField<47, 3, AttributeSize> size;
  81. bool IsPhysical() const {
  82. return element == 0 && static_cast<u64>(index.Value()) == 0;
  83. }
  84. } fmt20;
  85. union {
  86. BitField<30, 2, u64> element;
  87. BitField<32, 6, Index> index;
  88. } fmt28;
  89. BitField<39, 8, u64> reg;
  90. u64 value{};
  91. };
  92. union Sampler {
  93. Sampler() = default;
  94. constexpr explicit Sampler(u64 value) : value(value) {}
  95. enum class Index : u64 {
  96. Sampler_0 = 8,
  97. };
  98. BitField<36, 13, Index> index;
  99. u64 value{};
  100. };
  101. union Image {
  102. Image() = default;
  103. constexpr explicit Image(u64 value) : value{value} {}
  104. BitField<36, 13, u64> index;
  105. u64 value;
  106. };
  107. } // namespace Tegra::Shader
  108. namespace std {
  109. // TODO(bunnei): The below is forbidden by the C++ standard, but works fine. See #330.
  110. template <>
  111. struct make_unsigned<Tegra::Shader::Attribute> {
  112. using type = Tegra::Shader::Attribute;
  113. };
  114. template <>
  115. struct make_unsigned<Tegra::Shader::Register> {
  116. using type = Tegra::Shader::Register;
  117. };
  118. } // namespace std
  119. namespace Tegra::Shader {
  120. enum class Pred : u64 {
  121. UnusedIndex = 0x7,
  122. NeverExecute = 0xF,
  123. };
  124. enum class PredCondition : u64 {
  125. LessThan = 1,
  126. Equal = 2,
  127. LessEqual = 3,
  128. GreaterThan = 4,
  129. NotEqual = 5,
  130. GreaterEqual = 6,
  131. LessThanWithNan = 9,
  132. LessEqualWithNan = 11,
  133. GreaterThanWithNan = 12,
  134. NotEqualWithNan = 13,
  135. GreaterEqualWithNan = 14,
  136. // TODO(Subv): Other condition types
  137. };
  138. enum class PredOperation : u64 {
  139. And = 0,
  140. Or = 1,
  141. Xor = 2,
  142. };
  143. enum class LogicOperation : u64 {
  144. And = 0,
  145. Or = 1,
  146. Xor = 2,
  147. PassB = 3,
  148. };
  149. enum class SubOp : u64 {
  150. Cos = 0x0,
  151. Sin = 0x1,
  152. Ex2 = 0x2,
  153. Lg2 = 0x3,
  154. Rcp = 0x4,
  155. Rsq = 0x5,
  156. Sqrt = 0x8,
  157. };
  158. enum class F2iRoundingOp : u64 {
  159. RoundEven = 0,
  160. Floor = 1,
  161. Ceil = 2,
  162. Trunc = 3,
  163. };
  164. enum class F2fRoundingOp : u64 {
  165. None = 0,
  166. Pass = 3,
  167. Round = 8,
  168. Floor = 9,
  169. Ceil = 10,
  170. Trunc = 11,
  171. };
  172. enum class UniformType : u64 {
  173. UnsignedByte = 0,
  174. SignedByte = 1,
  175. UnsignedShort = 2,
  176. SignedShort = 3,
  177. Single = 4,
  178. Double = 5,
  179. Quad = 6,
  180. UnsignedQuad = 7,
  181. };
  182. enum class StoreType : u64 {
  183. Unsigned8 = 0,
  184. Signed8 = 1,
  185. Unsigned16 = 2,
  186. Signed16 = 3,
  187. Bits32 = 4,
  188. Bits64 = 5,
  189. Bits128 = 6,
  190. };
  191. enum class IMinMaxExchange : u64 {
  192. None = 0,
  193. XLo = 1,
  194. XMed = 2,
  195. XHi = 3,
  196. };
  197. enum class VideoType : u64 {
  198. Size16_Low = 0,
  199. Size16_High = 1,
  200. Size32 = 2,
  201. Invalid = 3,
  202. };
  203. enum class VmadShr : u64 {
  204. Shr7 = 1,
  205. Shr15 = 2,
  206. };
  207. enum class XmadMode : u64 {
  208. None = 0,
  209. CLo = 1,
  210. CHi = 2,
  211. CSfu = 3,
  212. CBcc = 4,
  213. };
  214. enum class IAdd3Mode : u64 {
  215. None = 0,
  216. RightShift = 1,
  217. LeftShift = 2,
  218. };
  219. enum class IAdd3Height : u64 {
  220. None = 0,
  221. LowerHalfWord = 1,
  222. UpperHalfWord = 2,
  223. };
  224. enum class FlowCondition : u64 {
  225. Always = 0xF,
  226. Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for?
  227. };
  228. enum class ConditionCode : u64 {
  229. F = 0,
  230. LT = 1,
  231. EQ = 2,
  232. LE = 3,
  233. GT = 4,
  234. NE = 5,
  235. GE = 6,
  236. Num = 7,
  237. Nan = 8,
  238. LTU = 9,
  239. EQU = 10,
  240. LEU = 11,
  241. GTU = 12,
  242. NEU = 13,
  243. GEU = 14,
  244. T = 15,
  245. OFF = 16,
  246. LO = 17,
  247. SFF = 18,
  248. LS = 19,
  249. HI = 20,
  250. SFT = 21,
  251. HS = 22,
  252. OFT = 23,
  253. CSM_TA = 24,
  254. CSM_TR = 25,
  255. CSM_MX = 26,
  256. FCSM_TA = 27,
  257. FCSM_TR = 28,
  258. FCSM_MX = 29,
  259. RLE = 30,
  260. RGT = 31,
  261. };
  262. enum class PredicateResultMode : u64 {
  263. None = 0x0,
  264. NotZero = 0x3,
  265. };
  266. enum class TextureType : u64 {
  267. Texture1D = 0,
  268. Texture2D = 1,
  269. Texture3D = 2,
  270. TextureCube = 3,
  271. };
  272. enum class TextureQueryType : u64 {
  273. Dimension = 1,
  274. TextureType = 2,
  275. SamplePosition = 5,
  276. Filter = 16,
  277. LevelOfDetail = 18,
  278. Wrap = 20,
  279. BorderColor = 22,
  280. };
  281. enum class TextureProcessMode : u64 {
  282. None = 0,
  283. LZ = 1, // Load LOD of zero.
  284. LB = 2, // Load Bias.
  285. LL = 3, // Load LOD.
  286. LBA = 6, // Load Bias. The A is unknown, does not appear to differ with LB.
  287. LLA = 7 // Load LOD. The A is unknown, does not appear to differ with LL.
  288. };
  289. enum class TextureMiscMode : u64 {
  290. DC,
  291. AOFFI, // Uses Offset
  292. NDV,
  293. NODEP,
  294. MZ,
  295. PTP,
  296. };
  297. enum class SurfaceDataMode : u64 {
  298. P = 0,
  299. D_BA = 1,
  300. };
  301. enum class OutOfBoundsStore : u64 {
  302. Ignore = 0,
  303. Clamp = 1,
  304. Trap = 2,
  305. };
  306. enum class ImageType : u64 {
  307. Texture1D = 0,
  308. TextureBuffer = 1,
  309. Texture1DArray = 2,
  310. Texture2D = 3,
  311. Texture2DArray = 4,
  312. Texture3D = 5,
  313. };
  314. enum class IsberdMode : u64 {
  315. None = 0,
  316. Patch = 1,
  317. Prim = 2,
  318. Attr = 3,
  319. };
  320. enum class IsberdShift : u64 { None = 0, U16 = 1, B32 = 2 };
  321. enum class HalfType : u64 {
  322. H0_H1 = 0,
  323. F32 = 1,
  324. H0_H0 = 2,
  325. H1_H1 = 3,
  326. };
  327. enum class HalfMerge : u64 {
  328. H0_H1 = 0,
  329. F32 = 1,
  330. Mrg_H0 = 2,
  331. Mrg_H1 = 3,
  332. };
  333. enum class HalfPrecision : u64 {
  334. None = 0,
  335. FTZ = 1,
  336. FMZ = 2,
  337. };
  338. enum class R2pMode : u64 {
  339. Pr = 0,
  340. Cc = 1,
  341. };
  342. enum class IpaInterpMode : u64 {
  343. Pass = 0,
  344. Multiply = 1,
  345. Constant = 2,
  346. Sc = 3,
  347. };
  348. enum class IpaSampleMode : u64 {
  349. Default = 0,
  350. Centroid = 1,
  351. Offset = 2,
  352. };
  353. enum class LmemLoadCacheManagement : u64 {
  354. Default = 0,
  355. LU = 1,
  356. CI = 2,
  357. CV = 3,
  358. };
  359. enum class StoreCacheManagement : u64 {
  360. Default = 0,
  361. CG = 1,
  362. CS = 2,
  363. WT = 3,
  364. };
  365. struct IpaMode {
  366. IpaInterpMode interpolation_mode;
  367. IpaSampleMode sampling_mode;
  368. bool operator==(const IpaMode& a) const {
  369. return std::tie(interpolation_mode, sampling_mode) ==
  370. std::tie(a.interpolation_mode, a.sampling_mode);
  371. }
  372. bool operator!=(const IpaMode& a) const {
  373. return !operator==(a);
  374. }
  375. bool operator<(const IpaMode& a) const {
  376. return std::tie(interpolation_mode, sampling_mode) <
  377. std::tie(a.interpolation_mode, a.sampling_mode);
  378. }
  379. };
  380. enum class SystemVariable : u64 {
  381. LaneId = 0x00,
  382. VirtCfg = 0x02,
  383. VirtId = 0x03,
  384. Pm0 = 0x04,
  385. Pm1 = 0x05,
  386. Pm2 = 0x06,
  387. Pm3 = 0x07,
  388. Pm4 = 0x08,
  389. Pm5 = 0x09,
  390. Pm6 = 0x0a,
  391. Pm7 = 0x0b,
  392. OrderingTicket = 0x0f,
  393. PrimType = 0x10,
  394. InvocationId = 0x11,
  395. Ydirection = 0x12,
  396. ThreadKill = 0x13,
  397. ShaderType = 0x14,
  398. DirectBeWriteAddressLow = 0x15,
  399. DirectBeWriteAddressHigh = 0x16,
  400. DirectBeWriteEnabled = 0x17,
  401. MachineId0 = 0x18,
  402. MachineId1 = 0x19,
  403. MachineId2 = 0x1a,
  404. MachineId3 = 0x1b,
  405. Affinity = 0x1c,
  406. InvocationInfo = 0x1d,
  407. WscaleFactorXY = 0x1e,
  408. WscaleFactorZ = 0x1f,
  409. Tid = 0x20,
  410. TidX = 0x21,
  411. TidY = 0x22,
  412. TidZ = 0x23,
  413. CtaParam = 0x24,
  414. CtaIdX = 0x25,
  415. CtaIdY = 0x26,
  416. CtaIdZ = 0x27,
  417. NtId = 0x28,
  418. CirQueueIncrMinusOne = 0x29,
  419. Nlatc = 0x2a,
  420. SmSpaVersion = 0x2c,
  421. MultiPassShaderInfo = 0x2d,
  422. LwinHi = 0x2e,
  423. SwinHi = 0x2f,
  424. SwinLo = 0x30,
  425. SwinSz = 0x31,
  426. SmemSz = 0x32,
  427. SmemBanks = 0x33,
  428. LwinLo = 0x34,
  429. LwinSz = 0x35,
  430. LmemLosz = 0x36,
  431. LmemHioff = 0x37,
  432. EqMask = 0x38,
  433. LtMask = 0x39,
  434. LeMask = 0x3a,
  435. GtMask = 0x3b,
  436. GeMask = 0x3c,
  437. RegAlloc = 0x3d,
  438. CtxAddr = 0x3e, // .fmask = F_SM50
  439. BarrierAlloc = 0x3e, // .fmask = F_SM60
  440. GlobalErrorStatus = 0x40,
  441. WarpErrorStatus = 0x42,
  442. WarpErrorStatusClear = 0x43,
  443. PmHi0 = 0x48,
  444. PmHi1 = 0x49,
  445. PmHi2 = 0x4a,
  446. PmHi3 = 0x4b,
  447. PmHi4 = 0x4c,
  448. PmHi5 = 0x4d,
  449. PmHi6 = 0x4e,
  450. PmHi7 = 0x4f,
  451. ClockLo = 0x50,
  452. ClockHi = 0x51,
  453. GlobalTimerLo = 0x52,
  454. GlobalTimerHi = 0x53,
  455. HwTaskId = 0x60,
  456. CircularQueueEntryIndex = 0x61,
  457. CircularQueueEntryAddressLow = 0x62,
  458. CircularQueueEntryAddressHigh = 0x63,
  459. };
  460. enum class PhysicalAttributeDirection : u64 {
  461. Input = 0,
  462. Output = 1,
  463. };
  464. enum class VoteOperation : u64 {
  465. All = 0, // allThreadsNV
  466. Any = 1, // anyThreadNV
  467. Eq = 2, // allThreadsEqualNV
  468. };
  469. enum class ImageAtomicOperationType : u64 {
  470. U32 = 0,
  471. S32 = 1,
  472. U64 = 2,
  473. F32 = 3,
  474. S64 = 5,
  475. SD32 = 6,
  476. SD64 = 7,
  477. };
  478. enum class ImageAtomicOperation : u64 {
  479. Add = 0,
  480. Min = 1,
  481. Max = 2,
  482. Inc = 3,
  483. Dec = 4,
  484. And = 5,
  485. Or = 6,
  486. Xor = 7,
  487. Exch = 8,
  488. };
  489. enum class ShuffleOperation : u64 {
  490. Idx = 0, // shuffleNV
  491. Up = 1, // shuffleUpNV
  492. Down = 2, // shuffleDownNV
  493. Bfly = 3, // shuffleXorNV
  494. };
  495. union Instruction {
  496. constexpr Instruction& operator=(const Instruction& instr) {
  497. value = instr.value;
  498. return *this;
  499. }
  500. constexpr Instruction(u64 value) : value{value} {}
  501. BitField<0, 8, Register> gpr0;
  502. BitField<8, 8, Register> gpr8;
  503. union {
  504. BitField<16, 4, Pred> full_pred;
  505. BitField<16, 3, u64> pred_index;
  506. } pred;
  507. BitField<19, 1, u64> negate_pred;
  508. BitField<20, 8, Register> gpr20;
  509. BitField<20, 4, SubOp> sub_op;
  510. BitField<28, 8, Register> gpr28;
  511. BitField<39, 8, Register> gpr39;
  512. BitField<48, 16, u64> opcode;
  513. union {
  514. BitField<8, 5, ConditionCode> cc;
  515. BitField<13, 1, u64> trigger;
  516. } nop;
  517. union {
  518. BitField<48, 2, VoteOperation> operation;
  519. BitField<45, 3, u64> dest_pred;
  520. BitField<39, 3, u64> value;
  521. BitField<42, 1, u64> negate_value;
  522. } vote;
  523. union {
  524. BitField<30, 2, ShuffleOperation> operation;
  525. BitField<48, 3, u64> pred48;
  526. BitField<28, 1, u64> is_index_imm;
  527. BitField<29, 1, u64> is_mask_imm;
  528. BitField<20, 5, u64> index_imm;
  529. BitField<34, 13, u64> mask_imm;
  530. } shfl;
  531. union {
  532. BitField<44, 1, u64> ftz;
  533. BitField<39, 2, u64> tab5cb8_2;
  534. BitField<38, 1, u64> ndv;
  535. BitField<47, 1, u64> cc;
  536. BitField<28, 8, u64> swizzle;
  537. } fswzadd;
  538. union {
  539. BitField<8, 8, Register> gpr;
  540. BitField<20, 24, s64> offset;
  541. } gmem;
  542. union {
  543. BitField<20, 16, u64> imm20_16;
  544. BitField<20, 19, u64> imm20_19;
  545. BitField<20, 32, s64> imm20_32;
  546. BitField<45, 1, u64> negate_b;
  547. BitField<46, 1, u64> abs_a;
  548. BitField<48, 1, u64> negate_a;
  549. BitField<49, 1, u64> abs_b;
  550. BitField<50, 1, u64> saturate_d;
  551. BitField<56, 1, u64> negate_imm;
  552. union {
  553. BitField<39, 3, u64> pred;
  554. BitField<42, 1, u64> negate_pred;
  555. } fmnmx;
  556. union {
  557. BitField<39, 1, u64> invert_a;
  558. BitField<40, 1, u64> invert_b;
  559. BitField<41, 2, LogicOperation> operation;
  560. BitField<44, 2, PredicateResultMode> pred_result_mode;
  561. BitField<48, 3, Pred> pred48;
  562. } lop;
  563. union {
  564. BitField<53, 2, LogicOperation> operation;
  565. BitField<55, 1, u64> invert_a;
  566. BitField<56, 1, u64> invert_b;
  567. } lop32i;
  568. union {
  569. BitField<28, 8, u64> imm_lut28;
  570. BitField<48, 8, u64> imm_lut48;
  571. u32 GetImmLut28() const {
  572. return static_cast<u32>(imm_lut28);
  573. }
  574. u32 GetImmLut48() const {
  575. return static_cast<u32>(imm_lut48);
  576. }
  577. } lop3;
  578. u16 GetImm20_16() const {
  579. return static_cast<u16>(imm20_16);
  580. }
  581. u32 GetImm20_19() const {
  582. u32 imm{static_cast<u32>(imm20_19)};
  583. imm <<= 12;
  584. imm |= negate_imm ? 0x80000000 : 0;
  585. return imm;
  586. }
  587. u32 GetImm20_32() const {
  588. return static_cast<u32>(imm20_32);
  589. }
  590. s32 GetSignedImm20_20() const {
  591. u32 immediate = static_cast<u32>(imm20_19 | (negate_imm << 19));
  592. // Sign extend the 20-bit value.
  593. u32 mask = 1U << (20 - 1);
  594. return static_cast<s32>((immediate ^ mask) - mask);
  595. }
  596. } alu;
  597. union {
  598. BitField<38, 1, u64> idx;
  599. BitField<51, 1, u64> saturate;
  600. BitField<52, 2, IpaSampleMode> sample_mode;
  601. BitField<54, 2, IpaInterpMode> interp_mode;
  602. } ipa;
  603. union {
  604. BitField<39, 2, u64> tab5cb8_2;
  605. BitField<41, 3, u64> postfactor;
  606. BitField<44, 2, u64> tab5c68_0;
  607. BitField<48, 1, u64> negate_b;
  608. } fmul;
  609. union {
  610. BitField<55, 1, u64> saturate;
  611. } fmul32;
  612. union {
  613. BitField<52, 1, u64> generates_cc;
  614. } op_32;
  615. union {
  616. BitField<48, 1, u64> is_signed;
  617. } shift;
  618. union {
  619. BitField<39, 1, u64> wrap;
  620. } shr;
  621. union {
  622. BitField<39, 5, u64> shift_amount;
  623. BitField<48, 1, u64> negate_b;
  624. BitField<49, 1, u64> negate_a;
  625. } alu_integer;
  626. union {
  627. BitField<39, 1, u64> ftz;
  628. BitField<32, 1, u64> saturate;
  629. BitField<49, 2, HalfMerge> merge;
  630. BitField<43, 1, u64> negate_a;
  631. BitField<44, 1, u64> abs_a;
  632. BitField<47, 2, HalfType> type_a;
  633. BitField<31, 1, u64> negate_b;
  634. BitField<30, 1, u64> abs_b;
  635. BitField<28, 2, HalfType> type_b;
  636. BitField<35, 2, HalfType> type_c;
  637. } alu_half;
  638. union {
  639. BitField<39, 2, HalfPrecision> precision;
  640. BitField<39, 1, u64> ftz;
  641. BitField<52, 1, u64> saturate;
  642. BitField<49, 2, HalfMerge> merge;
  643. BitField<43, 1, u64> negate_a;
  644. BitField<44, 1, u64> abs_a;
  645. BitField<47, 2, HalfType> type_a;
  646. } alu_half_imm;
  647. union {
  648. BitField<29, 1, u64> first_negate;
  649. BitField<20, 9, u64> first;
  650. BitField<56, 1, u64> second_negate;
  651. BitField<30, 9, u64> second;
  652. u32 PackImmediates() const {
  653. // Immediates are half floats shifted.
  654. constexpr u32 imm_shift = 6;
  655. return static_cast<u32>((first << imm_shift) | (second << (16 + imm_shift)));
  656. }
  657. } half_imm;
  658. union {
  659. union {
  660. BitField<37, 2, HalfPrecision> precision;
  661. BitField<32, 1, u64> saturate;
  662. BitField<31, 1, u64> negate_b;
  663. BitField<30, 1, u64> negate_c;
  664. BitField<35, 2, HalfType> type_c;
  665. } rr;
  666. BitField<57, 2, HalfPrecision> precision;
  667. BitField<52, 1, u64> saturate;
  668. BitField<49, 2, HalfMerge> merge;
  669. BitField<47, 2, HalfType> type_a;
  670. BitField<56, 1, u64> negate_b;
  671. BitField<28, 2, HalfType> type_b;
  672. BitField<51, 1, u64> negate_c;
  673. BitField<53, 2, HalfType> type_reg39;
  674. } hfma2;
  675. union {
  676. BitField<40, 1, u64> invert;
  677. } popc;
  678. union {
  679. BitField<39, 3, u64> pred;
  680. BitField<42, 1, u64> neg_pred;
  681. } sel;
  682. union {
  683. BitField<39, 3, u64> pred;
  684. BitField<42, 1, u64> negate_pred;
  685. BitField<43, 2, IMinMaxExchange> exchange;
  686. BitField<48, 1, u64> is_signed;
  687. } imnmx;
  688. union {
  689. BitField<31, 2, IAdd3Height> height_c;
  690. BitField<33, 2, IAdd3Height> height_b;
  691. BitField<35, 2, IAdd3Height> height_a;
  692. BitField<37, 2, IAdd3Mode> mode;
  693. BitField<49, 1, u64> neg_c;
  694. BitField<50, 1, u64> neg_b;
  695. BitField<51, 1, u64> neg_a;
  696. } iadd3;
  697. union {
  698. BitField<54, 1, u64> saturate;
  699. BitField<56, 1, u64> negate_a;
  700. } iadd32i;
  701. union {
  702. BitField<53, 1, u64> negate_b;
  703. BitField<54, 1, u64> abs_a;
  704. BitField<56, 1, u64> negate_a;
  705. BitField<57, 1, u64> abs_b;
  706. } fadd32i;
  707. union {
  708. BitField<20, 8, u64> shift_position;
  709. BitField<28, 8, u64> shift_length;
  710. BitField<48, 1, u64> negate_b;
  711. BitField<49, 1, u64> negate_a;
  712. u64 GetLeftShiftValue() const {
  713. return 32 - (shift_position + shift_length);
  714. }
  715. } bfe;
  716. union {
  717. BitField<48, 3, u64> pred48;
  718. union {
  719. BitField<20, 20, u64> entry_a;
  720. BitField<39, 5, u64> entry_b;
  721. BitField<45, 1, u64> neg;
  722. BitField<46, 1, u64> uses_cc;
  723. } imm;
  724. union {
  725. BitField<20, 14, u64> cb_index;
  726. BitField<34, 5, u64> cb_offset;
  727. BitField<56, 1, u64> neg;
  728. BitField<57, 1, u64> uses_cc;
  729. } hi;
  730. union {
  731. BitField<20, 14, u64> cb_index;
  732. BitField<34, 5, u64> cb_offset;
  733. BitField<39, 5, u64> entry_a;
  734. BitField<45, 1, u64> neg;
  735. BitField<46, 1, u64> uses_cc;
  736. } rz;
  737. union {
  738. BitField<39, 5, u64> entry_a;
  739. BitField<45, 1, u64> neg;
  740. BitField<46, 1, u64> uses_cc;
  741. } r1;
  742. union {
  743. BitField<28, 8, u64> entry_a;
  744. BitField<37, 1, u64> neg;
  745. BitField<38, 1, u64> uses_cc;
  746. } r2;
  747. } lea;
  748. union {
  749. BitField<0, 5, FlowCondition> cond;
  750. } flow;
  751. union {
  752. BitField<47, 1, u64> cc;
  753. BitField<48, 1, u64> negate_b;
  754. BitField<49, 1, u64> negate_c;
  755. BitField<51, 2, u64> tab5980_1;
  756. BitField<53, 2, u64> tab5980_0;
  757. } ffma;
  758. union {
  759. BitField<48, 3, UniformType> type;
  760. BitField<44, 2, u64> unknown;
  761. } ld_c;
  762. union {
  763. BitField<48, 3, StoreType> type;
  764. } ldst_sl;
  765. union {
  766. BitField<44, 2, u64> unknown;
  767. } ld_l;
  768. union {
  769. BitField<44, 2, StoreCacheManagement> cache_management;
  770. } st_l;
  771. union {
  772. BitField<48, 3, UniformType> type;
  773. BitField<46, 2, u64> cache_mode;
  774. } ldg;
  775. union {
  776. BitField<48, 3, UniformType> type;
  777. BitField<46, 2, u64> cache_mode;
  778. } stg;
  779. union {
  780. BitField<32, 1, PhysicalAttributeDirection> direction;
  781. BitField<47, 3, AttributeSize> size;
  782. BitField<20, 11, u64> address;
  783. } al2p;
  784. union {
  785. BitField<53, 3, UniformType> type;
  786. BitField<52, 1, u64> extended;
  787. } generic;
  788. union {
  789. BitField<0, 3, u64> pred0;
  790. BitField<3, 3, u64> pred3;
  791. BitField<6, 1, u64> neg_b;
  792. BitField<7, 1, u64> abs_a;
  793. BitField<39, 3, u64> pred39;
  794. BitField<42, 1, u64> neg_pred;
  795. BitField<43, 1, u64> neg_a;
  796. BitField<44, 1, u64> abs_b;
  797. BitField<45, 2, PredOperation> op;
  798. BitField<47, 1, u64> ftz;
  799. BitField<48, 4, PredCondition> cond;
  800. } fsetp;
  801. union {
  802. BitField<0, 3, u64> pred0;
  803. BitField<3, 3, u64> pred3;
  804. BitField<39, 3, u64> pred39;
  805. BitField<42, 1, u64> neg_pred;
  806. BitField<45, 2, PredOperation> op;
  807. BitField<48, 1, u64> is_signed;
  808. BitField<49, 3, PredCondition> cond;
  809. } isetp;
  810. union {
  811. BitField<48, 1, u64> is_signed;
  812. BitField<49, 3, PredCondition> cond;
  813. } icmp;
  814. union {
  815. BitField<0, 3, u64> pred0;
  816. BitField<3, 3, u64> pred3;
  817. BitField<12, 3, u64> pred12;
  818. BitField<15, 1, u64> neg_pred12;
  819. BitField<24, 2, PredOperation> cond;
  820. BitField<29, 3, u64> pred29;
  821. BitField<32, 1, u64> neg_pred29;
  822. BitField<39, 3, u64> pred39;
  823. BitField<42, 1, u64> neg_pred39;
  824. BitField<45, 2, PredOperation> op;
  825. } psetp;
  826. union {
  827. BitField<43, 4, PredCondition> cond;
  828. BitField<45, 2, PredOperation> op;
  829. BitField<3, 3, u64> pred3;
  830. BitField<0, 3, u64> pred0;
  831. BitField<39, 3, u64> pred39;
  832. } vsetp;
  833. union {
  834. BitField<12, 3, u64> pred12;
  835. BitField<15, 1, u64> neg_pred12;
  836. BitField<24, 2, PredOperation> cond;
  837. BitField<29, 3, u64> pred29;
  838. BitField<32, 1, u64> neg_pred29;
  839. BitField<39, 3, u64> pred39;
  840. BitField<42, 1, u64> neg_pred39;
  841. BitField<44, 1, u64> bf;
  842. BitField<45, 2, PredOperation> op;
  843. } pset;
  844. union {
  845. BitField<0, 3, u64> pred0;
  846. BitField<3, 3, u64> pred3;
  847. BitField<8, 5, ConditionCode> cc; // flag in cc
  848. BitField<39, 3, u64> pred39;
  849. BitField<42, 1, u64> neg_pred39;
  850. BitField<45, 4, PredOperation> op; // op with pred39
  851. } csetp;
  852. union {
  853. BitField<6, 1, u64> ftz;
  854. BitField<45, 2, PredOperation> op;
  855. BitField<3, 3, u64> pred3;
  856. BitField<0, 3, u64> pred0;
  857. BitField<43, 1, u64> negate_a;
  858. BitField<44, 1, u64> abs_a;
  859. BitField<47, 2, HalfType> type_a;
  860. union {
  861. BitField<35, 4, PredCondition> cond;
  862. BitField<49, 1, u64> h_and;
  863. BitField<31, 1, u64> negate_b;
  864. BitField<30, 1, u64> abs_b;
  865. BitField<28, 2, HalfType> type_b;
  866. } reg;
  867. union {
  868. BitField<56, 1, u64> negate_b;
  869. BitField<54, 1, u64> abs_b;
  870. } cbuf;
  871. union {
  872. BitField<49, 4, PredCondition> cond;
  873. BitField<53, 1, u64> h_and;
  874. } cbuf_and_imm;
  875. BitField<42, 1, u64> neg_pred;
  876. BitField<39, 3, u64> pred39;
  877. } hsetp2;
  878. union {
  879. BitField<40, 1, R2pMode> mode;
  880. BitField<41, 2, u64> byte;
  881. BitField<20, 7, u64> immediate_mask;
  882. } r2p;
  883. union {
  884. BitField<39, 3, u64> pred39;
  885. BitField<42, 1, u64> neg_pred;
  886. BitField<43, 1, u64> neg_a;
  887. BitField<44, 1, u64> abs_b;
  888. BitField<45, 2, PredOperation> op;
  889. BitField<48, 4, PredCondition> cond;
  890. BitField<52, 1, u64> bf;
  891. BitField<53, 1, u64> neg_b;
  892. BitField<54, 1, u64> abs_a;
  893. BitField<55, 1, u64> ftz;
  894. } fset;
  895. union {
  896. BitField<49, 1, u64> bf;
  897. BitField<35, 3, PredCondition> cond;
  898. BitField<50, 1, u64> ftz;
  899. BitField<45, 2, PredOperation> op;
  900. BitField<43, 1, u64> negate_a;
  901. BitField<44, 1, u64> abs_a;
  902. BitField<47, 2, HalfType> type_a;
  903. BitField<31, 1, u64> negate_b;
  904. BitField<30, 1, u64> abs_b;
  905. BitField<28, 2, HalfType> type_b;
  906. BitField<42, 1, u64> neg_pred;
  907. BitField<39, 3, u64> pred39;
  908. } hset2;
  909. union {
  910. BitField<39, 3, u64> pred39;
  911. BitField<42, 1, u64> neg_pred;
  912. BitField<44, 1, u64> bf;
  913. BitField<45, 2, PredOperation> op;
  914. BitField<48, 1, u64> is_signed;
  915. BitField<49, 3, PredCondition> cond;
  916. } iset;
  917. union {
  918. BitField<45, 1, u64> negate_a;
  919. BitField<49, 1, u64> abs_a;
  920. BitField<10, 2, Register::Size> src_size;
  921. BitField<13, 1, u64> is_input_signed;
  922. BitField<8, 2, Register::Size> dst_size;
  923. BitField<12, 1, u64> is_output_signed;
  924. union {
  925. BitField<39, 2, u64> tab5cb8_2;
  926. } i2f;
  927. union {
  928. BitField<39, 2, F2iRoundingOp> rounding;
  929. } f2i;
  930. union {
  931. BitField<39, 4, u64> rounding;
  932. // H0, H1 extract for F16 missing
  933. BitField<41, 1, u64> selector; // Guessed as some games set it, TODO: reverse this value
  934. F2fRoundingOp GetRoundingMode() const {
  935. constexpr u64 rounding_mask = 0x0B;
  936. return static_cast<F2fRoundingOp>(rounding.Value() & rounding_mask);
  937. }
  938. } f2f;
  939. union {
  940. BitField<41, 2, u64> selector;
  941. } int_src;
  942. union {
  943. BitField<41, 1, u64> selector;
  944. } float_src;
  945. } conversion;
  946. union {
  947. BitField<28, 1, u64> array;
  948. BitField<29, 2, TextureType> texture_type;
  949. BitField<31, 4, u64> component_mask;
  950. BitField<49, 1, u64> nodep_flag;
  951. BitField<50, 1, u64> dc_flag;
  952. BitField<54, 1, u64> aoffi_flag;
  953. BitField<55, 3, TextureProcessMode> process_mode;
  954. bool IsComponentEnabled(std::size_t component) const {
  955. return ((1ull << component) & component_mask) != 0;
  956. }
  957. TextureProcessMode GetTextureProcessMode() const {
  958. return process_mode;
  959. }
  960. bool UsesMiscMode(TextureMiscMode mode) const {
  961. switch (mode) {
  962. case TextureMiscMode::DC:
  963. return dc_flag != 0;
  964. case TextureMiscMode::NODEP:
  965. return nodep_flag != 0;
  966. case TextureMiscMode::AOFFI:
  967. return aoffi_flag != 0;
  968. default:
  969. break;
  970. }
  971. return false;
  972. }
  973. } tex;
  974. union {
  975. BitField<28, 1, u64> array;
  976. BitField<29, 2, TextureType> texture_type;
  977. BitField<31, 4, u64> component_mask;
  978. BitField<49, 1, u64> nodep_flag;
  979. BitField<50, 1, u64> dc_flag;
  980. BitField<36, 1, u64> aoffi_flag;
  981. BitField<37, 3, TextureProcessMode> process_mode;
  982. bool IsComponentEnabled(std::size_t component) const {
  983. return ((1ULL << component) & component_mask) != 0;
  984. }
  985. TextureProcessMode GetTextureProcessMode() const {
  986. return process_mode;
  987. }
  988. bool UsesMiscMode(TextureMiscMode mode) const {
  989. switch (mode) {
  990. case TextureMiscMode::DC:
  991. return dc_flag != 0;
  992. case TextureMiscMode::NODEP:
  993. return nodep_flag != 0;
  994. case TextureMiscMode::AOFFI:
  995. return aoffi_flag != 0;
  996. default:
  997. break;
  998. }
  999. return false;
  1000. }
  1001. } tex_b;
  1002. union {
  1003. BitField<22, 6, TextureQueryType> query_type;
  1004. BitField<31, 4, u64> component_mask;
  1005. BitField<49, 1, u64> nodep_flag;
  1006. bool UsesMiscMode(TextureMiscMode mode) const {
  1007. switch (mode) {
  1008. case TextureMiscMode::NODEP:
  1009. return nodep_flag != 0;
  1010. default:
  1011. break;
  1012. }
  1013. return false;
  1014. }
  1015. bool IsComponentEnabled(std::size_t component) const {
  1016. return ((1ULL << component) & component_mask) != 0;
  1017. }
  1018. } txq;
  1019. union {
  1020. BitField<28, 1, u64> array;
  1021. BitField<29, 2, TextureType> texture_type;
  1022. BitField<31, 4, u64> component_mask;
  1023. BitField<35, 1, u64> ndv_flag;
  1024. BitField<49, 1, u64> nodep_flag;
  1025. bool IsComponentEnabled(std::size_t component) const {
  1026. return ((1ull << component) & component_mask) != 0;
  1027. }
  1028. bool UsesMiscMode(TextureMiscMode mode) const {
  1029. switch (mode) {
  1030. case TextureMiscMode::NDV:
  1031. return (ndv_flag != 0);
  1032. case TextureMiscMode::NODEP:
  1033. return (nodep_flag != 0);
  1034. default:
  1035. break;
  1036. }
  1037. return false;
  1038. }
  1039. } tmml;
  1040. union {
  1041. BitField<28, 1, u64> array;
  1042. BitField<29, 2, TextureType> texture_type;
  1043. BitField<35, 1, u64> ndv_flag;
  1044. BitField<49, 1, u64> nodep_flag;
  1045. BitField<50, 1, u64> dc_flag;
  1046. BitField<54, 2, u64> info;
  1047. BitField<56, 2, u64> component;
  1048. bool UsesMiscMode(TextureMiscMode mode) const {
  1049. switch (mode) {
  1050. case TextureMiscMode::NDV:
  1051. return ndv_flag != 0;
  1052. case TextureMiscMode::NODEP:
  1053. return nodep_flag != 0;
  1054. case TextureMiscMode::DC:
  1055. return dc_flag != 0;
  1056. case TextureMiscMode::AOFFI:
  1057. return info == 1;
  1058. case TextureMiscMode::PTP:
  1059. return info == 2;
  1060. default:
  1061. break;
  1062. }
  1063. return false;
  1064. }
  1065. } tld4;
  1066. union {
  1067. BitField<35, 1, u64> ndv_flag;
  1068. BitField<49, 1, u64> nodep_flag;
  1069. BitField<50, 1, u64> dc_flag;
  1070. BitField<33, 2, u64> info;
  1071. BitField<37, 2, u64> component;
  1072. bool UsesMiscMode(TextureMiscMode mode) const {
  1073. switch (mode) {
  1074. case TextureMiscMode::NDV:
  1075. return ndv_flag != 0;
  1076. case TextureMiscMode::NODEP:
  1077. return nodep_flag != 0;
  1078. case TextureMiscMode::DC:
  1079. return dc_flag != 0;
  1080. case TextureMiscMode::AOFFI:
  1081. return info == 1;
  1082. case TextureMiscMode::PTP:
  1083. return info == 2;
  1084. default:
  1085. break;
  1086. }
  1087. return false;
  1088. }
  1089. } tld4_b;
  1090. union {
  1091. BitField<49, 1, u64> nodep_flag;
  1092. BitField<50, 1, u64> dc_flag;
  1093. BitField<51, 1, u64> aoffi_flag;
  1094. BitField<52, 2, u64> component;
  1095. bool UsesMiscMode(TextureMiscMode mode) const {
  1096. switch (mode) {
  1097. case TextureMiscMode::DC:
  1098. return dc_flag != 0;
  1099. case TextureMiscMode::NODEP:
  1100. return nodep_flag != 0;
  1101. case TextureMiscMode::AOFFI:
  1102. return aoffi_flag != 0;
  1103. default:
  1104. break;
  1105. }
  1106. return false;
  1107. }
  1108. } tld4s;
  1109. union {
  1110. BitField<0, 8, Register> gpr0;
  1111. BitField<28, 8, Register> gpr28;
  1112. BitField<49, 1, u64> nodep_flag;
  1113. BitField<50, 3, u64> component_mask_selector;
  1114. BitField<53, 4, u64> texture_info;
  1115. BitField<59, 1, u64> fp32_flag;
  1116. TextureType GetTextureType() const {
  1117. // The TEXS instruction has a weird encoding for the texture type.
  1118. if (texture_info == 0)
  1119. return TextureType::Texture1D;
  1120. if (texture_info >= 1 && texture_info <= 9)
  1121. return TextureType::Texture2D;
  1122. if (texture_info >= 10 && texture_info <= 11)
  1123. return TextureType::Texture3D;
  1124. if (texture_info >= 12 && texture_info <= 13)
  1125. return TextureType::TextureCube;
  1126. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  1127. static_cast<u32>(texture_info.Value()));
  1128. UNREACHABLE();
  1129. return TextureType::Texture1D;
  1130. }
  1131. TextureProcessMode GetTextureProcessMode() const {
  1132. switch (texture_info) {
  1133. case 0:
  1134. case 2:
  1135. case 6:
  1136. case 8:
  1137. case 9:
  1138. case 11:
  1139. return TextureProcessMode::LZ;
  1140. case 3:
  1141. case 5:
  1142. case 13:
  1143. return TextureProcessMode::LL;
  1144. default:
  1145. break;
  1146. }
  1147. return TextureProcessMode::None;
  1148. }
  1149. bool UsesMiscMode(TextureMiscMode mode) const {
  1150. switch (mode) {
  1151. case TextureMiscMode::DC:
  1152. return (texture_info >= 4 && texture_info <= 6) || texture_info == 9;
  1153. case TextureMiscMode::NODEP:
  1154. return nodep_flag != 0;
  1155. default:
  1156. break;
  1157. }
  1158. return false;
  1159. }
  1160. bool IsArrayTexture() const {
  1161. // TEXS only supports Texture2D arrays.
  1162. return texture_info >= 7 && texture_info <= 9;
  1163. }
  1164. bool HasTwoDestinations() const {
  1165. return gpr28.Value() != Register::ZeroIndex;
  1166. }
  1167. bool IsComponentEnabled(std::size_t component) const {
  1168. static constexpr std::array<std::array<u32, 8>, 4> mask_lut{{
  1169. {},
  1170. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  1171. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  1172. {0x7, 0xb, 0xd, 0xe, 0xf},
  1173. }};
  1174. std::size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
  1175. index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
  1176. u32 mask = mask_lut[index][component_mask_selector];
  1177. // A mask of 0 means this instruction uses an unimplemented mask.
  1178. ASSERT(mask != 0);
  1179. return ((1ull << component) & mask) != 0;
  1180. }
  1181. } texs;
  1182. union {
  1183. BitField<28, 1, u64> is_array;
  1184. BitField<29, 2, TextureType> texture_type;
  1185. BitField<35, 1, u64> aoffi;
  1186. BitField<49, 1, u64> nodep_flag;
  1187. BitField<50, 1, u64> ms; // Multisample?
  1188. BitField<54, 1, u64> cl;
  1189. BitField<55, 1, u64> process_mode;
  1190. TextureProcessMode GetTextureProcessMode() const {
  1191. return process_mode == 0 ? TextureProcessMode::LZ : TextureProcessMode::LL;
  1192. }
  1193. } tld;
  1194. union {
  1195. BitField<49, 1, u64> nodep_flag;
  1196. BitField<53, 4, u64> texture_info;
  1197. BitField<59, 1, u64> fp32_flag;
  1198. TextureType GetTextureType() const {
  1199. // The TLDS instruction has a weird encoding for the texture type.
  1200. if (texture_info >= 0 && texture_info <= 1) {
  1201. return TextureType::Texture1D;
  1202. }
  1203. if (texture_info == 2 || texture_info == 8 || texture_info == 12 ||
  1204. (texture_info >= 4 && texture_info <= 6)) {
  1205. return TextureType::Texture2D;
  1206. }
  1207. if (texture_info == 7) {
  1208. return TextureType::Texture3D;
  1209. }
  1210. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  1211. static_cast<u32>(texture_info.Value()));
  1212. UNREACHABLE();
  1213. return TextureType::Texture1D;
  1214. }
  1215. TextureProcessMode GetTextureProcessMode() const {
  1216. if (texture_info == 1 || texture_info == 5 || texture_info == 12)
  1217. return TextureProcessMode::LL;
  1218. return TextureProcessMode::LZ;
  1219. }
  1220. bool UsesMiscMode(TextureMiscMode mode) const {
  1221. switch (mode) {
  1222. case TextureMiscMode::AOFFI:
  1223. return texture_info == 12 || texture_info == 4;
  1224. case TextureMiscMode::MZ:
  1225. return texture_info == 5;
  1226. case TextureMiscMode::NODEP:
  1227. return nodep_flag != 0;
  1228. default:
  1229. break;
  1230. }
  1231. return false;
  1232. }
  1233. bool IsArrayTexture() const {
  1234. // TEXS only supports Texture2D arrays.
  1235. return texture_info == 8;
  1236. }
  1237. } tlds;
  1238. union {
  1239. BitField<24, 2, StoreCacheManagement> cache_management;
  1240. BitField<33, 3, ImageType> image_type;
  1241. BitField<49, 2, OutOfBoundsStore> out_of_bounds_store;
  1242. BitField<51, 1, u64> is_immediate;
  1243. BitField<52, 1, SurfaceDataMode> mode;
  1244. BitField<20, 3, StoreType> store_data_layout;
  1245. BitField<20, 4, u64> component_mask_selector;
  1246. bool IsComponentEnabled(std::size_t component) const {
  1247. ASSERT(mode == SurfaceDataMode::P);
  1248. constexpr u8 R = 0b0001;
  1249. constexpr u8 G = 0b0010;
  1250. constexpr u8 B = 0b0100;
  1251. constexpr u8 A = 0b1000;
  1252. constexpr std::array<u8, 16> mask = {
  1253. 0, (R), (G), (R | G), (B), (R | B),
  1254. (G | B), (R | G | B), (A), (R | A), (G | A), (R | G | A),
  1255. (B | A), (R | B | A), (G | B | A), (R | G | B | A)};
  1256. return std::bitset<4>{mask.at(component_mask_selector)}.test(component);
  1257. }
  1258. StoreType GetStoreDataLayout() const {
  1259. ASSERT(mode == SurfaceDataMode::D_BA);
  1260. return store_data_layout;
  1261. }
  1262. } suldst;
  1263. union {
  1264. BitField<28, 1, u64> is_ba;
  1265. BitField<51, 3, ImageAtomicOperationType> operation_type;
  1266. BitField<33, 3, ImageType> image_type;
  1267. BitField<29, 4, ImageAtomicOperation> operation;
  1268. BitField<49, 2, OutOfBoundsStore> out_of_bounds_store;
  1269. } suatom_d;
  1270. union {
  1271. BitField<20, 24, u64> target;
  1272. BitField<5, 1, u64> constant_buffer;
  1273. s32 GetBranchTarget() const {
  1274. // Sign extend the branch target offset
  1275. u32 mask = 1U << (24 - 1);
  1276. u32 value = static_cast<u32>(target);
  1277. // The branch offset is relative to the next instruction and is stored in bytes, so
  1278. // divide it by the size of an instruction and add 1 to it.
  1279. return static_cast<s32>((value ^ mask) - mask) / static_cast<s32>(sizeof(Instruction)) +
  1280. 1;
  1281. }
  1282. } bra;
  1283. union {
  1284. BitField<20, 24, u64> target;
  1285. BitField<5, 1, u64> constant_buffer;
  1286. s32 GetBranchExtend() const {
  1287. // Sign extend the branch target offset
  1288. u32 mask = 1U << (24 - 1);
  1289. u32 value = static_cast<u32>(target);
  1290. // The branch offset is relative to the next instruction and is stored in bytes, so
  1291. // divide it by the size of an instruction and add 1 to it.
  1292. return static_cast<s32>((value ^ mask) - mask) / static_cast<s32>(sizeof(Instruction)) +
  1293. 1;
  1294. }
  1295. } brx;
  1296. union {
  1297. BitField<39, 1, u64> emit; // EmitVertex
  1298. BitField<40, 1, u64> cut; // EndPrimitive
  1299. } out;
  1300. union {
  1301. BitField<31, 1, u64> skew;
  1302. BitField<32, 1, u64> o;
  1303. BitField<33, 2, IsberdMode> mode;
  1304. BitField<47, 2, IsberdShift> shift;
  1305. } isberd;
  1306. union {
  1307. BitField<48, 1, u64> signed_a;
  1308. BitField<38, 1, u64> is_byte_chunk_a;
  1309. BitField<36, 2, VideoType> type_a;
  1310. BitField<36, 2, u64> byte_height_a;
  1311. BitField<49, 1, u64> signed_b;
  1312. BitField<50, 1, u64> use_register_b;
  1313. BitField<30, 1, u64> is_byte_chunk_b;
  1314. BitField<28, 2, VideoType> type_b;
  1315. BitField<28, 2, u64> byte_height_b;
  1316. } video;
  1317. union {
  1318. BitField<51, 2, VmadShr> shr;
  1319. BitField<55, 1, u64> saturate; // Saturates the result (a * b + c)
  1320. BitField<47, 1, u64> cc;
  1321. } vmad;
  1322. union {
  1323. BitField<20, 16, u64> imm20_16;
  1324. BitField<35, 1, u64> high_b_rr; // used on RR
  1325. BitField<36, 1, u64> product_shift_left;
  1326. BitField<37, 1, u64> merge_37;
  1327. BitField<48, 1, u64> sign_a;
  1328. BitField<49, 1, u64> sign_b;
  1329. BitField<50, 2, XmadMode> mode_cbf; // used by CR, RC
  1330. BitField<50, 3, XmadMode> mode;
  1331. BitField<52, 1, u64> high_b;
  1332. BitField<53, 1, u64> high_a;
  1333. BitField<55, 1, u64> product_shift_left_second; // used on CR
  1334. BitField<56, 1, u64> merge_56;
  1335. } xmad;
  1336. union {
  1337. BitField<20, 14, u64> offset;
  1338. BitField<34, 5, u64> index;
  1339. u64 GetOffset() const {
  1340. return offset * 4;
  1341. }
  1342. } cbuf34;
  1343. union {
  1344. BitField<20, 16, s64> offset;
  1345. BitField<36, 5, u64> index;
  1346. s64 GetOffset() const {
  1347. return offset;
  1348. }
  1349. } cbuf36;
  1350. // Unsure about the size of this one.
  1351. // It's always used with a gpr0, so any size should be fine.
  1352. BitField<20, 8, SystemVariable> sys20;
  1353. BitField<47, 1, u64> generates_cc;
  1354. BitField<61, 1, u64> is_b_imm;
  1355. BitField<60, 1, u64> is_b_gpr;
  1356. BitField<59, 1, u64> is_c_gpr;
  1357. BitField<20, 24, s64> smem_imm;
  1358. BitField<0, 5, ConditionCode> flow_condition_code;
  1359. Attribute attribute;
  1360. Sampler sampler;
  1361. Image image;
  1362. u64 value;
  1363. };
  1364. static_assert(sizeof(Instruction) == 0x8, "Incorrect structure size");
  1365. static_assert(std::is_standard_layout_v<Instruction>, "Instruction is not standard layout");
  1366. class OpCode {
  1367. public:
  1368. enum class Id {
  1369. KIL,
  1370. SSY,
  1371. SYNC,
  1372. BRK,
  1373. DEPBAR,
  1374. VOTE,
  1375. SHFL,
  1376. FSWZADD,
  1377. BFE_C,
  1378. BFE_R,
  1379. BFE_IMM,
  1380. BFI_IMM_R,
  1381. BRA,
  1382. BRX,
  1383. PBK,
  1384. LD_A,
  1385. LD_L,
  1386. LD_S,
  1387. LD_C,
  1388. LD, // Load from generic memory
  1389. LDG, // Load from global memory
  1390. ST_A,
  1391. ST_L,
  1392. ST_S,
  1393. ST, // Store in generic memory
  1394. STG, // Store in global memory
  1395. AL2P, // Transforms attribute memory into physical memory
  1396. TEX,
  1397. TEX_B, // Texture Load Bindless
  1398. TXQ, // Texture Query
  1399. TXQ_B, // Texture Query Bindless
  1400. TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
  1401. TLD, // Texture Load
  1402. TLDS, // Texture Load with scalar/non-vec4 source/destinations
  1403. TLD4, // Texture Gather 4
  1404. TLD4_B, // Texture Gather 4 Bindless
  1405. TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations
  1406. TMML_B, // Texture Mip Map Level
  1407. TMML, // Texture Mip Map Level
  1408. SUST, // Surface Store
  1409. SULD, // Surface Load
  1410. SUATOM, // Surface Atomic Operation
  1411. EXIT,
  1412. NOP,
  1413. IPA,
  1414. OUT_R, // Emit vertex/primitive
  1415. ISBERD,
  1416. VMAD,
  1417. VSETP,
  1418. FFMA_IMM, // Fused Multiply and Add
  1419. FFMA_CR,
  1420. FFMA_RC,
  1421. FFMA_RR,
  1422. FADD_C,
  1423. FADD_R,
  1424. FADD_IMM,
  1425. FADD32I,
  1426. FMUL_C,
  1427. FMUL_R,
  1428. FMUL_IMM,
  1429. FMUL32_IMM,
  1430. IADD_C,
  1431. IADD_R,
  1432. IADD_IMM,
  1433. IADD3_C, // Add 3 Integers
  1434. IADD3_R,
  1435. IADD3_IMM,
  1436. IADD32I,
  1437. ISCADD_C, // Scale and Add
  1438. ISCADD_R,
  1439. ISCADD_IMM,
  1440. LEA_R1,
  1441. LEA_R2,
  1442. LEA_RZ,
  1443. LEA_IMM,
  1444. LEA_HI,
  1445. HADD2_C,
  1446. HADD2_R,
  1447. HADD2_IMM,
  1448. HMUL2_C,
  1449. HMUL2_R,
  1450. HMUL2_IMM,
  1451. HFMA2_CR,
  1452. HFMA2_RC,
  1453. HFMA2_RR,
  1454. HFMA2_IMM_R,
  1455. HSETP2_C,
  1456. HSETP2_R,
  1457. HSETP2_IMM,
  1458. HSET2_R,
  1459. POPC_C,
  1460. POPC_R,
  1461. POPC_IMM,
  1462. SEL_C,
  1463. SEL_R,
  1464. SEL_IMM,
  1465. ICMP_RC,
  1466. ICMP_R,
  1467. ICMP_CR,
  1468. ICMP_IMM,
  1469. MUFU, // Multi-Function Operator
  1470. RRO_C, // Range Reduction Operator
  1471. RRO_R,
  1472. RRO_IMM,
  1473. F2F_C,
  1474. F2F_R,
  1475. F2F_IMM,
  1476. F2I_C,
  1477. F2I_R,
  1478. F2I_IMM,
  1479. I2F_C,
  1480. I2F_R,
  1481. I2F_IMM,
  1482. I2I_C,
  1483. I2I_R,
  1484. I2I_IMM,
  1485. LOP_C,
  1486. LOP_R,
  1487. LOP_IMM,
  1488. LOP32I,
  1489. LOP3_C,
  1490. LOP3_R,
  1491. LOP3_IMM,
  1492. MOV_C,
  1493. MOV_R,
  1494. MOV_IMM,
  1495. MOV_SYS,
  1496. MOV32_IMM,
  1497. SHL_C,
  1498. SHL_R,
  1499. SHL_IMM,
  1500. SHR_C,
  1501. SHR_R,
  1502. SHR_IMM,
  1503. FMNMX_C,
  1504. FMNMX_R,
  1505. FMNMX_IMM,
  1506. IMNMX_C,
  1507. IMNMX_R,
  1508. IMNMX_IMM,
  1509. FSETP_C, // Set Predicate
  1510. FSETP_R,
  1511. FSETP_IMM,
  1512. FSET_C,
  1513. FSET_R,
  1514. FSET_IMM,
  1515. ISETP_C,
  1516. ISETP_IMM,
  1517. ISETP_R,
  1518. ISET_R,
  1519. ISET_C,
  1520. ISET_IMM,
  1521. PSETP,
  1522. PSET,
  1523. CSETP,
  1524. R2P_IMM,
  1525. XMAD_IMM,
  1526. XMAD_CR,
  1527. XMAD_RC,
  1528. XMAD_RR,
  1529. };
  1530. enum class Type {
  1531. Trivial,
  1532. Arithmetic,
  1533. ArithmeticImmediate,
  1534. ArithmeticInteger,
  1535. ArithmeticIntegerImmediate,
  1536. ArithmeticHalf,
  1537. ArithmeticHalfImmediate,
  1538. Bfe,
  1539. Bfi,
  1540. Shift,
  1541. Ffma,
  1542. Hfma2,
  1543. Flow,
  1544. Synch,
  1545. Warp,
  1546. Memory,
  1547. Texture,
  1548. Image,
  1549. FloatSet,
  1550. FloatSetPredicate,
  1551. IntegerSet,
  1552. IntegerSetPredicate,
  1553. HalfSet,
  1554. HalfSetPredicate,
  1555. PredicateSetPredicate,
  1556. PredicateSetRegister,
  1557. RegisterSetPredicate,
  1558. Conversion,
  1559. Video,
  1560. Xmad,
  1561. Unknown,
  1562. };
  1563. /// Returns whether an opcode has an execution predicate field or not (ie, whether it can be
  1564. /// conditionally executed).
  1565. static bool IsPredicatedInstruction(Id opcode) {
  1566. // TODO(Subv): Add the rest of unpredicated instructions.
  1567. return opcode != Id::SSY && opcode != Id::PBK;
  1568. }
  1569. class Matcher {
  1570. public:
  1571. constexpr Matcher(const char* const name, u16 mask, u16 expected, Id id, Type type)
  1572. : name{name}, mask{mask}, expected{expected}, id{id}, type{type} {}
  1573. constexpr const char* GetName() const {
  1574. return name;
  1575. }
  1576. constexpr u16 GetMask() const {
  1577. return mask;
  1578. }
  1579. constexpr Id GetId() const {
  1580. return id;
  1581. }
  1582. constexpr Type GetType() const {
  1583. return type;
  1584. }
  1585. /**
  1586. * Tests to see if the given instruction is the instruction this matcher represents.
  1587. * @param instruction The instruction to test
  1588. * @returns true if the given instruction matches.
  1589. */
  1590. constexpr bool Matches(u16 instruction) const {
  1591. return (instruction & mask) == expected;
  1592. }
  1593. private:
  1594. const char* name;
  1595. u16 mask;
  1596. u16 expected;
  1597. Id id;
  1598. Type type;
  1599. };
  1600. static std::optional<std::reference_wrapper<const Matcher>> Decode(Instruction instr) {
  1601. static const auto table{GetDecodeTable()};
  1602. const auto matches_instruction = [instr](const auto& matcher) {
  1603. return matcher.Matches(static_cast<u16>(instr.opcode));
  1604. };
  1605. auto iter = std::find_if(table.begin(), table.end(), matches_instruction);
  1606. return iter != table.end() ? std::optional<std::reference_wrapper<const Matcher>>(*iter)
  1607. : std::nullopt;
  1608. }
  1609. private:
  1610. struct Detail {
  1611. private:
  1612. static constexpr std::size_t opcode_bitsize = 16;
  1613. /**
  1614. * Generates the mask and the expected value after masking from a given bitstring.
  1615. * A '0' in a bitstring indicates that a zero must be present at that bit position.
  1616. * A '1' in a bitstring indicates that a one must be present at that bit position.
  1617. */
  1618. static constexpr auto GetMaskAndExpect(const char* const bitstring) {
  1619. u16 mask = 0, expect = 0;
  1620. for (std::size_t i = 0; i < opcode_bitsize; i++) {
  1621. const std::size_t bit_position = opcode_bitsize - i - 1;
  1622. switch (bitstring[i]) {
  1623. case '0':
  1624. mask |= static_cast<u16>(1U << bit_position);
  1625. break;
  1626. case '1':
  1627. expect |= static_cast<u16>(1U << bit_position);
  1628. mask |= static_cast<u16>(1U << bit_position);
  1629. break;
  1630. default:
  1631. // Ignore
  1632. break;
  1633. }
  1634. }
  1635. return std::make_pair(mask, expect);
  1636. }
  1637. public:
  1638. /// Creates a matcher that can match and parse instructions based on bitstring.
  1639. static constexpr auto GetMatcher(const char* const bitstring, Id op, Type type,
  1640. const char* const name) {
  1641. const auto [mask, expected] = GetMaskAndExpect(bitstring);
  1642. return Matcher(name, mask, expected, op, type);
  1643. }
  1644. };
  1645. static std::vector<Matcher> GetDecodeTable() {
  1646. std::vector<Matcher> table = {
  1647. #define INST(bitstring, op, type, name) Detail::GetMatcher(bitstring, op, type, name)
  1648. INST("111000110011----", Id::KIL, Type::Flow, "KIL"),
  1649. INST("111000101001----", Id::SSY, Type::Flow, "SSY"),
  1650. INST("111000101010----", Id::PBK, Type::Flow, "PBK"),
  1651. INST("111000100100----", Id::BRA, Type::Flow, "BRA"),
  1652. INST("111000100101----", Id::BRX, Type::Flow, "BRX"),
  1653. INST("1111000011111---", Id::SYNC, Type::Flow, "SYNC"),
  1654. INST("111000110100---", Id::BRK, Type::Flow, "BRK"),
  1655. INST("111000110000----", Id::EXIT, Type::Flow, "EXIT"),
  1656. INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"),
  1657. INST("0101000011011---", Id::VOTE, Type::Warp, "VOTE"),
  1658. INST("1110111100010---", Id::SHFL, Type::Warp, "SHFL"),
  1659. INST("0101000011111---", Id::FSWZADD, Type::Warp, "FSWZADD"),
  1660. INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
  1661. INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"),
  1662. INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"),
  1663. INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
  1664. INST("100-------------", Id::LD, Type::Memory, "LD"),
  1665. INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
  1666. INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
  1667. INST("1110111101011---", Id::ST_S, Type::Memory, "ST_S"),
  1668. INST("1110111101010---", Id::ST_L, Type::Memory, "ST_L"),
  1669. INST("101-------------", Id::ST, Type::Memory, "ST"),
  1670. INST("1110111011011---", Id::STG, Type::Memory, "STG"),
  1671. INST("1110111110100---", Id::AL2P, Type::Memory, "AL2P"),
  1672. INST("110000----111---", Id::TEX, Type::Texture, "TEX"),
  1673. INST("1101111010111---", Id::TEX_B, Type::Texture, "TEX_B"),
  1674. INST("1101111101001---", Id::TXQ, Type::Texture, "TXQ"),
  1675. INST("1101111101010---", Id::TXQ_B, Type::Texture, "TXQ_B"),
  1676. INST("1101-00---------", Id::TEXS, Type::Texture, "TEXS"),
  1677. INST("11011100--11----", Id::TLD, Type::Texture, "TLD"),
  1678. INST("1101-01---------", Id::TLDS, Type::Texture, "TLDS"),
  1679. INST("110010----111---", Id::TLD4, Type::Texture, "TLD4"),
  1680. INST("1101111011111---", Id::TLD4_B, Type::Texture, "TLD4_B"),
  1681. INST("1101111100------", Id::TLD4S, Type::Texture, "TLD4S"),
  1682. INST("110111110110----", Id::TMML_B, Type::Texture, "TMML_B"),
  1683. INST("1101111101011---", Id::TMML, Type::Texture, "TMML"),
  1684. INST("11101011001-----", Id::SUST, Type::Image, "SUST"),
  1685. INST("11101011000-----", Id::SULD, Type::Image, "SULD"),
  1686. INST("1110101000------", Id::SUATOM, Type::Image, "SUATOM_D"),
  1687. INST("0101000010110---", Id::NOP, Type::Trivial, "NOP"),
  1688. INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
  1689. INST("1111101111100---", Id::OUT_R, Type::Trivial, "OUT_R"),
  1690. INST("1110111111010---", Id::ISBERD, Type::Trivial, "ISBERD"),
  1691. INST("01011111--------", Id::VMAD, Type::Video, "VMAD"),
  1692. INST("0101000011110---", Id::VSETP, Type::Video, "VSETP"),
  1693. INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
  1694. INST("010010011-------", Id::FFMA_CR, Type::Ffma, "FFMA_CR"),
  1695. INST("010100011-------", Id::FFMA_RC, Type::Ffma, "FFMA_RC"),
  1696. INST("010110011-------", Id::FFMA_RR, Type::Ffma, "FFMA_RR"),
  1697. INST("0100110001011---", Id::FADD_C, Type::Arithmetic, "FADD_C"),
  1698. INST("0101110001011---", Id::FADD_R, Type::Arithmetic, "FADD_R"),
  1699. INST("0011100-01011---", Id::FADD_IMM, Type::Arithmetic, "FADD_IMM"),
  1700. INST("000010----------", Id::FADD32I, Type::ArithmeticImmediate, "FADD32I"),
  1701. INST("0100110001101---", Id::FMUL_C, Type::Arithmetic, "FMUL_C"),
  1702. INST("0101110001101---", Id::FMUL_R, Type::Arithmetic, "FMUL_R"),
  1703. INST("0011100-01101---", Id::FMUL_IMM, Type::Arithmetic, "FMUL_IMM"),
  1704. INST("00011110--------", Id::FMUL32_IMM, Type::ArithmeticImmediate, "FMUL32_IMM"),
  1705. INST("0100110000010---", Id::IADD_C, Type::ArithmeticInteger, "IADD_C"),
  1706. INST("0101110000010---", Id::IADD_R, Type::ArithmeticInteger, "IADD_R"),
  1707. INST("0011100-00010---", Id::IADD_IMM, Type::ArithmeticInteger, "IADD_IMM"),
  1708. INST("010011001100----", Id::IADD3_C, Type::ArithmeticInteger, "IADD3_C"),
  1709. INST("010111001100----", Id::IADD3_R, Type::ArithmeticInteger, "IADD3_R"),
  1710. INST("0011100-1100----", Id::IADD3_IMM, Type::ArithmeticInteger, "IADD3_IMM"),
  1711. INST("0001110---------", Id::IADD32I, Type::ArithmeticIntegerImmediate, "IADD32I"),
  1712. INST("0100110000011---", Id::ISCADD_C, Type::ArithmeticInteger, "ISCADD_C"),
  1713. INST("0101110000011---", Id::ISCADD_R, Type::ArithmeticInteger, "ISCADD_R"),
  1714. INST("0011100-00011---", Id::ISCADD_IMM, Type::ArithmeticInteger, "ISCADD_IMM"),
  1715. INST("0100110000001---", Id::POPC_C, Type::ArithmeticInteger, "POPC_C"),
  1716. INST("0101110000001---", Id::POPC_R, Type::ArithmeticInteger, "POPC_R"),
  1717. INST("0011100-00001---", Id::POPC_IMM, Type::ArithmeticInteger, "POPC_IMM"),
  1718. INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"),
  1719. INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"),
  1720. INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"),
  1721. INST("010100110100----", Id::ICMP_RC, Type::ArithmeticInteger, "ICMP_RC"),
  1722. INST("010110110100----", Id::ICMP_R, Type::ArithmeticInteger, "ICMP_R"),
  1723. INST("010010110100----", Id::ICMP_CR, Type::ArithmeticInteger, "ICMP_CR"),
  1724. INST("0011011-0100----", Id::ICMP_IMM, Type::ArithmeticInteger, "ICMP_IMM"),
  1725. INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"),
  1726. INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"),
  1727. INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"),
  1728. INST("010010111101----", Id::LEA_RZ, Type::ArithmeticInteger, "LEA_RZ"),
  1729. INST("00011000--------", Id::LEA_HI, Type::ArithmeticInteger, "LEA_HI"),
  1730. INST("0111101-1-------", Id::HADD2_C, Type::ArithmeticHalf, "HADD2_C"),
  1731. INST("0101110100010---", Id::HADD2_R, Type::ArithmeticHalf, "HADD2_R"),
  1732. INST("0111101-0-------", Id::HADD2_IMM, Type::ArithmeticHalfImmediate, "HADD2_IMM"),
  1733. INST("0111100-1-------", Id::HMUL2_C, Type::ArithmeticHalf, "HMUL2_C"),
  1734. INST("0101110100001---", Id::HMUL2_R, Type::ArithmeticHalf, "HMUL2_R"),
  1735. INST("0111100-0-------", Id::HMUL2_IMM, Type::ArithmeticHalfImmediate, "HMUL2_IMM"),
  1736. INST("01110---1-------", Id::HFMA2_CR, Type::Hfma2, "HFMA2_CR"),
  1737. INST("01100---1-------", Id::HFMA2_RC, Type::Hfma2, "HFMA2_RC"),
  1738. INST("0101110100000---", Id::HFMA2_RR, Type::Hfma2, "HFMA2_RR"),
  1739. INST("01110---0-------", Id::HFMA2_IMM_R, Type::Hfma2, "HFMA2_R_IMM"),
  1740. INST("0111111-1-------", Id::HSETP2_C, Type::HalfSetPredicate, "HSETP2_C"),
  1741. INST("0101110100100---", Id::HSETP2_R, Type::HalfSetPredicate, "HSETP2_R"),
  1742. INST("0111111-0-------", Id::HSETP2_IMM, Type::HalfSetPredicate, "HSETP2_IMM"),
  1743. INST("0101110100011---", Id::HSET2_R, Type::HalfSet, "HSET2_R"),
  1744. INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"),
  1745. INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"),
  1746. INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"),
  1747. INST("0011100-10010---", Id::RRO_IMM, Type::Arithmetic, "RRO_IMM"),
  1748. INST("0100110010101---", Id::F2F_C, Type::Conversion, "F2F_C"),
  1749. INST("0101110010101---", Id::F2F_R, Type::Conversion, "F2F_R"),
  1750. INST("0011100-10101---", Id::F2F_IMM, Type::Conversion, "F2F_IMM"),
  1751. INST("0100110010110---", Id::F2I_C, Type::Conversion, "F2I_C"),
  1752. INST("0101110010110---", Id::F2I_R, Type::Conversion, "F2I_R"),
  1753. INST("0011100-10110---", Id::F2I_IMM, Type::Conversion, "F2I_IMM"),
  1754. INST("0100110010011---", Id::MOV_C, Type::Arithmetic, "MOV_C"),
  1755. INST("0101110010011---", Id::MOV_R, Type::Arithmetic, "MOV_R"),
  1756. INST("0011100-10011---", Id::MOV_IMM, Type::Arithmetic, "MOV_IMM"),
  1757. INST("1111000011001---", Id::MOV_SYS, Type::Trivial, "MOV_SYS"),
  1758. INST("000000010000----", Id::MOV32_IMM, Type::ArithmeticImmediate, "MOV32_IMM"),
  1759. INST("0100110001100---", Id::FMNMX_C, Type::Arithmetic, "FMNMX_C"),
  1760. INST("0101110001100---", Id::FMNMX_R, Type::Arithmetic, "FMNMX_R"),
  1761. INST("0011100-01100---", Id::FMNMX_IMM, Type::Arithmetic, "FMNMX_IMM"),
  1762. INST("0100110000100---", Id::IMNMX_C, Type::ArithmeticInteger, "IMNMX_C"),
  1763. INST("0101110000100---", Id::IMNMX_R, Type::ArithmeticInteger, "IMNMX_R"),
  1764. INST("0011100-00100---", Id::IMNMX_IMM, Type::ArithmeticInteger, "IMNMX_IMM"),
  1765. INST("0100110000000---", Id::BFE_C, Type::Bfe, "BFE_C"),
  1766. INST("0101110000000---", Id::BFE_R, Type::Bfe, "BFE_R"),
  1767. INST("0011100-00000---", Id::BFE_IMM, Type::Bfe, "BFE_IMM"),
  1768. INST("0011011-11110---", Id::BFI_IMM_R, Type::Bfi, "BFI_IMM_R"),
  1769. INST("0100110001000---", Id::LOP_C, Type::ArithmeticInteger, "LOP_C"),
  1770. INST("0101110001000---", Id::LOP_R, Type::ArithmeticInteger, "LOP_R"),
  1771. INST("0011100-01000---", Id::LOP_IMM, Type::ArithmeticInteger, "LOP_IMM"),
  1772. INST("000001----------", Id::LOP32I, Type::ArithmeticIntegerImmediate, "LOP32I"),
  1773. INST("0000001---------", Id::LOP3_C, Type::ArithmeticInteger, "LOP3_C"),
  1774. INST("0101101111100---", Id::LOP3_R, Type::ArithmeticInteger, "LOP3_R"),
  1775. INST("0011110---------", Id::LOP3_IMM, Type::ArithmeticInteger, "LOP3_IMM"),
  1776. INST("0100110001001---", Id::SHL_C, Type::Shift, "SHL_C"),
  1777. INST("0101110001001---", Id::SHL_R, Type::Shift, "SHL_R"),
  1778. INST("0011100-01001---", Id::SHL_IMM, Type::Shift, "SHL_IMM"),
  1779. INST("0100110000101---", Id::SHR_C, Type::Shift, "SHR_C"),
  1780. INST("0101110000101---", Id::SHR_R, Type::Shift, "SHR_R"),
  1781. INST("0011100-00101---", Id::SHR_IMM, Type::Shift, "SHR_IMM"),
  1782. INST("0100110011100---", Id::I2I_C, Type::Conversion, "I2I_C"),
  1783. INST("0101110011100---", Id::I2I_R, Type::Conversion, "I2I_R"),
  1784. INST("0011101-11100---", Id::I2I_IMM, Type::Conversion, "I2I_IMM"),
  1785. INST("0100110010111---", Id::I2F_C, Type::Conversion, "I2F_C"),
  1786. INST("0101110010111---", Id::I2F_R, Type::Conversion, "I2F_R"),
  1787. INST("0011100-10111---", Id::I2F_IMM, Type::Conversion, "I2F_IMM"),
  1788. INST("01011000--------", Id::FSET_R, Type::FloatSet, "FSET_R"),
  1789. INST("0100100---------", Id::FSET_C, Type::FloatSet, "FSET_C"),
  1790. INST("0011000---------", Id::FSET_IMM, Type::FloatSet, "FSET_IMM"),
  1791. INST("010010111011----", Id::FSETP_C, Type::FloatSetPredicate, "FSETP_C"),
  1792. INST("010110111011----", Id::FSETP_R, Type::FloatSetPredicate, "FSETP_R"),
  1793. INST("0011011-1011----", Id::FSETP_IMM, Type::FloatSetPredicate, "FSETP_IMM"),
  1794. INST("010010110110----", Id::ISETP_C, Type::IntegerSetPredicate, "ISETP_C"),
  1795. INST("010110110110----", Id::ISETP_R, Type::IntegerSetPredicate, "ISETP_R"),
  1796. INST("0011011-0110----", Id::ISETP_IMM, Type::IntegerSetPredicate, "ISETP_IMM"),
  1797. INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"),
  1798. INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"),
  1799. INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"),
  1800. INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"),
  1801. INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"),
  1802. INST("010100001010----", Id::CSETP, Type::PredicateSetPredicate, "CSETP"),
  1803. INST("0011100-11110---", Id::R2P_IMM, Type::RegisterSetPredicate, "R2P_IMM"),
  1804. INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"),
  1805. INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"),
  1806. INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"),
  1807. INST("0101101100------", Id::XMAD_RR, Type::Xmad, "XMAD_RR"),
  1808. };
  1809. #undef INST
  1810. std::stable_sort(table.begin(), table.end(), [](const auto& a, const auto& b) {
  1811. // If a matcher has more bits in its mask it is more specific, so it
  1812. // should come first.
  1813. return std::bitset<16>(a.GetMask()).count() > std::bitset<16>(b.GetMask()).count();
  1814. });
  1815. return table;
  1816. }
  1817. };
  1818. } // namespace Tegra::Shader