shader_bytecode.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 <bitset>
  6. #include <cstring>
  7. #include <map>
  8. #include <string>
  9. #include <vector>
  10. #include <boost/optional.hpp>
  11. #include "common/assert.h"
  12. #include "common/bit_field.h"
  13. #include "common/common_types.h"
  14. namespace Tegra::Shader {
  15. struct Register {
  16. /// Number of registers
  17. static constexpr std::size_t NumRegisters = 256;
  18. /// Register 255 is special cased to always be 0
  19. static constexpr std::size_t ZeroIndex = 255;
  20. enum class Size : u64 {
  21. Byte = 0,
  22. Short = 1,
  23. Word = 2,
  24. Long = 3,
  25. };
  26. constexpr Register() = default;
  27. constexpr Register(u64 value) : value(value) {}
  28. constexpr operator u64() const {
  29. return value;
  30. }
  31. template <typename T>
  32. constexpr u64 operator-(const T& oth) const {
  33. return value - oth;
  34. }
  35. template <typename T>
  36. constexpr u64 operator&(const T& oth) const {
  37. return value & oth;
  38. }
  39. constexpr u64 operator&(const Register& oth) const {
  40. return value & oth.value;
  41. }
  42. constexpr u64 operator~() const {
  43. return ~value;
  44. }
  45. u64 GetSwizzledIndex(u64 elem) const {
  46. elem = (value + elem) & 3;
  47. return (value & ~3) + elem;
  48. }
  49. private:
  50. u64 value{};
  51. };
  52. enum class AttributeSize : u64 {
  53. Word = 0,
  54. DoubleWord = 1,
  55. TripleWord = 2,
  56. QuadWord = 3,
  57. };
  58. union Attribute {
  59. Attribute() = default;
  60. constexpr explicit Attribute(u64 value) : value(value) {}
  61. enum class Index : u64 {
  62. Position = 7,
  63. Attribute_0 = 8,
  64. Attribute_31 = 39,
  65. PointCoord = 46,
  66. // This attribute contains a tuple of (~, ~, InstanceId, VertexId) when inside a vertex
  67. // shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
  68. // shader.
  69. TessCoordInstanceIDVertexID = 47,
  70. // This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment
  71. // shader. It is unknown what the other values contain.
  72. FrontFacing = 63,
  73. };
  74. union {
  75. BitField<20, 10, u64> immediate;
  76. BitField<22, 2, u64> element;
  77. BitField<24, 6, Index> index;
  78. BitField<47, 3, AttributeSize> size;
  79. } fmt20;
  80. union {
  81. BitField<30, 2, u64> element;
  82. BitField<32, 6, Index> index;
  83. } fmt28;
  84. BitField<39, 8, u64> reg;
  85. u64 value{};
  86. };
  87. union Sampler {
  88. Sampler() = default;
  89. constexpr explicit Sampler(u64 value) : value(value) {}
  90. enum class Index : u64 {
  91. Sampler_0 = 8,
  92. };
  93. BitField<36, 13, Index> index;
  94. u64 value{};
  95. };
  96. } // namespace Tegra::Shader
  97. namespace std {
  98. // TODO(bunnei): The below is forbidden by the C++ standard, but works fine. See #330.
  99. template <>
  100. struct make_unsigned<Tegra::Shader::Attribute> {
  101. using type = Tegra::Shader::Attribute;
  102. };
  103. template <>
  104. struct make_unsigned<Tegra::Shader::Register> {
  105. using type = Tegra::Shader::Register;
  106. };
  107. } // namespace std
  108. namespace Tegra::Shader {
  109. enum class Pred : u64 {
  110. UnusedIndex = 0x7,
  111. NeverExecute = 0xF,
  112. };
  113. enum class PredCondition : u64 {
  114. LessThan = 1,
  115. Equal = 2,
  116. LessEqual = 3,
  117. GreaterThan = 4,
  118. NotEqual = 5,
  119. GreaterEqual = 6,
  120. LessThanWithNan = 9,
  121. GreaterThanWithNan = 12,
  122. NotEqualWithNan = 13,
  123. GreaterEqualWithNan = 14,
  124. // TODO(Subv): Other condition types
  125. };
  126. enum class PredOperation : u64 {
  127. And = 0,
  128. Or = 1,
  129. Xor = 2,
  130. };
  131. enum class LogicOperation : u64 {
  132. And = 0,
  133. Or = 1,
  134. Xor = 2,
  135. PassB = 3,
  136. };
  137. enum class SubOp : u64 {
  138. Cos = 0x0,
  139. Sin = 0x1,
  140. Ex2 = 0x2,
  141. Lg2 = 0x3,
  142. Rcp = 0x4,
  143. Rsq = 0x5,
  144. Sqrt = 0x8,
  145. };
  146. enum class F2iRoundingOp : u64 {
  147. None = 0,
  148. Floor = 1,
  149. Ceil = 2,
  150. Trunc = 3,
  151. };
  152. enum class F2fRoundingOp : u64 {
  153. None = 0,
  154. Pass = 3,
  155. Round = 8,
  156. Floor = 9,
  157. Ceil = 10,
  158. Trunc = 11,
  159. };
  160. enum class UniformType : u64 {
  161. UnsignedByte = 0,
  162. SignedByte = 1,
  163. UnsignedShort = 2,
  164. SignedShort = 3,
  165. Single = 4,
  166. Double = 5,
  167. };
  168. enum class IMinMaxExchange : u64 {
  169. None = 0,
  170. XLo = 1,
  171. XMed = 2,
  172. XHi = 3,
  173. };
  174. enum class XmadMode : u64 {
  175. None = 0,
  176. CLo = 1,
  177. CHi = 2,
  178. CSfu = 3,
  179. CBcc = 4,
  180. };
  181. enum class IAdd3Mode : u64 {
  182. None = 0,
  183. RightShift = 1,
  184. LeftShift = 2,
  185. };
  186. enum class IAdd3Height : u64 {
  187. None = 0,
  188. LowerHalfWord = 1,
  189. UpperHalfWord = 2,
  190. };
  191. enum class FlowCondition : u64 {
  192. Always = 0xF,
  193. Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for?
  194. };
  195. enum class PredicateResultMode : u64 {
  196. None = 0x0,
  197. NotZero = 0x3,
  198. };
  199. enum class TextureType : u64 {
  200. Texture1D = 0,
  201. Texture2D = 1,
  202. Texture3D = 2,
  203. TextureCube = 3,
  204. };
  205. enum class TextureQueryType : u64 {
  206. Dimension = 1,
  207. TextureType = 2,
  208. SamplePosition = 5,
  209. Filter = 16,
  210. LevelOfDetail = 18,
  211. Wrap = 20,
  212. BorderColor = 22,
  213. };
  214. enum class TextureProcessMode : u64 {
  215. None = 0,
  216. LZ = 1, // Unknown, appears to be the same as none.
  217. LB = 2, // Load Bias.
  218. LL = 3, // Load LOD (LevelOfDetail)
  219. LBA = 6, // Load Bias. The A is unknown, does not appear to differ with LB
  220. LLA = 7 // Load LOD. The A is unknown, does not appear to differ with LL
  221. };
  222. enum class TextureMiscMode : u64 {
  223. DC,
  224. AOFFI, // Uses Offset
  225. NDV,
  226. NODEP,
  227. MZ,
  228. PTP,
  229. };
  230. enum class IpaInterpMode : u64 { Linear = 0, Perspective = 1, Flat = 2, Sc = 3 };
  231. enum class IpaSampleMode : u64 { Default = 0, Centroid = 1, Offset = 2 };
  232. struct IpaMode {
  233. IpaInterpMode interpolation_mode;
  234. IpaSampleMode sampling_mode;
  235. inline bool operator==(const IpaMode& a) {
  236. return (a.interpolation_mode == interpolation_mode) && (a.sampling_mode == sampling_mode);
  237. }
  238. inline bool operator!=(const IpaMode& a) {
  239. return !((*this) == a);
  240. }
  241. };
  242. union Instruction {
  243. Instruction& operator=(const Instruction& instr) {
  244. value = instr.value;
  245. return *this;
  246. }
  247. constexpr Instruction(u64 value) : value{value} {}
  248. BitField<0, 8, Register> gpr0;
  249. BitField<8, 8, Register> gpr8;
  250. union {
  251. BitField<16, 4, Pred> full_pred;
  252. BitField<16, 3, u64> pred_index;
  253. } pred;
  254. BitField<19, 1, u64> negate_pred;
  255. BitField<20, 8, Register> gpr20;
  256. BitField<20, 4, SubOp> sub_op;
  257. BitField<28, 8, Register> gpr28;
  258. BitField<39, 8, Register> gpr39;
  259. BitField<48, 16, u64> opcode;
  260. union {
  261. BitField<20, 19, u64> imm20_19;
  262. BitField<20, 32, s64> imm20_32;
  263. BitField<45, 1, u64> negate_b;
  264. BitField<46, 1, u64> abs_a;
  265. BitField<48, 1, u64> negate_a;
  266. BitField<49, 1, u64> abs_b;
  267. BitField<50, 1, u64> saturate_d;
  268. BitField<56, 1, u64> negate_imm;
  269. union {
  270. BitField<39, 3, u64> pred;
  271. BitField<42, 1, u64> negate_pred;
  272. } fmnmx;
  273. union {
  274. BitField<39, 1, u64> invert_a;
  275. BitField<40, 1, u64> invert_b;
  276. BitField<41, 2, LogicOperation> operation;
  277. BitField<44, 2, PredicateResultMode> pred_result_mode;
  278. BitField<48, 3, Pred> pred48;
  279. } lop;
  280. union {
  281. BitField<53, 2, LogicOperation> operation;
  282. BitField<55, 1, u64> invert_a;
  283. BitField<56, 1, u64> invert_b;
  284. } lop32i;
  285. union {
  286. BitField<28, 8, u64> imm_lut28;
  287. BitField<48, 8, u64> imm_lut48;
  288. u32 GetImmLut28() const {
  289. return static_cast<u32>(imm_lut28);
  290. }
  291. u32 GetImmLut48() const {
  292. return static_cast<u32>(imm_lut48);
  293. }
  294. } lop3;
  295. u32 GetImm20_19() const {
  296. u32 imm{static_cast<u32>(imm20_19)};
  297. imm <<= 12;
  298. imm |= negate_imm ? 0x80000000 : 0;
  299. return imm;
  300. }
  301. u32 GetImm20_32() const {
  302. return static_cast<u32>(imm20_32);
  303. }
  304. s32 GetSignedImm20_20() const {
  305. u32 immediate = static_cast<u32>(imm20_19 | (negate_imm << 19));
  306. // Sign extend the 20-bit value.
  307. u32 mask = 1U << (20 - 1);
  308. return static_cast<s32>((immediate ^ mask) - mask);
  309. }
  310. } alu;
  311. union {
  312. BitField<51, 1, u64> saturate;
  313. BitField<52, 2, IpaSampleMode> sample_mode;
  314. BitField<54, 2, IpaInterpMode> interp_mode;
  315. } ipa;
  316. union {
  317. BitField<39, 2, u64> tab5cb8_2;
  318. BitField<41, 3, u64> tab5c68_1;
  319. BitField<44, 2, u64> tab5c68_0;
  320. BitField<47, 1, u64> cc;
  321. BitField<48, 1, u64> negate_b;
  322. } fmul;
  323. union {
  324. BitField<48, 1, u64> is_signed;
  325. } shift;
  326. union {
  327. BitField<39, 5, u64> shift_amount;
  328. BitField<48, 1, u64> negate_b;
  329. BitField<49, 1, u64> negate_a;
  330. } alu_integer;
  331. union {
  332. BitField<40, 1, u64> invert;
  333. } popc;
  334. union {
  335. BitField<39, 3, u64> pred;
  336. BitField<42, 1, u64> neg_pred;
  337. } sel;
  338. union {
  339. BitField<39, 3, u64> pred;
  340. BitField<42, 1, u64> negate_pred;
  341. BitField<43, 2, IMinMaxExchange> exchange;
  342. BitField<48, 1, u64> is_signed;
  343. } imnmx;
  344. union {
  345. BitField<31, 2, IAdd3Height> height_c;
  346. BitField<33, 2, IAdd3Height> height_b;
  347. BitField<35, 2, IAdd3Height> height_a;
  348. BitField<37, 2, IAdd3Mode> mode;
  349. BitField<49, 1, u64> neg_c;
  350. BitField<50, 1, u64> neg_b;
  351. BitField<51, 1, u64> neg_a;
  352. } iadd3;
  353. union {
  354. BitField<54, 1, u64> saturate;
  355. BitField<56, 1, u64> negate_a;
  356. } iadd32i;
  357. union {
  358. BitField<53, 1, u64> negate_b;
  359. BitField<54, 1, u64> abs_a;
  360. BitField<56, 1, u64> negate_a;
  361. BitField<57, 1, u64> abs_b;
  362. } fadd32i;
  363. union {
  364. BitField<20, 8, u64> shift_position;
  365. BitField<28, 8, u64> shift_length;
  366. BitField<48, 1, u64> negate_b;
  367. BitField<49, 1, u64> negate_a;
  368. u64 GetLeftShiftValue() const {
  369. return 32 - (shift_position + shift_length);
  370. }
  371. } bfe;
  372. union {
  373. BitField<48, 3, u64> pred48;
  374. union {
  375. BitField<20, 20, u64> entry_a;
  376. BitField<39, 5, u64> entry_b;
  377. BitField<45, 1, u64> neg;
  378. BitField<46, 1, u64> uses_cc;
  379. } imm;
  380. union {
  381. BitField<20, 14, u64> cb_index;
  382. BitField<34, 5, u64> cb_offset;
  383. BitField<56, 1, u64> neg;
  384. BitField<57, 1, u64> uses_cc;
  385. } hi;
  386. union {
  387. BitField<20, 14, u64> cb_index;
  388. BitField<34, 5, u64> cb_offset;
  389. BitField<39, 5, u64> entry_a;
  390. BitField<45, 1, u64> neg;
  391. BitField<46, 1, u64> uses_cc;
  392. } rz;
  393. union {
  394. BitField<39, 5, u64> entry_a;
  395. BitField<45, 1, u64> neg;
  396. BitField<46, 1, u64> uses_cc;
  397. } r1;
  398. union {
  399. BitField<28, 8, u64> entry_a;
  400. BitField<37, 1, u64> neg;
  401. BitField<38, 1, u64> uses_cc;
  402. } r2;
  403. } lea;
  404. union {
  405. BitField<0, 5, FlowCondition> cond;
  406. } flow;
  407. union {
  408. BitField<47, 1, u64> cc;
  409. BitField<48, 1, u64> negate_b;
  410. BitField<49, 1, u64> negate_c;
  411. BitField<51, 2, u64> tab5980_1;
  412. BitField<53, 2, u64> tab5980_0;
  413. } ffma;
  414. union {
  415. BitField<48, 3, UniformType> type;
  416. BitField<44, 2, u64> unknown;
  417. } ld_c;
  418. union {
  419. BitField<0, 3, u64> pred0;
  420. BitField<3, 3, u64> pred3;
  421. BitField<7, 1, u64> abs_a;
  422. BitField<39, 3, u64> pred39;
  423. BitField<42, 1, u64> neg_pred;
  424. BitField<43, 1, u64> neg_a;
  425. BitField<44, 1, u64> abs_b;
  426. BitField<45, 2, PredOperation> op;
  427. BitField<47, 1, u64> ftz;
  428. BitField<48, 4, PredCondition> cond;
  429. BitField<56, 1, u64> neg_b;
  430. } fsetp;
  431. union {
  432. BitField<0, 3, u64> pred0;
  433. BitField<3, 3, u64> pred3;
  434. BitField<39, 3, u64> pred39;
  435. BitField<42, 1, u64> neg_pred;
  436. BitField<45, 2, PredOperation> op;
  437. BitField<48, 1, u64> is_signed;
  438. BitField<49, 3, PredCondition> cond;
  439. } isetp;
  440. union {
  441. BitField<0, 3, u64> pred0;
  442. BitField<3, 3, u64> pred3;
  443. BitField<12, 3, u64> pred12;
  444. BitField<15, 1, u64> neg_pred12;
  445. BitField<24, 2, PredOperation> cond;
  446. BitField<29, 3, u64> pred29;
  447. BitField<32, 1, u64> neg_pred29;
  448. BitField<39, 3, u64> pred39;
  449. BitField<42, 1, u64> neg_pred39;
  450. BitField<45, 2, PredOperation> op;
  451. } psetp;
  452. union {
  453. BitField<12, 3, u64> pred12;
  454. BitField<15, 1, u64> neg_pred12;
  455. BitField<24, 2, PredOperation> cond;
  456. BitField<29, 3, u64> pred29;
  457. BitField<32, 1, u64> neg_pred29;
  458. BitField<39, 3, u64> pred39;
  459. BitField<42, 1, u64> neg_pred39;
  460. BitField<44, 1, u64> bf;
  461. BitField<45, 2, PredOperation> op;
  462. } pset;
  463. union {
  464. BitField<39, 3, u64> pred39;
  465. BitField<42, 1, u64> neg_pred;
  466. BitField<43, 1, u64> neg_a;
  467. BitField<44, 1, u64> abs_b;
  468. BitField<45, 2, PredOperation> op;
  469. BitField<48, 4, PredCondition> cond;
  470. BitField<52, 1, u64> bf;
  471. BitField<53, 1, u64> neg_b;
  472. BitField<54, 1, u64> abs_a;
  473. BitField<55, 1, u64> ftz;
  474. BitField<56, 1, u64> neg_imm;
  475. } fset;
  476. union {
  477. BitField<39, 3, u64> pred39;
  478. BitField<42, 1, u64> neg_pred;
  479. BitField<44, 1, u64> bf;
  480. BitField<45, 2, PredOperation> op;
  481. BitField<48, 1, u64> is_signed;
  482. BitField<49, 3, PredCondition> cond;
  483. } iset;
  484. union {
  485. BitField<8, 2, Register::Size> dest_size;
  486. BitField<10, 2, Register::Size> src_size;
  487. BitField<12, 1, u64> is_output_signed;
  488. BitField<13, 1, u64> is_input_signed;
  489. BitField<41, 2, u64> selector;
  490. BitField<45, 1, u64> negate_a;
  491. BitField<49, 1, u64> abs_a;
  492. union {
  493. BitField<39, 2, F2iRoundingOp> rounding;
  494. } f2i;
  495. union {
  496. BitField<39, 4, F2fRoundingOp> rounding;
  497. } f2f;
  498. } conversion;
  499. union {
  500. BitField<28, 1, u64> array;
  501. BitField<29, 2, TextureType> texture_type;
  502. BitField<31, 4, u64> component_mask;
  503. BitField<49, 1, u64> nodep_flag;
  504. BitField<50, 1, u64> dc_flag;
  505. BitField<54, 1, u64> aoffi_flag;
  506. BitField<55, 3, TextureProcessMode> process_mode;
  507. bool IsComponentEnabled(std::size_t component) const {
  508. return ((1ull << component) & component_mask) != 0;
  509. }
  510. TextureProcessMode GetTextureProcessMode() const {
  511. return process_mode;
  512. }
  513. bool UsesMiscMode(TextureMiscMode mode) const {
  514. switch (mode) {
  515. case TextureMiscMode::DC:
  516. return dc_flag != 0;
  517. case TextureMiscMode::NODEP:
  518. return nodep_flag != 0;
  519. case TextureMiscMode::AOFFI:
  520. return aoffi_flag != 0;
  521. default:
  522. break;
  523. }
  524. return false;
  525. }
  526. } tex;
  527. union {
  528. BitField<22, 6, TextureQueryType> query_type;
  529. BitField<31, 4, u64> component_mask;
  530. BitField<49, 1, u64> nodep_flag;
  531. bool UsesMiscMode(TextureMiscMode mode) const {
  532. switch (mode) {
  533. case TextureMiscMode::NODEP:
  534. return nodep_flag != 0;
  535. default:
  536. break;
  537. }
  538. return false;
  539. }
  540. } txq;
  541. union {
  542. BitField<28, 1, u64> array;
  543. BitField<29, 2, TextureType> texture_type;
  544. BitField<31, 4, u64> component_mask;
  545. BitField<35, 1, u64> ndv_flag;
  546. BitField<49, 1, u64> nodep_flag;
  547. bool IsComponentEnabled(std::size_t component) const {
  548. return ((1ull << component) & component_mask) != 0;
  549. }
  550. bool UsesMiscMode(TextureMiscMode mode) const {
  551. switch (mode) {
  552. case TextureMiscMode::NDV:
  553. return (ndv_flag != 0);
  554. case TextureMiscMode::NODEP:
  555. return (nodep_flag != 0);
  556. default:
  557. break;
  558. }
  559. return false;
  560. }
  561. } tmml;
  562. union {
  563. BitField<28, 1, u64> array;
  564. BitField<29, 2, TextureType> texture_type;
  565. BitField<35, 1, u64> ndv_flag;
  566. BitField<49, 1, u64> nodep_flag;
  567. BitField<50, 1, u64> dc_flag;
  568. BitField<54, 2, u64> info;
  569. BitField<56, 2, u64> component;
  570. bool UsesMiscMode(TextureMiscMode mode) const {
  571. switch (mode) {
  572. case TextureMiscMode::NDV:
  573. return ndv_flag != 0;
  574. case TextureMiscMode::NODEP:
  575. return nodep_flag != 0;
  576. case TextureMiscMode::DC:
  577. return dc_flag != 0;
  578. case TextureMiscMode::AOFFI:
  579. return info == 1;
  580. case TextureMiscMode::PTP:
  581. return info == 2;
  582. default:
  583. break;
  584. }
  585. return false;
  586. }
  587. } tld4;
  588. union {
  589. BitField<49, 1, u64> nodep_flag;
  590. BitField<50, 1, u64> dc_flag;
  591. BitField<51, 1, u64> aoffi_flag;
  592. BitField<52, 2, u64> component;
  593. bool UsesMiscMode(TextureMiscMode mode) const {
  594. switch (mode) {
  595. case TextureMiscMode::DC:
  596. return dc_flag != 0;
  597. case TextureMiscMode::NODEP:
  598. return nodep_flag != 0;
  599. case TextureMiscMode::AOFFI:
  600. return aoffi_flag != 0;
  601. default:
  602. break;
  603. }
  604. return false;
  605. }
  606. } tld4s;
  607. union {
  608. BitField<0, 8, Register> gpr0;
  609. BitField<28, 8, Register> gpr28;
  610. BitField<49, 1, u64> nodep_flag;
  611. BitField<50, 3, u64> component_mask_selector;
  612. BitField<53, 4, u64> texture_info;
  613. TextureType GetTextureType() const {
  614. // The TEXS instruction has a weird encoding for the texture type.
  615. if (texture_info == 0)
  616. return TextureType::Texture1D;
  617. if (texture_info >= 1 && texture_info <= 9)
  618. return TextureType::Texture2D;
  619. if (texture_info >= 10 && texture_info <= 11)
  620. return TextureType::Texture3D;
  621. if (texture_info >= 12 && texture_info <= 13)
  622. return TextureType::TextureCube;
  623. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  624. static_cast<u32>(texture_info.Value()));
  625. UNREACHABLE();
  626. }
  627. TextureProcessMode GetTextureProcessMode() const {
  628. switch (texture_info) {
  629. case 0:
  630. case 2:
  631. case 6:
  632. case 8:
  633. case 9:
  634. case 11:
  635. return TextureProcessMode::LZ;
  636. case 3:
  637. case 5:
  638. case 13:
  639. return TextureProcessMode::LL;
  640. default:
  641. break;
  642. }
  643. return TextureProcessMode::None;
  644. }
  645. bool UsesMiscMode(TextureMiscMode mode) const {
  646. switch (mode) {
  647. case TextureMiscMode::DC:
  648. return (texture_info >= 4 && texture_info <= 6) || texture_info == 9;
  649. case TextureMiscMode::NODEP:
  650. return nodep_flag != 0;
  651. default:
  652. break;
  653. }
  654. return false;
  655. }
  656. bool IsArrayTexture() const {
  657. // TEXS only supports Texture2D arrays.
  658. return texture_info >= 7 && texture_info <= 9;
  659. }
  660. bool HasTwoDestinations() const {
  661. return gpr28.Value() != Register::ZeroIndex;
  662. }
  663. bool IsComponentEnabled(std::size_t component) const {
  664. static constexpr std::array<std::array<u32, 8>, 4> mask_lut{{
  665. {},
  666. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  667. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  668. {0x7, 0xb, 0xd, 0xe, 0xf},
  669. }};
  670. std::size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
  671. index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
  672. u32 mask = mask_lut[index][component_mask_selector];
  673. // A mask of 0 means this instruction uses an unimplemented mask.
  674. ASSERT(mask != 0);
  675. return ((1ull << component) & mask) != 0;
  676. }
  677. } texs;
  678. union {
  679. BitField<49, 1, u64> nodep_flag;
  680. BitField<53, 4, u64> texture_info;
  681. TextureType GetTextureType() const {
  682. // The TLDS instruction has a weird encoding for the texture type.
  683. if (texture_info >= 0 && texture_info <= 1) {
  684. return TextureType::Texture1D;
  685. }
  686. if (texture_info == 2 || texture_info == 8 || texture_info == 12 ||
  687. (texture_info >= 4 && texture_info <= 6)) {
  688. return TextureType::Texture2D;
  689. }
  690. if (texture_info == 7) {
  691. return TextureType::Texture3D;
  692. }
  693. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  694. static_cast<u32>(texture_info.Value()));
  695. UNREACHABLE();
  696. }
  697. TextureProcessMode GetTextureProcessMode() const {
  698. if (texture_info == 1 || texture_info == 5 || texture_info == 12)
  699. return TextureProcessMode::LL;
  700. return TextureProcessMode::LZ;
  701. }
  702. bool UsesMiscMode(TextureMiscMode mode) const {
  703. switch (mode) {
  704. case TextureMiscMode::AOFFI:
  705. return texture_info == 12 || texture_info == 4;
  706. case TextureMiscMode::MZ:
  707. return texture_info == 5;
  708. case TextureMiscMode::NODEP:
  709. return nodep_flag != 0;
  710. default:
  711. break;
  712. }
  713. return false;
  714. }
  715. bool IsArrayTexture() const {
  716. // TEXS only supports Texture2D arrays.
  717. return texture_info == 8;
  718. }
  719. } tlds;
  720. union {
  721. BitField<20, 24, u64> target;
  722. BitField<5, 1, u64> constant_buffer;
  723. s32 GetBranchTarget() const {
  724. // Sign extend the branch target offset
  725. u32 mask = 1U << (24 - 1);
  726. u32 value = static_cast<u32>(target);
  727. // The branch offset is relative to the next instruction and is stored in bytes, so
  728. // divide it by the size of an instruction and add 1 to it.
  729. return static_cast<s32>((value ^ mask) - mask) / sizeof(Instruction) + 1;
  730. }
  731. } bra;
  732. union {
  733. BitField<20, 16, u64> imm20_16;
  734. BitField<36, 1, u64> product_shift_left;
  735. BitField<37, 1, u64> merge_37;
  736. BitField<48, 1, u64> sign_a;
  737. BitField<49, 1, u64> sign_b;
  738. BitField<50, 3, XmadMode> mode;
  739. BitField<52, 1, u64> high_b;
  740. BitField<53, 1, u64> high_a;
  741. BitField<56, 1, u64> merge_56;
  742. } xmad;
  743. union {
  744. BitField<20, 14, u64> offset;
  745. BitField<34, 5, u64> index;
  746. } cbuf34;
  747. union {
  748. BitField<20, 16, s64> offset;
  749. BitField<36, 5, u64> index;
  750. } cbuf36;
  751. BitField<61, 1, u64> is_b_imm;
  752. BitField<60, 1, u64> is_b_gpr;
  753. BitField<59, 1, u64> is_c_gpr;
  754. Attribute attribute;
  755. Sampler sampler;
  756. u64 value;
  757. };
  758. static_assert(sizeof(Instruction) == 0x8, "Incorrect structure size");
  759. static_assert(std::is_standard_layout_v<Instruction>, "Instruction is not standard layout");
  760. class OpCode {
  761. public:
  762. enum class Id {
  763. KIL,
  764. SSY,
  765. SYNC,
  766. DEPBAR,
  767. BFE_C,
  768. BFE_R,
  769. BFE_IMM,
  770. BRA,
  771. LD_A,
  772. LD_C,
  773. ST_A,
  774. LDG, // Load from global memory
  775. STG, // Store in global memory
  776. TEX,
  777. TXQ, // Texture Query
  778. TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
  779. TLDS, // Texture Load with scalar/non-vec4 source/destinations
  780. TLD4, // Texture Load 4
  781. TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations
  782. TMML_B, // Texture Mip Map Level
  783. TMML, // Texture Mip Map Level
  784. EXIT,
  785. IPA,
  786. FFMA_IMM, // Fused Multiply and Add
  787. FFMA_CR,
  788. FFMA_RC,
  789. FFMA_RR,
  790. FADD_C,
  791. FADD_R,
  792. FADD_IMM,
  793. FADD32I,
  794. FMUL_C,
  795. FMUL_R,
  796. FMUL_IMM,
  797. FMUL32_IMM,
  798. IADD_C,
  799. IADD_R,
  800. IADD_IMM,
  801. IADD3_C, // Add 3 Integers
  802. IADD3_R,
  803. IADD3_IMM,
  804. IADD32I,
  805. ISCADD_C, // Scale and Add
  806. ISCADD_R,
  807. ISCADD_IMM,
  808. LEA_R1,
  809. LEA_R2,
  810. LEA_RZ,
  811. LEA_IMM,
  812. LEA_HI,
  813. POPC_C,
  814. POPC_R,
  815. POPC_IMM,
  816. SEL_C,
  817. SEL_R,
  818. SEL_IMM,
  819. MUFU, // Multi-Function Operator
  820. RRO_C, // Range Reduction Operator
  821. RRO_R,
  822. RRO_IMM,
  823. F2F_C,
  824. F2F_R,
  825. F2F_IMM,
  826. F2I_C,
  827. F2I_R,
  828. F2I_IMM,
  829. I2F_C,
  830. I2F_R,
  831. I2F_IMM,
  832. I2I_C,
  833. I2I_R,
  834. I2I_IMM,
  835. LOP_C,
  836. LOP_R,
  837. LOP_IMM,
  838. LOP32I,
  839. LOP3_C,
  840. LOP3_R,
  841. LOP3_IMM,
  842. MOV_C,
  843. MOV_R,
  844. MOV_IMM,
  845. MOV32_IMM,
  846. SHL_C,
  847. SHL_R,
  848. SHL_IMM,
  849. SHR_C,
  850. SHR_R,
  851. SHR_IMM,
  852. FMNMX_C,
  853. FMNMX_R,
  854. FMNMX_IMM,
  855. IMNMX_C,
  856. IMNMX_R,
  857. IMNMX_IMM,
  858. FSETP_C, // Set Predicate
  859. FSETP_R,
  860. FSETP_IMM,
  861. FSET_C,
  862. FSET_R,
  863. FSET_IMM,
  864. ISETP_C,
  865. ISETP_IMM,
  866. ISETP_R,
  867. ISET_R,
  868. ISET_C,
  869. ISET_IMM,
  870. PSETP,
  871. PSET,
  872. XMAD_IMM,
  873. XMAD_CR,
  874. XMAD_RC,
  875. XMAD_RR,
  876. };
  877. enum class Type {
  878. Trivial,
  879. Arithmetic,
  880. ArithmeticImmediate,
  881. ArithmeticInteger,
  882. ArithmeticIntegerImmediate,
  883. Bfe,
  884. Shift,
  885. Ffma,
  886. Flow,
  887. Synch,
  888. Memory,
  889. FloatSet,
  890. FloatSetPredicate,
  891. IntegerSet,
  892. IntegerSetPredicate,
  893. PredicateSetPredicate,
  894. PredicateSetRegister,
  895. Conversion,
  896. Xmad,
  897. Unknown,
  898. };
  899. /// Returns whether an opcode has an execution predicate field or not (ie, whether it can be
  900. /// conditionally executed).
  901. static bool IsPredicatedInstruction(Id opcode) {
  902. // TODO(Subv): Add the rest of unpredicated instructions.
  903. return opcode != Id::SSY;
  904. }
  905. class Matcher {
  906. public:
  907. Matcher(const char* const name, u16 mask, u16 expected, OpCode::Id id, OpCode::Type type)
  908. : name{name}, mask{mask}, expected{expected}, id{id}, type{type} {}
  909. const char* GetName() const {
  910. return name;
  911. }
  912. u16 GetMask() const {
  913. return mask;
  914. }
  915. Id GetId() const {
  916. return id;
  917. }
  918. Type GetType() const {
  919. return type;
  920. }
  921. /**
  922. * Tests to see if the given instruction is the instruction this matcher represents.
  923. * @param instruction The instruction to test
  924. * @returns true if the given instruction matches.
  925. */
  926. bool Matches(u16 instruction) const {
  927. return (instruction & mask) == expected;
  928. }
  929. private:
  930. const char* name;
  931. u16 mask;
  932. u16 expected;
  933. Id id;
  934. Type type;
  935. };
  936. static boost::optional<const Matcher&> Decode(Instruction instr) {
  937. static const auto table{GetDecodeTable()};
  938. const auto matches_instruction = [instr](const auto& matcher) {
  939. return matcher.Matches(static_cast<u16>(instr.opcode));
  940. };
  941. auto iter = std::find_if(table.begin(), table.end(), matches_instruction);
  942. return iter != table.end() ? boost::optional<const Matcher&>(*iter) : boost::none;
  943. }
  944. private:
  945. struct Detail {
  946. private:
  947. static constexpr std::size_t opcode_bitsize = 16;
  948. /**
  949. * Generates the mask and the expected value after masking from a given bitstring.
  950. * A '0' in a bitstring indicates that a zero must be present at that bit position.
  951. * A '1' in a bitstring indicates that a one must be present at that bit position.
  952. */
  953. static auto GetMaskAndExpect(const char* const bitstring) {
  954. u16 mask = 0, expect = 0;
  955. for (std::size_t i = 0; i < opcode_bitsize; i++) {
  956. const std::size_t bit_position = opcode_bitsize - i - 1;
  957. switch (bitstring[i]) {
  958. case '0':
  959. mask |= 1 << bit_position;
  960. break;
  961. case '1':
  962. expect |= 1 << bit_position;
  963. mask |= 1 << bit_position;
  964. break;
  965. default:
  966. // Ignore
  967. break;
  968. }
  969. }
  970. return std::make_tuple(mask, expect);
  971. }
  972. public:
  973. /// Creates a matcher that can match and parse instructions based on bitstring.
  974. static auto GetMatcher(const char* const bitstring, OpCode::Id op, OpCode::Type type,
  975. const char* const name) {
  976. const auto mask_expect = GetMaskAndExpect(bitstring);
  977. return Matcher(name, std::get<0>(mask_expect), std::get<1>(mask_expect), op, type);
  978. }
  979. };
  980. static std::vector<Matcher> GetDecodeTable() {
  981. std::vector<Matcher> table = {
  982. #define INST(bitstring, op, type, name) Detail::GetMatcher(bitstring, op, type, name)
  983. INST("111000110011----", Id::KIL, Type::Flow, "KIL"),
  984. INST("111000101001----", Id::SSY, Type::Flow, "SSY"),
  985. INST("111000100100----", Id::BRA, Type::Flow, "BRA"),
  986. INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"),
  987. INST("1111000011111---", Id::SYNC, Type::Synch, "SYNC"),
  988. INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
  989. INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
  990. INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
  991. INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
  992. INST("1110111011011---", Id::STG, Type::Memory, "STG"),
  993. INST("110000----111---", Id::TEX, Type::Memory, "TEX"),
  994. INST("1101111101001---", Id::TXQ, Type::Memory, "TXQ"),
  995. INST("1101100---------", Id::TEXS, Type::Memory, "TEXS"),
  996. INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"),
  997. INST("110010----111---", Id::TLD4, Type::Memory, "TLD4"),
  998. INST("1101111100------", Id::TLD4S, Type::Memory, "TLD4S"),
  999. INST("110111110110----", Id::TMML_B, Type::Memory, "TMML_B"),
  1000. INST("1101111101011---", Id::TMML, Type::Memory, "TMML"),
  1001. INST("111000110000----", Id::EXIT, Type::Trivial, "EXIT"),
  1002. INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
  1003. INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
  1004. INST("010010011-------", Id::FFMA_CR, Type::Ffma, "FFMA_CR"),
  1005. INST("010100011-------", Id::FFMA_RC, Type::Ffma, "FFMA_RC"),
  1006. INST("010110011-------", Id::FFMA_RR, Type::Ffma, "FFMA_RR"),
  1007. INST("0100110001011---", Id::FADD_C, Type::Arithmetic, "FADD_C"),
  1008. INST("0101110001011---", Id::FADD_R, Type::Arithmetic, "FADD_R"),
  1009. INST("0011100-01011---", Id::FADD_IMM, Type::Arithmetic, "FADD_IMM"),
  1010. INST("000010----------", Id::FADD32I, Type::ArithmeticImmediate, "FADD32I"),
  1011. INST("0100110001101---", Id::FMUL_C, Type::Arithmetic, "FMUL_C"),
  1012. INST("0101110001101---", Id::FMUL_R, Type::Arithmetic, "FMUL_R"),
  1013. INST("0011100-01101---", Id::FMUL_IMM, Type::Arithmetic, "FMUL_IMM"),
  1014. INST("00011110--------", Id::FMUL32_IMM, Type::ArithmeticImmediate, "FMUL32_IMM"),
  1015. INST("0100110000010---", Id::IADD_C, Type::ArithmeticInteger, "IADD_C"),
  1016. INST("0101110000010---", Id::IADD_R, Type::ArithmeticInteger, "IADD_R"),
  1017. INST("0011100-00010---", Id::IADD_IMM, Type::ArithmeticInteger, "IADD_IMM"),
  1018. INST("010011001100----", Id::IADD3_C, Type::ArithmeticInteger, "IADD3_C"),
  1019. INST("010111001100----", Id::IADD3_R, Type::ArithmeticInteger, "IADD3_R"),
  1020. INST("0011100-1100----", Id::IADD3_IMM, Type::ArithmeticInteger, "IADD3_IMM"),
  1021. INST("0001110---------", Id::IADD32I, Type::ArithmeticIntegerImmediate, "IADD32I"),
  1022. INST("0100110000011---", Id::ISCADD_C, Type::ArithmeticInteger, "ISCADD_C"),
  1023. INST("0101110000011---", Id::ISCADD_R, Type::ArithmeticInteger, "ISCADD_R"),
  1024. INST("0011100-00011---", Id::ISCADD_IMM, Type::ArithmeticInteger, "ISCADD_IMM"),
  1025. INST("0100110000001---", Id::POPC_C, Type::ArithmeticInteger, "POPC_C"),
  1026. INST("0101110000001---", Id::POPC_R, Type::ArithmeticInteger, "POPC_R"),
  1027. INST("0011100-00001---", Id::POPC_IMM, Type::ArithmeticInteger, "POPC_IMM"),
  1028. INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"),
  1029. INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"),
  1030. INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"),
  1031. INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"),
  1032. INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"),
  1033. INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"),
  1034. INST("010010111101----", Id::LEA_RZ, Type::ArithmeticInteger, "LEA_RZ"),
  1035. INST("00011000--------", Id::LEA_HI, Type::ArithmeticInteger, "LEA_HI"),
  1036. INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"),
  1037. INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"),
  1038. INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"),
  1039. INST("0011100-10010---", Id::RRO_IMM, Type::Arithmetic, "RRO_IMM"),
  1040. INST("0100110010101---", Id::F2F_C, Type::Conversion, "F2F_C"),
  1041. INST("0101110010101---", Id::F2F_R, Type::Conversion, "F2F_R"),
  1042. INST("0011100-10101---", Id::F2F_IMM, Type::Conversion, "F2F_IMM"),
  1043. INST("0100110010110---", Id::F2I_C, Type::Conversion, "F2I_C"),
  1044. INST("0101110010110---", Id::F2I_R, Type::Conversion, "F2I_R"),
  1045. INST("0011100-10110---", Id::F2I_IMM, Type::Conversion, "F2I_IMM"),
  1046. INST("0100110010011---", Id::MOV_C, Type::Arithmetic, "MOV_C"),
  1047. INST("0101110010011---", Id::MOV_R, Type::Arithmetic, "MOV_R"),
  1048. INST("0011100-10011---", Id::MOV_IMM, Type::Arithmetic, "MOV_IMM"),
  1049. INST("000000010000----", Id::MOV32_IMM, Type::ArithmeticImmediate, "MOV32_IMM"),
  1050. INST("0100110001100---", Id::FMNMX_C, Type::Arithmetic, "FMNMX_C"),
  1051. INST("0101110001100---", Id::FMNMX_R, Type::Arithmetic, "FMNMX_R"),
  1052. INST("0011100-01100---", Id::FMNMX_IMM, Type::Arithmetic, "FMNMX_IMM"),
  1053. INST("0100110000100---", Id::IMNMX_C, Type::ArithmeticInteger, "IMNMX_C"),
  1054. INST("0101110000100---", Id::IMNMX_R, Type::ArithmeticInteger, "IMNMX_R"),
  1055. INST("0011100-00100---", Id::IMNMX_IMM, Type::ArithmeticInteger, "IMNMX_IMM"),
  1056. INST("0100110000000---", Id::BFE_C, Type::Bfe, "BFE_C"),
  1057. INST("0101110000000---", Id::BFE_R, Type::Bfe, "BFE_R"),
  1058. INST("0011100-00000---", Id::BFE_IMM, Type::Bfe, "BFE_IMM"),
  1059. INST("0100110001000---", Id::LOP_C, Type::ArithmeticInteger, "LOP_C"),
  1060. INST("0101110001000---", Id::LOP_R, Type::ArithmeticInteger, "LOP_R"),
  1061. INST("0011100001000---", Id::LOP_IMM, Type::ArithmeticInteger, "LOP_IMM"),
  1062. INST("000001----------", Id::LOP32I, Type::ArithmeticIntegerImmediate, "LOP32I"),
  1063. INST("0000001---------", Id::LOP3_C, Type::ArithmeticInteger, "LOP3_C"),
  1064. INST("0101101111100---", Id::LOP3_R, Type::ArithmeticInteger, "LOP3_R"),
  1065. INST("0011110---------", Id::LOP3_IMM, Type::ArithmeticInteger, "LOP3_IMM"),
  1066. INST("0100110001001---", Id::SHL_C, Type::Shift, "SHL_C"),
  1067. INST("0101110001001---", Id::SHL_R, Type::Shift, "SHL_R"),
  1068. INST("0011100-01001---", Id::SHL_IMM, Type::Shift, "SHL_IMM"),
  1069. INST("0100110000101---", Id::SHR_C, Type::Shift, "SHR_C"),
  1070. INST("0101110000101---", Id::SHR_R, Type::Shift, "SHR_R"),
  1071. INST("0011100-00101---", Id::SHR_IMM, Type::Shift, "SHR_IMM"),
  1072. INST("0100110011100---", Id::I2I_C, Type::Conversion, "I2I_C"),
  1073. INST("0101110011100---", Id::I2I_R, Type::Conversion, "I2I_R"),
  1074. INST("01110001-1000---", Id::I2I_IMM, Type::Conversion, "I2I_IMM"),
  1075. INST("0100110010111---", Id::I2F_C, Type::Conversion, "I2F_C"),
  1076. INST("0101110010111---", Id::I2F_R, Type::Conversion, "I2F_R"),
  1077. INST("0011100-10111---", Id::I2F_IMM, Type::Conversion, "I2F_IMM"),
  1078. INST("01011000--------", Id::FSET_R, Type::FloatSet, "FSET_R"),
  1079. INST("0100100---------", Id::FSET_C, Type::FloatSet, "FSET_C"),
  1080. INST("0011000---------", Id::FSET_IMM, Type::FloatSet, "FSET_IMM"),
  1081. INST("010010111011----", Id::FSETP_C, Type::FloatSetPredicate, "FSETP_C"),
  1082. INST("010110111011----", Id::FSETP_R, Type::FloatSetPredicate, "FSETP_R"),
  1083. INST("0011011-1011----", Id::FSETP_IMM, Type::FloatSetPredicate, "FSETP_IMM"),
  1084. INST("010010110110----", Id::ISETP_C, Type::IntegerSetPredicate, "ISETP_C"),
  1085. INST("010110110110----", Id::ISETP_R, Type::IntegerSetPredicate, "ISETP_R"),
  1086. INST("0011011-0110----", Id::ISETP_IMM, Type::IntegerSetPredicate, "ISETP_IMM"),
  1087. INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"),
  1088. INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"),
  1089. INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"),
  1090. INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"),
  1091. INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"),
  1092. INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"),
  1093. INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"),
  1094. INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"),
  1095. INST("0101101100------", Id::XMAD_RR, Type::Xmad, "XMAD_RR"),
  1096. };
  1097. #undef INST
  1098. std::stable_sort(table.begin(), table.end(), [](const auto& a, const auto& b) {
  1099. // If a matcher has more bits in its mask it is more specific, so it
  1100. // should come first.
  1101. return std::bitset<16>(a.GetMask()).count() > std::bitset<16>(b.GetMask()).count();
  1102. });
  1103. return table;
  1104. }
  1105. };
  1106. } // namespace Tegra::Shader