shader_bytecode.h 58 KB

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