Skip to content
Permalink
Browse files

interp: Correct prefixes on vfad and vavg.

Including write mask, which didn't work before.
  • Loading branch information...
unknownbrackets committed Feb 25, 2019
1 parent 4d580c3 commit 442d6450bb13ec6282395161075c54849bfc7fe7
Showing with 37 additions and 23 deletions.
  1. +37 −23 Core/MIPS/MIPSIntVFPU.cpp
@@ -1390,46 +1390,60 @@ namespace MIPSInt
EatPrefixes();
}

void Int_Vfad(MIPSOpcode op)
{
float s[4];
void Int_Vfad(MIPSOpcode op) {
float s[4]{}, t[4]{};
float d;
int vd = _VD;
int vs = _VS;
VectorSize sz = GetVecSize(op);
ReadVector(s, sz, vs);
ApplySwizzleS(s, sz);
float sum = 0.0f;
int n = GetNumVectorElements(sz);
for (int i = 0; i < n; i++)
{
sum += s[i];
ApplySwizzleS(s, V_Quad);

// T prefix generates constants, but abs can change the constant.
u32 tprefixRemove = VFPU_ANY_SWIZZLE();
u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE, VFPUConst::ONE);
ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad);

d = 0.0f;
for (int i = 0; i < 4; i++) {
d += s[i] * t[i];
}
d = sum;
ApplyPrefixD(&d,V_Single);
V(vd) = d;
ApplyPrefixD(&d, V_Single);
WriteVector(&d, V_Single, vd);
PC += 4;
EatPrefixes();
}

void Int_Vavg(MIPSOpcode op)
{
float s[4];
void Int_Vavg(MIPSOpcode op) {
float s[4]{}, t[4]{};
float d;
int vd = _VD;
int vs = _VS;
VectorSize sz = GetVecSize(op);
ReadVector(s, sz, vs);
ApplySwizzleS(s, sz);
float sum = 0.0f;
int n = GetNumVectorElements(sz);
for (int i = 0; i < n; i++)
{
sum += s[i];
ApplySwizzleS(s, V_Quad);

// T prefix generates constants, but supports negate.
u32 tprefixRemove = VFPU_ANY_SWIZZLE() | VFPU_ABS(1, 1, 1, 1);
u32 tprefixAdd;
if (sz == V_Single)
tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO);
else if (sz == V_Pair)
tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::HALF, VFPUConst::HALF, VFPUConst::HALF, VFPUConst::HALF);
else if (sz == V_Triple)
tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::THIRD, VFPUConst::THIRD, VFPUConst::THIRD, VFPUConst::THIRD);
else if (sz == V_Quad)
tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::FOURTH, VFPUConst::FOURTH, VFPUConst::FOURTH, VFPUConst::FOURTH);
else
tprefixAdd = 0;
ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), V_Quad);

d = 0.0f;
for (int i = 0; i < 4; i++) {
d += s[i] * t[i];
}
d = sum / n;
ApplyPrefixD(&d, V_Single);
V(vd) = d;
WriteVector(&d, V_Single, vd);
PC += 4;
EatPrefixes();
}

0 comments on commit 442d645

Please sign in to comment.
You can’t perform that action at this time.