emit_glasm_select.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h"
  5. #include "shader_recompiler/backend/glasm/glasm_emit_context.h"
  6. #include "shader_recompiler/frontend/ir/value.h"
  7. namespace Shader::Backend::GLASM {
  8. void EmitSelectU1(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, ScalarS32 true_value,
  9. ScalarS32 false_value) {
  10. ctx.Add("CMP.S {},{},{},{};", inst, cond, true_value, false_value);
  11. }
  12. void EmitSelectU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond,
  13. [[maybe_unused]] ScalarS32 true_value, [[maybe_unused]] ScalarS32 false_value) {
  14. throw NotImplementedException("GLASM instruction");
  15. }
  16. void EmitSelectU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond,
  17. [[maybe_unused]] ScalarS32 true_value, [[maybe_unused]] ScalarS32 false_value) {
  18. throw NotImplementedException("GLASM instruction");
  19. }
  20. void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, ScalarS32 true_value,
  21. ScalarS32 false_value) {
  22. ctx.Add("CMP.S {},{},{},{};", inst, cond, true_value, false_value);
  23. }
  24. void EmitSelectU64(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, Register true_value,
  25. Register false_value) {
  26. ctx.reg_alloc.InvalidateConditionCodes();
  27. const Register ret{ctx.reg_alloc.LongDefine(inst)};
  28. if (ret == true_value) {
  29. ctx.Add("MOV.S.CC RC.x,{};"
  30. "MOV.U64 {}.x(EQ.x),{};",
  31. cond, ret, false_value);
  32. } else if (ret == false_value) {
  33. ctx.Add("MOV.S.CC RC.x,{};"
  34. "MOV.U64 {}.x(NE.x),{};",
  35. cond, ret, true_value);
  36. } else {
  37. ctx.Add("MOV.S.CC RC.x,{};"
  38. "MOV.U64 {}.x,{};"
  39. "MOV.U64 {}.x(NE.x),{};",
  40. cond, ret, false_value, ret, true_value);
  41. }
  42. }
  43. void EmitSelectF16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond,
  44. [[maybe_unused]] Register true_value, [[maybe_unused]] Register false_value) {
  45. throw NotImplementedException("GLASM instruction");
  46. }
  47. void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, ScalarS32 true_value,
  48. ScalarS32 false_value) {
  49. ctx.Add("CMP.S {},{},{},{};", inst, cond, true_value, false_value);
  50. }
  51. void EmitSelectF64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond,
  52. [[maybe_unused]] Register true_value, [[maybe_unused]] Register false_value) {
  53. throw NotImplementedException("GLASM instruction");
  54. }
  55. } // namespace Shader::Backend::GLASM