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

Side by Side Diff: src/opts/opts_check_x86.cpp

Issue 655573002: Fix race in supports_simd(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: external linkage Created 6 years, 2 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 | « 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 2009 The Android Open Source Project 2 * Copyright 2009 The Android Open Source Project
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 "SkBitmapFilter_opts_SSE2.h" 8 #include "SkBitmapFilter_opts_SSE2.h"
9 #include "SkBitmapProcState_opts_SSE2.h" 9 #include "SkBitmapProcState_opts_SSE2.h"
10 #include "SkBitmapProcState_opts_SSSE3.h" 10 #include "SkBitmapProcState_opts_SSSE3.h"
11 #include "SkBitmapScaler.h" 11 #include "SkBitmapScaler.h"
12 #include "SkBlitMask.h" 12 #include "SkBlitMask.h"
13 #include "SkBlitRect_opts_SSE2.h" 13 #include "SkBlitRect_opts_SSE2.h"
14 #include "SkBlitRow.h" 14 #include "SkBlitRow.h"
15 #include "SkBlitRow_opts_SSE2.h" 15 #include "SkBlitRow_opts_SSE2.h"
16 #include "SkBlitRow_opts_SSE4.h" 16 #include "SkBlitRow_opts_SSE4.h"
17 #include "SkBlurImage_opts_SSE2.h" 17 #include "SkBlurImage_opts_SSE2.h"
18 #include "SkBlurImage_opts_SSE4.h" 18 #include "SkBlurImage_opts_SSE4.h"
19 #include "SkLazyPtr.h"
19 #include "SkMorphology_opts.h" 20 #include "SkMorphology_opts.h"
20 #include "SkMorphology_opts_SSE2.h" 21 #include "SkMorphology_opts_SSE2.h"
21 #include "SkRTConf.h" 22 #include "SkRTConf.h"
22 #include "SkUtils.h" 23 #include "SkUtils.h"
23 #include "SkUtils_opts_SSE2.h" 24 #include "SkUtils_opts_SSE2.h"
24 #include "SkXfermode.h" 25 #include "SkXfermode.h"
25 #include "SkXfermode_proccoeff.h" 26 #include "SkXfermode_proccoeff.h"
26 27
27 #if defined(_MSC_VER) && defined(_WIN64) 28 #if defined(_MSC_VER) && defined(_WIN64)
28 #include <intrin.h> 29 #include <intrin.h>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 : "a"(info_type) 73 : "a"(info_type)
73 ); 74 );
74 } 75 }
75 #endif 76 #endif
76 77
77 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
78 79
79 /* Fetch the SIMD level directly from the CPU, at run-time. 80 /* Fetch the SIMD level directly from the CPU, at run-time.
80 * Only checks the levels needed by the optimizations in this file. 81 * Only checks the levels needed by the optimizations in this file.
81 */ 82 */
82 static int get_SIMD_level() { 83 namespace { // get_SIMD_level() technically must have external linkage, so no s tatic.
83 int cpu_info[4] = { 0 }; 84 int* get_SIMD_level() {
85 int cpu_info[4] = { 0, 0, 0, 0 };
86 getcpuid(1, cpu_info);
84 87
85 getcpuid(1, cpu_info); 88 int* level = SkNEW(int);
89
86 if ((cpu_info[2] & (1<<20)) != 0) { 90 if ((cpu_info[2] & (1<<20)) != 0) {
87 return SK_CPU_SSE_LEVEL_SSE42; 91 *level = SK_CPU_SSE_LEVEL_SSE42;
88 } else if ((cpu_info[2] & (1<<19)) != 0) { 92 } else if ((cpu_info[2] & (1<<19)) != 0) {
89 return SK_CPU_SSE_LEVEL_SSE41; 93 *level = SK_CPU_SSE_LEVEL_SSE41;
90 } else if ((cpu_info[2] & (1<<9)) != 0) { 94 } else if ((cpu_info[2] & (1<<9)) != 0) {
91 return SK_CPU_SSE_LEVEL_SSSE3; 95 *level = SK_CPU_SSE_LEVEL_SSSE3;
92 } else if ((cpu_info[3] & (1<<26)) != 0) { 96 } else if ((cpu_info[3] & (1<<26)) != 0) {
93 return SK_CPU_SSE_LEVEL_SSE2; 97 *level = SK_CPU_SSE_LEVEL_SSE2;
94 } else { 98 } else {
95 return 0; 99 *level = 0;
96 } 100 }
101 return level;
97 } 102 }
103 } // namespace
104
105 SK_DECLARE_STATIC_LAZY_PTR(int, gSIMDLevel, get_SIMD_level);
98 106
99 /* Verify that the requested SIMD level is supported in the build. 107 /* Verify that the requested SIMD level is supported in the build.
100 * If not, check if the platform supports it. 108 * If not, check if the platform supports it.
101 */ 109 */
102 static inline bool supports_simd(int minLevel) { 110 static inline bool supports_simd(int minLevel) {
103 #if defined(SK_CPU_SSE_LEVEL) 111 #if defined(SK_CPU_SSE_LEVEL)
104 if (minLevel <= SK_CPU_SSE_LEVEL) { 112 if (minLevel <= SK_CPU_SSE_LEVEL) {
105 return true; 113 return true;
106 } else 114 } else
107 #endif 115 #endif
108 { 116 {
109 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 117 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
110 /* For the Android framework we should always know at compile time if th e device 118 /* For the Android framework we should always know at compile time if th e device
111 * we are building for supports SSSE3. The one exception to this rule i s on the 119 * we are building for supports SSSE3. The one exception to this rule i s on the
112 * emulator where we are compiled without the -mssse3 option (so we have no 120 * emulator where we are compiled without the -mssse3 option (so we have no
113 * SSSE3 procs) but can be run on a host machine that supports SSSE3 121 * SSSE3 procs) but can be run on a host machine that supports SSSE3
114 * instructions. So for that particular case we disable our SSSE3 option s. 122 * instructions. So for that particular case we disable our SSSE3 option s.
115 */ 123 */
116 return false; 124 return false;
117 #else 125 #else
118 static int gSIMDLevel = get_SIMD_level(); 126 return minLevel <= *gSIMDLevel.get();
119 return (minLevel <= gSIMDLevel);
120 #endif 127 #endif
121 } 128 }
122 } 129 }
123 130
124 //////////////////////////////////////////////////////////////////////////////// 131 ////////////////////////////////////////////////////////////////////////////////
125 132
126 SK_CONF_DECLARE( bool, c_hqfilter_sse, "bitmap.filter.highQualitySSE", true, "Us e SSE optimized version of high quality image filters"); 133 SK_CONF_DECLARE( bool, c_hqfilter_sse, "bitmap.filter.highQualitySSE", true, "Us e SSE optimized version of high quality image filters");
127 134
128 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) { 135 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) {
129 if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) { 136 if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } else { 399 } else {
393 return SkPlatformXfermodeFactory_impl(rec, mode); 400 return SkPlatformXfermodeFactory_impl(rec, mode);
394 } 401 }
395 } 402 }
396 403
397 SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode); 404 SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode);
398 405
399 SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode) { 406 SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode) {
400 return NULL; 407 return NULL;
401 } 408 }
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