shader_bytecode.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  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 <array>
  6. #include <bitset>
  7. #include <optional>
  8. #include <tuple>
  9. #include <vector>
  10. #include "common/assert.h"
  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 std::size_t NumRegisters = 256;
  17. /// Register 255 is special cased to always be 0
  18. static constexpr std::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. enum class AttributeSize : u64 {
  52. Word = 0,
  53. DoubleWord = 1,
  54. TripleWord = 2,
  55. QuadWord = 3,
  56. };
  57. union Attribute {
  58. Attribute() = default;
  59. constexpr explicit Attribute(u64 value) : value(value) {}
  60. enum class Index : u64 {
  61. PointSize = 6,
  62. Position = 7,
  63. Attribute_0 = 8,
  64. Attribute_31 = 39,
  65. ClipDistances0123 = 44,
  66. ClipDistances4567 = 45,
  67. PointCoord = 46,
  68. // This attribute contains a tuple of (~, ~, InstanceId, VertexId) when inside a vertex
  69. // shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
  70. // shader.
  71. TessCoordInstanceIDVertexID = 47,
  72. // This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment
  73. // shader. It is unknown what the other values contain.
  74. FrontFacing = 63,
  75. };
  76. union {
  77. BitField<20, 10, u64> immediate;
  78. BitField<22, 2, u64> element;
  79. BitField<24, 6, Index> index;
  80. BitField<47, 3, AttributeSize> size;
  81. bool IsPhysical() const {
  82. return element == 0 && static_cast<u64>(index.Value()) == 0;
  83. }
  84. } fmt20;
  85. union {
  86. BitField<30, 2, u64> element;
  87. BitField<32, 6, Index> index;
  88. } fmt28;
  89. BitField<39, 8, u64> reg;
  90. u64 value{};
  91. };
  92. union Sampler {
  93. Sampler() = default;
  94. constexpr explicit Sampler(u64 value) : value(value) {}
  95. enum class Index : u64 {
  96. Sampler_0 = 8,
  97. };
  98. BitField<36, 13, Index> index;
  99. u64 value{};
  100. };
  101. union Image {
  102. Image() = default;
  103. constexpr explicit Image(u64 value) : value{value} {}
  104. BitField<36, 13, u64> index;
  105. u64 value;
  106. };
  107. } // namespace Tegra::Shader
  108. namespace std {
  109. // TODO(bunnei): The below is forbidden by the C++ standard, but works fine. See #330.
  110. template <>
  111. struct make_unsigned<Tegra::Shader::Attribute> {
  112. using type = Tegra::Shader::Attribute;
  113. };
  114. template <>
  115. struct make_unsigned<Tegra::Shader::Register> {
  116. using type = Tegra::Shader::Register;
  117. };
  118. } // namespace std
  119. namespace Tegra::Shader {
  120. enum class Pred : u64 {
  121. UnusedIndex = 0x7,
  122. NeverExecute = 0xF,
  123. };
  124. enum class PredCondition : u64 {
  125. LessThan = 1,
  126. Equal = 2,
  127. LessEqual = 3,
  128. GreaterThan = 4,
  129. NotEqual = 5,
  130. GreaterEqual = 6,
  131. LessThanWithNan = 9,
  132. LessEqualWithNan = 11,
  133. GreaterThanWithNan = 12,
  134. NotEqualWithNan = 13,
  135. GreaterEqualWithNan = 14,
  136. // TODO(Subv): Other condition types
  137. };
  138. enum class PredOperation : u64 {
  139. And = 0,
  140. Or = 1,
  141. Xor = 2,
  142. };
  143. enum class LogicOperation : u64 {
  144. And = 0,
  145. Or = 1,
  146. Xor = 2,
  147. PassB = 3,
  148. };
  149. enum class SubOp : u64 {
  150. Cos = 0x0,
  151. Sin = 0x1,
  152. Ex2 = 0x2,
  153. Lg2 = 0x3,
  154. Rcp = 0x4,
  155. Rsq = 0x5,
  156. Sqrt = 0x8,
  157. };
  158. enum class F2iRoundingOp : u64 {
  159. RoundEven = 0,
  160. Floor = 1,
  161. Ceil = 2,
  162. Trunc = 3,
  163. };
  164. enum class F2fRoundingOp : u64 {
  165. None = 0,
  166. Pass = 3,
  167. Round = 8,
  168. Floor = 9,
  169. Ceil = 10,
  170. Trunc = 11,
  171. };
  172. enum class UniformType : u64 {
  173. UnsignedByte = 0,
  174. SignedByte = 1,
  175. UnsignedShort = 2,
  176. SignedShort = 3,
  177. Single = 4,
  178. Double = 5,
  179. Quad = 6,
  180. UnsignedQuad = 7,
  181. };
  182. enum class StoreType : u64 {
  183. Unsigned8 = 0,
  184. Signed8 = 1,
  185. Unsigned16 = 2,
  186. Signed16 = 3,
  187. Bits32 = 4,
  188. Bits64 = 5,
  189. Bits128 = 6,
  190. };
  191. enum class IMinMaxExchange : u64 {
  192. None = 0,
  193. XLo = 1,
  194. XMed = 2,
  195. XHi = 3,
  196. };
  197. enum class VideoType : u64 {
  198. Size16_Low = 0,
  199. Size16_High = 1,
  200. Size32 = 2,
  201. Invalid = 3,
  202. };
  203. enum class VmadShr : u64 {
  204. Shr7 = 1,
  205. Shr15 = 2,
  206. };
  207. enum class XmadMode : u64 {
  208. None = 0,
  209. CLo = 1,
  210. CHi = 2,
  211. CSfu = 3,
  212. CBcc = 4,
  213. };
  214. enum class IAdd3Mode : u64 {
  215. None = 0,
  216. RightShift = 1,
  217. LeftShift = 2,
  218. };
  219. enum class IAdd3Height : u64 {
  220. None = 0,
  221. LowerHalfWord = 1,
  222. UpperHalfWord = 2,
  223. };
  224. enum class FlowCondition : u64 {
  225. Always = 0xF,
  226. Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for?
  227. };
  228. enum class ConditionCode : u64 {
  229. F = 0,
  230. LT = 1,
  231. EQ = 2,
  232. LE = 3,
  233. GT = 4,
  234. NE = 5,
  235. GE = 6,
  236. Num = 7,
  237. Nan = 8,
  238. LTU = 9,
  239. EQU = 10,
  240. LEU = 11,
  241. GTU = 12,
  242. NEU = 13,
  243. GEU = 14,
  244. T = 15,
  245. OFF = 16,
  246. LO = 17,
  247. SFF = 18,
  248. LS = 19,
  249. HI = 20,
  250. SFT = 21,
  251. HS = 22,
  252. OFT = 23,
  253. CSM_TA = 24,
  254. CSM_TR = 25,
  255. CSM_MX = 26,
  256. FCSM_TA = 27,
  257. FCSM_TR = 28,
  258. FCSM_MX = 29,
  259. RLE = 30,
  260. RGT = 31,
  261. };
  262. enum class PredicateResultMode : u64 {
  263. None = 0x0,
  264. NotZero = 0x3,
  265. };
  266. enum class TextureType : u64 {
  267. Texture1D = 0,
  268. Texture2D = 1,
  269. Texture3D = 2,
  270. TextureCube = 3,
  271. };
  272. enum class TextureQueryType : u64 {
  273. Dimension = 1,
  274. TextureType = 2,
  275. SamplePosition = 5,
  276. Filter = 16,
  277. LevelOfDetail = 18,
  278. Wrap = 20,
  279. BorderColor = 22,
  280. };
  281. enum class TextureProcessMode : u64 {
  282. None = 0,
  283. LZ = 1, // Load LOD of zero.
  284. LB = 2, // Load Bias.
  285. LL = 3, // Load LOD.
  286. LBA = 6, // Load Bias. The A is unknown, does not appear to differ with LB.
  287. LLA = 7 // Load LOD. The A is unknown, does not appear to differ with LL.
  288. };
  289. enum class TextureMiscMode : u64 {
  290. DC,
  291. AOFFI, // Uses Offset
  292. NDV,
  293. NODEP,
  294. MZ,
  295. PTP,
  296. };
  297. enum class SurfaceDataMode : u64 {
  298. P = 0,
  299. D_BA = 1,
  300. };
  301. enum class OutOfBoundsStore : u64 {
  302. Ignore = 0,
  303. Clamp = 1,
  304. Trap = 2,
  305. };
  306. enum class ImageType : u64 {
  307. Texture1D = 0,
  308. TextureBuffer = 1,
  309. Texture1DArray = 2,
  310. Texture2D = 3,
  311. Texture2DArray = 4,
  312. Texture3D = 5,
  313. };
  314. enum class IsberdMode : u64 {
  315. None = 0,
  316. Patch = 1,
  317. Prim = 2,
  318. Attr = 3,
  319. };
  320. enum class IsberdShift : u64 { None = 0, U16 = 1, B32 = 2 };
  321. enum class HalfType : u64 {
  322. H0_H1 = 0,
  323. F32 = 1,
  324. H0_H0 = 2,
  325. H1_H1 = 3,
  326. };
  327. enum class HalfMerge : u64 {
  328. H0_H1 = 0,
  329. F32 = 1,
  330. Mrg_H0 = 2,
  331. Mrg_H1 = 3,
  332. };
  333. enum class HalfPrecision : u64 {
  334. None = 0,
  335. FTZ = 1,
  336. FMZ = 2,
  337. };
  338. enum class R2pMode : u64 {
  339. Pr = 0,
  340. Cc = 1,
  341. };
  342. enum class IpaInterpMode : u64 {
  343. Pass = 0,
  344. Multiply = 1,
  345. Constant = 2,
  346. Sc = 3,
  347. };
  348. enum class IpaSampleMode : u64 {
  349. Default = 0,
  350. Centroid = 1,
  351. Offset = 2,
  352. };
  353. enum class LmemLoadCacheManagement : u64 {
  354. Default = 0,
  355. LU = 1,
  356. CI = 2,
  357. CV = 3,
  358. };
  359. enum class StoreCacheManagement : u64 {
  360. Default = 0,
  361. CG = 1,
  362. CS = 2,
  363. WT = 3,
  364. };
  365. struct IpaMode {
  366. IpaInterpMode interpolation_mode;
  367. IpaSampleMode sampling_mode;
  368. bool operator==(const IpaMode& a) const {
  369. return std::tie(interpolation_mode, sampling_mode) ==
  370. std::tie(a.interpolation_mode, a.sampling_mode);
  371. }
  372. bool operator!=(const IpaMode& a) const {
  373. return !operator==(a);
  374. }
  375. bool operator<(const IpaMode& a) const {
  376. return std::tie(interpolation_mode, sampling_mode) <
  377. std::tie(a.interpolation_mode, a.sampling_mode);
  378. }
  379. };
  380. enum class SystemVariable : u64 {
  381. LaneId = 0x00,
  382. VirtCfg = 0x02,
  383. VirtId = 0x03,
  384. Pm0 = 0x04,
  385. Pm1 = 0x05,
  386. Pm2 = 0x06,
  387. Pm3 = 0x07,
  388. Pm4 = 0x08,
  389. Pm5 = 0x09,
  390. Pm6 = 0x0a,
  391. Pm7 = 0x0b,
  392. OrderingTicket = 0x0f,
  393. PrimType = 0x10,
  394. InvocationId = 0x11,
  395. Ydirection = 0x12,
  396. ThreadKill = 0x13,
  397. ShaderType = 0x14,
  398. DirectBeWriteAddressLow = 0x15,
  399. DirectBeWriteAddressHigh = 0x16,
  400. DirectBeWriteEnabled = 0x17,
  401. MachineId0 = 0x18,
  402. MachineId1 = 0x19,
  403. MachineId2 = 0x1a,
  404. MachineId3 = 0x1b,
  405. Affinity = 0x1c,
  406. InvocationInfo = 0x1d,
  407. WscaleFactorXY = 0x1e,
  408. WscaleFactorZ = 0x1f,
  409. Tid = 0x20,
  410. TidX = 0x21,
  411. TidY = 0x22,
  412. TidZ = 0x23,
  413. CtaParam = 0x24,
  414. CtaIdX = 0x25,
  415. CtaIdY = 0x26,
  416. CtaIdZ = 0x27,
  417. NtId = 0x28,
  418. CirQueueIncrMinusOne = 0x29,
  419. Nlatc = 0x2a,
  420. SmSpaVersion = 0x2c,
  421. MultiPassShaderInfo = 0x2d,
  422. LwinHi = 0x2e,
  423. SwinHi = 0x2f,
  424. SwinLo = 0x30,
  425. SwinSz = 0x31,
  426. SmemSz = 0x32,
  427. SmemBanks = 0x33,
  428. LwinLo = 0x34,
  429. LwinSz = 0x35,
  430. LmemLosz = 0x36,
  431. LmemHioff = 0x37,
  432. EqMask = 0x38,
  433. LtMask = 0x39,
  434. LeMask = 0x3a,
  435. GtMask = 0x3b,
  436. GeMask = 0x3c,
  437. RegAlloc = 0x3d,
  438. CtxAddr = 0x3e, // .fmask = F_SM50
  439. BarrierAlloc = 0x3e, // .fmask = F_SM60
  440. GlobalErrorStatus = 0x40,
  441. WarpErrorStatus = 0x42,
  442. WarpErrorStatusClear = 0x43,
  443. PmHi0 = 0x48,
  444. PmHi1 = 0x49,
  445. PmHi2 = 0x4a,
  446. PmHi3 = 0x4b,
  447. PmHi4 = 0x4c,
  448. PmHi5 = 0x4d,
  449. PmHi6 = 0x4e,
  450. PmHi7 = 0x4f,
  451. ClockLo = 0x50,
  452. ClockHi = 0x51,
  453. GlobalTimerLo = 0x52,
  454. GlobalTimerHi = 0x53,
  455. HwTaskId = 0x60,
  456. CircularQueueEntryIndex = 0x61,
  457. CircularQueueEntryAddressLow = 0x62,
  458. CircularQueueEntryAddressHigh = 0x63,
  459. };
  460. enum class PhysicalAttributeDirection : u64 {
  461. Input = 0,
  462. Output = 1,
  463. };
  464. union Instruction {
  465. Instruction& operator=(const Instruction& instr) {
  466. value = instr.value;
  467. return *this;
  468. }
  469. constexpr Instruction(u64 value) : value{value} {}
  470. BitField<0, 8, Register> gpr0;
  471. BitField<8, 8, Register> gpr8;
  472. union {
  473. BitField<16, 4, Pred> full_pred;
  474. BitField<16, 3, u64> pred_index;
  475. } pred;
  476. BitField<19, 1, u64> negate_pred;
  477. BitField<20, 8, Register> gpr20;
  478. BitField<20, 4, SubOp> sub_op;
  479. BitField<28, 8, Register> gpr28;
  480. BitField<39, 8, Register> gpr39;
  481. BitField<48, 16, u64> opcode;
  482. union {
  483. BitField<8, 8, Register> gpr;
  484. BitField<20, 24, s64> offset;
  485. } gmem;
  486. union {
  487. BitField<20, 16, u64> imm20_16;
  488. BitField<20, 19, u64> imm20_19;
  489. BitField<20, 32, s64> imm20_32;
  490. BitField<45, 1, u64> negate_b;
  491. BitField<46, 1, u64> abs_a;
  492. BitField<48, 1, u64> negate_a;
  493. BitField<49, 1, u64> abs_b;
  494. BitField<50, 1, u64> saturate_d;
  495. BitField<56, 1, u64> negate_imm;
  496. union {
  497. BitField<39, 3, u64> pred;
  498. BitField<42, 1, u64> negate_pred;
  499. } fmnmx;
  500. union {
  501. BitField<39, 1, u64> invert_a;
  502. BitField<40, 1, u64> invert_b;
  503. BitField<41, 2, LogicOperation> operation;
  504. BitField<44, 2, PredicateResultMode> pred_result_mode;
  505. BitField<48, 3, Pred> pred48;
  506. } lop;
  507. union {
  508. BitField<53, 2, LogicOperation> operation;
  509. BitField<55, 1, u64> invert_a;
  510. BitField<56, 1, u64> invert_b;
  511. } lop32i;
  512. union {
  513. BitField<28, 8, u64> imm_lut28;
  514. BitField<48, 8, u64> imm_lut48;
  515. u32 GetImmLut28() const {
  516. return static_cast<u32>(imm_lut28);
  517. }
  518. u32 GetImmLut48() const {
  519. return static_cast<u32>(imm_lut48);
  520. }
  521. } lop3;
  522. u16 GetImm20_16() const {
  523. return static_cast<u16>(imm20_16);
  524. }
  525. u32 GetImm20_19() const {
  526. u32 imm{static_cast<u32>(imm20_19)};
  527. imm <<= 12;
  528. imm |= negate_imm ? 0x80000000 : 0;
  529. return imm;
  530. }
  531. u32 GetImm20_32() const {
  532. return static_cast<u32>(imm20_32);
  533. }
  534. s32 GetSignedImm20_20() const {
  535. u32 immediate = static_cast<u32>(imm20_19 | (negate_imm << 19));
  536. // Sign extend the 20-bit value.
  537. u32 mask = 1U << (20 - 1);
  538. return static_cast<s32>((immediate ^ mask) - mask);
  539. }
  540. } alu;
  541. union {
  542. BitField<38, 1, u64> idx;
  543. BitField<51, 1, u64> saturate;
  544. BitField<52, 2, IpaSampleMode> sample_mode;
  545. BitField<54, 2, IpaInterpMode> interp_mode;
  546. } ipa;
  547. union {
  548. BitField<39, 2, u64> tab5cb8_2;
  549. BitField<41, 3, u64> postfactor;
  550. BitField<44, 2, u64> tab5c68_0;
  551. BitField<48, 1, u64> negate_b;
  552. } fmul;
  553. union {
  554. BitField<55, 1, u64> saturate;
  555. } fmul32;
  556. union {
  557. BitField<52, 1, u64> generates_cc;
  558. } op_32;
  559. union {
  560. BitField<48, 1, u64> is_signed;
  561. } shift;
  562. union {
  563. BitField<39, 5, u64> shift_amount;
  564. BitField<48, 1, u64> negate_b;
  565. BitField<49, 1, u64> negate_a;
  566. } alu_integer;
  567. union {
  568. BitField<39, 1, u64> ftz;
  569. BitField<32, 1, u64> saturate;
  570. BitField<49, 2, HalfMerge> merge;
  571. BitField<43, 1, u64> negate_a;
  572. BitField<44, 1, u64> abs_a;
  573. BitField<47, 2, HalfType> type_a;
  574. BitField<31, 1, u64> negate_b;
  575. BitField<30, 1, u64> abs_b;
  576. BitField<28, 2, HalfType> type_b;
  577. BitField<35, 2, HalfType> type_c;
  578. } alu_half;
  579. union {
  580. BitField<39, 2, HalfPrecision> precision;
  581. BitField<39, 1, u64> ftz;
  582. BitField<52, 1, u64> saturate;
  583. BitField<49, 2, HalfMerge> merge;
  584. BitField<43, 1, u64> negate_a;
  585. BitField<44, 1, u64> abs_a;
  586. BitField<47, 2, HalfType> type_a;
  587. } alu_half_imm;
  588. union {
  589. BitField<29, 1, u64> first_negate;
  590. BitField<20, 9, u64> first;
  591. BitField<56, 1, u64> second_negate;
  592. BitField<30, 9, u64> second;
  593. u32 PackImmediates() const {
  594. // Immediates are half floats shifted.
  595. constexpr u32 imm_shift = 6;
  596. return static_cast<u32>((first << imm_shift) | (second << (16 + imm_shift)));
  597. }
  598. } half_imm;
  599. union {
  600. union {
  601. BitField<37, 2, HalfPrecision> precision;
  602. BitField<32, 1, u64> saturate;
  603. BitField<31, 1, u64> negate_b;
  604. BitField<30, 1, u64> negate_c;
  605. BitField<35, 2, HalfType> type_c;
  606. } rr;
  607. BitField<57, 2, HalfPrecision> precision;
  608. BitField<52, 1, u64> saturate;
  609. BitField<49, 2, HalfMerge> merge;
  610. BitField<47, 2, HalfType> type_a;
  611. BitField<56, 1, u64> negate_b;
  612. BitField<28, 2, HalfType> type_b;
  613. BitField<51, 1, u64> negate_c;
  614. BitField<53, 2, HalfType> type_reg39;
  615. } hfma2;
  616. union {
  617. BitField<40, 1, u64> invert;
  618. } popc;
  619. union {
  620. BitField<39, 3, u64> pred;
  621. BitField<42, 1, u64> neg_pred;
  622. } sel;
  623. union {
  624. BitField<39, 3, u64> pred;
  625. BitField<42, 1, u64> negate_pred;
  626. BitField<43, 2, IMinMaxExchange> exchange;
  627. BitField<48, 1, u64> is_signed;
  628. } imnmx;
  629. union {
  630. BitField<31, 2, IAdd3Height> height_c;
  631. BitField<33, 2, IAdd3Height> height_b;
  632. BitField<35, 2, IAdd3Height> height_a;
  633. BitField<37, 2, IAdd3Mode> mode;
  634. BitField<49, 1, u64> neg_c;
  635. BitField<50, 1, u64> neg_b;
  636. BitField<51, 1, u64> neg_a;
  637. } iadd3;
  638. union {
  639. BitField<54, 1, u64> saturate;
  640. BitField<56, 1, u64> negate_a;
  641. } iadd32i;
  642. union {
  643. BitField<53, 1, u64> negate_b;
  644. BitField<54, 1, u64> abs_a;
  645. BitField<56, 1, u64> negate_a;
  646. BitField<57, 1, u64> abs_b;
  647. } fadd32i;
  648. union {
  649. BitField<20, 8, u64> shift_position;
  650. BitField<28, 8, u64> shift_length;
  651. BitField<48, 1, u64> negate_b;
  652. BitField<49, 1, u64> negate_a;
  653. u64 GetLeftShiftValue() const {
  654. return 32 - (shift_position + shift_length);
  655. }
  656. } bfe;
  657. union {
  658. BitField<48, 3, u64> pred48;
  659. union {
  660. BitField<20, 20, u64> entry_a;
  661. BitField<39, 5, u64> entry_b;
  662. BitField<45, 1, u64> neg;
  663. BitField<46, 1, u64> uses_cc;
  664. } imm;
  665. union {
  666. BitField<20, 14, u64> cb_index;
  667. BitField<34, 5, u64> cb_offset;
  668. BitField<56, 1, u64> neg;
  669. BitField<57, 1, u64> uses_cc;
  670. } hi;
  671. union {
  672. BitField<20, 14, u64> cb_index;
  673. BitField<34, 5, u64> cb_offset;
  674. BitField<39, 5, u64> entry_a;
  675. BitField<45, 1, u64> neg;
  676. BitField<46, 1, u64> uses_cc;
  677. } rz;
  678. union {
  679. BitField<39, 5, u64> entry_a;
  680. BitField<45, 1, u64> neg;
  681. BitField<46, 1, u64> uses_cc;
  682. } r1;
  683. union {
  684. BitField<28, 8, u64> entry_a;
  685. BitField<37, 1, u64> neg;
  686. BitField<38, 1, u64> uses_cc;
  687. } r2;
  688. } lea;
  689. union {
  690. BitField<0, 5, FlowCondition> cond;
  691. } flow;
  692. union {
  693. BitField<47, 1, u64> cc;
  694. BitField<48, 1, u64> negate_b;
  695. BitField<49, 1, u64> negate_c;
  696. BitField<51, 2, u64> tab5980_1;
  697. BitField<53, 2, u64> tab5980_0;
  698. } ffma;
  699. union {
  700. BitField<48, 3, UniformType> type;
  701. BitField<44, 2, u64> unknown;
  702. } ld_c;
  703. union {
  704. BitField<48, 3, StoreType> type;
  705. } ldst_sl;
  706. union {
  707. BitField<44, 2, u64> unknown;
  708. } ld_l;
  709. union {
  710. BitField<44, 2, StoreCacheManagement> cache_management;
  711. } st_l;
  712. union {
  713. BitField<48, 3, UniformType> type;
  714. BitField<46, 2, u64> cache_mode;
  715. } ldg;
  716. union {
  717. BitField<48, 3, UniformType> type;
  718. BitField<46, 2, u64> cache_mode;
  719. } stg;
  720. union {
  721. BitField<32, 1, PhysicalAttributeDirection> direction;
  722. BitField<47, 3, AttributeSize> size;
  723. BitField<20, 11, u64> address;
  724. } al2p;
  725. union {
  726. BitField<53, 3, UniformType> type;
  727. BitField<52, 1, u64> extended;
  728. } generic;
  729. union {
  730. BitField<0, 3, u64> pred0;
  731. BitField<3, 3, u64> pred3;
  732. BitField<7, 1, u64> abs_a;
  733. BitField<39, 3, u64> pred39;
  734. BitField<42, 1, u64> neg_pred;
  735. BitField<43, 1, u64> neg_a;
  736. BitField<44, 1, u64> abs_b;
  737. BitField<45, 2, PredOperation> op;
  738. BitField<47, 1, u64> ftz;
  739. BitField<48, 4, PredCondition> cond;
  740. } fsetp;
  741. union {
  742. BitField<0, 3, u64> pred0;
  743. BitField<3, 3, u64> pred3;
  744. BitField<39, 3, u64> pred39;
  745. BitField<42, 1, u64> neg_pred;
  746. BitField<45, 2, PredOperation> op;
  747. BitField<48, 1, u64> is_signed;
  748. BitField<49, 3, PredCondition> cond;
  749. } isetp;
  750. union {
  751. BitField<0, 3, u64> pred0;
  752. BitField<3, 3, u64> pred3;
  753. BitField<12, 3, u64> pred12;
  754. BitField<15, 1, u64> neg_pred12;
  755. BitField<24, 2, PredOperation> cond;
  756. BitField<29, 3, u64> pred29;
  757. BitField<32, 1, u64> neg_pred29;
  758. BitField<39, 3, u64> pred39;
  759. BitField<42, 1, u64> neg_pred39;
  760. BitField<45, 2, PredOperation> op;
  761. } psetp;
  762. union {
  763. BitField<43, 4, PredCondition> cond;
  764. BitField<45, 2, PredOperation> op;
  765. BitField<3, 3, u64> pred3;
  766. BitField<0, 3, u64> pred0;
  767. BitField<39, 3, u64> pred39;
  768. } vsetp;
  769. union {
  770. BitField<12, 3, u64> pred12;
  771. BitField<15, 1, u64> neg_pred12;
  772. BitField<24, 2, PredOperation> cond;
  773. BitField<29, 3, u64> pred29;
  774. BitField<32, 1, u64> neg_pred29;
  775. BitField<39, 3, u64> pred39;
  776. BitField<42, 1, u64> neg_pred39;
  777. BitField<44, 1, u64> bf;
  778. BitField<45, 2, PredOperation> op;
  779. } pset;
  780. union {
  781. BitField<0, 3, u64> pred0;
  782. BitField<3, 3, u64> pred3;
  783. BitField<8, 5, ConditionCode> cc; // flag in cc
  784. BitField<39, 3, u64> pred39;
  785. BitField<42, 1, u64> neg_pred39;
  786. BitField<45, 4, PredOperation> op; // op with pred39
  787. } csetp;
  788. union {
  789. BitField<35, 4, PredCondition> cond;
  790. BitField<49, 1, u64> h_and;
  791. BitField<6, 1, u64> ftz;
  792. BitField<45, 2, PredOperation> op;
  793. BitField<3, 3, u64> pred3;
  794. BitField<0, 3, u64> pred0;
  795. BitField<43, 1, u64> negate_a;
  796. BitField<44, 1, u64> abs_a;
  797. BitField<47, 2, HalfType> type_a;
  798. BitField<31, 1, u64> negate_b;
  799. BitField<30, 1, u64> abs_b;
  800. BitField<28, 2, HalfType> type_b;
  801. BitField<42, 1, u64> neg_pred;
  802. BitField<39, 3, u64> pred39;
  803. } hsetp2;
  804. union {
  805. BitField<40, 1, R2pMode> mode;
  806. BitField<41, 2, u64> byte;
  807. BitField<20, 7, u64> immediate_mask;
  808. } r2p;
  809. union {
  810. BitField<39, 3, u64> pred39;
  811. BitField<42, 1, u64> neg_pred;
  812. BitField<43, 1, u64> neg_a;
  813. BitField<44, 1, u64> abs_b;
  814. BitField<45, 2, PredOperation> op;
  815. BitField<48, 4, PredCondition> cond;
  816. BitField<52, 1, u64> bf;
  817. BitField<53, 1, u64> neg_b;
  818. BitField<54, 1, u64> abs_a;
  819. BitField<55, 1, u64> ftz;
  820. } fset;
  821. union {
  822. BitField<49, 1, u64> bf;
  823. BitField<35, 3, PredCondition> cond;
  824. BitField<50, 1, u64> ftz;
  825. BitField<45, 2, PredOperation> op;
  826. BitField<43, 1, u64> negate_a;
  827. BitField<44, 1, u64> abs_a;
  828. BitField<47, 2, HalfType> type_a;
  829. BitField<31, 1, u64> negate_b;
  830. BitField<30, 1, u64> abs_b;
  831. BitField<28, 2, HalfType> type_b;
  832. BitField<42, 1, u64> neg_pred;
  833. BitField<39, 3, u64> pred39;
  834. } hset2;
  835. union {
  836. BitField<39, 3, u64> pred39;
  837. BitField<42, 1, u64> neg_pred;
  838. BitField<44, 1, u64> bf;
  839. BitField<45, 2, PredOperation> op;
  840. BitField<48, 1, u64> is_signed;
  841. BitField<49, 3, PredCondition> cond;
  842. } iset;
  843. union {
  844. BitField<41, 2, u64> selector; // i2i and i2f only
  845. BitField<45, 1, u64> negate_a;
  846. BitField<49, 1, u64> abs_a;
  847. BitField<10, 2, Register::Size> src_size;
  848. BitField<13, 1, u64> is_input_signed;
  849. BitField<8, 2, Register::Size> dst_size;
  850. BitField<12, 1, u64> is_output_signed;
  851. union {
  852. BitField<39, 2, u64> tab5cb8_2;
  853. } i2f;
  854. union {
  855. BitField<39, 2, F2iRoundingOp> rounding;
  856. } f2i;
  857. union {
  858. BitField<8, 2, Register::Size> src_size;
  859. BitField<10, 2, Register::Size> dst_size;
  860. BitField<39, 4, u64> rounding;
  861. // H0, H1 extract for F16 missing
  862. BitField<41, 1, u64> selector; // Guessed as some games set it, TODO: reverse this value
  863. F2fRoundingOp GetRoundingMode() const {
  864. constexpr u64 rounding_mask = 0x0B;
  865. return static_cast<F2fRoundingOp>(rounding.Value() & rounding_mask);
  866. }
  867. } f2f;
  868. } conversion;
  869. union {
  870. BitField<28, 1, u64> array;
  871. BitField<29, 2, TextureType> texture_type;
  872. BitField<31, 4, u64> component_mask;
  873. BitField<49, 1, u64> nodep_flag;
  874. BitField<50, 1, u64> dc_flag;
  875. BitField<54, 1, u64> aoffi_flag;
  876. BitField<55, 3, TextureProcessMode> process_mode;
  877. bool IsComponentEnabled(std::size_t component) const {
  878. return ((1ull << component) & component_mask) != 0;
  879. }
  880. TextureProcessMode GetTextureProcessMode() const {
  881. return process_mode;
  882. }
  883. bool UsesMiscMode(TextureMiscMode mode) const {
  884. switch (mode) {
  885. case TextureMiscMode::DC:
  886. return dc_flag != 0;
  887. case TextureMiscMode::NODEP:
  888. return nodep_flag != 0;
  889. case TextureMiscMode::AOFFI:
  890. return aoffi_flag != 0;
  891. default:
  892. break;
  893. }
  894. return false;
  895. }
  896. } tex;
  897. union {
  898. BitField<28, 1, u64> array;
  899. BitField<29, 2, TextureType> texture_type;
  900. BitField<31, 4, u64> component_mask;
  901. BitField<49, 1, u64> nodep_flag;
  902. BitField<50, 1, u64> dc_flag;
  903. BitField<36, 1, u64> aoffi_flag;
  904. BitField<37, 3, TextureProcessMode> process_mode;
  905. bool IsComponentEnabled(std::size_t component) const {
  906. return ((1ULL << component) & component_mask) != 0;
  907. }
  908. TextureProcessMode GetTextureProcessMode() const {
  909. return process_mode;
  910. }
  911. bool UsesMiscMode(TextureMiscMode mode) const {
  912. switch (mode) {
  913. case TextureMiscMode::DC:
  914. return dc_flag != 0;
  915. case TextureMiscMode::NODEP:
  916. return nodep_flag != 0;
  917. case TextureMiscMode::AOFFI:
  918. return aoffi_flag != 0;
  919. default:
  920. break;
  921. }
  922. return false;
  923. }
  924. } tex_b;
  925. union {
  926. BitField<22, 6, TextureQueryType> query_type;
  927. BitField<31, 4, u64> component_mask;
  928. BitField<49, 1, u64> nodep_flag;
  929. bool UsesMiscMode(TextureMiscMode mode) const {
  930. switch (mode) {
  931. case TextureMiscMode::NODEP:
  932. return nodep_flag != 0;
  933. default:
  934. break;
  935. }
  936. return false;
  937. }
  938. bool IsComponentEnabled(std::size_t component) const {
  939. return ((1ULL << component) & component_mask) != 0;
  940. }
  941. } txq;
  942. union {
  943. BitField<28, 1, u64> array;
  944. BitField<29, 2, TextureType> texture_type;
  945. BitField<31, 4, u64> component_mask;
  946. BitField<35, 1, u64> ndv_flag;
  947. BitField<49, 1, u64> nodep_flag;
  948. bool IsComponentEnabled(std::size_t component) const {
  949. return ((1ull << component) & component_mask) != 0;
  950. }
  951. bool UsesMiscMode(TextureMiscMode mode) const {
  952. switch (mode) {
  953. case TextureMiscMode::NDV:
  954. return (ndv_flag != 0);
  955. case TextureMiscMode::NODEP:
  956. return (nodep_flag != 0);
  957. default:
  958. break;
  959. }
  960. return false;
  961. }
  962. } tmml;
  963. union {
  964. BitField<28, 1, u64> array;
  965. BitField<29, 2, TextureType> texture_type;
  966. BitField<35, 1, u64> ndv_flag;
  967. BitField<49, 1, u64> nodep_flag;
  968. BitField<50, 1, u64> dc_flag;
  969. BitField<54, 2, u64> info;
  970. BitField<56, 2, u64> component;
  971. bool UsesMiscMode(TextureMiscMode mode) const {
  972. switch (mode) {
  973. case TextureMiscMode::NDV:
  974. return ndv_flag != 0;
  975. case TextureMiscMode::NODEP:
  976. return nodep_flag != 0;
  977. case TextureMiscMode::DC:
  978. return dc_flag != 0;
  979. case TextureMiscMode::AOFFI:
  980. return info == 1;
  981. case TextureMiscMode::PTP:
  982. return info == 2;
  983. default:
  984. break;
  985. }
  986. return false;
  987. }
  988. } tld4;
  989. union {
  990. BitField<49, 1, u64> nodep_flag;
  991. BitField<50, 1, u64> dc_flag;
  992. BitField<51, 1, u64> aoffi_flag;
  993. BitField<52, 2, u64> component;
  994. bool UsesMiscMode(TextureMiscMode mode) const {
  995. switch (mode) {
  996. case TextureMiscMode::DC:
  997. return dc_flag != 0;
  998. case TextureMiscMode::NODEP:
  999. return nodep_flag != 0;
  1000. case TextureMiscMode::AOFFI:
  1001. return aoffi_flag != 0;
  1002. default:
  1003. break;
  1004. }
  1005. return false;
  1006. }
  1007. } tld4s;
  1008. union {
  1009. BitField<0, 8, Register> gpr0;
  1010. BitField<28, 8, Register> gpr28;
  1011. BitField<49, 1, u64> nodep_flag;
  1012. BitField<50, 3, u64> component_mask_selector;
  1013. BitField<53, 4, u64> texture_info;
  1014. BitField<59, 1, u64> fp32_flag;
  1015. TextureType GetTextureType() const {
  1016. // The TEXS instruction has a weird encoding for the texture type.
  1017. if (texture_info == 0)
  1018. return TextureType::Texture1D;
  1019. if (texture_info >= 1 && texture_info <= 9)
  1020. return TextureType::Texture2D;
  1021. if (texture_info >= 10 && texture_info <= 11)
  1022. return TextureType::Texture3D;
  1023. if (texture_info >= 12 && texture_info <= 13)
  1024. return TextureType::TextureCube;
  1025. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  1026. static_cast<u32>(texture_info.Value()));
  1027. UNREACHABLE();
  1028. return TextureType::Texture1D;
  1029. }
  1030. TextureProcessMode GetTextureProcessMode() const {
  1031. switch (texture_info) {
  1032. case 0:
  1033. case 2:
  1034. case 6:
  1035. case 8:
  1036. case 9:
  1037. case 11:
  1038. return TextureProcessMode::LZ;
  1039. case 3:
  1040. case 5:
  1041. case 13:
  1042. return TextureProcessMode::LL;
  1043. default:
  1044. break;
  1045. }
  1046. return TextureProcessMode::None;
  1047. }
  1048. bool UsesMiscMode(TextureMiscMode mode) const {
  1049. switch (mode) {
  1050. case TextureMiscMode::DC:
  1051. return (texture_info >= 4 && texture_info <= 6) || texture_info == 9;
  1052. case TextureMiscMode::NODEP:
  1053. return nodep_flag != 0;
  1054. default:
  1055. break;
  1056. }
  1057. return false;
  1058. }
  1059. bool IsArrayTexture() const {
  1060. // TEXS only supports Texture2D arrays.
  1061. return texture_info >= 7 && texture_info <= 9;
  1062. }
  1063. bool HasTwoDestinations() const {
  1064. return gpr28.Value() != Register::ZeroIndex;
  1065. }
  1066. bool IsComponentEnabled(std::size_t component) const {
  1067. static constexpr std::array<std::array<u32, 8>, 4> mask_lut{{
  1068. {},
  1069. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  1070. {0x1, 0x2, 0x4, 0x8, 0x3, 0x9, 0xa, 0xc},
  1071. {0x7, 0xb, 0xd, 0xe, 0xf},
  1072. }};
  1073. std::size_t index{gpr0.Value() != Register::ZeroIndex ? 1U : 0U};
  1074. index |= gpr28.Value() != Register::ZeroIndex ? 2 : 0;
  1075. u32 mask = mask_lut[index][component_mask_selector];
  1076. // A mask of 0 means this instruction uses an unimplemented mask.
  1077. ASSERT(mask != 0);
  1078. return ((1ull << component) & mask) != 0;
  1079. }
  1080. } texs;
  1081. union {
  1082. BitField<28, 1, u64> is_array;
  1083. BitField<29, 2, TextureType> texture_type;
  1084. BitField<35, 1, u64> aoffi;
  1085. BitField<49, 1, u64> nodep_flag;
  1086. BitField<50, 1, u64> ms; // Multisample?
  1087. BitField<54, 1, u64> cl;
  1088. BitField<55, 1, u64> process_mode;
  1089. TextureProcessMode GetTextureProcessMode() const {
  1090. return process_mode == 0 ? TextureProcessMode::LZ : TextureProcessMode::LL;
  1091. }
  1092. } tld;
  1093. union {
  1094. BitField<49, 1, u64> nodep_flag;
  1095. BitField<53, 4, u64> texture_info;
  1096. TextureType GetTextureType() const {
  1097. // The TLDS instruction has a weird encoding for the texture type.
  1098. if (texture_info >= 0 && texture_info <= 1) {
  1099. return TextureType::Texture1D;
  1100. }
  1101. if (texture_info == 2 || texture_info == 8 || texture_info == 12 ||
  1102. (texture_info >= 4 && texture_info <= 6)) {
  1103. return TextureType::Texture2D;
  1104. }
  1105. if (texture_info == 7) {
  1106. return TextureType::Texture3D;
  1107. }
  1108. LOG_CRITICAL(HW_GPU, "Unhandled texture_info: {}",
  1109. static_cast<u32>(texture_info.Value()));
  1110. UNREACHABLE();
  1111. return TextureType::Texture1D;
  1112. }
  1113. TextureProcessMode GetTextureProcessMode() const {
  1114. if (texture_info == 1 || texture_info == 5 || texture_info == 12)
  1115. return TextureProcessMode::LL;
  1116. return TextureProcessMode::LZ;
  1117. }
  1118. bool UsesMiscMode(TextureMiscMode mode) const {
  1119. switch (mode) {
  1120. case TextureMiscMode::AOFFI:
  1121. return texture_info == 12 || texture_info == 4;
  1122. case TextureMiscMode::MZ:
  1123. return texture_info == 5;
  1124. case TextureMiscMode::NODEP:
  1125. return nodep_flag != 0;
  1126. default:
  1127. break;
  1128. }
  1129. return false;
  1130. }
  1131. bool IsArrayTexture() const {
  1132. // TEXS only supports Texture2D arrays.
  1133. return texture_info == 8;
  1134. }
  1135. } tlds;
  1136. union {
  1137. BitField<24, 2, StoreCacheManagement> cache_management;
  1138. BitField<33, 3, ImageType> image_type;
  1139. BitField<49, 2, OutOfBoundsStore> out_of_bounds_store;
  1140. BitField<51, 1, u64> is_immediate;
  1141. BitField<52, 1, SurfaceDataMode> mode;
  1142. BitField<20, 3, StoreType> store_data_layout;
  1143. BitField<20, 4, u64> component_mask_selector;
  1144. bool IsComponentEnabled(std::size_t component) const {
  1145. ASSERT(mode == SurfaceDataMode::P);
  1146. constexpr u8 R = 0b0001;
  1147. constexpr u8 G = 0b0010;
  1148. constexpr u8 B = 0b0100;
  1149. constexpr u8 A = 0b1000;
  1150. constexpr std::array<u8, 16> mask = {
  1151. 0, (R), (G), (R | G), (B), (R | B),
  1152. (G | B), (R | G | B), (A), (R | A), (G | A), (R | G | A),
  1153. (B | A), (R | B | A), (G | B | A), (R | G | B | A)};
  1154. return std::bitset<4>{mask.at(component_mask_selector)}.test(component);
  1155. }
  1156. StoreType GetStoreDataLayout() const {
  1157. ASSERT(mode == SurfaceDataMode::D_BA);
  1158. return store_data_layout;
  1159. }
  1160. } sust;
  1161. union {
  1162. BitField<20, 24, u64> target;
  1163. BitField<5, 1, u64> constant_buffer;
  1164. s32 GetBranchTarget() const {
  1165. // Sign extend the branch target offset
  1166. u32 mask = 1U << (24 - 1);
  1167. u32 value = static_cast<u32>(target);
  1168. // The branch offset is relative to the next instruction and is stored in bytes, so
  1169. // divide it by the size of an instruction and add 1 to it.
  1170. return static_cast<s32>((value ^ mask) - mask) / sizeof(Instruction) + 1;
  1171. }
  1172. } bra;
  1173. union {
  1174. BitField<39, 1, u64> emit; // EmitVertex
  1175. BitField<40, 1, u64> cut; // EndPrimitive
  1176. } out;
  1177. union {
  1178. BitField<31, 1, u64> skew;
  1179. BitField<32, 1, u64> o;
  1180. BitField<33, 2, IsberdMode> mode;
  1181. BitField<47, 2, IsberdShift> shift;
  1182. } isberd;
  1183. union {
  1184. BitField<48, 1, u64> signed_a;
  1185. BitField<38, 1, u64> is_byte_chunk_a;
  1186. BitField<36, 2, VideoType> type_a;
  1187. BitField<36, 2, u64> byte_height_a;
  1188. BitField<49, 1, u64> signed_b;
  1189. BitField<50, 1, u64> use_register_b;
  1190. BitField<30, 1, u64> is_byte_chunk_b;
  1191. BitField<28, 2, VideoType> type_b;
  1192. BitField<28, 2, u64> byte_height_b;
  1193. } video;
  1194. union {
  1195. BitField<51, 2, VmadShr> shr;
  1196. BitField<55, 1, u64> saturate; // Saturates the result (a * b + c)
  1197. BitField<47, 1, u64> cc;
  1198. } vmad;
  1199. union {
  1200. BitField<20, 16, u64> imm20_16;
  1201. BitField<35, 1, u64> high_b_rr; // used on RR
  1202. BitField<36, 1, u64> product_shift_left;
  1203. BitField<37, 1, u64> merge_37;
  1204. BitField<48, 1, u64> sign_a;
  1205. BitField<49, 1, u64> sign_b;
  1206. BitField<50, 2, XmadMode> mode_cbf; // used by CR, RC
  1207. BitField<50, 3, XmadMode> mode;
  1208. BitField<52, 1, u64> high_b;
  1209. BitField<53, 1, u64> high_a;
  1210. BitField<55, 1, u64> product_shift_left_second; // used on CR
  1211. BitField<56, 1, u64> merge_56;
  1212. } xmad;
  1213. union {
  1214. BitField<20, 14, u64> offset;
  1215. BitField<34, 5, u64> index;
  1216. u64 GetOffset() const {
  1217. return offset * 4;
  1218. }
  1219. } cbuf34;
  1220. union {
  1221. BitField<20, 16, s64> offset;
  1222. BitField<36, 5, u64> index;
  1223. s64 GetOffset() const {
  1224. return offset;
  1225. }
  1226. } cbuf36;
  1227. // Unsure about the size of this one.
  1228. // It's always used with a gpr0, so any size should be fine.
  1229. BitField<20, 8, SystemVariable> sys20;
  1230. BitField<47, 1, u64> generates_cc;
  1231. BitField<61, 1, u64> is_b_imm;
  1232. BitField<60, 1, u64> is_b_gpr;
  1233. BitField<59, 1, u64> is_c_gpr;
  1234. BitField<20, 24, s64> smem_imm;
  1235. BitField<0, 5, ConditionCode> flow_condition_code;
  1236. Attribute attribute;
  1237. Sampler sampler;
  1238. Image image;
  1239. u64 value;
  1240. };
  1241. static_assert(sizeof(Instruction) == 0x8, "Incorrect structure size");
  1242. static_assert(std::is_standard_layout_v<Instruction>, "Instruction is not standard layout");
  1243. class OpCode {
  1244. public:
  1245. enum class Id {
  1246. KIL,
  1247. SSY,
  1248. SYNC,
  1249. BRK,
  1250. DEPBAR,
  1251. BFE_C,
  1252. BFE_R,
  1253. BFE_IMM,
  1254. BFI_IMM_R,
  1255. BRA,
  1256. PBK,
  1257. LD_A,
  1258. LD_L,
  1259. LD_S,
  1260. LD_C,
  1261. LD, // Load from generic memory
  1262. LDG, // Load from global memory
  1263. ST_A,
  1264. ST_L,
  1265. ST_S,
  1266. ST, // Store in generic memory
  1267. STG, // Store in global memory
  1268. AL2P, // Transforms attribute memory into physical memory
  1269. TEX,
  1270. TEX_B, // Texture Load Bindless
  1271. TXQ, // Texture Query
  1272. TXQ_B, // Texture Query Bindless
  1273. TEXS, // Texture Fetch with scalar/non-vec4 source/destinations
  1274. TLD, // Texture Load
  1275. TLDS, // Texture Load with scalar/non-vec4 source/destinations
  1276. TLD4, // Texture Load 4
  1277. TLD4S, // Texture Load 4 with scalar / non - vec4 source / destinations
  1278. TMML_B, // Texture Mip Map Level
  1279. TMML, // Texture Mip Map Level
  1280. SUST, // Surface Store
  1281. EXIT,
  1282. IPA,
  1283. OUT_R, // Emit vertex/primitive
  1284. ISBERD,
  1285. VMAD,
  1286. VSETP,
  1287. FFMA_IMM, // Fused Multiply and Add
  1288. FFMA_CR,
  1289. FFMA_RC,
  1290. FFMA_RR,
  1291. FADD_C,
  1292. FADD_R,
  1293. FADD_IMM,
  1294. FADD32I,
  1295. FMUL_C,
  1296. FMUL_R,
  1297. FMUL_IMM,
  1298. FMUL32_IMM,
  1299. IADD_C,
  1300. IADD_R,
  1301. IADD_IMM,
  1302. IADD3_C, // Add 3 Integers
  1303. IADD3_R,
  1304. IADD3_IMM,
  1305. IADD32I,
  1306. ISCADD_C, // Scale and Add
  1307. ISCADD_R,
  1308. ISCADD_IMM,
  1309. LEA_R1,
  1310. LEA_R2,
  1311. LEA_RZ,
  1312. LEA_IMM,
  1313. LEA_HI,
  1314. HADD2_C,
  1315. HADD2_R,
  1316. HADD2_IMM,
  1317. HMUL2_C,
  1318. HMUL2_R,
  1319. HMUL2_IMM,
  1320. HFMA2_CR,
  1321. HFMA2_RC,
  1322. HFMA2_RR,
  1323. HFMA2_IMM_R,
  1324. HSETP2_R,
  1325. HSET2_R,
  1326. POPC_C,
  1327. POPC_R,
  1328. POPC_IMM,
  1329. SEL_C,
  1330. SEL_R,
  1331. SEL_IMM,
  1332. MUFU, // Multi-Function Operator
  1333. RRO_C, // Range Reduction Operator
  1334. RRO_R,
  1335. RRO_IMM,
  1336. F2F_C,
  1337. F2F_R,
  1338. F2F_IMM,
  1339. F2I_C,
  1340. F2I_R,
  1341. F2I_IMM,
  1342. I2F_C,
  1343. I2F_R,
  1344. I2F_IMM,
  1345. I2I_C,
  1346. I2I_R,
  1347. I2I_IMM,
  1348. LOP_C,
  1349. LOP_R,
  1350. LOP_IMM,
  1351. LOP32I,
  1352. LOP3_C,
  1353. LOP3_R,
  1354. LOP3_IMM,
  1355. MOV_C,
  1356. MOV_R,
  1357. MOV_IMM,
  1358. MOV_SYS,
  1359. MOV32_IMM,
  1360. SHL_C,
  1361. SHL_R,
  1362. SHL_IMM,
  1363. SHR_C,
  1364. SHR_R,
  1365. SHR_IMM,
  1366. FMNMX_C,
  1367. FMNMX_R,
  1368. FMNMX_IMM,
  1369. IMNMX_C,
  1370. IMNMX_R,
  1371. IMNMX_IMM,
  1372. FSETP_C, // Set Predicate
  1373. FSETP_R,
  1374. FSETP_IMM,
  1375. FSET_C,
  1376. FSET_R,
  1377. FSET_IMM,
  1378. ISETP_C,
  1379. ISETP_IMM,
  1380. ISETP_R,
  1381. ISET_R,
  1382. ISET_C,
  1383. ISET_IMM,
  1384. PSETP,
  1385. PSET,
  1386. CSETP,
  1387. R2P_IMM,
  1388. XMAD_IMM,
  1389. XMAD_CR,
  1390. XMAD_RC,
  1391. XMAD_RR,
  1392. };
  1393. enum class Type {
  1394. Trivial,
  1395. Arithmetic,
  1396. ArithmeticImmediate,
  1397. ArithmeticInteger,
  1398. ArithmeticIntegerImmediate,
  1399. ArithmeticHalf,
  1400. ArithmeticHalfImmediate,
  1401. Bfe,
  1402. Bfi,
  1403. Shift,
  1404. Ffma,
  1405. Hfma2,
  1406. Flow,
  1407. Synch,
  1408. Memory,
  1409. Texture,
  1410. Image,
  1411. FloatSet,
  1412. FloatSetPredicate,
  1413. IntegerSet,
  1414. IntegerSetPredicate,
  1415. HalfSet,
  1416. HalfSetPredicate,
  1417. PredicateSetPredicate,
  1418. PredicateSetRegister,
  1419. RegisterSetPredicate,
  1420. Conversion,
  1421. Video,
  1422. Xmad,
  1423. Unknown,
  1424. };
  1425. /// Returns whether an opcode has an execution predicate field or not (ie, whether it can be
  1426. /// conditionally executed).
  1427. static bool IsPredicatedInstruction(Id opcode) {
  1428. // TODO(Subv): Add the rest of unpredicated instructions.
  1429. return opcode != Id::SSY && opcode != Id::PBK;
  1430. }
  1431. class Matcher {
  1432. public:
  1433. Matcher(const char* const name, u16 mask, u16 expected, OpCode::Id id, OpCode::Type type)
  1434. : name{name}, mask{mask}, expected{expected}, id{id}, type{type} {}
  1435. const char* GetName() const {
  1436. return name;
  1437. }
  1438. u16 GetMask() const {
  1439. return mask;
  1440. }
  1441. Id GetId() const {
  1442. return id;
  1443. }
  1444. Type GetType() const {
  1445. return type;
  1446. }
  1447. /**
  1448. * Tests to see if the given instruction is the instruction this matcher represents.
  1449. * @param instruction The instruction to test
  1450. * @returns true if the given instruction matches.
  1451. */
  1452. bool Matches(u16 instruction) const {
  1453. return (instruction & mask) == expected;
  1454. }
  1455. private:
  1456. const char* name;
  1457. u16 mask;
  1458. u16 expected;
  1459. Id id;
  1460. Type type;
  1461. };
  1462. static std::optional<std::reference_wrapper<const Matcher>> Decode(Instruction instr) {
  1463. static const auto table{GetDecodeTable()};
  1464. const auto matches_instruction = [instr](const auto& matcher) {
  1465. return matcher.Matches(static_cast<u16>(instr.opcode));
  1466. };
  1467. auto iter = std::find_if(table.begin(), table.end(), matches_instruction);
  1468. return iter != table.end() ? std::optional<std::reference_wrapper<const Matcher>>(*iter)
  1469. : std::nullopt;
  1470. }
  1471. private:
  1472. struct Detail {
  1473. private:
  1474. static constexpr std::size_t opcode_bitsize = 16;
  1475. /**
  1476. * Generates the mask and the expected value after masking from a given bitstring.
  1477. * A '0' in a bitstring indicates that a zero must be present at that bit position.
  1478. * A '1' in a bitstring indicates that a one must be present at that bit position.
  1479. */
  1480. static auto GetMaskAndExpect(const char* const bitstring) {
  1481. u16 mask = 0, expect = 0;
  1482. for (std::size_t i = 0; i < opcode_bitsize; i++) {
  1483. const std::size_t bit_position = opcode_bitsize - i - 1;
  1484. switch (bitstring[i]) {
  1485. case '0':
  1486. mask |= 1 << bit_position;
  1487. break;
  1488. case '1':
  1489. expect |= 1 << bit_position;
  1490. mask |= 1 << bit_position;
  1491. break;
  1492. default:
  1493. // Ignore
  1494. break;
  1495. }
  1496. }
  1497. return std::make_tuple(mask, expect);
  1498. }
  1499. public:
  1500. /// Creates a matcher that can match and parse instructions based on bitstring.
  1501. static auto GetMatcher(const char* const bitstring, OpCode::Id op, OpCode::Type type,
  1502. const char* const name) {
  1503. const auto mask_expect = GetMaskAndExpect(bitstring);
  1504. return Matcher(name, std::get<0>(mask_expect), std::get<1>(mask_expect), op, type);
  1505. }
  1506. };
  1507. static std::vector<Matcher> GetDecodeTable() {
  1508. std::vector<Matcher> table = {
  1509. #define INST(bitstring, op, type, name) Detail::GetMatcher(bitstring, op, type, name)
  1510. INST("111000110011----", Id::KIL, Type::Flow, "KIL"),
  1511. INST("111000101001----", Id::SSY, Type::Flow, "SSY"),
  1512. INST("111000101010----", Id::PBK, Type::Flow, "PBK"),
  1513. INST("111000100100----", Id::BRA, Type::Flow, "BRA"),
  1514. INST("1111000011111---", Id::SYNC, Type::Flow, "SYNC"),
  1515. INST("111000110100---", Id::BRK, Type::Flow, "BRK"),
  1516. INST("111000110000----", Id::EXIT, Type::Flow, "EXIT"),
  1517. INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"),
  1518. INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
  1519. INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"),
  1520. INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"),
  1521. INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
  1522. INST("100-------------", Id::LD, Type::Memory, "LD"),
  1523. INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
  1524. INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
  1525. INST("1110111101011---", Id::ST_S, Type::Memory, "ST_S"),
  1526. INST("1110111101010---", Id::ST_L, Type::Memory, "ST_L"),
  1527. INST("101-------------", Id::ST, Type::Memory, "ST"),
  1528. INST("1110111011011---", Id::STG, Type::Memory, "STG"),
  1529. INST("1110111110100---", Id::AL2P, Type::Memory, "AL2P"),
  1530. INST("110000----111---", Id::TEX, Type::Texture, "TEX"),
  1531. INST("1101111010111---", Id::TEX_B, Type::Texture, "TEX_B"),
  1532. INST("1101111101001---", Id::TXQ, Type::Texture, "TXQ"),
  1533. INST("1101111101010---", Id::TXQ_B, Type::Texture, "TXQ_B"),
  1534. INST("1101-00---------", Id::TEXS, Type::Texture, "TEXS"),
  1535. INST("11011100--11----", Id::TLD, Type::Texture, "TLD"),
  1536. INST("1101101---------", Id::TLDS, Type::Texture, "TLDS"),
  1537. INST("110010----111---", Id::TLD4, Type::Texture, "TLD4"),
  1538. INST("1101111100------", Id::TLD4S, Type::Texture, "TLD4S"),
  1539. INST("110111110110----", Id::TMML_B, Type::Texture, "TMML_B"),
  1540. INST("1101111101011---", Id::TMML, Type::Texture, "TMML"),
  1541. INST("11101011001-----", Id::SUST, Type::Image, "SUST"),
  1542. INST("11100000--------", Id::IPA, Type::Trivial, "IPA"),
  1543. INST("1111101111100---", Id::OUT_R, Type::Trivial, "OUT_R"),
  1544. INST("1110111111010---", Id::ISBERD, Type::Trivial, "ISBERD"),
  1545. INST("01011111--------", Id::VMAD, Type::Video, "VMAD"),
  1546. INST("0101000011110---", Id::VSETP, Type::Video, "VSETP"),
  1547. INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"),
  1548. INST("010010011-------", Id::FFMA_CR, Type::Ffma, "FFMA_CR"),
  1549. INST("010100011-------", Id::FFMA_RC, Type::Ffma, "FFMA_RC"),
  1550. INST("010110011-------", Id::FFMA_RR, Type::Ffma, "FFMA_RR"),
  1551. INST("0100110001011---", Id::FADD_C, Type::Arithmetic, "FADD_C"),
  1552. INST("0101110001011---", Id::FADD_R, Type::Arithmetic, "FADD_R"),
  1553. INST("0011100-01011---", Id::FADD_IMM, Type::Arithmetic, "FADD_IMM"),
  1554. INST("000010----------", Id::FADD32I, Type::ArithmeticImmediate, "FADD32I"),
  1555. INST("0100110001101---", Id::FMUL_C, Type::Arithmetic, "FMUL_C"),
  1556. INST("0101110001101---", Id::FMUL_R, Type::Arithmetic, "FMUL_R"),
  1557. INST("0011100-01101---", Id::FMUL_IMM, Type::Arithmetic, "FMUL_IMM"),
  1558. INST("00011110--------", Id::FMUL32_IMM, Type::ArithmeticImmediate, "FMUL32_IMM"),
  1559. INST("0100110000010---", Id::IADD_C, Type::ArithmeticInteger, "IADD_C"),
  1560. INST("0101110000010---", Id::IADD_R, Type::ArithmeticInteger, "IADD_R"),
  1561. INST("0011100-00010---", Id::IADD_IMM, Type::ArithmeticInteger, "IADD_IMM"),
  1562. INST("010011001100----", Id::IADD3_C, Type::ArithmeticInteger, "IADD3_C"),
  1563. INST("010111001100----", Id::IADD3_R, Type::ArithmeticInteger, "IADD3_R"),
  1564. INST("0011100-1100----", Id::IADD3_IMM, Type::ArithmeticInteger, "IADD3_IMM"),
  1565. INST("0001110---------", Id::IADD32I, Type::ArithmeticIntegerImmediate, "IADD32I"),
  1566. INST("0100110000011---", Id::ISCADD_C, Type::ArithmeticInteger, "ISCADD_C"),
  1567. INST("0101110000011---", Id::ISCADD_R, Type::ArithmeticInteger, "ISCADD_R"),
  1568. INST("0011100-00011---", Id::ISCADD_IMM, Type::ArithmeticInteger, "ISCADD_IMM"),
  1569. INST("0100110000001---", Id::POPC_C, Type::ArithmeticInteger, "POPC_C"),
  1570. INST("0101110000001---", Id::POPC_R, Type::ArithmeticInteger, "POPC_R"),
  1571. INST("0011100-00001---", Id::POPC_IMM, Type::ArithmeticInteger, "POPC_IMM"),
  1572. INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"),
  1573. INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"),
  1574. INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"),
  1575. INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"),
  1576. INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"),
  1577. INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"),
  1578. INST("010010111101----", Id::LEA_RZ, Type::ArithmeticInteger, "LEA_RZ"),
  1579. INST("00011000--------", Id::LEA_HI, Type::ArithmeticInteger, "LEA_HI"),
  1580. INST("0111101-1-------", Id::HADD2_C, Type::ArithmeticHalf, "HADD2_C"),
  1581. INST("0101110100010---", Id::HADD2_R, Type::ArithmeticHalf, "HADD2_R"),
  1582. INST("0111101-0-------", Id::HADD2_IMM, Type::ArithmeticHalfImmediate, "HADD2_IMM"),
  1583. INST("0111100-1-------", Id::HMUL2_C, Type::ArithmeticHalf, "HMUL2_C"),
  1584. INST("0101110100001---", Id::HMUL2_R, Type::ArithmeticHalf, "HMUL2_R"),
  1585. INST("0111100-0-------", Id::HMUL2_IMM, Type::ArithmeticHalfImmediate, "HMUL2_IMM"),
  1586. INST("01110---1-------", Id::HFMA2_CR, Type::Hfma2, "HFMA2_CR"),
  1587. INST("01100---1-------", Id::HFMA2_RC, Type::Hfma2, "HFMA2_RC"),
  1588. INST("0101110100000---", Id::HFMA2_RR, Type::Hfma2, "HFMA2_RR"),
  1589. INST("01110---0-------", Id::HFMA2_IMM_R, Type::Hfma2, "HFMA2_R_IMM"),
  1590. INST("0101110100100---", Id::HSETP2_R, Type::HalfSetPredicate, "HSETP_R"),
  1591. INST("0101110100011---", Id::HSET2_R, Type::HalfSet, "HSET2_R"),
  1592. INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"),
  1593. INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"),
  1594. INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"),
  1595. INST("0011100-10010---", Id::RRO_IMM, Type::Arithmetic, "RRO_IMM"),
  1596. INST("0100110010101---", Id::F2F_C, Type::Conversion, "F2F_C"),
  1597. INST("0101110010101---", Id::F2F_R, Type::Conversion, "F2F_R"),
  1598. INST("0011100-10101---", Id::F2F_IMM, Type::Conversion, "F2F_IMM"),
  1599. INST("0100110010110---", Id::F2I_C, Type::Conversion, "F2I_C"),
  1600. INST("0101110010110---", Id::F2I_R, Type::Conversion, "F2I_R"),
  1601. INST("0011100-10110---", Id::F2I_IMM, Type::Conversion, "F2I_IMM"),
  1602. INST("0100110010011---", Id::MOV_C, Type::Arithmetic, "MOV_C"),
  1603. INST("0101110010011---", Id::MOV_R, Type::Arithmetic, "MOV_R"),
  1604. INST("0011100-10011---", Id::MOV_IMM, Type::Arithmetic, "MOV_IMM"),
  1605. INST("1111000011001---", Id::MOV_SYS, Type::Trivial, "MOV_SYS"),
  1606. INST("000000010000----", Id::MOV32_IMM, Type::ArithmeticImmediate, "MOV32_IMM"),
  1607. INST("0100110001100---", Id::FMNMX_C, Type::Arithmetic, "FMNMX_C"),
  1608. INST("0101110001100---", Id::FMNMX_R, Type::Arithmetic, "FMNMX_R"),
  1609. INST("0011100-01100---", Id::FMNMX_IMM, Type::Arithmetic, "FMNMX_IMM"),
  1610. INST("0100110000100---", Id::IMNMX_C, Type::ArithmeticInteger, "IMNMX_C"),
  1611. INST("0101110000100---", Id::IMNMX_R, Type::ArithmeticInteger, "IMNMX_R"),
  1612. INST("0011100-00100---", Id::IMNMX_IMM, Type::ArithmeticInteger, "IMNMX_IMM"),
  1613. INST("0100110000000---", Id::BFE_C, Type::Bfe, "BFE_C"),
  1614. INST("0101110000000---", Id::BFE_R, Type::Bfe, "BFE_R"),
  1615. INST("0011100-00000---", Id::BFE_IMM, Type::Bfe, "BFE_IMM"),
  1616. INST("0011011-11110---", Id::BFI_IMM_R, Type::Bfi, "BFI_IMM_R"),
  1617. INST("0100110001000---", Id::LOP_C, Type::ArithmeticInteger, "LOP_C"),
  1618. INST("0101110001000---", Id::LOP_R, Type::ArithmeticInteger, "LOP_R"),
  1619. INST("0011100-01000---", Id::LOP_IMM, Type::ArithmeticInteger, "LOP_IMM"),
  1620. INST("000001----------", Id::LOP32I, Type::ArithmeticIntegerImmediate, "LOP32I"),
  1621. INST("0000001---------", Id::LOP3_C, Type::ArithmeticInteger, "LOP3_C"),
  1622. INST("0101101111100---", Id::LOP3_R, Type::ArithmeticInteger, "LOP3_R"),
  1623. INST("0011110---------", Id::LOP3_IMM, Type::ArithmeticInteger, "LOP3_IMM"),
  1624. INST("0100110001001---", Id::SHL_C, Type::Shift, "SHL_C"),
  1625. INST("0101110001001---", Id::SHL_R, Type::Shift, "SHL_R"),
  1626. INST("0011100-01001---", Id::SHL_IMM, Type::Shift, "SHL_IMM"),
  1627. INST("0100110000101---", Id::SHR_C, Type::Shift, "SHR_C"),
  1628. INST("0101110000101---", Id::SHR_R, Type::Shift, "SHR_R"),
  1629. INST("0011100-00101---", Id::SHR_IMM, Type::Shift, "SHR_IMM"),
  1630. INST("0100110011100---", Id::I2I_C, Type::Conversion, "I2I_C"),
  1631. INST("0101110011100---", Id::I2I_R, Type::Conversion, "I2I_R"),
  1632. INST("0011101-11100---", Id::I2I_IMM, Type::Conversion, "I2I_IMM"),
  1633. INST("0100110010111---", Id::I2F_C, Type::Conversion, "I2F_C"),
  1634. INST("0101110010111---", Id::I2F_R, Type::Conversion, "I2F_R"),
  1635. INST("0011100-10111---", Id::I2F_IMM, Type::Conversion, "I2F_IMM"),
  1636. INST("01011000--------", Id::FSET_R, Type::FloatSet, "FSET_R"),
  1637. INST("0100100---------", Id::FSET_C, Type::FloatSet, "FSET_C"),
  1638. INST("0011000---------", Id::FSET_IMM, Type::FloatSet, "FSET_IMM"),
  1639. INST("010010111011----", Id::FSETP_C, Type::FloatSetPredicate, "FSETP_C"),
  1640. INST("010110111011----", Id::FSETP_R, Type::FloatSetPredicate, "FSETP_R"),
  1641. INST("0011011-1011----", Id::FSETP_IMM, Type::FloatSetPredicate, "FSETP_IMM"),
  1642. INST("010010110110----", Id::ISETP_C, Type::IntegerSetPredicate, "ISETP_C"),
  1643. INST("010110110110----", Id::ISETP_R, Type::IntegerSetPredicate, "ISETP_R"),
  1644. INST("0011011-0110----", Id::ISETP_IMM, Type::IntegerSetPredicate, "ISETP_IMM"),
  1645. INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"),
  1646. INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"),
  1647. INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"),
  1648. INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"),
  1649. INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"),
  1650. INST("010100001010----", Id::CSETP, Type::PredicateSetPredicate, "CSETP"),
  1651. INST("0011100-11110---", Id::R2P_IMM, Type::RegisterSetPredicate, "R2P_IMM"),
  1652. INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"),
  1653. INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"),
  1654. INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"),
  1655. INST("0101101100------", Id::XMAD_RR, Type::Xmad, "XMAD_RR"),
  1656. };
  1657. #undef INST
  1658. std::stable_sort(table.begin(), table.end(), [](const auto& a, const auto& b) {
  1659. // If a matcher has more bits in its mask it is more specific, so it
  1660. // should come first.
  1661. return std::bitset<16>(a.GetMask()).count() > std::bitset<16>(b.GetMask()).count();
  1662. });
  1663. return table;
  1664. }
  1665. };
  1666. } // namespace Tegra::Shader