shader_bytecode.h 57 KB

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