Skip to content

Commit

Permalink
interp: Correct vsgn out of swizzle bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Apr 1, 2019
1 parent 85ff32e commit 59905de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRCompVFPU.cpp
Expand Up @@ -1869,7 +1869,7 @@ namespace MIPSComp {

void IRFrontend::Comp_Vsgn(MIPSOpcode op) {
CONDITIONAL_DISABLE(VFPU_VEC);
if (js.HasUnknownPrefix()) {
if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || !IsPrefixWithinSize(js.prefixT, op)) {
DISABLE;
}

Expand Down
10 changes: 8 additions & 2 deletions Core/MIPS/MIPSIntVFPU.cpp
Expand Up @@ -648,14 +648,20 @@ namespace MIPSInt
int vs = _VS;
VectorSize sz = GetVecSize(op);
ReadVector(s, sz, vs);
ApplySwizzleS(s, sz);

// Not sure who would do this, but using abs/neg allows a compare against 3 or -3.
u32 tprefixRemove = VFPU_ANY_SWIZZLE();
u32 tprefixAdd = VFPU_MAKE_CONSTANTS(VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO, VFPUConst::ZERO);
ApplyPrefixST(t, VFPURewritePrefix(VFPU_CTRL_TPREFIX, tprefixRemove, tprefixAdd), sz);

for (int i = 0; i < GetNumVectorElements(sz); i++) {
int n = GetNumVectorElements(sz);
if (n < 4) {
// Compare with a swizzled value out of bounds always produces 0.
memcpy(&s[n], &t[n], sizeof(float) * (4 - n));
}
ApplySwizzleS(s, V_Quad);

for (int i = 0; i < n; i++) {
float diff = s[i] - t[i];
// To handle NaNs correctly, we do this with integer hackery
u32 val;
Expand Down

0 comments on commit 59905de

Please sign in to comment.