EmitterContextInsts.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using System;
  3. using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
  4. namespace Ryujinx.Graphics.Shader.Translation
  5. {
  6. static class EmitterContextInsts
  7. {
  8. public static Operand AtomicAdd(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  9. {
  10. return context.Add(Instruction.AtomicAdd, storageKind, Local(), a, b, c);
  11. }
  12. public static Operand AtomicAnd(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  13. {
  14. return context.Add(Instruction.AtomicAnd, storageKind, Local(), a, b, c);
  15. }
  16. public static Operand AtomicCompareAndSwap(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c, Operand d)
  17. {
  18. return context.Add(Instruction.AtomicCompareAndSwap, storageKind, Local(), a, b, c, d);
  19. }
  20. public static Operand AtomicMaxS32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  21. {
  22. return context.Add(Instruction.AtomicMaxS32, storageKind, Local(), a, b, c);
  23. }
  24. public static Operand AtomicMaxU32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  25. {
  26. return context.Add(Instruction.AtomicMaxU32, storageKind, Local(), a, b, c);
  27. }
  28. public static Operand AtomicMinS32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  29. {
  30. return context.Add(Instruction.AtomicMinS32, storageKind, Local(), a, b, c);
  31. }
  32. public static Operand AtomicMinU32(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  33. {
  34. return context.Add(Instruction.AtomicMinU32, storageKind, Local(), a, b, c);
  35. }
  36. public static Operand AtomicOr(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  37. {
  38. return context.Add(Instruction.AtomicOr, storageKind, Local(), a, b, c);
  39. }
  40. public static Operand AtomicSwap(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  41. {
  42. return context.Add(Instruction.AtomicSwap, storageKind, Local(), a, b, c);
  43. }
  44. public static Operand AtomicXor(this EmitterContext context, StorageKind storageKind, Operand a, Operand b, Operand c)
  45. {
  46. return context.Add(Instruction.AtomicXor, storageKind, Local(), a, b, c);
  47. }
  48. public static Operand Ballot(this EmitterContext context, Operand a)
  49. {
  50. return context.Add(Instruction.Ballot, Local(), a);
  51. }
  52. public static Operand Barrier(this EmitterContext context)
  53. {
  54. return context.Add(Instruction.Barrier);
  55. }
  56. public static Operand BitCount(this EmitterContext context, Operand a)
  57. {
  58. return context.Add(Instruction.BitCount, Local(), a);
  59. }
  60. public static Operand BitfieldExtractS32(this EmitterContext context, Operand a, Operand b, Operand c)
  61. {
  62. return context.Add(Instruction.BitfieldExtractS32, Local(), a, b, c);
  63. }
  64. public static Operand BitfieldExtractU32(this EmitterContext context, Operand a, Operand b, Operand c)
  65. {
  66. return context.Add(Instruction.BitfieldExtractU32, Local(), a, b, c);
  67. }
  68. public static Operand BitfieldInsert(this EmitterContext context, Operand a, Operand b, Operand c, Operand d)
  69. {
  70. return context.Add(Instruction.BitfieldInsert, Local(), a, b, c, d);
  71. }
  72. public static Operand BitfieldReverse(this EmitterContext context, Operand a)
  73. {
  74. return context.Add(Instruction.BitfieldReverse, Local(), a);
  75. }
  76. public static Operand BitwiseAnd(this EmitterContext context, Operand a, Operand b)
  77. {
  78. return context.Add(Instruction.BitwiseAnd, Local(), a, b);
  79. }
  80. public static Operand BitwiseExclusiveOr(this EmitterContext context, Operand a, Operand b)
  81. {
  82. return context.Add(Instruction.BitwiseExclusiveOr, Local(), a, b);
  83. }
  84. public static Operand BitwiseNot(this EmitterContext context, Operand a, bool invert)
  85. {
  86. if (invert)
  87. {
  88. a = context.BitwiseNot(a);
  89. }
  90. return a;
  91. }
  92. public static Operand BitwiseNot(this EmitterContext context, Operand a)
  93. {
  94. return context.Add(Instruction.BitwiseNot, Local(), a);
  95. }
  96. public static Operand BitwiseOr(this EmitterContext context, Operand a, Operand b)
  97. {
  98. return context.Add(Instruction.BitwiseOr, Local(), a, b);
  99. }
  100. public static Operand Branch(this EmitterContext context, Operand d)
  101. {
  102. return context.Add(Instruction.Branch, d);
  103. }
  104. public static Operand BranchIfFalse(this EmitterContext context, Operand d, Operand a)
  105. {
  106. return context.Add(Instruction.BranchIfFalse, d, a);
  107. }
  108. public static Operand BranchIfTrue(this EmitterContext context, Operand d, Operand a)
  109. {
  110. return context.Add(Instruction.BranchIfTrue, d, a);
  111. }
  112. public static Operand Call(this EmitterContext context, int funcId, bool returns, params Operand[] args)
  113. {
  114. Operand[] args2 = new Operand[args.Length + 1];
  115. args2[0] = Const(funcId);
  116. args.CopyTo(args2, 1);
  117. return context.Add(Instruction.Call, returns ? Local() : null, args2);
  118. }
  119. public static Operand ConditionalSelect(this EmitterContext context, Operand a, Operand b, Operand c)
  120. {
  121. return context.Add(Instruction.ConditionalSelect, Local(), a, b, c);
  122. }
  123. public static Operand Copy(this EmitterContext context, Operand a)
  124. {
  125. return context.Add(Instruction.Copy, Local(), a);
  126. }
  127. public static void Copy(this EmitterContext context, Operand d, Operand a)
  128. {
  129. if (d.Type == OperandType.Constant)
  130. {
  131. return;
  132. }
  133. context.Add(Instruction.Copy, d, a);
  134. }
  135. public static Operand Discard(this EmitterContext context)
  136. {
  137. return context.Add(Instruction.Discard);
  138. }
  139. public static Operand EmitVertex(this EmitterContext context)
  140. {
  141. return context.Add(Instruction.EmitVertex);
  142. }
  143. public static Operand EndPrimitive(this EmitterContext context)
  144. {
  145. return context.Add(Instruction.EndPrimitive);
  146. }
  147. public static Operand FindLSB(this EmitterContext context, Operand a)
  148. {
  149. return context.Add(Instruction.FindLSB, Local(), a);
  150. }
  151. public static Operand FindMSBS32(this EmitterContext context, Operand a)
  152. {
  153. return context.Add(Instruction.FindMSBS32, Local(), a);
  154. }
  155. public static Operand FindMSBU32(this EmitterContext context, Operand a)
  156. {
  157. return context.Add(Instruction.FindMSBU32, Local(), a);
  158. }
  159. public static Operand FP32ConvertToFP64(this EmitterContext context, Operand a)
  160. {
  161. return context.Add(Instruction.ConvertFP32ToFP64, Local(), a);
  162. }
  163. public static Operand FP64ConvertToFP32(this EmitterContext context, Operand a)
  164. {
  165. return context.Add(Instruction.ConvertFP64ToFP32, Local(), a);
  166. }
  167. public static Operand FPAbsNeg(this EmitterContext context, Operand a, bool abs, bool neg, Instruction fpType = Instruction.FP32)
  168. {
  169. return context.FPNegate(context.FPAbsolute(a, abs, fpType), neg, fpType);
  170. }
  171. public static Operand FPAbsolute(this EmitterContext context, Operand a, bool abs, Instruction fpType = Instruction.FP32)
  172. {
  173. if (abs)
  174. {
  175. a = context.FPAbsolute(a, fpType);
  176. }
  177. return a;
  178. }
  179. public static Operand FPAbsolute(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  180. {
  181. return context.Add(fpType | Instruction.Absolute, Local(), a);
  182. }
  183. public static Operand FPAdd(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  184. {
  185. return context.Add(fpType | Instruction.Add, Local(), a, b);
  186. }
  187. public static Operand FPCeiling(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  188. {
  189. return context.Add(fpType | Instruction.Ceiling, Local(), a);
  190. }
  191. public static Operand FPCompareEqual(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  192. {
  193. return context.Add(fpType | Instruction.CompareEqual, Local(), a, b);
  194. }
  195. public static Operand FPCompareLess(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  196. {
  197. return context.Add(fpType | Instruction.CompareLess, Local(), a, b);
  198. }
  199. public static Operand FP32ConvertToS32(this EmitterContext context, Operand a)
  200. {
  201. return context.Add(Instruction.ConvertFP32ToS32, Local(), a);
  202. }
  203. public static Operand FP32ConvertToU32(this EmitterContext context, Operand a)
  204. {
  205. return context.Add(Instruction.ConvertFP32ToU32, Local(), a);
  206. }
  207. public static Operand FP64ConvertToS32(this EmitterContext context, Operand a)
  208. {
  209. return context.Add(Instruction.ConvertFP64ToS32, Local(), a);
  210. }
  211. public static Operand FP64ConvertToU32(this EmitterContext context, Operand a)
  212. {
  213. return context.Add(Instruction.ConvertFP64ToU32, Local(), a);
  214. }
  215. public static Operand FPCosine(this EmitterContext context, Operand a)
  216. {
  217. return context.Add(Instruction.FP32 | Instruction.Cosine, Local(), a);
  218. }
  219. public static Operand FPDivide(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  220. {
  221. return context.Add(fpType | Instruction.Divide, Local(), a, b);
  222. }
  223. public static Operand FPExponentB2(this EmitterContext context, Operand a)
  224. {
  225. return context.Add(Instruction.FP32 | Instruction.ExponentB2, Local(), a);
  226. }
  227. public static Operand FPFloor(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  228. {
  229. return context.Add(fpType | Instruction.Floor, Local(), a);
  230. }
  231. public static Operand FPFusedMultiplyAdd(this EmitterContext context, Operand a, Operand b, Operand c, Instruction fpType = Instruction.FP32)
  232. {
  233. return context.Add(fpType | Instruction.FusedMultiplyAdd, Local(), a, b, c);
  234. }
  235. public static Operand FPLogarithmB2(this EmitterContext context, Operand a)
  236. {
  237. return context.Add(Instruction.FP32 | Instruction.LogarithmB2, Local(), a);
  238. }
  239. public static Operand FPMaximum(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  240. {
  241. return context.Add(fpType | Instruction.Maximum, Local(), a, b);
  242. }
  243. public static Operand FPMinimum(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  244. {
  245. return context.Add(fpType | Instruction.Minimum, Local(), a, b);
  246. }
  247. public static Operand FPMultiply(this EmitterContext context, Operand a, Operand b, Instruction fpType = Instruction.FP32)
  248. {
  249. return context.Add(fpType | Instruction.Multiply, Local(), a, b);
  250. }
  251. public static Operand FPNegate(this EmitterContext context, Operand a, bool neg, Instruction fpType = Instruction.FP32)
  252. {
  253. if (neg)
  254. {
  255. a = context.FPNegate(a, fpType);
  256. }
  257. return a;
  258. }
  259. public static Operand FPNegate(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  260. {
  261. return context.Add(fpType | Instruction.Negate, Local(), a);
  262. }
  263. public static Operand FPReciprocal(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  264. {
  265. return context.FPDivide(fpType == Instruction.FP64 ? context.PackDouble2x32(1.0) : ConstF(1), a, fpType);
  266. }
  267. public static Operand FPReciprocalSquareRoot(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  268. {
  269. return context.Add(fpType | Instruction.ReciprocalSquareRoot, Local(), a);
  270. }
  271. public static Operand FPRound(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  272. {
  273. return context.Add(fpType | Instruction.Round, Local(), a);
  274. }
  275. public static Operand FPSaturate(this EmitterContext context, Operand a, bool sat, Instruction fpType = Instruction.FP32)
  276. {
  277. if (sat)
  278. {
  279. a = context.FPSaturate(a, fpType);
  280. }
  281. return a;
  282. }
  283. public static Operand FPSaturate(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  284. {
  285. return fpType == Instruction.FP64
  286. ? context.Add(fpType | Instruction.Clamp, Local(), a, context.PackDouble2x32(0.0), context.PackDouble2x32(1.0))
  287. : context.Add(fpType | Instruction.Clamp, Local(), a, ConstF(0), ConstF(1));
  288. }
  289. public static Operand FPSine(this EmitterContext context, Operand a)
  290. {
  291. return context.Add(Instruction.FP32 | Instruction.Sine, Local(), a);
  292. }
  293. public static Operand FPSquareRoot(this EmitterContext context, Operand a)
  294. {
  295. return context.Add(Instruction.FP32 | Instruction.SquareRoot, Local(), a);
  296. }
  297. public static Operand FPTruncate(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  298. {
  299. return context.Add(fpType | Instruction.Truncate, Local(), a);
  300. }
  301. public static Operand FPSwizzleAdd(this EmitterContext context, Operand a, Operand b, int mask)
  302. {
  303. return context.Add(Instruction.SwizzleAdd, Local(), a, b, Const(mask));
  304. }
  305. public static void FSIBegin(this EmitterContext context)
  306. {
  307. context.Add(Instruction.FSIBegin);
  308. }
  309. public static void FSIEnd(this EmitterContext context)
  310. {
  311. context.Add(Instruction.FSIEnd);
  312. }
  313. public static Operand GroupMemoryBarrier(this EmitterContext context)
  314. {
  315. return context.Add(Instruction.GroupMemoryBarrier);
  316. }
  317. public static Operand IAbsNeg(this EmitterContext context, Operand a, bool abs, bool neg)
  318. {
  319. return context.INegate(context.IAbsolute(a, abs), neg);
  320. }
  321. public static Operand IAbsolute(this EmitterContext context, Operand a, bool abs)
  322. {
  323. if (abs)
  324. {
  325. a = context.IAbsolute(a);
  326. }
  327. return a;
  328. }
  329. public static Operand IAbsolute(this EmitterContext context, Operand a)
  330. {
  331. return context.Add(Instruction.Absolute, Local(), a);
  332. }
  333. public static Operand IAdd(this EmitterContext context, Operand a, Operand b)
  334. {
  335. return context.Add(Instruction.Add, Local(), a, b);
  336. }
  337. public static Operand IClampS32(this EmitterContext context, Operand a, Operand b, Operand c)
  338. {
  339. return context.Add(Instruction.Clamp, Local(), a, b, c);
  340. }
  341. public static Operand IClampU32(this EmitterContext context, Operand a, Operand b, Operand c)
  342. {
  343. return context.Add(Instruction.ClampU32, Local(), a, b, c);
  344. }
  345. public static Operand ICompareEqual(this EmitterContext context, Operand a, Operand b)
  346. {
  347. return context.Add(Instruction.CompareEqual, Local(), a, b);
  348. }
  349. public static Operand ICompareGreater(this EmitterContext context, Operand a, Operand b)
  350. {
  351. return context.Add(Instruction.CompareGreater, Local(), a, b);
  352. }
  353. public static Operand ICompareGreaterOrEqual(this EmitterContext context, Operand a, Operand b)
  354. {
  355. return context.Add(Instruction.CompareGreaterOrEqual, Local(), a, b);
  356. }
  357. public static Operand ICompareGreaterOrEqualUnsigned(this EmitterContext context, Operand a, Operand b)
  358. {
  359. return context.Add(Instruction.CompareGreaterOrEqualU32, Local(), a, b);
  360. }
  361. public static Operand ICompareGreaterUnsigned(this EmitterContext context, Operand a, Operand b)
  362. {
  363. return context.Add(Instruction.CompareGreaterU32, Local(), a, b);
  364. }
  365. public static Operand ICompareLess(this EmitterContext context, Operand a, Operand b)
  366. {
  367. return context.Add(Instruction.CompareLess, Local(), a, b);
  368. }
  369. public static Operand ICompareLessOrEqual(this EmitterContext context, Operand a, Operand b)
  370. {
  371. return context.Add(Instruction.CompareLessOrEqual, Local(), a, b);
  372. }
  373. public static Operand ICompareLessOrEqualUnsigned(this EmitterContext context, Operand a, Operand b)
  374. {
  375. return context.Add(Instruction.CompareLessOrEqualU32, Local(), a, b);
  376. }
  377. public static Operand ICompareLessUnsigned(this EmitterContext context, Operand a, Operand b)
  378. {
  379. return context.Add(Instruction.CompareLessU32, Local(), a, b);
  380. }
  381. public static Operand ICompareNotEqual(this EmitterContext context, Operand a, Operand b)
  382. {
  383. return context.Add(Instruction.CompareNotEqual, Local(), a, b);
  384. }
  385. public static Operand IConvertS32ToFP32(this EmitterContext context, Operand a)
  386. {
  387. return context.Add(Instruction.ConvertS32ToFP32, Local(), a);
  388. }
  389. public static Operand IConvertS32ToFP64(this EmitterContext context, Operand a)
  390. {
  391. return context.Add(Instruction.ConvertS32ToFP64, Local(), a);
  392. }
  393. public static Operand IConvertU32ToFP32(this EmitterContext context, Operand a)
  394. {
  395. return context.Add(Instruction.ConvertU32ToFP32, Local(), a);
  396. }
  397. public static Operand IConvertU32ToFP64(this EmitterContext context, Operand a)
  398. {
  399. return context.Add(Instruction.ConvertU32ToFP64, Local(), a);
  400. }
  401. public static Operand IMaximumS32(this EmitterContext context, Operand a, Operand b)
  402. {
  403. return context.Add(Instruction.Maximum, Local(), a, b);
  404. }
  405. public static Operand IMaximumU32(this EmitterContext context, Operand a, Operand b)
  406. {
  407. return context.Add(Instruction.MaximumU32, Local(), a, b);
  408. }
  409. public static Operand IMinimumS32(this EmitterContext context, Operand a, Operand b)
  410. {
  411. return context.Add(Instruction.Minimum, Local(), a, b);
  412. }
  413. public static Operand IMinimumU32(this EmitterContext context, Operand a, Operand b)
  414. {
  415. return context.Add(Instruction.MinimumU32, Local(), a, b);
  416. }
  417. public static Operand IMultiply(this EmitterContext context, Operand a, Operand b)
  418. {
  419. return context.Add(Instruction.Multiply, Local(), a, b);
  420. }
  421. public static Operand INegate(this EmitterContext context, Operand a, bool neg)
  422. {
  423. if (neg)
  424. {
  425. a = context.INegate(a);
  426. }
  427. return a;
  428. }
  429. public static Operand INegate(this EmitterContext context, Operand a)
  430. {
  431. return context.Add(Instruction.Negate, Local(), a);
  432. }
  433. public static Operand ISubtract(this EmitterContext context, Operand a, Operand b)
  434. {
  435. return context.Add(Instruction.Subtract, Local(), a, b);
  436. }
  437. public static Operand IsNan(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
  438. {
  439. return context.Add(fpType | Instruction.IsNan, Local(), a);
  440. }
  441. public static Operand Load(this EmitterContext context, StorageKind storageKind, IoVariable ioVariable, Operand primVertex = null)
  442. {
  443. return primVertex != null
  444. ? context.Add(Instruction.Load, storageKind, Local(), Const((int)ioVariable), primVertex)
  445. : context.Add(Instruction.Load, storageKind, Local(), Const((int)ioVariable));
  446. }
  447. public static Operand Load(
  448. this EmitterContext context,
  449. StorageKind storageKind,
  450. IoVariable ioVariable,
  451. Operand primVertex,
  452. Operand elemIndex)
  453. {
  454. return primVertex != null
  455. ? context.Add(Instruction.Load, storageKind, Local(), Const((int)ioVariable), primVertex, elemIndex)
  456. : context.Add(Instruction.Load, storageKind, Local(), Const((int)ioVariable), elemIndex);
  457. }
  458. public static Operand Load(
  459. this EmitterContext context,
  460. StorageKind storageKind,
  461. IoVariable ioVariable,
  462. Operand primVertex,
  463. Operand arrayIndex,
  464. Operand elemIndex)
  465. {
  466. return primVertex != null
  467. ? context.Add(Instruction.Load, storageKind, Local(), Const((int)ioVariable), primVertex, arrayIndex, elemIndex)
  468. : context.Add(Instruction.Load, storageKind, Local(), Const((int)ioVariable), arrayIndex, elemIndex);
  469. }
  470. public static Operand LoadConstant(this EmitterContext context, Operand a, Operand b)
  471. {
  472. if (a.Type == OperandType.Constant)
  473. {
  474. context.Config.SetUsedConstantBuffer(a.Value);
  475. }
  476. else
  477. {
  478. context.Config.SetUsedFeature(FeatureFlags.CbIndexing);
  479. }
  480. return context.Add(Instruction.LoadConstant, Local(), a, b);
  481. }
  482. public static Operand LoadGlobal(this EmitterContext context, Operand a, Operand b)
  483. {
  484. return context.Add(Instruction.LoadGlobal, Local(), a, b);
  485. }
  486. public static Operand LoadLocal(this EmitterContext context, Operand a)
  487. {
  488. return context.Add(Instruction.LoadLocal, Local(), a);
  489. }
  490. public static Operand LoadShared(this EmitterContext context, Operand a)
  491. {
  492. return context.Add(Instruction.LoadShared, Local(), a);
  493. }
  494. public static Operand MemoryBarrier(this EmitterContext context)
  495. {
  496. return context.Add(Instruction.MemoryBarrier);
  497. }
  498. public static Operand MultiplyHighS32(this EmitterContext context, Operand a, Operand b)
  499. {
  500. return context.Add(Instruction.MultiplyHighS32, Local(), a, b);
  501. }
  502. public static Operand MultiplyHighU32(this EmitterContext context, Operand a, Operand b)
  503. {
  504. return context.Add(Instruction.MultiplyHighU32, Local(), a, b);
  505. }
  506. public static Operand PackDouble2x32(this EmitterContext context, double value)
  507. {
  508. long valueAsLong = BitConverter.DoubleToInt64Bits(value);
  509. return context.Add(Instruction.PackDouble2x32, Local(), Const((int)valueAsLong), Const((int)(valueAsLong >> 32)));
  510. }
  511. public static Operand PackDouble2x32(this EmitterContext context, Operand a, Operand b)
  512. {
  513. return context.Add(Instruction.PackDouble2x32, Local(), a, b);
  514. }
  515. public static Operand PackHalf2x16(this EmitterContext context, Operand a, Operand b)
  516. {
  517. return context.Add(Instruction.PackHalf2x16, Local(), a, b);
  518. }
  519. public static void Return(this EmitterContext context)
  520. {
  521. context.PrepareForReturn();
  522. context.Add(Instruction.Return);
  523. }
  524. public static void Return(this EmitterContext context, Operand returnValue)
  525. {
  526. context.PrepareForReturn();
  527. context.Add(Instruction.Return, null, returnValue);
  528. }
  529. public static Operand ShiftLeft(this EmitterContext context, Operand a, Operand b)
  530. {
  531. return context.Add(Instruction.ShiftLeft, Local(), a, b);
  532. }
  533. public static Operand ShiftRightS32(this EmitterContext context, Operand a, Operand b)
  534. {
  535. return context.Add(Instruction.ShiftRightS32, Local(), a, b);
  536. }
  537. public static Operand ShiftRightU32(this EmitterContext context, Operand a, Operand b)
  538. {
  539. return context.Add(Instruction.ShiftRightU32, Local(), a, b);
  540. }
  541. public static (Operand, Operand) Shuffle(this EmitterContext context, Operand a, Operand b, Operand c)
  542. {
  543. return context.Add(Instruction.Shuffle, (Local(), Local()), a, b, c);
  544. }
  545. public static (Operand, Operand) ShuffleDown(this EmitterContext context, Operand a, Operand b, Operand c)
  546. {
  547. return context.Add(Instruction.ShuffleDown, (Local(), Local()), a, b, c);
  548. }
  549. public static (Operand, Operand) ShuffleUp(this EmitterContext context, Operand a, Operand b, Operand c)
  550. {
  551. return context.Add(Instruction.ShuffleUp, (Local(), Local()), a, b, c);
  552. }
  553. public static (Operand, Operand) ShuffleXor(this EmitterContext context, Operand a, Operand b, Operand c)
  554. {
  555. return context.Add(Instruction.ShuffleXor, (Local(), Local()), a, b, c);
  556. }
  557. public static Operand Store(
  558. this EmitterContext context,
  559. StorageKind storageKind,
  560. IoVariable ioVariable,
  561. Operand invocationId,
  562. Operand value)
  563. {
  564. return invocationId != null
  565. ? context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), invocationId, value)
  566. : context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), value);
  567. }
  568. public static Operand Store(
  569. this EmitterContext context,
  570. StorageKind storageKind,
  571. IoVariable ioVariable,
  572. Operand invocationId,
  573. Operand elemIndex,
  574. Operand value)
  575. {
  576. return invocationId != null
  577. ? context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), invocationId, elemIndex, value)
  578. : context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), elemIndex, value);
  579. }
  580. public static Operand Store(
  581. this EmitterContext context,
  582. StorageKind storageKind,
  583. IoVariable ioVariable,
  584. Operand invocationId,
  585. Operand arrayIndex,
  586. Operand elemIndex,
  587. Operand value)
  588. {
  589. return invocationId != null
  590. ? context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), invocationId, arrayIndex, elemIndex, value)
  591. : context.Add(Instruction.Store, storageKind, null, Const((int)ioVariable), arrayIndex, elemIndex, value);
  592. }
  593. public static Operand StoreGlobal(this EmitterContext context, Operand a, Operand b, Operand c)
  594. {
  595. return context.Add(Instruction.StoreGlobal, null, a, b, c);
  596. }
  597. public static Operand StoreGlobal16(this EmitterContext context, Operand a, Operand b, Operand c)
  598. {
  599. return context.Add(Instruction.StoreGlobal16, null, a, b, c);
  600. }
  601. public static Operand StoreGlobal8(this EmitterContext context, Operand a, Operand b, Operand c)
  602. {
  603. return context.Add(Instruction.StoreGlobal8, null, a, b, c);
  604. }
  605. public static Operand StoreLocal(this EmitterContext context, Operand a, Operand b)
  606. {
  607. return context.Add(Instruction.StoreLocal, null, a, b);
  608. }
  609. public static Operand StoreShared(this EmitterContext context, Operand a, Operand b)
  610. {
  611. return context.Add(Instruction.StoreShared, null, a, b);
  612. }
  613. public static Operand StoreShared16(this EmitterContext context, Operand a, Operand b)
  614. {
  615. return context.Add(Instruction.StoreShared16, null, a, b);
  616. }
  617. public static Operand StoreShared8(this EmitterContext context, Operand a, Operand b)
  618. {
  619. return context.Add(Instruction.StoreShared8, null, a, b);
  620. }
  621. public static Operand UnpackDouble2x32High(this EmitterContext context, Operand a)
  622. {
  623. return UnpackDouble2x32(context, a, 1);
  624. }
  625. public static Operand UnpackDouble2x32Low(this EmitterContext context, Operand a)
  626. {
  627. return UnpackDouble2x32(context, a, 0);
  628. }
  629. private static Operand UnpackDouble2x32(this EmitterContext context, Operand a, int index)
  630. {
  631. Operand dest = Local();
  632. context.Add(new Operation(Instruction.UnpackDouble2x32, index, dest, a));
  633. return dest;
  634. }
  635. public static Operand UnpackHalf2x16High(this EmitterContext context, Operand a)
  636. {
  637. return UnpackHalf2x16(context, a, 1);
  638. }
  639. public static Operand UnpackHalf2x16Low(this EmitterContext context, Operand a)
  640. {
  641. return UnpackHalf2x16(context, a, 0);
  642. }
  643. private static Operand UnpackHalf2x16(this EmitterContext context, Operand a, int index)
  644. {
  645. Operand dest = Local();
  646. context.Add(new Operation(Instruction.UnpackHalf2x16, index, dest, a));
  647. return dest;
  648. }
  649. public static Operand VoteAll(this EmitterContext context, Operand a)
  650. {
  651. return context.Add(Instruction.VoteAll, Local(), a);
  652. }
  653. public static Operand VoteAllEqual(this EmitterContext context, Operand a)
  654. {
  655. return context.Add(Instruction.VoteAllEqual, Local(), a);
  656. }
  657. public static Operand VoteAny(this EmitterContext context, Operand a)
  658. {
  659. return context.Add(Instruction.VoteAny, Local(), a);
  660. }
  661. }
  662. }