Fixed rsqrt, and sqrt. Added more tests.

This commit is contained in:
Бранимир Караџић
2023-04-19 19:01:00 -07:00
parent 9a9a871d9a
commit 0d51df1779
2 changed files with 77 additions and 32 deletions

View File

@@ -212,17 +212,27 @@ namespace bx
inline BX_CONST_FUNC float rsqrtRef(float _a)
{
if (_a < kNearZero)
{
return kInfinity;
}
return pow(_a, -0.5f);
}
inline BX_CONST_FUNC float sqrtRef(float _a)
{
if (_a < kNearZero)
{
return 0.0f;
}
return _a*pow(_a, -0.5f);
}
return 1.0f/rsqrtRef(_a);
inline BX_CONST_FUNC float rsqrtSimd(float _a)
{
const simd128_t aa = simd_splat(_a);
const simd128_t rsqrta = simd_rsqrt_nr(aa);
float result;
simd_stx(&result, rsqrta);
return result;
}
inline BX_CONST_FUNC float sqrtSimd(float _a)
@@ -235,30 +245,6 @@ namespace bx
return result;
}
inline BX_CONST_FUNC float sqrt(float _a)
{
#if BX_CONFIG_SUPPORTS_SIMD
return sqrtSimd(_a);
#else
return sqrtRef(_a);
#endif // BX_CONFIG_SUPPORTS_SIMD
}
inline BX_CONST_FUNC float rsqrtSimd(float _a)
{
if (_a < kNearZero)
{
return 0.0f;
}
const simd128_t aa = simd_splat(_a);
const simd128_t rsqrta = simd_rsqrt_nr(aa);
float result;
simd_stx(&result, rsqrta);
return result;
}
inline BX_CONST_FUNC float rsqrt(float _a)
{
#if BX_CONFIG_SUPPORTS_SIMD
@@ -268,6 +254,15 @@ namespace bx
#endif // BX_CONFIG_SUPPORTS_SIMD
}
inline BX_CONST_FUNC float sqrt(float _a)
{
#if BX_CONFIG_SUPPORTS_SIMD
return sqrtSimd(_a);
#else
return sqrtRef(_a);
#endif // BX_CONFIG_SUPPORTS_SIMD
}
inline BX_CONSTEXPR_FUNC float trunc(float _a)
{
return float(int(_a) );