summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-05-10 06:37:30 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:31 +0200
commit6237300e3605c0b12fb65e2a8818487ec2cb4580 (patch)
tree9551638b7a4807cc1449c50214cd55de29c31e98
parentglasm: Fix moving U64 immediates to registers in GLASM (diff)
downloadyuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.tar
yuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.tar.gz
yuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.tar.bz2
yuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.tar.lz
yuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.tar.xz
yuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.tar.zst
yuzu-6237300e3605c0b12fb65e2a8818487ec2cb4580.zip
Diffstat (limited to '')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp
index 2aee5a56c..2e1c7d55f 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm_floating_point.cpp
@@ -9,11 +9,10 @@
#include "shader_recompiler/frontend/ir/value.h"
namespace Shader::Backend::GLASM {
-
+namespace {
template <typename InputType>
-static void Compare(EmitContext& ctx, IR::Inst& inst, InputType lhs, InputType rhs,
- std::string_view op, std::string_view type, bool ordered,
- bool inequality = false) {
+void Compare(EmitContext& ctx, IR::Inst& inst, InputType lhs, InputType rhs, std::string_view op,
+ std::string_view type, bool ordered, bool inequality = false) {
const Register ret{ctx.reg_alloc.Define(inst)};
ctx.Add("{}.{} RC.x,{},{};", op, type, lhs, rhs);
if (ordered && inequality) {
@@ -35,6 +34,16 @@ static void Compare(EmitContext& ctx, IR::Inst& inst, InputType lhs, InputType r
}
}
+template <typename InputType>
+void Clamp(EmitContext& ctx, Register ret, InputType value, InputType min_value,
+ InputType max_value) {
+ // Call MAX first to properly clamp nan to min_value instead
+ ctx.Add("MAX.F {}.x,{},{};"
+ "MIN.F {}.x,{},{};",
+ ret, min_value, value, ret, ret, max_value);
+}
+} // Anonymous namespace
+
void EmitFPAbs16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] Register value) {
throw NotImplementedException("GLASM instruction");
@@ -171,18 +180,12 @@ void EmitFPClamp16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register
void EmitFPClamp32(EmitContext& ctx, IR::Inst& inst, ScalarF32 value, ScalarF32 min_value,
ScalarF32 max_value) {
- const Register ret{ctx.reg_alloc.Define(inst)};
- ctx.Add("MIN.F {}.x,{},{};"
- "MAX.F {}.x,{},{};",
- ret, max_value, value, ret, ret, min_value);
+ Clamp(ctx, ctx.reg_alloc.Define(inst), value, min_value, max_value);
}
void EmitFPClamp64(EmitContext& ctx, IR::Inst& inst, ScalarF64 value, ScalarF64 min_value,
ScalarF64 max_value) {
- const Register ret{ctx.reg_alloc.LongDefine(inst)};
- ctx.Add("MIN.F64 {}.x,{},{};"
- "MAX.F64 {}.x,{},{};",
- ret, max_value, value, ret, ret, min_value);
+ Clamp(ctx, ctx.reg_alloc.LongDefine(inst), value, min_value, max_value);
}
void EmitFPRoundEven16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register value) {