shader_bytecode.h 64 KB

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