shader_bytecode.h 25 KB

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