Skip to content
Permalink
Browse files

interp: Correct prefixes on vdot/vhdp.

  • Loading branch information...
unknownbrackets committed Mar 3, 2019
1 parent b24f84d commit 6f87987e7bffc08001625093e869cbdce52662d3
Showing with 34 additions and 22 deletions.
  1. +34 −22 Core/MIPS/MIPSIntVFPU.cpp
@@ -1065,51 +1065,63 @@ namespace MIPSInt
EatPrefixes();
}

void Int_VDot(MIPSOpcode op)
{
float s[4], t[4];
void Int_VDot(MIPSOpcode op) {
float s[4]{}, t[4]{};
float d;
int vd = _VD;
int vs = _VS;
int vt = _VT;
VectorSize sz = GetVecSize(op);
ReadVector(s, sz, vs);
ApplySwizzleS(s, sz);
ApplySwizzleS(s, V_Quad);
ReadVector(t, sz, vt);
ApplySwizzleT(t, sz);
float sum = 0.0f;
int n = GetNumVectorElements(sz);
for (int i = 0; i < n; i++)
{
sum += s[i]*t[i];
ApplySwizzleT(t, V_Quad);
d = 0.0f;
for (int i = 0; i < 4; i++) {
d += s[i] * t[i];
}
d = sum;
ApplyPrefixD(&d,V_Single);
ApplyPrefixD(&d, V_Single);
WriteVector(&d, V_Single, vd);
PC += 4;
EatPrefixes();
}

void Int_VHdp(MIPSOpcode op)
{
float s[4], t[4];
void Int_VHdp(MIPSOpcode op) {
float s[4]{}, t[4]{};
float d;
int vd = _VD;
int vs = _VS;
int vt = _VT;
VectorSize sz = GetVecSize(op);
ReadVector(s, sz, vs);
ApplySwizzleS(s, sz);
ReadVector(t, sz, vt);
ApplySwizzleT(t, sz);
ApplySwizzleT(t, V_Quad);

// S prefix forces constant 1 for the last element (w for quad.)
// Otherwise it is the same as vdot.
u32 sprefixRemove;
u32 sprefixAdd;
if (sz == V_Quad) {
sprefixRemove = VFPU_SWIZZLE(0, 0, 0, 3);
sprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::NONE, VFPUConst::NONE, VFPUConst::NONE, VFPUConst::ONE);
} else if (sz == V_Triple) {
sprefixRemove = VFPU_SWIZZLE(0, 0, 3, 0);
sprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::NONE, VFPUConst::NONE, VFPUConst::ONE, VFPUConst::NONE);
} else if (sz == V_Pair) {
sprefixRemove = VFPU_SWIZZLE(0, 3, 0, 0);
sprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::NONE, VFPUConst::ONE, VFPUConst::NONE, VFPUConst::NONE);
} else {
sprefixRemove = VFPU_SWIZZLE(3, 0, 0, 0);
sprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ONE, VFPUConst::NONE, VFPUConst::NONE, VFPUConst::NONE);
}
ApplyPrefixST(s, VFPURewritePrefix(VFPU_CTRL_SPREFIX, sprefixRemove, sprefixAdd), V_Quad);

float sum = 0.0f;
int n = GetNumVectorElements(sz);
for (int i = 0; i < n; i++)
{
sum += (i == n - 1) ? t[i] : s[i]*t[i];
for (int i = 0; i < 4; i++) {
sum += s[i] * t[i];
}
d = my_isnan(sum) ? fabsf(sum) : sum;
ApplyPrefixD(&d,V_Single);
ApplyPrefixD(&d, V_Single);
WriteVector(&d, V_Single, vd);
PC += 4;
EatPrefixes();

0 comments on commit 6f87987

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