aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/private/SkFloatingPoint.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/private/SkFloatingPoint.h')
-rw-r--r--include/private/SkFloatingPoint.h23
1 files changed, 8 insertions, 15 deletions
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h
index ffed5c0747..f7ee816b12 100644
--- a/include/private/SkFloatingPoint.h
+++ b/include/private/SkFloatingPoint.h
@@ -127,28 +127,20 @@ extern const uint32_t gIEEENegativeInfinity;
#define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity))
#define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfinity))
-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;
-}
+// We forward declare this to break an #include cycle.
+// (SkScalar -> SkFloatingPoint -> SkOpts.h -> SkXfermode -> SkColor -> SkScalar)
+namespace SkOpts { extern float (*rsqrt)(float); }
// 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(float x) {
+static inline float sk_float_rsqrt(const 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 portable paths. No
+// We do one step of Newton's method to refine the estimates in the NEON and null paths. No
// refinement is faster, but very innacurate. Two steps is more accurate, but slower than 1/sqrt.
//
-// Optimized constants in the portable path courtesy of http://rrrola.wz.cz/inv_sqrt.html
+// Optimized constants in the null 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)
@@ -161,7 +153,8 @@ static inline float sk_float_rsqrt(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
- return sk_float_rsqrt_portable(x);
+ // Perhaps runtime-detected NEON, or a portable fallback.
+ return SkOpts::rsqrt(x);
#endif
}