Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: src/core/SkOpts.cpp

Issue 1890483002: Move CPU feature detection to its own file. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: link Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkCpu.cpp ('k') | src/core/SkUtilsArm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "SkHalf.h" 9 #include "SkHalf.h"
9 #include "SkOnce.h" 10 #include "SkOnce.h"
10 #include "SkOpts.h" 11 #include "SkOpts.h"
11 12
12 #define SK_OPTS_NS sk_default 13 #define SK_OPTS_NS sk_default
13 #include "SkBlitMask_opts.h" 14 #include "SkBlitMask_opts.h"
14 #include "SkBlitRow_opts.h" 15 #include "SkBlitRow_opts.h"
15 #include "SkBlurImageFilter_opts.h" 16 #include "SkBlurImageFilter_opts.h"
16 #include "SkColorCubeFilter_opts.h" 17 #include "SkColorCubeFilter_opts.h"
17 #include "SkMatrix_opts.h" 18 #include "SkMatrix_opts.h"
18 #include "SkMorphologyImageFilter_opts.h" 19 #include "SkMorphologyImageFilter_opts.h"
19 #include "SkSwizzler_opts.h" 20 #include "SkSwizzler_opts.h"
20 #include "SkTextureCompressor_opts.h" 21 #include "SkTextureCompressor_opts.h"
21 #include "SkXfermode_opts.h" 22 #include "SkXfermode_opts.h"
22 23
23 namespace SK_OPTS_NS { 24 namespace SK_OPTS_NS {
24 static void float_to_half(uint16_t dst[], const float src[], int n) { 25 static void float_to_half(uint16_t dst[], const float src[], int n) {
25 while (n-->0) { 26 while (n-->0) {
26 *dst++ = SkFloatToHalf(*src++); 27 *dst++ = SkFloatToHalf(*src++);
27 } 28 }
28 } 29 }
29 static void half_to_float(float dst[], const uint16_t src[], int n) { 30 static void half_to_float(float dst[], const uint16_t src[], int n) {
30 while (n-->0) { 31 while (n-->0) {
31 *dst++ = SkHalfToFloat(*src++); 32 *dst++ = SkHalfToFloat(*src++);
32 } 33 }
33 } 34 }
34 } 35 }
35 36
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
65 namespace SkOpts { 37 namespace SkOpts {
66 38
67 // Define default function pointer values here... 39 // Define default function pointer values here...
68 // If our global compile options are set high enough, these defaults might e ven be 40 // If our global compile options are set high enough, these defaults might e ven be
69 // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defa ults. 41 // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defa ults.
70 // They'll still get a chance to be replaced with even better ones, e.g. usi ng SSE4.1. 42 // They'll still get a chance to be replaced with even better ones, e.g. usi ng SSE4.1.
71 decltype(create_xfermode) create_xfermode = sk_default::create_xfermode; 43 decltype(create_xfermode) create_xfermode = sk_default::create_xfermode;
72 decltype(color_cube_filter_span) color_cube_filter_span = sk_default::color_ cube_filter_span; 44 decltype(color_cube_filter_span) color_cube_filter_span = sk_default::color_ cube_filter_span;
73 45
74 decltype(box_blur_xx) box_blur_xx = sk_default::box_blur_xx; 46 decltype(box_blur_xx) box_blur_xx = sk_default::box_blur_xx;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void Init_ssse3(); 82 void Init_ssse3();
111 void Init_sse41(); 83 void Init_sse41();
112 void Init_sse42() {} 84 void Init_sse42() {}
113 void Init_avx() {} 85 void Init_avx() {}
114 void Init_avx2() {} 86 void Init_avx2() {}
115 void Init_neon(); 87 void Init_neon();
116 88
117 static void init() { 89 static void init() {
118 // TODO: Chrome's not linking _sse* opts on iOS simulator builds. Bug o r feature? 90 // TODO: Chrome's not linking _sse* opts on iOS simulator builds. Bug o r feature?
119 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) 91 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS)
120 uint32_t abcd[] = {0,0,0,0}; 92 if (SkCpu::Supports(SkCpu::SSSE3)) { Init_ssse3(); }
121 cpuid(abcd); 93 if (SkCpu::Supports(SkCpu::SSE41)) { Init_sse41(); }
122 if (abcd[2] & (1<< 9)) { Init_ssse3(); } 94 if (SkCpu::Supports(SkCpu::SSE42)) { Init_sse42(); }
123 if (abcd[2] & (1<<19)) { Init_sse41(); } 95 if (SkCpu::Supports(SkCpu::AVX )) { Init_avx(); }
124 if (abcd[2] & (1<<20)) { Init_sse42(); } 96 if (SkCpu::Supports(SkCpu::AVX2 )) { Init_avx2(); }
125 97
126 // AVX detection's kind of a pain. This is cribbed from Chromium. 98 #elif defined(SK_CPU_ARM32) && \
127 if ( ( abcd[2] & (7<<26)) == (7<<26) && // Check bits 26-28 of ecx a re all set, 99 defined(SK_BUILD_FOR_ANDROID) && \
128 (xgetbv(0) & 6 ) == 6 ){ // and check the OS support s XSAVE. 100 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
129 Init_avx(); 101 if (SkCpu::Supports(SkCpu::NEON)) { Init_neon(); }
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 (); }
142 #endif 102 #endif
143 } 103 }
144 104
145 SK_DECLARE_STATIC_ONCE(gInitOnce); 105 SK_DECLARE_STATIC_ONCE(gInitOnce);
146 void Init() { SkOnce(&gInitOnce, init); } 106 void Init() { SkOnce(&gInitOnce, init); }
147 107
148 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 108 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
149 static struct AutoInit { 109 static struct AutoInit {
150 AutoInit() { Init(); } 110 AutoInit() { Init(); }
151 } gAutoInit; 111 } gAutoInit;
152 #endif 112 #endif
153 } 113 }
OLDNEW
« no previous file with comments | « src/core/SkCpu.cpp ('k') | src/core/SkUtilsArm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698