From 2ff91fab2b14ebcee4002e8e71575ddd685ba251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 8 Jun 2024 23:10:29 +0200 Subject: [PATCH] Optimize a common case of the ins instruction --- Core/MIPS/IR/IRCompALU.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Core/MIPS/IR/IRCompALU.cpp b/Core/MIPS/IR/IRCompALU.cpp index e8fe1c46b6..1432d6b720 100644 --- a/Core/MIPS/IR/IRCompALU.cpp +++ b/Core/MIPS/IR/IRCompALU.cpp @@ -248,9 +248,20 @@ void IRFrontend::Comp_Special3(MIPSOpcode op) { { u32 sourcemask = mask >> pos; u32 destmask = ~(sourcemask << pos); - ir.Write(IROp::AndConst, IRTEMP_0, rs, ir.AddConstant(sourcemask)); - if (pos != 0) { - ir.Write(IROp::ShlImm, IRTEMP_0, IRTEMP_0, pos); + + if (size != 32) { + // Need to use the sourcemask. + ir.Write(IROp::AndConst, IRTEMP_0, rs, ir.AddConstant(sourcemask)); + if (pos != 0) { + ir.Write(IROp::ShlImm, IRTEMP_0, IRTEMP_0, pos); + } + } else { + // If the shl takes care of the sourcemask, don't need to and. + if (pos != 0) { + ir.Write(IROp::ShlImm, IRTEMP_0, rs, pos); + } else { + ir.Write(IROp::Mov, IRTEMP_0, rs); + } } ir.Write(IROp::AndConst, rt, rt, ir.AddConstant(destmask)); ir.Write(IROp::Or, rt, rt, IRTEMP_0);