diff options
author | mtklein <mtklein@chromium.org> | 2016-01-26 07:40:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-26 07:40:30 -0800 |
commit | a766ca87bfb1129a8cf4f8a428121caf60726de4 (patch) | |
tree | bd37c26c416e32433953ea8909b52f4587ce0730 /include/private | |
parent | 05332d9c8aefe00c361c893410deca33f4438695 (diff) |
de-proc sk_float_rsqrt
This is the first of many little baby steps to have us stop runtime-detecting NEON.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1616013003
CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot
Committed: https://skia.googlesource.com/skia/+/efcc125acd2d71eb077caf6db65fdd6b9eb1dc0d
Review URL: https://codereview.chromium.org/1616013003
Diffstat (limited to 'include/private')
-rw-r--r-- | include/private/SkFloatingPoint.h | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h index f7ee816b12..ffed5c0747 100644 --- a/include/private/SkFloatingPoint.h +++ b/include/private/SkFloatingPoint.h @@ -127,20 +127,28 @@ extern const uint32_t gIEEENegativeInfinity; #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity)) #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfinity)) -// We forward declare this to break an #include cycle. -// (SkScalar -> SkFloatingPoint -> SkOpts.h -> SkXfermode -> SkColor -> SkScalar) -namespace SkOpts { extern float (*rsqrt)(float); } +static inline float sk_float_rsqrt_portable(float x) { + // Get initial estimate. + int i = *SkTCast<int*>(&x); + i = 0x5F1FFFF9 - (i>>1); + float estimate = *SkTCast<float*>(&i); + + // One step of Newton's method to refine. + const float estimate_sq = estimate*estimate; + estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); + return estimate; +} // Fast, approximate inverse square root. // Compare to name-brand "1.0f / sk_float_sqrt(x)". Should be around 10x faster on SSE, 2x on NEON. -static inline float sk_float_rsqrt(const float x) { +static inline float sk_float_rsqrt(float x) { // We want all this inlined, so we'll inline SIMD and just take the hit when we don't know we've got // it at compile time. This is going to be too fast to productively hide behind a function pointer. // -// We do one step of Newton's method to refine the estimates in the NEON and null paths. No +// We do one step of Newton's method to refine the estimates in the NEON and portable paths. No // refinement is faster, but very innacurate. Two steps is more accurate, but slower than 1/sqrt. // -// Optimized constants in the null path courtesy of http://rrrola.wz.cz/inv_sqrt.html +// Optimized constants in the portable path courtesy of http://rrrola.wz.cz/inv_sqrt.html #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1 return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(x))); #elif defined(SK_ARM_HAS_NEON) @@ -153,8 +161,7 @@ static inline float sk_float_rsqrt(const float x) { estimate = vmul_f32(estimate, vrsqrts_f32(xx, estimate_sq)); return vget_lane_f32(estimate, 0); // 1 will work fine too; the answer's in both places. #else - // Perhaps runtime-detected NEON, or a portable fallback. - return SkOpts::rsqrt(x); + return sk_float_rsqrt_portable(x); #endif } |