emit_glasm_floating_point.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <string_view>
  5. #include "shader_recompiler/backend/glasm/emit_context.h"
  6. #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h"
  7. #include "shader_recompiler/frontend/ir/value.h"
  8. namespace Shader::Backend::GLASM {
  9. void EmitFPAbs16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  10. throw NotImplementedException("GLASM instruction");
  11. }
  12. void EmitFPAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
  13. ctx.Add("MOV.F {},|{}|;", inst, value);
  14. }
  15. void EmitFPAbs64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  16. throw NotImplementedException("GLASM instruction");
  17. }
  18. void EmitFPAdd16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
  19. [[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
  20. throw NotImplementedException("GLASM instruction");
  21. }
  22. void EmitFPAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
  23. ctx.Add("ADD.F {},{},{};", inst, a, b);
  24. }
  25. void EmitFPAdd64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
  26. [[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
  27. throw NotImplementedException("GLASM instruction");
  28. }
  29. void EmitFPFma16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
  30. [[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b,
  31. [[maybe_unused]] std::string_view c) {
  32. throw NotImplementedException("GLASM instruction");
  33. }
  34. void EmitFPFma32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b,
  35. std::string_view c) {
  36. ctx.Add("MAD.F {},{},{},{};", inst, a, b, c);
  37. }
  38. void EmitFPFma64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
  39. [[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b,
  40. [[maybe_unused]] std::string_view c) {
  41. throw NotImplementedException("GLASM instruction");
  42. }
  43. void EmitFPMax32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view a,
  44. [[maybe_unused]] std::string_view b) {
  45. throw NotImplementedException("GLASM instruction");
  46. }
  47. void EmitFPMax64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view a,
  48. [[maybe_unused]] std::string_view b) {
  49. throw NotImplementedException("GLASM instruction");
  50. }
  51. void EmitFPMin32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view a,
  52. [[maybe_unused]] std::string_view b) {
  53. throw NotImplementedException("GLASM instruction");
  54. }
  55. void EmitFPMin64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view a,
  56. [[maybe_unused]] std::string_view b) {
  57. throw NotImplementedException("GLASM instruction");
  58. }
  59. void EmitFPMul16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
  60. [[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
  61. throw NotImplementedException("GLASM instruction");
  62. }
  63. void EmitFPMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
  64. ctx.Add("MUL.F {},{},{};", inst, a, b);
  65. }
  66. void EmitFPMul64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
  67. [[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
  68. throw NotImplementedException("GLASM instruction");
  69. }
  70. void EmitFPNeg16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  71. throw NotImplementedException("GLASM instruction");
  72. }
  73. void EmitFPNeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
  74. if (value[0] == '-') {
  75. // Guard against negating a negative immediate
  76. ctx.Add("MOV.F {},{};", inst, value.substr(1));
  77. } else {
  78. ctx.Add("MOV.F {},-{};", inst, value);
  79. }
  80. }
  81. void EmitFPNeg64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  82. throw NotImplementedException("GLASM instruction");
  83. }
  84. void EmitFPSin([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  85. throw NotImplementedException("GLASM instruction");
  86. }
  87. void EmitFPCos([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  88. throw NotImplementedException("GLASM instruction");
  89. }
  90. void EmitFPExp2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  91. throw NotImplementedException("GLASM instruction");
  92. }
  93. void EmitFPLog2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  94. throw NotImplementedException("GLASM instruction");
  95. }
  96. void EmitFPRecip32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  97. throw NotImplementedException("GLASM instruction");
  98. }
  99. void EmitFPRecip64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  100. throw NotImplementedException("GLASM instruction");
  101. }
  102. void EmitFPRecipSqrt32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  103. throw NotImplementedException("GLASM instruction");
  104. }
  105. void EmitFPRecipSqrt64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  106. throw NotImplementedException("GLASM instruction");
  107. }
  108. void EmitFPSqrt([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  109. throw NotImplementedException("GLASM instruction");
  110. }
  111. void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  112. throw NotImplementedException("GLASM instruction");
  113. }
  114. void EmitFPSaturate32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
  115. ctx.Add("MOV.F.SAT {},{};", inst, value);
  116. }
  117. void EmitFPSaturate64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  118. throw NotImplementedException("GLASM instruction");
  119. }
  120. void EmitFPClamp16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value,
  121. [[maybe_unused]] std::string_view min_value,
  122. [[maybe_unused]] std::string_view max_value) {
  123. throw NotImplementedException("GLASM instruction");
  124. }
  125. void EmitFPClamp32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value,
  126. [[maybe_unused]] std::string_view min_value,
  127. [[maybe_unused]] std::string_view max_value) {
  128. throw NotImplementedException("GLASM instruction");
  129. }
  130. void EmitFPClamp64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value,
  131. [[maybe_unused]] std::string_view min_value,
  132. [[maybe_unused]] std::string_view max_value) {
  133. throw NotImplementedException("GLASM instruction");
  134. }
  135. void EmitFPRoundEven16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  136. throw NotImplementedException("GLASM instruction");
  137. }
  138. void EmitFPRoundEven32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  139. throw NotImplementedException("GLASM instruction");
  140. }
  141. void EmitFPRoundEven64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  142. throw NotImplementedException("GLASM instruction");
  143. }
  144. void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  145. throw NotImplementedException("GLASM instruction");
  146. }
  147. void EmitFPFloor32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  148. throw NotImplementedException("GLASM instruction");
  149. }
  150. void EmitFPFloor64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  151. throw NotImplementedException("GLASM instruction");
  152. }
  153. void EmitFPCeil16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  154. throw NotImplementedException("GLASM instruction");
  155. }
  156. void EmitFPCeil32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  157. throw NotImplementedException("GLASM instruction");
  158. }
  159. void EmitFPCeil64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  160. throw NotImplementedException("GLASM instruction");
  161. }
  162. void EmitFPTrunc16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  163. throw NotImplementedException("GLASM instruction");
  164. }
  165. void EmitFPTrunc32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  166. throw NotImplementedException("GLASM instruction");
  167. }
  168. void EmitFPTrunc64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) {
  169. throw NotImplementedException("GLASM instruction");
  170. }
  171. void EmitFPOrdEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  172. [[maybe_unused]] std::string_view rhs) {
  173. throw NotImplementedException("GLASM instruction");
  174. }
  175. void EmitFPOrdEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
  176. std::string_view rhs) {
  177. const std::string ret{ctx.reg_alloc.Define(inst)};
  178. ctx.Add("SEQ.F {},{},{};SNE.S {},{},0;", ret, lhs, rhs, ret, ret);
  179. }
  180. void EmitFPOrdEqual64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  181. [[maybe_unused]] std::string_view rhs) {
  182. throw NotImplementedException("GLASM instruction");
  183. }
  184. void EmitFPUnordEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  185. [[maybe_unused]] std::string_view rhs) {
  186. throw NotImplementedException("GLASM instruction");
  187. }
  188. void EmitFPUnordEqual32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  189. [[maybe_unused]] std::string_view rhs) {
  190. throw NotImplementedException("GLASM instruction");
  191. }
  192. void EmitFPUnordEqual64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  193. [[maybe_unused]] std::string_view rhs) {
  194. throw NotImplementedException("GLASM instruction");
  195. }
  196. void EmitFPOrdNotEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  197. [[maybe_unused]] std::string_view rhs) {
  198. throw NotImplementedException("GLASM instruction");
  199. }
  200. void EmitFPOrdNotEqual32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  201. [[maybe_unused]] std::string_view rhs) {
  202. throw NotImplementedException("GLASM instruction");
  203. }
  204. void EmitFPOrdNotEqual64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  205. [[maybe_unused]] std::string_view rhs) {
  206. throw NotImplementedException("GLASM instruction");
  207. }
  208. void EmitFPUnordNotEqual16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  209. [[maybe_unused]] std::string_view rhs) {
  210. throw NotImplementedException("GLASM instruction");
  211. }
  212. void EmitFPUnordNotEqual32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  213. [[maybe_unused]] std::string_view rhs) {
  214. throw NotImplementedException("GLASM instruction");
  215. }
  216. void EmitFPUnordNotEqual64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  217. [[maybe_unused]] std::string_view rhs) {
  218. throw NotImplementedException("GLASM instruction");
  219. }
  220. void EmitFPOrdLessThan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  221. [[maybe_unused]] std::string_view rhs) {
  222. throw NotImplementedException("GLASM instruction");
  223. }
  224. void EmitFPOrdLessThan32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
  225. std::string_view rhs) {
  226. const std::string ret{ctx.reg_alloc.Define(inst)};
  227. ctx.Add("SLT.F {},{},{};SNE.S {},{},0;", ret, lhs, rhs, ret, ret);
  228. }
  229. void EmitFPOrdLessThan64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  230. [[maybe_unused]] std::string_view rhs) {
  231. throw NotImplementedException("GLASM instruction");
  232. }
  233. void EmitFPUnordLessThan16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  234. [[maybe_unused]] std::string_view rhs) {
  235. throw NotImplementedException("GLASM instruction");
  236. }
  237. void EmitFPUnordLessThan32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  238. [[maybe_unused]] std::string_view rhs) {
  239. throw NotImplementedException("GLASM instruction");
  240. }
  241. void EmitFPUnordLessThan64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view lhs,
  242. [[maybe_unused]] std::string_view rhs) {
  243. throw NotImplementedException("GLASM instruction");
  244. }
  245. void EmitFPOrdGreaterThan16([[maybe_unused]] EmitContext& ctx,
  246. [[maybe_unused]] std::string_view lhs,
  247. [[maybe_unused]] std::string_view rhs) {
  248. throw NotImplementedException("GLASM instruction");
  249. }
  250. void EmitFPOrdGreaterThan32([[maybe_unused]] EmitContext& ctx,
  251. [[maybe_unused]] std::string_view lhs,
  252. [[maybe_unused]] std::string_view rhs) {
  253. throw NotImplementedException("GLASM instruction");
  254. }
  255. void EmitFPOrdGreaterThan64([[maybe_unused]] EmitContext& ctx,
  256. [[maybe_unused]] std::string_view lhs,
  257. [[maybe_unused]] std::string_view rhs) {
  258. throw NotImplementedException("GLASM instruction");
  259. }
  260. void EmitFPUnordGreaterThan16([[maybe_unused]] EmitContext& ctx,
  261. [[maybe_unused]] std::string_view lhs,
  262. [[maybe_unused]] std::string_view rhs) {
  263. throw NotImplementedException("GLASM instruction");
  264. }
  265. void EmitFPUnordGreaterThan32([[maybe_unused]] EmitContext& ctx,
  266. [[maybe_unused]] std::string_view lhs,
  267. [[maybe_unused]] std::string_view rhs) {
  268. throw NotImplementedException("GLASM instruction");
  269. }
  270. void EmitFPUnordGreaterThan64([[maybe_unused]] EmitContext& ctx,
  271. [[maybe_unused]] std::string_view lhs,
  272. [[maybe_unused]] std::string_view rhs) {
  273. throw NotImplementedException("GLASM instruction");
  274. }
  275. void EmitFPOrdLessThanEqual16([[maybe_unused]] EmitContext& ctx,
  276. [[maybe_unused]] std::string_view lhs,
  277. [[maybe_unused]] std::string_view rhs) {
  278. throw NotImplementedException("GLASM instruction");
  279. }
  280. void EmitFPOrdLessThanEqual32(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
  281. std::string_view rhs) {
  282. const std::string ret{ctx.reg_alloc.Define(inst)};
  283. ctx.Add("SLE.F {},{},{};SNE.S {},{},0;", ret, lhs, rhs, ret, ret);
  284. }
  285. void EmitFPOrdLessThanEqual64([[maybe_unused]] EmitContext& ctx,
  286. [[maybe_unused]] std::string_view lhs,
  287. [[maybe_unused]] std::string_view rhs) {
  288. throw NotImplementedException("GLASM instruction");
  289. }
  290. void EmitFPUnordLessThanEqual16([[maybe_unused]] EmitContext& ctx,
  291. [[maybe_unused]] std::string_view lhs,
  292. [[maybe_unused]] std::string_view rhs) {
  293. throw NotImplementedException("GLASM instruction");
  294. }
  295. void EmitFPUnordLessThanEqual32([[maybe_unused]] EmitContext& ctx,
  296. [[maybe_unused]] std::string_view lhs,
  297. [[maybe_unused]] std::string_view rhs) {
  298. throw NotImplementedException("GLASM instruction");
  299. }
  300. void EmitFPUnordLessThanEqual64([[maybe_unused]] EmitContext& ctx,
  301. [[maybe_unused]] std::string_view lhs,
  302. [[maybe_unused]] std::string_view rhs) {
  303. throw NotImplementedException("GLASM instruction");
  304. }
  305. void EmitFPOrdGreaterThanEqual16([[maybe_unused]] EmitContext& ctx,
  306. [[maybe_unused]] std::string_view lhs,
  307. [[maybe_unused]] std::string_view rhs) {
  308. throw NotImplementedException("GLASM instruction");
  309. }
  310. void EmitFPOrdGreaterThanEqual32([[maybe_unused]] EmitContext& ctx,
  311. [[maybe_unused]] std::string_view lhs,
  312. [[maybe_unused]] std::string_view rhs) {
  313. throw NotImplementedException("GLASM instruction");
  314. }
  315. void EmitFPOrdGreaterThanEqual64([[maybe_unused]] EmitContext& ctx,
  316. [[maybe_unused]] std::string_view lhs,
  317. [[maybe_unused]] std::string_view rhs) {
  318. throw NotImplementedException("GLASM instruction");
  319. }
  320. void EmitFPUnordGreaterThanEqual16([[maybe_unused]] EmitContext& ctx,
  321. [[maybe_unused]] std::string_view lhs,
  322. [[maybe_unused]] std::string_view rhs) {
  323. throw NotImplementedException("GLASM instruction");
  324. }
  325. void EmitFPUnordGreaterThanEqual32([[maybe_unused]] EmitContext& ctx,
  326. [[maybe_unused]] std::string_view lhs,
  327. [[maybe_unused]] std::string_view rhs) {
  328. throw NotImplementedException("GLASM instruction");
  329. }
  330. void EmitFPUnordGreaterThanEqual64([[maybe_unused]] EmitContext& ctx,
  331. [[maybe_unused]] std::string_view lhs,
  332. [[maybe_unused]] std::string_view rhs) {
  333. throw NotImplementedException("GLASM instruction");
  334. }
  335. } // namespace Shader::Backend::GLASM