From c9ca3904d3be65d174e044bd9178ffc31a7f91b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 8 Jun 2024 22:52:47 +0200 Subject: [PATCH] Combine move-from-gpr and float cast. --- Core/MIPS/IR/IRInst.cpp | 1 + Core/MIPS/IR/IRInst.h | 1 + Core/MIPS/IR/IRInterpreter.cpp | 4 ++++ Core/MIPS/IR/IRPassSimplify.cpp | 14 +++++++++++--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Core/MIPS/IR/IRInst.cpp b/Core/MIPS/IR/IRInst.cpp index 083b6acba3..6c686c85af 100644 --- a/Core/MIPS/IR/IRInst.cpp +++ b/Core/MIPS/IR/IRInst.cpp @@ -121,6 +121,7 @@ static const IRMeta irMeta[] = { { IROp::FMovFromGPR, "FMovFromGPR", "FG" }, { IROp::FMovToGPR, "FMovToGPR", "GF" }, { IROp::OptFMovToGPRShr8, "OptFMovToGPRShr8", "GF" }, + { IROp::OptFCvtSWFromGPR, "OptFCvtSWFromGPR", "FG" }, { IROp::FpCondFromReg, "FpCondFromReg", "_G" }, { IROp::FpCondToReg, "FpCondToReg", "G" }, { IROp::FpCtrlFromReg, "FpCtrlFromReg", "_G" }, diff --git a/Core/MIPS/IR/IRInst.h b/Core/MIPS/IR/IRInst.h index 6cdd3b88ba..c7f1e30ecc 100644 --- a/Core/MIPS/IR/IRInst.h +++ b/Core/MIPS/IR/IRInst.h @@ -138,6 +138,7 @@ enum class IROp : uint8_t { FCvtScaledSW, FMovFromGPR, + OptFCvtSWFromGPR, FMovToGPR, OptFMovToGPRShr8, diff --git a/Core/MIPS/IR/IRInterpreter.cpp b/Core/MIPS/IR/IRInterpreter.cpp index 7fe2990ff4..4d46983c97 100644 --- a/Core/MIPS/IR/IRInterpreter.cpp +++ b/Core/MIPS/IR/IRInterpreter.cpp @@ -997,6 +997,9 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst) { case IROp::FMovFromGPR: memcpy(&mips->f[inst->dest], &mips->r[inst->src1], 4); break; + case IROp::OptFCvtSWFromGPR: + mips->f[inst->dest] = (float)(int)mips->r[inst->src1]; + break; case IROp::FMovToGPR: memcpy(&mips->r[inst->dest], &mips->f[inst->src1], 4); break; @@ -1007,6 +1010,7 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst) { mips->r[inst->dest] = temp >> 8; break; } + case IROp::ExitToConst: return inst->constant; diff --git a/Core/MIPS/IR/IRPassSimplify.cpp b/Core/MIPS/IR/IRPassSimplify.cpp index df384e923c..70c668fe98 100644 --- a/Core/MIPS/IR/IRPassSimplify.cpp +++ b/Core/MIPS/IR/IRPassSimplify.cpp @@ -2269,10 +2269,18 @@ bool OptimizeForInterpreter(const IRWriter &in, IRWriter &out, const IROptions & inst.op = IROp::OptFMovToGPRShr8; i++; // Skip the next instruction. } - out.Write(inst); - } else { - out.Write(inst); } + out.Write(inst); + break; + case IROp::FMovFromGPR: + if (!last) { + IRInst next = in.GetInstructions()[i + 1]; + if (next.op == IROp::FCvtSW && next.src1 == inst.dest && next.dest == inst.dest) { + inst.op = IROp::OptFCvtSWFromGPR; + i++; // Skip the next + } + } + out.Write(inst); break; default: out.Write(inst);