mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-30 09:43:45 +01:00
IR: Merge the FPU and VFPU instruction sets, no reason to keep them apart
This commit is contained in:
1 parent
45efcda6b1
commit
db1d1ff9fd
5 files changed
+62
-108
No files matched your search
+20
-18
@@ -50,10 +50,12 @@
|
||||
#define _IMM16 (signed short)(op & 0xFFFF)
|
||||
#define _IMM26 (op & 0x03FFFFFF)
|
||||
|
||||
const int vfpuBase = 32; // skip the FP registers
|
||||
|
||||
namespace MIPSComp {
|
||||
static void ApplyVoffset(u8 regs[4], int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
regs[i] = voffset[regs[i]];
|
||||
regs[i] = vfpuBase + voffset[regs[i]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +196,11 @@ namespace MIPSComp {
|
||||
MIPSGPReg rs = _RS;
|
||||
switch (op >> 26) {
|
||||
case 50: //lv.s
|
||||
ir.Write(IROp::LoadFloatV, voffset[vt], rs, ir.AddConstant(offset));
|
||||
ir.Write(IROp::LoadFloat, vfpuBase + voffset[vt], rs, ir.AddConstant(offset));
|
||||
break;
|
||||
|
||||
case 58: //sv.s
|
||||
ir.Write(IROp::StoreFloatV, voffset[vt], rs, ir.AddConstant(offset));
|
||||
ir.Write(IROp::StoreFloat, vfpuBase + voffset[vt], rs, ir.AddConstant(offset));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -221,10 +223,10 @@ namespace MIPSComp {
|
||||
ir.Write(IROp::LoadVec4, vregs[0], rs, ir.AddConstant(imm));
|
||||
} else {
|
||||
// Let's not even bother with "vertical" loads for now.
|
||||
ir.Write(IROp::LoadFloatV, vregs[0], rs, ir.AddConstant(imm));
|
||||
ir.Write(IROp::LoadFloatV, vregs[1], rs, ir.AddConstant(imm + 4));
|
||||
ir.Write(IROp::LoadFloatV, vregs[2], rs, ir.AddConstant(imm + 8));
|
||||
ir.Write(IROp::LoadFloatV, vregs[3], rs, ir.AddConstant(imm + 12));
|
||||
ir.Write(IROp::LoadFloat, vregs[0], rs, ir.AddConstant(imm));
|
||||
ir.Write(IROp::LoadFloat, vregs[1], rs, ir.AddConstant(imm + 4));
|
||||
ir.Write(IROp::LoadFloat, vregs[2], rs, ir.AddConstant(imm + 8));
|
||||
ir.Write(IROp::LoadFloat, vregs[3], rs, ir.AddConstant(imm + 12));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -233,10 +235,10 @@ namespace MIPSComp {
|
||||
ir.Write(IROp::StoreVec4, vregs[0], rs, ir.AddConstant(imm));
|
||||
} else {
|
||||
// Let's not even bother with "vertical" stores for now.
|
||||
ir.Write(IROp::StoreFloatV, vregs[0], rs, ir.AddConstant(imm));
|
||||
ir.Write(IROp::StoreFloatV, vregs[1], rs, ir.AddConstant(imm + 4));
|
||||
ir.Write(IROp::StoreFloatV, vregs[2], rs, ir.AddConstant(imm + 8));
|
||||
ir.Write(IROp::StoreFloatV, vregs[3], rs, ir.AddConstant(imm + 12));
|
||||
ir.Write(IROp::StoreFloat, vregs[0], rs, ir.AddConstant(imm));
|
||||
ir.Write(IROp::StoreFloat, vregs[1], rs, ir.AddConstant(imm + 4));
|
||||
ir.Write(IROp::StoreFloat, vregs[2], rs, ir.AddConstant(imm + 8));
|
||||
ir.Write(IROp::StoreFloat, vregs[3], rs, ir.AddConstant(imm + 12));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -257,9 +259,9 @@ namespace MIPSComp {
|
||||
if (sz == 4 && IsVectorColumn(vd)) {
|
||||
u8 dregs[4];
|
||||
GetVectorRegs(dregs, sz, vd);
|
||||
ir.Write(IROp::InitVec4, voffset[dregs[0]], (int)(type == 6 ? Vec4Init::AllZERO : Vec4Init::AllONE));
|
||||
ir.Write(IROp::InitVec4, vfpuBase + voffset[dregs[0]], (int)(type == 6 ? Vec4Init::AllZERO : Vec4Init::AllONE));
|
||||
} else if (sz == 1) {
|
||||
ir.Write(IROp::SetConstV, voffset[vd], ir.AddConstantFloat(type == 6 ? 0.0f : 1.0f));
|
||||
ir.Write(IROp::SetConstF, vfpuBase + voffset[vd], ir.AddConstantFloat(type == 6 ? 0.0f : 1.0f));
|
||||
} else {
|
||||
DISABLE;
|
||||
}
|
||||
@@ -281,7 +283,7 @@ namespace MIPSComp {
|
||||
GetVectorRegs(dregs, sz, vd);
|
||||
int row = vd & 3;
|
||||
Vec4Init init = Vec4Init((int)Vec4Init::Set_1000 + row);
|
||||
ir.Write(IROp::InitVec4, voffset[dregs[0]], (int)init);
|
||||
ir.Write(IROp::InitVec4, vfpuBase + voffset[dregs[0]], (int)init);
|
||||
}
|
||||
|
||||
void IRFrontend::Comp_VMatrixInit(MIPSOpcode op) {
|
||||
@@ -317,7 +319,7 @@ namespace MIPSComp {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
ir.Write(IROp::InitVec4, voffset[vec[0]], (int)init);
|
||||
ir.Write(IROp::InitVec4, vfpuBase + voffset[vec[0]], (int)init);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -369,7 +371,7 @@ namespace MIPSComp {
|
||||
// rt = 0, imm = 255 appears to be used as a CPU interlock by some games.
|
||||
if (rt != 0) {
|
||||
if (imm < 128) { //R(rt) = VI(imm);
|
||||
ir.Write(IROp::VMovToGPR, rt, voffset[imm]);
|
||||
ir.Write(IROp::FMovToGPR, rt, vfpuBase + voffset[imm]);
|
||||
} else {
|
||||
DISABLE;
|
||||
}
|
||||
@@ -378,7 +380,7 @@ namespace MIPSComp {
|
||||
|
||||
case 7: // mtv
|
||||
if (imm < 128) {
|
||||
ir.Write(IROp::VMovFromGPR, voffset[imm], rt);
|
||||
ir.Write(IROp::FMovFromGPR, vfpuBase + voffset[imm], rt);
|
||||
} else {
|
||||
DISABLE;
|
||||
}
|
||||
@@ -451,7 +453,7 @@ namespace MIPSComp {
|
||||
|
||||
u8 dreg = _VT;
|
||||
s32 imm = (s32)(s16)(u16)(op & 0xFFFF);
|
||||
ir.Write(IROp::SetConstV, voffset[dreg], ir.AddConstantFloat((float)imm));
|
||||
ir.Write(IROp::SetConstF, vfpuBase + voffset[dreg], ir.AddConstantFloat((float)imm));
|
||||
}
|
||||
|
||||
void IRFrontend::Comp_Vfim(MIPSOpcode op) {
|
||||
|
||||
+14
-18
@@ -6,7 +6,6 @@
|
||||
static const IRMeta irMeta[] = {
|
||||
{ IROp::SetConst, "SetConst", "GC" },
|
||||
{ IROp::SetConstF, "SetConstF", "FC" },
|
||||
{ IROp::SetConstV, "SetConstV", "VC" },
|
||||
{ IROp::Mov, "Mov", "GG" },
|
||||
{ IROp::Add, "Add", "GGG" },
|
||||
{ IROp::Sub, "Sub", "GGG" },
|
||||
@@ -59,14 +58,12 @@ static const IRMeta irMeta[] = {
|
||||
{ IROp::Load16Ext, "Load16Ext", "GGC" },
|
||||
{ IROp::Load32, "Load32", "GGC" },
|
||||
{ IROp::LoadFloat, "LoadFloat", "FGC" },
|
||||
{ IROp::LoadFloatV, "LoadFloatV", "VGC" },
|
||||
{ IROp::LoadVec4, "LoadVec4", "VGC" },
|
||||
{ IROp::LoadVec4, "LoadVec4", "FGC" },
|
||||
{ IROp::Store8, "Store8", "GGC" },
|
||||
{ IROp::Store16, "Store16", "GGC" },
|
||||
{ IROp::Store32, "Store32", "GGC" },
|
||||
{ IROp::StoreFloat, "StoreFloat", "FGC" },
|
||||
{ IROp::StoreFloatV, "StoreFloatV", "VGC" },
|
||||
{ IROp::StoreVec4, "StoreVec4", "VGC" },
|
||||
{ IROp::StoreVec4, "StoreVec4", "FGC" },
|
||||
{ IROp::FAdd, "FAdd", "FFF" },
|
||||
{ IROp::FSub, "FSub", "FFF" },
|
||||
{ IROp::FMul, "FMul", "FFF" },
|
||||
@@ -83,19 +80,17 @@ static const IRMeta irMeta[] = {
|
||||
{ IROp::FCvtSW, "FCvtSW", "FF" },
|
||||
{ IROp::FMovFromGPR, "FMovFromGPR", "FG" },
|
||||
{ IROp::FMovToGPR, "FMovToGPR", "GF" },
|
||||
{ IROp::VMovFromGPR, "VMovFromGPR", "VG" },
|
||||
{ IROp::VMovToGPR, "VMovToGPR", "GV" },
|
||||
{ IROp::InitVec4, "InitVec4", "Vv"},
|
||||
{ IROp::InitVec4, "InitVec4", "Fv"},
|
||||
{ IROp::FpCondToReg, "FpCondToReg", "G" },
|
||||
{ IROp::VfpuCtrlToReg, "VfpuCtrlToReg", "GI" },
|
||||
{ IROp::SetCtrlVFPU, "SetCtrlVFPU", "TC" },
|
||||
|
||||
{ IROp::VSin, "VSin", "VV" },
|
||||
{ IROp::VCos, "VCos", "VV" },
|
||||
{ IROp::VSqrt, "VSqrt", "VV" },
|
||||
{ IROp::VRSqrt, "VRSqrt", "VV" },
|
||||
{ IROp::VRecip, "VRecip", "VV" },
|
||||
{ IROp::VAsin, "VAsin", "VV" },
|
||||
{ IROp::FSin, "FSin", "FF" },
|
||||
{ IROp::FCos, "FCos", "FF" },
|
||||
{ IROp::FSqrt, "FSqrt", "FF" },
|
||||
{ IROp::FRSqrt, "FRSqrt", "FF" },
|
||||
{ IROp::FRecip, "FRecip", "FF" },
|
||||
{ IROp::FAsin, "FAsin", "FF" },
|
||||
|
||||
{ IROp::Interpret, "Interpret", "_C" },
|
||||
{ IROp::Downcount, "Downcount", "_II" },
|
||||
@@ -201,7 +196,11 @@ void DisassembleParam(char *buf, int bufSize, u8 param, char type, const u32 *co
|
||||
snprintf(buf, bufSize, "%s", GetGPRName(param));
|
||||
break;
|
||||
case 'F':
|
||||
snprintf(buf, bufSize, "f%d", param);
|
||||
if (param >= 32) {
|
||||
snprintf(buf, bufSize, "v%d", param - 32);
|
||||
} else {
|
||||
snprintf(buf, bufSize, "f%d", param);
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
snprintf(buf, bufSize, "%08x", constPool[param]);
|
||||
@@ -209,9 +208,6 @@ void DisassembleParam(char *buf, int bufSize, u8 param, char type, const u32 *co
|
||||
case 'I':
|
||||
snprintf(buf, bufSize, "%02x", param);
|
||||
break;
|
||||
case 'V':
|
||||
snprintf(buf, bufSize, "v%d", param);
|
||||
break;
|
||||
case 'T':
|
||||
snprintf(buf, bufSize, "%s", vfpuCtrlNames[param]);
|
||||
break;
|
||||
|
||||
+5
-11
@@ -18,7 +18,6 @@
|
||||
enum class IROp : u8 {
|
||||
SetConst,
|
||||
SetConstF,
|
||||
SetConstV,
|
||||
|
||||
Mov,
|
||||
|
||||
@@ -89,14 +88,12 @@ enum class IROp : u8 {
|
||||
Load16Ext,
|
||||
Load32,
|
||||
LoadFloat,
|
||||
LoadFloatV,
|
||||
LoadVec4,
|
||||
|
||||
Store8,
|
||||
Store16,
|
||||
Store32,
|
||||
StoreFloat,
|
||||
StoreFloatV,
|
||||
StoreVec4,
|
||||
|
||||
Ext8to32,
|
||||
@@ -141,18 +138,15 @@ enum class IROp : u8 {
|
||||
UpdateRoundingMode,
|
||||
|
||||
SetCtrlVFPU,
|
||||
VMovFromGPR,
|
||||
VMovToGPR,
|
||||
|
||||
InitVec4,
|
||||
|
||||
// Slow special functions. Used on singles.
|
||||
VSin,
|
||||
VCos,
|
||||
VSqrt,
|
||||
VRSqrt,
|
||||
VRecip,
|
||||
VAsin,
|
||||
FSin,
|
||||
FCos,
|
||||
FRSqrt,
|
||||
FRecip,
|
||||
FAsin,
|
||||
|
||||
// Fake/System instructions
|
||||
Interpret,
|
||||
|
||||
@@ -35,9 +35,6 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, const u32 *constPool, int c
|
||||
case IROp::SetConstF:
|
||||
memcpy(&mips->f[inst->dest], &constPool[inst->src1], 4);
|
||||
break;
|
||||
case IROp::SetConstV:
|
||||
memcpy(&mips->v[inst->dest], &constPool[inst->src1], 4);
|
||||
break;
|
||||
case IROp::Add:
|
||||
mips->r[inst->dest] = mips->r[inst->src1] + mips->r[inst->src2];
|
||||
break;
|
||||
@@ -102,9 +99,6 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, const u32 *constPool, int c
|
||||
case IROp::LoadFloat:
|
||||
mips->f[inst->dest] = Memory::ReadUnchecked_Float(mips->r[inst->src1] + constPool[inst->src2]);
|
||||
break;
|
||||
case IROp::LoadFloatV:
|
||||
mips->v[inst->dest] = Memory::ReadUnchecked_Float(mips->r[inst->src1] + constPool[inst->src2]);
|
||||
break;
|
||||
|
||||
case IROp::Store8:
|
||||
Memory::WriteUnchecked_U8(mips->r[inst->src3], mips->r[inst->src1] + constPool[inst->src2]);
|
||||
@@ -118,18 +112,15 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, const u32 *constPool, int c
|
||||
case IROp::StoreFloat:
|
||||
Memory::WriteUnchecked_Float(mips->f[inst->src3], mips->r[inst->src1] + constPool[inst->src2]);
|
||||
break;
|
||||
case IROp::StoreFloatV:
|
||||
Memory::WriteUnchecked_Float(mips->v[inst->src3], mips->r[inst->src1] + constPool[inst->src2]);
|
||||
break;
|
||||
|
||||
case IROp::LoadVec4:
|
||||
{
|
||||
u32 base = mips->r[inst->src1] + constPool[inst->src2];
|
||||
#if defined(_M_SSE)
|
||||
_mm_store_ps(&mips->v[inst->dest], _mm_load_ps((const float *)Memory::GetPointerUnchecked(base)));
|
||||
_mm_store_ps(&mips->f[inst->dest], _mm_load_ps((const float *)Memory::GetPointerUnchecked(base)));
|
||||
#else
|
||||
for (int i = 0; i < 4; i++)
|
||||
mips->v[inst->dest + i] = Memory::ReadUnchecked_Float(base + 4 * i);
|
||||
mips->f[inst->dest + i] = Memory::ReadUnchecked_Float(base + 4 * i);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@@ -137,39 +128,36 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, const u32 *constPool, int c
|
||||
{
|
||||
u32 base = mips->r[inst->src1] + constPool[inst->src2];
|
||||
#if defined(_M_SSE)
|
||||
_mm_store_ps((float *)Memory::GetPointerUnchecked(base), _mm_load_ps(&mips->v[inst->dest]));
|
||||
_mm_store_ps((float *)Memory::GetPointerUnchecked(base), _mm_load_ps(&mips->f[inst->dest]));
|
||||
#else
|
||||
for (int i = 0; i < 4; i++)
|
||||
Memory::WriteUnchecked_Float(mips->v[inst->dest + i], base + 4 * i);
|
||||
Memory::WriteUnchecked_Float(mips->f[inst->dest + i], base + 4 * i);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case IROp::InitVec4:
|
||||
#if defined(_M_SSE)
|
||||
_mm_store_ps(&mips->v[inst->dest], _mm_load_ps(vec4InitValues[inst->src1]));
|
||||
_mm_store_ps(&mips->f[inst->dest], _mm_load_ps(vec4InitValues[inst->src1]));
|
||||
#else
|
||||
memcpy(&mips->v[inst->dest + i], vec4InitValues[inst->src1], 4 * sizeof(float));
|
||||
memcpy(&mips->f[inst->dest + i], vec4InitValues[inst->src1], 4 * sizeof(float));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case IROp::VSin:
|
||||
mips->v[inst->dest] = vfpu_sin(mips->v[inst->src1]);
|
||||
case IROp::FSin:
|
||||
mips->f[inst->dest] = vfpu_sin(mips->f[inst->src1]);
|
||||
break;
|
||||
case IROp::VCos:
|
||||
mips->v[inst->dest] = vfpu_cos(mips->v[inst->src1]);
|
||||
case IROp::FCos:
|
||||
mips->f[inst->dest] = vfpu_cos(mips->f[inst->src1]);
|
||||
break;
|
||||
case IROp::VSqrt:
|
||||
mips->v[inst->dest] = sqrtf(mips->v[inst->src1]);
|
||||
case IROp::FRSqrt:
|
||||
mips->f[inst->dest] = 1.0f / sqrtf(mips->f[inst->src1]);
|
||||
break;
|
||||
case IROp::VRSqrt:
|
||||
mips->v[inst->dest] = 1.0f / sqrtf(mips->v[inst->src1]);
|
||||
case IROp::FRecip:
|
||||
mips->f[inst->dest] = 1.0f / mips->f[inst->src1];
|
||||
break;
|
||||
case IROp::VRecip:
|
||||
mips->v[inst->dest] = 1.0f / mips->v[inst->src1];
|
||||
break;
|
||||
case IROp::VAsin:
|
||||
mips->v[inst->dest] = vfpu_asin(mips->v[inst->src1]);
|
||||
case IROp::FAsin:
|
||||
mips->f[inst->dest] = vfpu_asin(mips->f[inst->src1]);
|
||||
break;
|
||||
|
||||
case IROp::ShlImm:
|
||||
@@ -378,13 +366,6 @@ u32 IRInterpret(MIPSState *mips, const IRInst *inst, const u32 *constPool, int c
|
||||
memcpy(&mips->r[inst->dest], &mips->f[inst->src1], 4);
|
||||
break;
|
||||
|
||||
case IROp::VMovFromGPR:
|
||||
memcpy(&mips->v[inst->dest], &mips->r[inst->src1], 4);
|
||||
break;
|
||||
case IROp::VMovToGPR:
|
||||
memcpy(&mips->r[inst->dest], &mips->v[inst->src1], 4);
|
||||
break;
|
||||
|
||||
case IROp::ExitToConst:
|
||||
return constPool[inst->dest];
|
||||
|
||||
|
||||
@@ -110,7 +110,6 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
|
||||
gpr.SetImm(inst.dest, constants[inst.src1]);
|
||||
break;
|
||||
case IROp::SetConstF:
|
||||
case IROp::SetConstV:
|
||||
goto doDefault;
|
||||
|
||||
case IROp::Sub:
|
||||
@@ -251,23 +250,10 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
|
||||
}
|
||||
break;
|
||||
|
||||
case IROp::VMovFromGPR:
|
||||
if (gpr.IsImm(inst.src1)) {
|
||||
out.Write(IROp::SetConstV, inst.dest, out.AddConstant(gpr.GetImm(inst.src1)));
|
||||
} else {
|
||||
gpr.MapIn(inst.src1);
|
||||
goto doDefault;
|
||||
}
|
||||
break;
|
||||
|
||||
case IROp::FMovToGPR:
|
||||
gpr.MapDirty(inst.dest);
|
||||
goto doDefault;
|
||||
|
||||
case IROp::VMovToGPR:
|
||||
gpr.MapDirty(inst.dest);
|
||||
goto doDefault;
|
||||
|
||||
case IROp::MfHi:
|
||||
case IROp::MfLo:
|
||||
gpr.MapDirty(inst.dest);
|
||||
@@ -290,7 +276,6 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
|
||||
}
|
||||
break;
|
||||
case IROp::StoreFloat:
|
||||
case IROp::StoreFloatV:
|
||||
case IROp::StoreVec4:
|
||||
if (gpr.IsImm(inst.src1)) {
|
||||
out.Write(inst.op, inst.dest, 0, out.AddConstant(gpr.GetImm(inst.src1) + constants[inst.src2]));
|
||||
@@ -314,7 +299,6 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
|
||||
}
|
||||
break;
|
||||
case IROp::LoadFloat:
|
||||
case IROp::LoadFloatV:
|
||||
case IROp::LoadVec4:
|
||||
if (gpr.IsImm(inst.src1)) {
|
||||
out.Write(inst.op, inst.dest, 0, out.AddConstant(gpr.GetImm(inst.src1) + constants[inst.src2]));
|
||||
@@ -345,17 +329,23 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
|
||||
std::swap(inst.src1, inst.src2);
|
||||
out.Write(inst);
|
||||
break;
|
||||
|
||||
case IROp::FSub:
|
||||
case IROp::FDiv:
|
||||
case IROp::FNeg:
|
||||
case IROp::FAbs:
|
||||
case IROp::FSqrt:
|
||||
case IROp::FMov:
|
||||
case IROp::FRound:
|
||||
case IROp::FTrunc:
|
||||
case IROp::FCeil:
|
||||
case IROp::FFloor:
|
||||
case IROp::FCvtSW:
|
||||
case IROp::FSin:
|
||||
case IROp::FCos:
|
||||
case IROp::FSqrt:
|
||||
case IROp::FRSqrt:
|
||||
case IROp::FRecip:
|
||||
case IROp::FAsin:
|
||||
out.Write(inst);
|
||||
break;
|
||||
|
||||
@@ -382,15 +372,6 @@ bool PropagateConstants(const IRWriter &in, IRWriter &out) {
|
||||
out.Write(inst);
|
||||
break;
|
||||
|
||||
case IROp::VSin:
|
||||
case IROp::VCos:
|
||||
case IROp::VSqrt:
|
||||
case IROp::VRSqrt:
|
||||
case IROp::VRecip:
|
||||
case IROp::VAsin:
|
||||
out.Write(inst);
|
||||
break;
|
||||
|
||||
case IROp::ZeroFpCond:
|
||||
case IROp::FCmpUnordered:
|
||||
case IROp::FCmpEqual:
|
||||
|
||||
Reference in new issue
Block a user