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 "SkCpu.h" | |
9 #include "SkHalf.h" | 8 #include "SkHalf.h" |
10 #include "SkOnce.h" | 9 #include "SkOnce.h" |
11 #include "SkOpts.h" | 10 #include "SkOpts.h" |
12 | 11 |
13 #define SK_OPTS_NS sk_default | 12 #define SK_OPTS_NS sk_default |
14 #include "SkBlitMask_opts.h" | 13 #include "SkBlitMask_opts.h" |
15 #include "SkBlitRow_opts.h" | 14 #include "SkBlitRow_opts.h" |
16 #include "SkBlurImageFilter_opts.h" | 15 #include "SkBlurImageFilter_opts.h" |
17 #include "SkColorCubeFilter_opts.h" | 16 #include "SkColorCubeFilter_opts.h" |
18 #include "SkMatrix_opts.h" | 17 #include "SkMatrix_opts.h" |
19 #include "SkMorphologyImageFilter_opts.h" | 18 #include "SkMorphologyImageFilter_opts.h" |
20 #include "SkSwizzler_opts.h" | 19 #include "SkSwizzler_opts.h" |
21 #include "SkTextureCompressor_opts.h" | 20 #include "SkTextureCompressor_opts.h" |
22 #include "SkXfermode_opts.h" | 21 #include "SkXfermode_opts.h" |
23 | 22 |
24 namespace SK_OPTS_NS { | 23 namespace SK_OPTS_NS { |
25 static void float_to_half(uint16_t dst[], const float src[], int n) { | 24 static void float_to_half(uint16_t dst[], const float src[], int n) { |
26 while (n-->0) { | 25 while (n-->0) { |
27 *dst++ = SkFloatToHalf(*src++); | 26 *dst++ = SkFloatToHalf(*src++); |
28 } | 27 } |
29 } | 28 } |
30 static void half_to_float(float dst[], const uint16_t src[], int n) { | 29 static void half_to_float(float dst[], const uint16_t src[], int n) { |
31 while (n-->0) { | 30 while (n-->0) { |
32 *dst++ = SkHalfToFloat(*src++); | 31 *dst++ = SkHalfToFloat(*src++); |
33 } | 32 } |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
| 36 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) |
| 37 #if defined(SK_BUILD_FOR_WIN32) |
| 38 #include <intrin.h> |
| 39 static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); } |
| 40 static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); } |
| 41 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); } |
| 42 #else |
| 43 #include <cpuid.h> |
| 44 #if !defined(__cpuid_count) // Old Mac Clang doesn't have this defined. |
| 45 #define __cpuid_count(eax, ecx, a, b, c, d) \ |
| 46 __asm__("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(eax),
"2"(ecx)) |
| 47 #endif |
| 48 static void cpuid (uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, ab
cd+2, abcd+3); } |
| 49 static void cpuid7(uint32_t abcd[4]) { |
| 50 __cpuid_count(7, 0, abcd[0], abcd[1], abcd[2], abcd[3]); |
| 51 } |
| 52 static uint64_t xgetbv(uint32_t xcr) { |
| 53 uint32_t eax, edx; |
| 54 __asm__ __volatile__ ( "xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr)); |
| 55 return (uint64_t)(edx) << 32 | eax; |
| 56 } |
| 57 #endif |
| 58 #elif !defined(SK_ARM_HAS_NEON) && \ |
| 59 defined(SK_CPU_ARM32) && \ |
| 60 defined(SK_BUILD_FOR_ANDROID) && \ |
| 61 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
| 62 #include <cpu-features.h> |
| 63 #endif |
| 64 |
37 namespace SkOpts { | 65 namespace SkOpts { |
38 | 66 |
39 // Define default function pointer values here... | 67 // Define default function pointer values here... |
40 // If our global compile options are set high enough, these defaults might e
ven be | 68 // If our global compile options are set high enough, these defaults might e
ven be |
41 // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defa
ults. | 69 // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defa
ults. |
42 // They'll still get a chance to be replaced with even better ones, e.g. usi
ng SSE4.1. | 70 // They'll still get a chance to be replaced with even better ones, e.g. usi
ng SSE4.1. |
43 decltype(create_xfermode) create_xfermode = sk_default::create_xfermode; | 71 decltype(create_xfermode) create_xfermode = sk_default::create_xfermode; |
44 decltype(color_cube_filter_span) color_cube_filter_span = sk_default::color_
cube_filter_span; | 72 decltype(color_cube_filter_span) color_cube_filter_span = sk_default::color_
cube_filter_span; |
45 | 73 |
46 decltype(box_blur_xx) box_blur_xx = sk_default::box_blur_xx; | 74 decltype(box_blur_xx) box_blur_xx = sk_default::box_blur_xx; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 void Init_ssse3(); | 110 void Init_ssse3(); |
83 void Init_sse41(); | 111 void Init_sse41(); |
84 void Init_sse42() {} | 112 void Init_sse42() {} |
85 void Init_avx() {} | 113 void Init_avx() {} |
86 void Init_avx2() {} | 114 void Init_avx2() {} |
87 void Init_neon(); | 115 void Init_neon(); |
88 | 116 |
89 static void init() { | 117 static void init() { |
90 // TODO: Chrome's not linking _sse* opts on iOS simulator builds. Bug o
r feature? | 118 // TODO: Chrome's not linking _sse* opts on iOS simulator builds. Bug o
r feature? |
91 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) | 119 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) |
92 if (SkCpu::Supports(SkCpu::SSSE3)) { Init_ssse3(); } | 120 uint32_t abcd[] = {0,0,0,0}; |
93 if (SkCpu::Supports(SkCpu::SSE41)) { Init_sse41(); } | 121 cpuid(abcd); |
94 if (SkCpu::Supports(SkCpu::SSE42)) { Init_sse42(); } | 122 if (abcd[2] & (1<< 9)) { Init_ssse3(); } |
95 if (SkCpu::Supports(SkCpu::AVX )) { Init_avx(); } | 123 if (abcd[2] & (1<<19)) { Init_sse41(); } |
96 if (SkCpu::Supports(SkCpu::AVX2 )) { Init_avx2(); } | 124 if (abcd[2] & (1<<20)) { Init_sse42(); } |
97 | 125 |
98 #elif defined(SK_CPU_ARM32) && \ | 126 // AVX detection's kind of a pain. This is cribbed from Chromium. |
99 defined(SK_BUILD_FOR_ANDROID) && \ | 127 if ( ( abcd[2] & (7<<26)) == (7<<26) && // Check bits 26-28 of ecx a
re all set, |
100 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | 128 (xgetbv(0) & 6 ) == 6 ){ // and check the OS support
s XSAVE. |
101 if (SkCpu::Supports(SkCpu::NEON)) { Init_neon(); } | 129 Init_avx(); |
| 130 |
| 131 // AVX2 additionally needs bit 5 set on ebx after calling cpuid(7). |
| 132 uint32_t abcd7[] = {0,0,0,0}; |
| 133 cpuid7(abcd7); |
| 134 if (abcd7[1] & (1<<5)) { Init_avx2(); } |
| 135 } |
| 136 |
| 137 #elif !defined(SK_ARM_HAS_NEON) && \ |
| 138 defined(SK_CPU_ARM32) && \ |
| 139 defined(SK_BUILD_FOR_ANDROID) && \ |
| 140 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
| 141 if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) { Init_neon
(); } |
102 #endif | 142 #endif |
103 } | 143 } |
104 | 144 |
105 SK_DECLARE_STATIC_ONCE(gInitOnce); | 145 SK_DECLARE_STATIC_ONCE(gInitOnce); |
106 void Init() { SkOnce(&gInitOnce, init); } | 146 void Init() { SkOnce(&gInitOnce, init); } |
107 | 147 |
108 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 148 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
109 static struct AutoInit { | 149 static struct AutoInit { |
110 AutoInit() { Init(); } | 150 AutoInit() { Init(); } |
111 } gAutoInit; | 151 } gAutoInit; |
112 #endif | 152 #endif |
113 } | 153 } |
OLD | NEW |