Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: include/core/SkFloatingPoint.h

Issue 1251423002: Update fallback rsqrt implementation to use optimal constants. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/MathTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkFloatingPoint.h
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h
index 7c34706f7a05093007aebbb131c0e6cbf26ba298..13e8963c140f68d995c7f8dd8485e0db26dddea2 100644
--- a/include/core/SkFloatingPoint.h
+++ b/include/core/SkFloatingPoint.h
@@ -151,6 +151,8 @@ static inline float sk_float_rsqrt(const float x) {
//
// 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 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)
@@ -165,12 +167,12 @@ static inline float sk_float_rsqrt(const float x) {
#else
// Get initial estimate.
int i = *SkTCast<int*>(&x);
- i = 0x5f3759df - (i>>1);
+ i = 0x5F1FFFF9 - (i>>1);
float estimate = *SkTCast<float*>(&i);
// One step of Newton's method to refine.
const float estimate_sq = estimate*estimate;
- estimate *= (1.5f-0.5f*x*estimate_sq);
+ estimate *= 0.703952253f*(2.38924456f-x*estimate_sq);
return estimate;
#endif
}
« no previous file with comments | « no previous file | tests/MathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698