shader_bytecode.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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/bit_field.h"
  12. #include "common/common_types.h"
  13. namespace Tegra::Shader {
  14. struct Register {
  15. /// Number of registers
  16. static constexpr size_t NumRegisters = 256;
  17. /// Register 255 is special cased to always be 0
  18. static constexpr 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. union Attribute {
  52. Attribute() = default;
  53. constexpr explicit Attribute(u64 value) : value(value) {}
  54. enum class Index : u64 {
  55. Position = 7,
  56. Attribute_0 = 8,
  57. Attribute_31 = 39,
  58. // This attribute contains a tuple of (~, ~, InstanceId, VertexId) when inside a vertex
  59. // shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
  60. // shader.
  61. TessCoordInstanceIDVertexID = 47,
  62. };
  63. union {
  64. BitField<22, 2, u64> element;
  65. BitField<24, 6, Index> index;
  66. BitField<47, 3, u64> size;
  67. } fmt20;
  68. union {
  69. BitField<30, 2, u64> element;
  70. BitField<32, 6, Index> index;
  71. } fmt28;
  72. BitField<39, 8, u64> reg;
  73. u64 value{};
  74. };
  75. union Sampler {
  76. Sampler() = default;
  77. constexpr explicit Sampler(u64 value) : value(value) {}
  78. enum class Index : u64 {
  79. Sampler_0 = 8,
  80. };
  81. BitField<36, 13, Index> index;
  82. u64 value{};
  83. };
  84. } // namespace Tegra::Shader
  85. namespace std {
  86. // TODO(bunnei): The below is forbidden by the C++ standard, but works fine. See #330.
  87. template <>
  88. struct make_unsigned<Tegra::Shader::Attribute> {
  89. using type = Tegra::Shader::Attribute;
  90. };
  91. template <>
  92. struct make_unsigned<Tegra::Shader::Register> {
  93. using type = Tegra::Shader::Register;
  94. };
  95. } // namespace std
  96. namespace Tegra::Shader {
  97. enum class Pred : u64 {
  98. UnusedIndex = 0x7,
  99. NeverExecute = 0xF,
  100. };
  101. enum class PredCondition : u64 {
  102. LessThan = 1,
  103. Equal = 2,
  104. LessEqual = 3,
  105. GreaterThan = 4,
  106. NotEqual = 5,
  107. GreaterEqual = 6,
  108. LessThanWithNan = 9,
  109. NotEqualWithNan = 13,
  110. // TODO(Subv): Other condition types
  111. };
  112. enum class PredOperation : u64 {
  113. And = 0,
  114. Or = 1,
  115. Xor = 2,
  116. };
  117. enum class LogicOperation : u64 {
  118. And = 0,
  119. Or = 1,
  120. Xor = 2,
  121. PassB = 3,
  122. };
  123. enum class SubOp : u64 {
  124. Cos = 0x0,
  125. Sin = 0x1,
  126. Ex2 = 0x2,
  127. Lg2 = 0x3,
  128. Rcp = 0x4,
  129. Rsq = 0x5,
  130. Sqrt = 0x8,
  131. };
  132. enum class F2iRoundingOp : u64 {
  133. None = 0,
  134. Floor = 1,
  135. Ceil = 2,
  136. Trunc = 3,
  137. };
  138. enum class F2fRoundingOp : u64 {
  139. None = 0,
  140. Pass = 3,
  141. Round = 8,
  142. Floor = 9,
  143. Ceil = 10,
  144. Trunc = 11,
  145. };
  146. enum class UniformType : u64 {
  147. UnsignedByte = 0,
  148. SignedByte = 1,
  149. UnsignedShort = 2,
  150. SignedShort = 3,
  151. Single = 4,
  152. Double = 5,
  153. };
  154. enum class IMinMaxExchange : u64 {
  155. None = 0,
  156. XLo = 1,
  157. XMed = 2,
  158. XHi = 3,
  159. };
  160. enum class XmadMode : u64 {
  161. None = 0,
  162. CLo = 1,
  163. CHi = 2,
  164. CSfu = 3,
  165. CBcc = 4,
  166. };
  167. enum class FlowCondition : u64 {
  168. Always = 0xF,
  169. Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for?
  170. };
  171. union Instruction {
  172. Instruction& operator=(const Instruction& instr) {
  173. value = instr.value;
  174. return *this;
  175. }
  176. constexpr Instruction(u64 value) : value{value} {}
  177. BitField<0, 8, Register> gpr0;
  178. BitField<8, 8, Register> gpr8;
  179. union {
  180. BitField<16, 4, Pred> full_pred;
  181. BitField<16, 3, u64> pred_index;
  182. } pred;
  183. BitField<19, 1, u64> negate_pred;
  184. BitField<20, 8, Register> gpr20;
  185. BitField<20, 4, SubOp> sub_op;
  186. BitField<28, 8, Register> gpr28;
  187. BitField<39, 8, Register> gpr39;
  188. BitField<48, 16, u64> opcode;
  189. union {
  190. BitField<20, 19, u64> imm20_19;
  191. BitField<20, 32, s64> imm20_32;
  192. BitField<45, 1, u64> negate_b;
  193. BitField<46, 1, u64> abs_a;
  194. BitField<48, 1, u64> negate_a;
  195. BitField<49, 1, u64> abs_b;
  196. BitField<50, 1, u64> saturate_d;
  197. BitField<56, 1, u64> negate_imm;
  198. union {
  199. BitField<39, 3, u64> pred;
  200. BitField<42, 1, u64> negate_pred;
  201. } fmnmx;
  202. union {
  203. BitField<39, 1, u64> invert_a;
  204. BitField<40, 1, u64> invert_b;
  205. BitField<41, 2, LogicOperation> operation;
  206. BitField<44, 2, u64> unk44;
  207. BitField<48, 3, Pred> pred48;
  208. } lop;
  209. union {
  210. BitField<53, 2, LogicOperation> operation;
  211. BitField<55, 1, u64> invert_a;
  212. BitField<56, 1, u64> invert_b;
  213. } lop32i;
  214. u32 GetImm20_19() const {
  215. u32 imm{static_cast<u32>(imm20_19)};
  216. imm <<= 12;
  217. imm |= negate_imm ? 0x80000000 : 0;
  218. return imm;
  219. }
  220. u32 GetImm20_32() const {
  221. return static_cast<u32>(imm20_32);
  222. }
  223. s32 GetSignedImm20_20() const {
  224. u32 immediate = static_cast<u32>(imm20_19 | (negate_imm << 19));
  225. // Sign extend the 20-bit value.
  226. u32 mask = 1U << (20 - 1);
  227. return static_cast<s32>((immediate ^ mask) - mask);
  228. }
  229. } alu;
  230. union {
  231. BitField<48, 1, u64> is_signed;
  232. } shift;
  233. union {
  234. BitField<39, 5, u64> shift_amount;
  235. BitField<48, 1, u64> negate_b;
  236. BitField<49, 1, u64> negate_a;
  237. } alu_integer;
  238. union {
  239. BitField<39, 3, u64> pred;
  240. BitField<42, 1, u64> neg_pred;
  241. } sel;
  242. union {
  243. BitField<39, 3, u64> pred;
  244. BitField<42, 1, u64> negate_pred;
  245. BitField<43, 2, IMinMaxExchange> exchange;
  246. BitField<48, 1, u64> is_signed;
  247. } imnmx;
  248. union {
  249. BitField<54, 1, u64> saturate;
  250. BitField<56, 1, u64> negate_a;
  251. } iadd32i;
  252. union {
  253. BitField<53, 1, u64> negate_b;
  254. BitField<54, 1, u64> abs_a;
  255. BitField<56, 1, u64> negate_a;
  256. BitField<57, 1, u64> abs_b;
  257. } fadd32i;
  258. union {
  259. BitField<20, 8, u64> shift_position;
  260. BitField<28, 8, u64> shift_length;
  261. BitField<48, 1, u64> negate_b;
  262. BitField<49, 1, u64> negate_a;
  263. u64 GetLeftShiftValue() const {
  264. return 32 - (shift_position + shift_length);
  265. }
  266. } bfe;
  267. union {
  268. BitField<0, 5, FlowCondition> cond;
  269. } flow;
  270. union {
  271. BitField<48, 1, u64> negate_b;
  272. BitField<49, 1, u64> negate_c;
  273. } ffma;
  274. union {
  275. BitField<48, 3, UniformType> type;
  276. BitField<44, 2, u64> unknown;
  277. } ld_c;
  278. union {
  279. BitField<0, 3, u64> pred0;
  280. BitField<3, 3, u64> pred3;
  281. BitField<7, 1, u64> abs_a;
  282. BitField<39, 3, u64> pred39;
  283. BitField<42, 1, u64> neg_pred;
  284. BitField<43, 1, u64> neg_a;
  285. BitField<44, 1, u64> abs_b;
  286. BitField<45, 2, PredOperation> op;
  287. BitField<47, 1, u64> ftz;
  288. BitField<48, 4, PredCondition> cond;
  289. BitField<56, 1, u64> neg_b;
  290. } fsetp;
  291. union {
  292. BitField<0, 3, u64> pred0;
  293. BitField<3, 3, u64> pred3;
  294. BitField<39, 3, u64> pred39;
  295. BitField<42, 1, u64> neg_pred;
  296. BitField<45, 2, PredOperation> op;
  297. BitField<48, 1, u64> is_signed;
  298. BitField<49, 3, PredCondition> cond;
  299. } isetp;
  300. union {
  301. BitField<0, 3, u64> pred0;
  302. BitField<3, 3, u64> pred3;
  303. BitField<12, 3, u64> pred12;
  304. BitField<15, 1, u64> neg_pred12;
  305. BitField<24, 2, PredOperation> cond;
  306. BitField<29, 3, u64> pred29;
  307. BitField<32, 1, u64> neg_pred29;
  308. BitField<39, 3, u64> pred39;
  309. BitField<42, 1, u64> neg_pred39;
  310. BitField<45, 2, PredOperation> op;
  311. } psetp;
  312. union {
  313. BitField<39, 3, u64> pred39;
  314. BitField<42, 1, u64> neg_pred;
  315. BitField<43, 1, u64> neg_a;
  316. BitField<44, 1, u64> abs_b;
  317. BitField<45, 2, PredOperation> op;
  318. BitField<48, 4, PredCondition> cond;
  319. BitField<52, 1, u64> bf;
  320. BitField<53, 1, u64> neg_b;
  321. BitField<54, 1, u64> abs_a;
  322. BitField<55, 1, u64> ftz;
  323. BitField<56, 1, u64> neg_imm;
  324. } fset;
  325. union {
  326. BitField<39, 3, u64> pred39;
  327. BitField<42, 1, u64> neg_pred;
  328. BitField<44, 1, u64> bf;
  329. BitField<45, 2, PredOperation> op;
  330. BitField<48, 1, u64> is_signed;
  331. BitField<49, 3, PredCondition> cond;
  332. } iset;
  333. union {
  334. BitField<8, 2, Register::Size> dest_size;
  335. BitField<10, 2, Register::Size> src_size;
  336. BitField<12, 1, u64> is_output_signed;
  337. BitField<13, 1, u64> is_input_signed;
  338. BitField<41, 2, u64> selector;
  339. BitField<45, 1, u64> negate_a;
  340. BitField<49, 1, u64> abs_a;
  341. union {
  342. BitField<39, 2, F2iRoundingOp> rounding;
  343. } f2i;
  344. union {
  345. BitField<39, 4, F2fRoundingOp> rounding;
  346. } f2f;
  347. } conversion;
  348. union {
  349. BitField<31, 4, u64> component_mask;
  350. bool IsComponentEnabled(size_t component) const {
  351. return ((1ull << component) & component_mask) != 0;
  352. }
  353. } tex;
  354. union {
  355. BitField<50, 3, u64> component_mask_selector;
  356. BitField<0, 8, Register> gpr0;
  357. BitField<28, 8, Register> gpr28;
  358. bool HasTwoDestinations() const {
  359. return gpr28.Value() != Register::ZeroIndex;
  360. }
  361. bool IsComponentEnabled(size_t component) const {
  362. static constexpr std::array<std::array<u32, 8>, 4> mask_lut{
  363. {{},
  364. {0x1, 0x2, 0x4, 0x8, 0x3},
  365. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  366. {0x7, 0xb, 0xd, 0xe, 0xf}}};
  367. size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
  368. index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
  369. return ((1ull << component) & mask_lut[index][component_mask_selector]) != 0;
  370. }
  371. } texs;
  372. union {
  373. BitField<20, 24, u64> target;
  374. BitField<5, 1, u64> constant_buffer;
  375. s32 GetBranchTarget() const {
  376. // Sign extend the branch target offset
  377. u32 mask = 1U << (24 - 1);
  378. u32 value = static_cast<u32>(target);
  379. // The branch offset is relative to the next instruction and is stored in bytes, so
  380. // divide it by the size of an instruction and add 1 to it.
  381. return static_cast<s32>((value ^ mask) - mask) / sizeof(Instruction) + 1;
  382. }
  383. } bra;
  384. union {
  385. BitField<20, 16, u64> imm20_16;
  386. BitField<36, 1, u64> product_shift_left;
  387. BitField<37, 1, u64> merge_37;
  388. BitField<48, 1, u64> sign_a;
  389. BitField<49, 1, u64> sign_b;
  390. BitField<50, 3, XmadMode> mode;
  391. BitField<52, 1, u64> high_b;
  392. BitField<53, 1, u64> high_a;
  393. BitField<56, 1, u64> merge_56;
  394. } xmad;
  395. union {
  396. BitField<20, 14, u64> offset;
  397. BitField<34, 5, u64> index;
  398. } cbuf34;
  399. union {
  400. BitField<20, 16, s64> offset;
  401. BitField<36, 5, u64> index;
  402. } cbuf36;
  403. BitField<61, 1, u64> is_b_imm;
  404. BitField<60, 1, u64> is_b_gpr;
  405. BitField<59, 1, u64> is_c_gpr;
  406. Attribute attribute;
  407. Sampler sampler;
  408. u64 value;
  409. };
  410. static_assert(sizeof(Instruction) == 0x8, "Incorrect structure size");
  411. static_assert(std::is_standard_layout_v<Instruction>, "Instruction is not standard layout");
  412. class OpCode {
  413. public:
  414. enum class Id {
  415. KIL,
  416. SSY,
  417. SYNC,
  418. DEPBAR,
  419. BFE_C,
  420. BFE_R,
  421. BFE_IMM,
  422. BRA,
  423. LD_A,
  424. LD_C,
  425. ST_A,
  426. TEX,
  427. TEXQ, // Texture Query
  428. TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
  429. TLDS, // Texture Load with scalar/non-vec4 source/destinations
  430. EXIT,
  431. IPA,
  432. FFMA_IMM, // Fused Multiply and Add
  433. FFMA_CR,
  434. FFMA_RC,
  435. FFMA_RR,
  436. FADD_C,
  437. FADD_R,
  438. FADD_IMM,
  439. FADD32I,
  440. FMUL_C,
  441. FMUL_R,
  442. FMUL_IMM,
  443. FMUL32_IMM,
  444. IADD_C,
  445. IADD_R,
  446. IADD_IMM,
  447. IADD32I,
  448. ISCADD_C, // Scale and Add
  449. ISCADD_R,
  450. ISCADD_IMM,
  451. SEL_C,
  452. SEL_R,
  453. SEL_IMM,
  454. MUFU, // Multi-Function Operator
  455. RRO_C, // Range Reduction Operator
  456. RRO_R,
  457. RRO_IMM,
  458. F2F_C,
  459. F2F_R,
  460. F2F_IMM,
  461. F2I_C,
  462. F2I_R,
  463. F2I_IMM,
  464. I2F_C,
  465. I2F_R,
  466. I2F_IMM,
  467. I2I_C,
  468. I2I_R,
  469. I2I_IMM,
  470. LOP_C,
  471. LOP_R,
  472. LOP_IMM,
  473. LOP32I,
  474. MOV_C,
  475. MOV_R,
  476. MOV_IMM,
  477. MOV32_IMM,
  478. SHL_C,
  479. SHL_R,
  480. SHL_IMM,
  481. SHR_C,
  482. SHR_R,
  483. SHR_IMM,
  484. FMNMX_C,
  485. FMNMX_R,
  486. FMNMX_IMM,
  487. IMNMX_C,
  488. IMNMX_R,
  489. IMNMX_IMM,
  490. FSETP_C, // Set Predicate
  491. FSETP_R,
  492. FSETP_IMM,
  493. FSET_C,
  494. FSET_R,
  495. FSET_IMM,
  496. ISETP_C,
  497. ISETP_IMM,
  498. ISETP_R,
  499. ISET_R,
  500. ISET_C,
  501. ISET_IMM,
  502. PSETP,
  503. XMAD_IMM,
  504. XMAD_CR,
  505. XMAD_RC,
  506. XMAD_RR,
  507. };
  508. enum class Type {
  509. Trivial,
  510. Arithmetic,
  511. ArithmeticImmediate,
  512. ArithmeticInteger,
  513. ArithmeticIntegerImmediate,
  514. Bfe,
  515. Shift,
  516. Ffma,
  517. Flow,
  518. Synch,
  519. Memory,
  520. FloatSet,
  521. FloatSetPredicate,
  522. IntegerSet,
  523. IntegerSetPredicate,
  524. PredicateSetPredicate,
  525. Conversion,
  526. Xmad,
  527. Unknown,
  528. };
  529. /// Returns whether an opcode has an execution predicate field or not (ie, whether it can be
  530. /// conditionally executed).
  531. static bool IsPredicatedInstruction(Id opcode) {
  532. // TODO(Subv): Add the rest of unpredicated instructions.
  533. return opcode != Id::SSY;
  534. }
  535. class Matcher {
  536. public:
  537. Matcher(const char* const name, u16 mask, u16 expected, OpCode::Id id, OpCode::Type type)
  538. : name{name}, mask{mask}, expected{expected}, id{id}, type{type} {}
  539. const char* GetName() const {
  540. return name;
  541. }
  542. u16 GetMask() const {
  543. return mask;
  544. }
  545. Id GetId() const {
  546. return id;
  547. }
  548. Type GetType() const {
  549. return type;
  550. }
  551. /**
  552. * Tests to see if the given instruction is the instruction this matcher represents.
  553. * @param instruction The instruction to test
  554. * @returns true if the given instruction matches.
  555. */
  556. bool Matches(u16 instruction) const {
  557. return (instruction & mask) == expected;
  558. }
  559. private:
  560. const char* name;
  561. u16 mask;
  562. u16 expected;
  563. Id id;
  564. Type type;
  565. };
  566. static boost::optional<const Matcher&> Decode(Instruction instr) {
  567. static const auto table{GetDecodeTable()};
  568. const auto matches_instruction = [instr](const auto& matcher) {
  569. return matcher.Matches(static_cast<u16>(instr.opcode));
  570. };
  571. auto iter = std::find_if(table.begin(), table.end(), matches_instruction);
  572. return iter != table.end() ? boost::optional<const Matcher&>(*iter) : boost::none;
  573. }
  574. private:
  575. struct Detail {
  576. private:
  577. static constexpr size_t opcode_bitsize = 16;
  578. /**
  579. * Generates the mask and the expected value after masking from a given bitstring.
  580. * A '0' in a bitstring indicates that a zero must be present at that bit position.
  581. * A '1' in a bitstring indicates that a one must be present at that bit position.
  582. */
  583. static auto GetMaskAndExpect(const char* const bitstring) {
  584. u16 mask = 0, expect = 0;
  585. for (size_t i = 0; i < opcode_bitsize; i++) {
  586. const size_t bit_position = opcode_bitsize - i - 1;
  587. switch (bitstring[i]) {
  588. case '0':
  589. mask |= 1 << bit_position;
  590. break;
  591. case '1':
  592. expect |= 1 << bit_position;
  593. mask |= 1 << bit_position;
  594. break;
  595. default:
  596. // Ignore
  597. break;
  598. }
  599. }
  600. return std::make_tuple(mask, expect);
  601. }
  602. public:
  603. /// Creates a matcher that can match and parse instructions based on bitstring.
  604. static auto GetMatcher(const char* const bitstring, OpCode::Id op, OpCode::Type type,
  605. const char* const name) {
  606. const auto mask_expect = GetMaskAndExpect(bitstring);
  607. return Matcher(name, std::get<0>(mask_expect), std::get<1>(mask_expect), op, type);
  608. }
  609. };
  610. static std::vector<Matcher> GetDecodeTable() {
  611. std::vector<Matcher> table = {
  612. #define INST(bitstring, op, type, name) Detail::GetMatcher(bitstring, op, type, name)
  613. INST("111000110011----", Id::KIL, Type::Flow, "KIL"),
  614. INST("111000101001----", Id::SSY, Type::Flow, "SSY"),
  615. INST("111000100100----", Id::BRA, Type::Flow, "BRA"),
  616. INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"),
  617. INST("1111000011111---", Id::SYNC, Type::Synch, "SYNC"),
  618. INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
  619. INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
  620. INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
  621. INST("110000----111---", Id::TEX, Type::Memory, "TEX"),
  622. INST("1101111101001---", Id::TEXQ, Type::Memory, "TEXQ"),
  623. INST("1101100---------", Id::TEXS, Type::Memory, "TEXS"),
  624. INST("1101101---------", Id::TLDS, Type::Memory, "TLDS"),
  625. INST("111000110000----", Id::EXIT, Type::Trivial, "EXIT"),
  626. INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
  627. INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
  628. INST("010010011-------", Id::FFMA_CR, Type::Ffma, "FFMA_CR"),
  629. INST("010100011-------", Id::FFMA_RC, Type::Ffma, "FFMA_RC"),
  630. INST("010110011-------", Id::FFMA_RR, Type::Ffma, "FFMA_RR"),
  631. INST("0100110001011---", Id::FADD_C, Type::Arithmetic, "FADD_C"),
  632. INST("0101110001011---", Id::FADD_R, Type::Arithmetic, "FADD_R"),
  633. INST("0011100-01011---", Id::FADD_IMM, Type::Arithmetic, "FADD_IMM"),
  634. INST("000010----------", Id::FADD32I, Type::ArithmeticImmediate, "FADD32I"),
  635. INST("0100110001101---", Id::FMUL_C, Type::Arithmetic, "FMUL_C"),
  636. INST("0101110001101---", Id::FMUL_R, Type::Arithmetic, "FMUL_R"),
  637. INST("0011100-01101---", Id::FMUL_IMM, Type::Arithmetic, "FMUL_IMM"),
  638. INST("00011110--------", Id::FMUL32_IMM, Type::ArithmeticImmediate, "FMUL32_IMM"),
  639. INST("0100110000010---", Id::IADD_C, Type::ArithmeticInteger, "IADD_C"),
  640. INST("0101110000010---", Id::IADD_R, Type::ArithmeticInteger, "IADD_R"),
  641. INST("0011100-00010---", Id::IADD_IMM, Type::ArithmeticInteger, "IADD_IMM"),
  642. INST("0001110---------", Id::IADD32I, Type::ArithmeticIntegerImmediate, "IADD32I"),
  643. INST("0100110000011---", Id::ISCADD_C, Type::ArithmeticInteger, "ISCADD_C"),
  644. INST("0101110000011---", Id::ISCADD_R, Type::ArithmeticInteger, "ISCADD_R"),
  645. INST("0011100-00011---", Id::ISCADD_IMM, Type::ArithmeticInteger, "ISCADD_IMM"),
  646. INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"),
  647. INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"),
  648. INST("0011100010100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"),
  649. INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"),
  650. INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"),
  651. INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"),
  652. INST("0011100-10010---", Id::RRO_IMM, Type::Arithmetic, "RRO_IMM"),
  653. INST("0100110010101---", Id::F2F_C, Type::Conversion, "F2F_C"),
  654. INST("0101110010101---", Id::F2F_R, Type::Conversion, "F2F_R"),
  655. INST("0011100-10101---", Id::F2F_IMM, Type::Conversion, "F2F_IMM"),
  656. INST("0100110010110---", Id::F2I_C, Type::Conversion, "F2I_C"),
  657. INST("0101110010110---", Id::F2I_R, Type::Conversion, "F2I_R"),
  658. INST("0011100-10110---", Id::F2I_IMM, Type::Conversion, "F2I_IMM"),
  659. INST("0100110010011---", Id::MOV_C, Type::Arithmetic, "MOV_C"),
  660. INST("0101110010011---", Id::MOV_R, Type::Arithmetic, "MOV_R"),
  661. INST("0011100-10011---", Id::MOV_IMM, Type::Arithmetic, "MOV_IMM"),
  662. INST("000000010000----", Id::MOV32_IMM, Type::ArithmeticImmediate, "MOV32_IMM"),
  663. INST("0100110001100---", Id::FMNMX_C, Type::Arithmetic, "FMNMX_C"),
  664. INST("0101110001100---", Id::FMNMX_R, Type::Arithmetic, "FMNMX_R"),
  665. INST("0011100-01100---", Id::FMNMX_IMM, Type::Arithmetic, "FMNMX_IMM"),
  666. INST("0100110000100---", Id::IMNMX_C, Type::ArithmeticInteger, "IMNMX_C"),
  667. INST("0101110000100---", Id::IMNMX_R, Type::ArithmeticInteger, "IMNMX_R"),
  668. INST("0011100-00100---", Id::IMNMX_IMM, Type::ArithmeticInteger, "IMNMX_IMM"),
  669. INST("0100110000000---", Id::BFE_C, Type::Bfe, "BFE_C"),
  670. INST("0101110000000---", Id::BFE_R, Type::Bfe, "BFE_R"),
  671. INST("0011100-00000---", Id::BFE_IMM, Type::Bfe, "BFE_IMM"),
  672. INST("0100110001000---", Id::LOP_C, Type::ArithmeticInteger, "LOP_C"),
  673. INST("0101110001000---", Id::LOP_R, Type::ArithmeticInteger, "LOP_R"),
  674. INST("0011100001000---", Id::LOP_IMM, Type::ArithmeticInteger, "LOP_IMM"),
  675. INST("000001----------", Id::LOP32I, Type::ArithmeticIntegerImmediate, "LOP32I"),
  676. INST("0100110001001---", Id::SHL_C, Type::Shift, "SHL_C"),
  677. INST("0101110001001---", Id::SHL_R, Type::Shift, "SHL_R"),
  678. INST("0011100-01001---", Id::SHL_IMM, Type::Shift, "SHL_IMM"),
  679. INST("0100110000101---", Id::SHR_C, Type::Shift, "SHR_C"),
  680. INST("0101110000101---", Id::SHR_R, Type::Shift, "SHR_R"),
  681. INST("0011100-00101---", Id::SHR_IMM, Type::Shift, "SHR_IMM"),
  682. INST("0100110011100---", Id::I2I_C, Type::Conversion, "I2I_C"),
  683. INST("0101110011100---", Id::I2I_R, Type::Conversion, "I2I_R"),
  684. INST("01110001-1000---", Id::I2I_IMM, Type::Conversion, "I2I_IMM"),
  685. INST("0100110010111---", Id::I2F_C, Type::Conversion, "I2F_C"),
  686. INST("0101110010111---", Id::I2F_R, Type::Conversion, "I2F_R"),
  687. INST("0011100-10111---", Id::I2F_IMM, Type::Conversion, "I2F_IMM"),
  688. INST("01011000--------", Id::FSET_R, Type::FloatSet, "FSET_R"),
  689. INST("0100100---------", Id::FSET_C, Type::FloatSet, "FSET_C"),
  690. INST("0011000---------", Id::FSET_IMM, Type::FloatSet, "FSET_IMM"),
  691. INST("010010111011----", Id::FSETP_C, Type::FloatSetPredicate, "FSETP_C"),
  692. INST("010110111011----", Id::FSETP_R, Type::FloatSetPredicate, "FSETP_R"),
  693. INST("0011011-1011----", Id::FSETP_IMM, Type::FloatSetPredicate, "FSETP_IMM"),
  694. INST("010010110110----", Id::ISETP_C, Type::IntegerSetPredicate, "ISETP_C"),
  695. INST("010110110110----", Id::ISETP_R, Type::IntegerSetPredicate, "ISETP_R"),
  696. INST("0011011-0110----", Id::ISETP_IMM, Type::IntegerSetPredicate, "ISETP_IMM"),
  697. INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"),
  698. INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"),
  699. INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"),
  700. INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"),
  701. INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"),
  702. INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"),
  703. INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"),
  704. INST("0101101100------", Id::XMAD_RR, Type::Xmad, "XMAD_RR"),
  705. };
  706. #undef INST
  707. std::stable_sort(table.begin(), table.end(), [](const auto& a, const auto& b) {
  708. // If a matcher has more bits in its mask it is more specific, so it
  709. // should come first.
  710. return std::bitset<16>(a.GetMask()).count() > std::bitset<16>(b.GetMask()).count();
  711. });
  712. return table;
  713. }
  714. };
  715. } // namespace Tegra::Shader