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

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

Issue 1428153003: avx and avx2 detection (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: __cpuid_count Created 5 years, 1 month 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 | « no previous file | no next file » | 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 "SkOnce.h" 8 #include "SkOnce.h"
9 #include "SkOpts.h" 9 #include "SkOpts.h"
10 10
11 #define SK_OPTS_NS sk_default 11 #define SK_OPTS_NS sk_default
12 #include "SkBlitMask_opts.h" 12 #include "SkBlitMask_opts.h"
13 #include "SkBlitRow_opts.h" 13 #include "SkBlitRow_opts.h"
14 #include "SkBlurImageFilter_opts.h" 14 #include "SkBlurImageFilter_opts.h"
15 #include "SkColorCubeFilter_opts.h" 15 #include "SkColorCubeFilter_opts.h"
16 #include "SkFloatingPoint_opts.h" 16 #include "SkFloatingPoint_opts.h"
17 #include "SkMatrix_opts.h" 17 #include "SkMatrix_opts.h"
18 #include "SkMorphologyImageFilter_opts.h" 18 #include "SkMorphologyImageFilter_opts.h"
19 #include "SkTextureCompressor_opts.h" 19 #include "SkTextureCompressor_opts.h"
20 #include "SkUtils_opts.h" 20 #include "SkUtils_opts.h"
21 #include "SkXfermode_opts.h" 21 #include "SkXfermode_opts.h"
22 22
23 #if defined(SK_CPU_X86) 23 #if defined(SK_CPU_X86)
24 #if defined(SK_BUILD_FOR_WIN32) 24 #if defined(SK_BUILD_FOR_WIN32)
25 #include <intrin.h> 25 #include <intrin.h>
26 static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } 26 static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); }
27 static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); }
28 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); }
27 #else 29 #else
28 #include <cpuid.h> 30 #include <cpuid.h>
29 static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abc d+2, abcd+3); } 31 #if !defined(__cpuid_count) // Old Mac Clang doesn't have this defined.
32 #define __cpuid_count(eax, ecx, a, b, c, d) \
33 __asm__("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(eax), "2"(ecx))
34 #endif
35 static void cpuid (uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, ab cd+2, abcd+3); }
36 static void cpuid7(uint32_t abcd[4]) {
37 __cpuid_count(7, 0, abcd[0], abcd[1], abcd[2], abcd[3]);
38 }
39 static uint64_t xgetbv(uint32_t xcr) {
40 uint32_t eax, edx;
41 __asm__ __volatile__ ( "xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr));
42 return (uint64_t)(edx) << 32 | eax;
43 }
30 #endif 44 #endif
31 #elif !defined(SK_ARM_HAS_NEON) && \ 45 #elif !defined(SK_ARM_HAS_NEON) && \
32 defined(SK_CPU_ARM32) && \ 46 defined(SK_CPU_ARM32) && \
33 defined(SK_BUILD_FOR_ANDROID) && \ 47 defined(SK_BUILD_FOR_ANDROID) && \
34 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 48 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
35 #include <cpu-features.h> 49 #include <cpu-features.h>
36 #endif 50 #endif
37 51
38 namespace SkOpts { 52 namespace SkOpts {
39 // Define default function pointer values here... 53 // Define default function pointer values here...
(...skipping 23 matching lines...) Expand all
63 decltype(blit_row_color32) blit_row_color32 = sk_default::blit_row_color32; 77 decltype(blit_row_color32) blit_row_color32 = sk_default::blit_row_color32;
64 78
65 decltype(matrix_translate) matrix_translate = sk_default::matrix _translate; 79 decltype(matrix_translate) matrix_translate = sk_default::matrix _translate;
66 decltype(matrix_scale_translate) matrix_scale_translate = sk_default::matrix _scale_translate; 80 decltype(matrix_scale_translate) matrix_scale_translate = sk_default::matrix _scale_translate;
67 decltype(matrix_affine) matrix_affine = sk_default::matrix _affine; 81 decltype(matrix_affine) matrix_affine = sk_default::matrix _affine;
68 82
69 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. 83 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp.
70 void Init_ssse3(); 84 void Init_ssse3();
71 void Init_sse41(); 85 void Init_sse41();
72 void Init_neon(); 86 void Init_neon();
73 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? 87 void Init_avx() { SkDEBUGCODE( SkDebugf("avx detected\n"); ) }
88 void Init_avx2() { SkDEBUGCODE( SkDebugf("avx2 detected\n"); ) }
89 //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, ... ?
74 90
75 static void init() { 91 static void init() {
76 // TODO: Chrome's not linking _sse* opts on iOS simulator builds. Bug o r feature? 92 // TODO: Chrome's not linking _sse* opts on iOS simulator builds. Bug o r feature?
77 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS) 93 #if defined(SK_CPU_X86) && !defined(SK_BUILD_FOR_IOS)
78 uint32_t abcd[] = {0,0,0,0}; 94 uint32_t abcd[] = {0,0,0,0};
79 cpuid(abcd); 95 cpuid(abcd);
80 if (abcd[2] & (1<< 9)) { Init_ssse3(); } 96 if (abcd[2] & (1<< 9)) { Init_ssse3(); }
81 if (abcd[2] & (1<<19)) { Init_sse41(); } 97 if (abcd[2] & (1<<19)) { Init_sse41(); }
98
99 // AVX detection's kind of a pain. This is cribbed from Chromium.
100 if ( ( abcd[2] & (7<<26)) == (7<<26) && // Check bits 26-28 of ecx a re all set,
101 (xgetbv(0) & 6 ) == 6 ){ // and check the OS support s XSAVE.
102 Init_avx();
103
104 // AVX2 additionally needs bit 5 set on ebx after calling cpuid(7).
105 uint32_t abcd7[] = {0,0,0,0};
106 cpuid7(abcd7);
107 if (abcd7[1] & (1<<5)) { Init_avx2(); }
108 }
109
82 #elif !defined(SK_ARM_HAS_NEON) && \ 110 #elif !defined(SK_ARM_HAS_NEON) && \
83 defined(SK_CPU_ARM32) && \ 111 defined(SK_CPU_ARM32) && \
84 defined(SK_BUILD_FOR_ANDROID) && \ 112 defined(SK_BUILD_FOR_ANDROID) && \
85 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 113 !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
86 if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) { Init_neon (); } 114 if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) { Init_neon (); }
87 #endif 115 #endif
88 } 116 }
89 117
90 SK_DECLARE_STATIC_ONCE(gInitOnce); 118 SK_DECLARE_STATIC_ONCE(gInitOnce);
91 void Init() { SkOnce(&gInitOnce, init); } 119 void Init() { SkOnce(&gInitOnce, init); }
92 120
93 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 121 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
94 static struct AutoInit { 122 static struct AutoInit {
95 AutoInit() { Init(); } 123 AutoInit() { Init(); }
96 } gAutoInit; 124 } gAutoInit;
97 #endif 125 #endif
98 } 126 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698