| 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 #define SK_OPTS_NS portable | 11 #define SK_OPTS_NS portable |
| 11 #include "SkBlurImageFilter_opts.h" | 12 #include "SkBlurImageFilter_opts.h" |
| 13 #include "SkFloatingPoint_opts.h" |
| 14 #include "SkUtils_opts.h" |
| 12 #include "SkXfermode_opts.h" | 15 #include "SkXfermode_opts.h" |
| 13 | 16 |
| 14 #if defined(SK_CPU_X86) | 17 #if defined(SK_CPU_X86) |
| 15 #if defined(SK_BUILD_FOR_WIN32) | 18 #if defined(SK_BUILD_FOR_WIN32) |
| 16 #include <intrin.h> | 19 #include <intrin.h> |
| 17 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } | 20 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } |
| 18 #else | 21 #else |
| 19 #include <cpuid.h> | 22 #include <cpuid.h> |
| 20 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc
d+2, abcd+3); } | 23 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc
d+2, abcd+3); } |
| 21 #endif | 24 #endif |
| 22 #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR
_ANDROID) | 25 #elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR
_ANDROID) |
| 23 #include <cpu-features.h> | 26 #include <cpu-features.h> |
| 24 #endif | 27 #endif |
| 25 | 28 |
| 26 namespace portable { // This helps identify methods from this file when debuggi
ng / profiling. | |
| 27 | |
| 28 static float rsqrt(float x) { | |
| 29 // Get initial estimate. | |
| 30 int i = *SkTCast<int*>(&x); | |
| 31 i = 0x5F1FFFF9 - (i>>1); | |
| 32 float estimate = *SkTCast<float*>(&i); | |
| 33 | |
| 34 // One step of Newton's method to refine. | |
| 35 const float estimate_sq = estimate*estimate; | |
| 36 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); | |
| 37 return estimate; | |
| 38 } | |
| 39 | |
| 40 template <typename T> | |
| 41 static void memsetT(T dst[], T val, int n) { while (n --> 0) { *dst++ = val; } } | |
| 42 | |
| 43 } // namespace portable | |
| 44 | |
| 45 namespace SkOpts { | 29 namespace SkOpts { |
| 46 // Define default function pointer values here... | 30 // Define default function pointer values here... |
| 31 // If our global compile options are set high enough, these 'portable' defau
lts might |
| 32 // even be CPU-specialized, e.g. a typical x86-64 machine might start with S
SE2 defaults. |
| 33 // They'll still get a chance to be replaced with even better ones, e.g. usi
ng SSE4.1. |
| 47 decltype(rsqrt) rsqrt = portable::rsqrt; | 34 decltype(rsqrt) rsqrt = portable::rsqrt; |
| 48 decltype(memset16) memset16 = portable::memsetT<uint16_t>; | 35 decltype(memset16) memset16 = portable::memset16; |
| 49 decltype(memset32) memset32 = portable::memsetT<uint32_t>; | 36 decltype(memset32) memset32 = portable::memset32; |
| 50 decltype(create_xfermode) create_xfermode = SkCreate4pxXfermode; | 37 decltype(create_xfermode) create_xfermode = SkCreate4pxXfermode; |
| 51 | 38 |
| 52 static const auto x = portable::kX, y = portable::kY; | 39 static const auto x = portable::kX, y = portable::kY; |
| 53 decltype(box_blur_xx) box_blur_xx = portable::box_blur<x,x>; | 40 decltype(box_blur_xx) box_blur_xx = portable::box_blur<x,x>; |
| 54 decltype(box_blur_xy) box_blur_xy = portable::box_blur<x,y>; | 41 decltype(box_blur_xy) box_blur_xy = portable::box_blur<x,y>; |
| 55 decltype(box_blur_yx) box_blur_yx = portable::box_blur<y,x>; | 42 decltype(box_blur_yx) box_blur_yx = portable::box_blur<y,x>; |
| 56 | 43 |
| 57 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. | 44 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. |
| 58 void Init_sse2(); | 45 void Init_sse2(); |
| 59 void Init_ssse3(); | 46 void Init_ssse3(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 78 | 65 |
| 79 SK_DECLARE_STATIC_ONCE(gInitOnce); | 66 SK_DECLARE_STATIC_ONCE(gInitOnce); |
| 80 void Init() { SkOnce(&gInitOnce, init); } | 67 void Init() { SkOnce(&gInitOnce, init); } |
| 81 | 68 |
| 82 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 69 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 83 static struct AutoInit { | 70 static struct AutoInit { |
| 84 AutoInit() { Init(); } | 71 AutoInit() { Init(); } |
| 85 } gAutoInit; | 72 } gAutoInit; |
| 86 #endif | 73 #endif |
| 87 } | 74 } |
| OLD | NEW |