shader_bytecode.h 24 KB

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