shader_bytecode.h 24 KB

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