shader_bytecode.h 63 KB

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