Skip to content

Commit 5b25041

Browse files
committed
Optimize some common prefixes
1 parent 91a6cf5 commit 5b25041

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

Core/MIPS/IR/IRCompVFPU.cpp

+31-4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ namespace MIPSComp {
108108
}
109109
}
110110

111+
static void InitRegs(u8 *vregs, int reg) {
112+
vregs[0] = reg;
113+
vregs[1] = reg + 1;
114+
vregs[2] = reg + 2;
115+
vregs[3] = reg + 3;
116+
}
117+
111118
void IRFrontend::ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz, int tempReg) {
112119
if (prefix == 0xE4)
113120
return;
@@ -119,6 +126,27 @@ namespace MIPSComp {
119126
for (int i = 0; i < n; i++)
120127
origV[i] = vregs[i];
121128

129+
// Some common vector prefixes
130+
if (sz == V_Quad && IsConsecutive4(vregs)) {
131+
if (prefix == 0xF00E4 && IsConsecutive4(vregs)) {
132+
InitRegs(vregs, tempReg);
133+
ir.Write(IROp::Vec4Neg, vregs[0], origV[0]);
134+
return;
135+
}
136+
if (prefix == 0x00FE4 && IsConsecutive4(vregs)) {
137+
InitRegs(vregs, tempReg);
138+
ir.Write(IROp::Vec4Abs, vregs[0], origV[0]);
139+
return;
140+
}
141+
// Pure shuffle
142+
if (prefix == (prefix & 0xFF)) {
143+
InitRegs(vregs, tempReg);
144+
ir.Write(IROp::Vec4Shuffle, vregs[0], origV[0], prefix);
145+
return;
146+
}
147+
}
148+
149+
// Alright, fall back to the generic approach.
122150
for (int i = 0; i < n; i++) {
123151
int regnum = (prefix >> (i * 2)) & 3;
124152
int abs = (prefix >> (8 + i)) & 1;
@@ -395,7 +423,6 @@ namespace MIPSComp {
395423
GetVectorRegsPrefixT(tregs, sz, vt);
396424
GetVectorRegsPrefixD(dregs, V_Single, vd);
397425

398-
// TODO: applyprefixST here somehow (shuffle, etc...)
399426
ir.Write(IROp::FMul, IRVTEMP_0, sregs[0], tregs[0]);
400427

401428
int n = GetNumVectorElements(sz);
@@ -1050,7 +1077,7 @@ namespace MIPSComp {
10501077
}
10511078
} else if (sz == M_4x4) {
10521079
// Tekken 6 has a case here: MEE
1053-
logBlocks = 1;
1080+
// logBlocks = 1;
10541081
}
10551082

10561083
// Fallback. Expands a LOT
@@ -1141,8 +1168,8 @@ namespace MIPSComp {
11411168
tempregs[i] = temp;
11421169
}
11431170
for (int i = 0; i < n; i++) {
1144-
u8 temp = tempregs[i];
1145-
ir.Write(IROp::FMov, dregs[i], temp);
1171+
if (tempregs[i] != dregs[i])
1172+
ir.Write(IROp::FMov, dregs[i], tempregs[i]);
11461173
}
11471174
}
11481175

Core/MIPS/IR/IRInst.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ static const IRMeta irMeta[] = {
109109
{ IROp::Vec4Mul, "Vec4Mul", "FFF" },
110110
{ IROp::Vec4Scale, "Vec4Scale", "FFF" },
111111
{ IROp::Vec4Dot, "Vec4Dot", "FFF" },
112+
{ IROp::Vec4Neg, "Vec4Neg", "FF" },
113+
{ IROp::Vec4Abs, "Vec4Abs", "FF" },
112114

113115
{ IROp::Interpret, "Interpret", "_C" },
114116
{ IROp::Downcount, "Downcount", "_II" },

Core/MIPS/IR/IRInst.h

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ enum class IROp : u8 {
159159
Vec4Div,
160160
Vec4Scale,
161161
Vec4Dot,
162+
Vec4Neg,
163+
Vec4Abs,
162164

163165
// vx2i
164166
Vec4ExpandU16ToU32Hi,

Core/MIPS/IR/IRInterpreter.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, const u32 *constPool, int c
212212
#endif
213213
break;
214214

215+
case IROp::Vec4Neg:
216+
for (int i = 0; i < 4; i++)
217+
mips->f[inst->dest + i] = -mips->f[inst->src1 + i];
218+
break;
219+
220+
case IROp::Vec4Abs:
221+
for (int i = 0; i < 4; i++)
222+
mips->f[inst->dest + i] = fabsf(mips->f[inst->src1 + i]);
223+
break;
224+
215225
case IROp::FCmpVfpuBit:
216226
{
217227
int op = inst->dest & 0xF;

Core/MIPS/IR/IRPassSimplify.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ bool OptimizeFPMoves(const IRWriter &in, IRWriter &out) {
114114
inst.op = IROp::FMov;
115115
inst.src1 = prev.src1;
116116
out.Write(inst);
117-
logBlocks = true;
118117
} else {
119118
out.Write(inst);
120119
}
121120
break;
121+
122122
default:
123123
// Remap constants to the new reality
124124
const IRMeta *m = GetIRMeta(inst.op);
@@ -487,6 +487,8 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
487487
case IROp::Vec4Dot:
488488
case IROp::Vec4Scale:
489489
case IROp::Vec4Shuffle:
490+
case IROp::Vec4Neg:
491+
case IROp::Vec4Abs:
490492
out.Write(inst);
491493
break;
492494

0 commit comments

Comments
 (0)