| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkOnce.h" | 8 #include "SkOnce.h" |
| 9 #include "SkOpts.h" | 9 #include "SkOpts.h" |
| 10 | 10 |
| 11 #if defined(SK_CPU_X86) | 11 #if defined(SK_CPU_X86) |
| 12 #if defined(SK_BUILD_FOR_WIN32) | 12 #if defined(SK_BUILD_FOR_WIN32) |
| 13 #include <intrin.h> | 13 #include <intrin.h> |
| 14 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } | 14 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } |
| 15 #else | 15 #else |
| 16 #include <cpuid.h> | 16 #include <cpuid.h> |
| 17 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc
d+2, abcd+3); } | 17 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc
d+2, abcd+3); } |
| 18 #endif | 18 #endif |
| 19 #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR
_ANDROID) | 19 #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR
_ANDROID) |
| 20 #include <cpu-features.h> | 20 #include <cpu-features.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 static float rsqrt_portable(float x) { |
| 24 // Get initial estimate. |
| 25 int i = *SkTCast<int*>(&x); |
| 26 i = 0x5F1FFFF9 - (i>>1); |
| 27 float estimate = *SkTCast<float*>(&i); |
| 28 |
| 29 // One step of Newton's method to refine. |
| 30 const float estimate_sq = estimate*estimate; |
| 31 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); |
| 32 return estimate; |
| 33 } |
| 34 |
| 23 namespace SkOpts { | 35 namespace SkOpts { |
| 24 // (Define default function pointer values here...) | 36 // Define default function pointer values here... |
| 37 decltype(rsqrt) rsqrt = rsqrt_portable; |
| 25 | 38 |
| 26 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. | 39 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. |
| 27 void Init_sse2(); | 40 void Init_sse2(); |
| 28 void Init_ssse3(); | 41 void Init_ssse3(); |
| 29 void Init_sse41(); | 42 void Init_sse41(); |
| 30 void Init_neon(); | 43 void Init_neon(); |
| 31 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? | 44 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? |
| 32 | 45 |
| 33 static void init() { | 46 static void init() { |
| 34 #if defined(SK_CPU_X86) | 47 #if defined(SK_CPU_X86) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 | 59 |
| 47 SK_DECLARE_STATIC_ONCE(gInitOnce); | 60 SK_DECLARE_STATIC_ONCE(gInitOnce); |
| 48 void Init() { SkOnce(&gInitOnce, init); } | 61 void Init() { SkOnce(&gInitOnce, init); } |
| 49 | 62 |
| 50 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 63 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 51 static struct AutoInit { | 64 static struct AutoInit { |
| 52 AutoInit() { Init(); } | 65 AutoInit() { Init(); } |
| 53 } gAutoInit; | 66 } gAutoInit; |
| 54 #endif | 67 #endif |
| 55 } | 68 } |
| OLD | NEW |