Combine move-from-gpr and float cast.

This commit is contained in:
Henrik Rydgård 2024-06-08 22:52:47 +02:00
parent 0abcd00372
commit c9ca3904d3
4 changed files with 17 additions and 3 deletions

View file

@ -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" },

View file

@ -138,6 +138,7 @@ enum class IROp : uint8_t {
FCvtScaledSW,
FMovFromGPR,
OptFCvtSWFromGPR,
FMovToGPR,
OptFMovToGPRShr8,

View file

@ -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;

View file

@ -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);