Skip to content

Commit

Permalink
Core: Make sure precision is correct for COP1_D_SQRT
Browse files Browse the repository at this point in the history
  • Loading branch information
project64 committed Oct 12, 2023
1 parent 3a68d3d commit 00c5057
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Source/Project64-core/N64System/Interpreter/InterpreterOps.cpp
Expand Up @@ -2519,8 +2519,22 @@ void R4300iOp::COP1_D_DIV()
*_FPR_UDW[m_Opcode.fd] = *(uint64_t *)&Result;
}

#if defined(__i386__) || defined(_M_IX86)
static double correct_sqrt(double a)
{
__asm
{
fld QWORD PTR [a]
fsqrt
}
}
#endif

void R4300iOp::COP1_D_SQRT()
{
#if defined(__i386__) || defined(_M_IX86)
_controlfp(_PC_53, _MCW_PC);
#endif
if (InitFpuOperation(((FPStatusReg &)_FPCR[31]).RoundingMode))
{
return;
Expand All @@ -2530,7 +2544,11 @@ void R4300iOp::COP1_D_SQRT()
{
return;
}
#if defined(__i386__) || defined(_M_IX86)
double Result = (double)correct_sqrt(*(double *)_FPR_D[m_Opcode.fs]);
#else
double Result = (double)sqrt(*(double *)_FPR_D[m_Opcode.fs]);
#endif
if (CheckFPUResult64(Result))
{
return;
Expand Down Expand Up @@ -3345,7 +3363,6 @@ bool R4300iOp::InitFpuOperation(FPRoundingMode RoundingModel)
case FPRoundingMode_RoundTowardPlusInfinity: fesetround(FE_UPWARD); break;
case FPRoundingMode_RoundTowardMinusInfinity: fesetround(FE_DOWNWARD); break;
}
fesetround(RoundingModel);
feclearexcept(FE_ALL_EXCEPT);
return false;
}
Expand Down

0 comments on commit 00c5057

Please sign in to comment.