nipkownix / re4_tweaks

Fixes and tweaks for the "UHD" port of Resident Evil 4
zlib License
329 stars 32 forks source link

An insteresting thing about SQRTF_new #598

Open Lioncky opened 3 months ago

Lioncky commented 3 months ago

Validation

Describe your issue here (drag+drop ZIP to attach it)

// this will be ok
double SQRTF_new(float in)
{
    if (in <= 0.00001f)
        return 0.0;

    __m128 in128 = _mm_load_ss(&in);
    return _mm_cvtss_f32(_mm_mul_ss(in128, _mm_rsqrt_ss(in128)));
}

// this make Rising Of Evil Mod crash in r10d
double SQRTF_new_ori(float in)
{
    if (in > 0.00001f)
    {
        __m128 in128 = _mm_load_ss(&in);
        return _mm_cvtss_f32(_mm_mul_ss(in128, _mm_rsqrt_ss(in128)));
    }
    return 0.0f;
}

Original game code:
float __cdecl SQRTF(float src)
{
  if ( src <= 0.0000099999997 )
    return 0.0;
  return sqrt(src);
}
Lioncky commented 3 months ago

Be careful about floating numbers!

Whorespawn commented 2 months ago

How do I fix it?