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

Unified Diff: src/core/SkOpts.cpp

Issue 1264893002: Runtime CPU detection for rsqrt(). (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 | « src/core/SkOpts.h ('k') | src/opts/SkOpts_neon.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkOpts.cpp
diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp
index 4f7c5e9345ee2dd816090b252f565286d9872b28..7da306c99d538417eb2948210f1e2bc9629fa8cb 100644
--- a/src/core/SkOpts.cpp
+++ b/src/core/SkOpts.cpp
@@ -20,8 +20,21 @@
#include <cpu-features.h>
#endif
+static 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;
+}
+
namespace SkOpts {
- // (Define default function pointer values here...)
+ // Define default function pointer values here...
+ decltype(rsqrt) rsqrt = rsqrt_portable;
// Each Init_foo() is defined in src/opts/SkOpts_foo.cpp.
void Init_sse2();
« no previous file with comments | « src/core/SkOpts.h ('k') | src/opts/SkOpts_neon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698