shader_bytecode.h 23 KB

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