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) { | 23 namespace portable { // This helps identify methods from this file when debuggi
ng / profiling. |
| 24 |
| 25 static float rsqrt(float x) { |
24 // Get initial estimate. | 26 // Get initial estimate. |
25 int i = *SkTCast<int*>(&x); | 27 int i = *SkTCast<int*>(&x); |
26 i = 0x5F1FFFF9 - (i>>1); | 28 i = 0x5F1FFFF9 - (i>>1); |
27 float estimate = *SkTCast<float*>(&i); | 29 float estimate = *SkTCast<float*>(&i); |
28 | 30 |
29 // One step of Newton's method to refine. | 31 // One step of Newton's method to refine. |
30 const float estimate_sq = estimate*estimate; | 32 const float estimate_sq = estimate*estimate; |
31 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); | 33 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); |
32 return estimate; | 34 return estimate; |
33 } | 35 } |
34 | 36 |
| 37 template <typename T> |
| 38 static void memsetT(T dst[], T val, int n) { while (n --> 0) { *dst++ = val; } } |
| 39 |
| 40 } // namespace portable |
| 41 |
35 namespace SkOpts { | 42 namespace SkOpts { |
36 // Define default function pointer values here... | 43 // Define default function pointer values here... |
37 decltype(rsqrt) rsqrt = rsqrt_portable; | 44 decltype(rsqrt) rsqrt = portable::rsqrt; |
| 45 decltype(memset16) memset16 = portable::memsetT<uint16_t>; |
| 46 decltype(memset32) memset32 = portable::memsetT<uint32_t>; |
| 47 |
38 | 48 |
39 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. | 49 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. |
40 void Init_sse2(); | 50 void Init_sse2(); |
41 void Init_ssse3(); | 51 void Init_ssse3(); |
42 void Init_sse41(); | 52 void Init_sse41(); |
43 void Init_neon(); | 53 void Init_neon(); |
44 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? | 54 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? |
45 | 55 |
46 static void init() { | 56 static void init() { |
47 #if defined(SK_CPU_X86) | 57 #if defined(SK_CPU_X86) |
(...skipping 11 matching lines...) Expand all Loading... |
59 | 69 |
60 SK_DECLARE_STATIC_ONCE(gInitOnce); | 70 SK_DECLARE_STATIC_ONCE(gInitOnce); |
61 void Init() { SkOnce(&gInitOnce, init); } | 71 void Init() { SkOnce(&gInitOnce, init); } |
62 | 72 |
63 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 73 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
64 static struct AutoInit { | 74 static struct AutoInit { |
65 AutoInit() { Init(); } | 75 AutoInit() { Init(); } |
66 } gAutoInit; | 76 } gAutoInit; |
67 #endif | 77 #endif |
68 } | 78 } |
OLD | NEW |