diff options
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm_select.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm_select.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_select.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_select.cpp new file mode 100644 index 000000000..68fff613c --- /dev/null +++ b/src/shader_recompiler/backend/glasm/emit_glasm_select.cpp | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | |||
| 2 | // Copyright 2021 yuzu Emulator Project | ||
| 3 | // Licensed under GPLv2 or any later version | ||
| 4 | // Refer to the license.txt file included. | ||
| 5 | |||
| 6 | #include "shader_recompiler/backend/glasm/emit_context.h" | ||
| 7 | #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h" | ||
| 8 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 9 | |||
| 10 | namespace Shader::Backend::GLASM { | ||
| 11 | |||
| 12 | void EmitSelectU1(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, ScalarS32 true_value, | ||
| 13 | ScalarS32 false_value) { | ||
| 14 | ctx.Add("CMP.S {},{},{},{};", inst, cond, true_value, false_value); | ||
| 15 | } | ||
| 16 | |||
| 17 | void EmitSelectU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond, | ||
| 18 | [[maybe_unused]] ScalarS32 true_value, [[maybe_unused]] ScalarS32 false_value) { | ||
| 19 | throw NotImplementedException("GLASM instruction"); | ||
| 20 | } | ||
| 21 | |||
| 22 | void EmitSelectU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond, | ||
| 23 | [[maybe_unused]] ScalarS32 true_value, [[maybe_unused]] ScalarS32 false_value) { | ||
| 24 | throw NotImplementedException("GLASM instruction"); | ||
| 25 | } | ||
| 26 | |||
| 27 | void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, ScalarS32 true_value, | ||
| 28 | ScalarS32 false_value) { | ||
| 29 | ctx.Add("CMP.S {},{},{},{};", inst, cond, true_value, false_value); | ||
| 30 | } | ||
| 31 | |||
| 32 | void EmitSelectU64(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, Register true_value, | ||
| 33 | Register false_value) { | ||
| 34 | ctx.reg_alloc.InvalidateConditionCodes(); | ||
| 35 | const Register ret{ctx.reg_alloc.LongDefine(inst)}; | ||
| 36 | if (ret == true_value) { | ||
| 37 | ctx.Add("MOV.S.CC RC.x,{};" | ||
| 38 | "MOV.U64 {}.x(EQ.x),{};", | ||
| 39 | cond, ret, false_value); | ||
| 40 | } else if (ret == false_value) { | ||
| 41 | ctx.Add("MOV.S.CC RC.x,{};" | ||
| 42 | "MOV.U64 {}.x(NE.x),{};", | ||
| 43 | cond, ret, true_value); | ||
| 44 | } else { | ||
| 45 | ctx.Add("MOV.S.CC RC.x,{};" | ||
| 46 | "MOV.U64 {}.x,{};" | ||
| 47 | "MOV.U64 {}.x(NE.x),{};", | ||
| 48 | cond, ret, false_value, ret, true_value); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void EmitSelectF16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond, | ||
| 53 | [[maybe_unused]] Register true_value, [[maybe_unused]] Register false_value) { | ||
| 54 | throw NotImplementedException("GLASM instruction"); | ||
| 55 | } | ||
| 56 | |||
| 57 | void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, ScalarS32 cond, ScalarS32 true_value, | ||
| 58 | ScalarS32 false_value) { | ||
| 59 | ctx.Add("CMP.S {},{},{},{};", inst, cond, true_value, false_value); | ||
| 60 | } | ||
| 61 | |||
| 62 | void EmitSelectF64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] ScalarS32 cond, | ||
| 63 | [[maybe_unused]] Register true_value, [[maybe_unused]] Register false_value) { | ||
| 64 | throw NotImplementedException("GLASM instruction"); | ||
| 65 | } | ||
| 66 | |||
| 67 | } // namespace Shader::Backend::GLASM | ||