diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkOpts.cpp | 15 | ||||
-rw-r--r-- | src/core/SkOpts.h | 5 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp index 4f7c5e9345..7da306c99d 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(); diff --git a/src/core/SkOpts.h b/src/core/SkOpts.h index 71abae5d7a..f02ec97553 100644 --- a/src/core/SkOpts.h +++ b/src/core/SkOpts.h @@ -16,7 +16,10 @@ namespace SkOpts { // Called by SkGraphics::Init(), and automatically #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS. void Init(); - // (Function pointers go here). + // Declare function pointers here... + + // Returns a fast approximation of 1.0f/sqrtf(x). + extern float (*rsqrt)(float); } #endif//SkOpts_DEFINED |