shader_bytecode.h 21 KB

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