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

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

Issue 1550893002: Try using std::call_once (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 "SkBlitRow.h" 13 #include "SkBlitRow.h"
14 #include "SkBlitRow_opts_SSE2.h" 14 #include "SkBlitRow_opts_SSE2.h"
15 #include "SkBlitRow_opts_SSE4.h" 15 #include "SkBlitRow_opts_SSE4.h"
16 #include "SkOncePtr.h"
17 #include "SkRTConf.h" 16 #include "SkRTConf.h"
17 #include <mutex>
18 18
19 #if defined(_MSC_VER) && defined(_WIN64) 19 #if defined(_MSC_VER) && defined(_WIN64)
20 #include <intrin.h> 20 #include <intrin.h>
21 #endif 21 #endif
22 22
23 /* This file must *not* be compiled with -msse or any other optional SIMD 23 /* This file must *not* be compiled with -msse or any other optional SIMD
24 extension, otherwise gcc may generate SIMD instructions even for scalar ops 24 extension, otherwise gcc may generate SIMD instructions even for scalar ops
25 (and thus give an invalid instruction on Pentium3 on the code below). 25 (and thus give an invalid instruction on Pentium3 on the code below).
26 For example, only files named *_SSE2.cpp in this directory should be 26 For example, only files named *_SSE2.cpp in this directory should be
27 compiled with -msse2 or higher. */ 27 compiled with -msse2 or higher. */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 "movl %%ebx, %1 \n\t" 61 "movl %%ebx, %1 \n\t"
62 "popl %%ebx \n\t" 62 "popl %%ebx \n\t"
63 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) 63 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
64 : "a"(info_type) 64 : "a"(info_type)
65 ); 65 );
66 } 66 }
67 #endif 67 #endif
68 68
69 //////////////////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////////////////
70 70
71 /* Fetch the SIMD level directly from the CPU, at run-time.
72 * Only checks the levels needed by the optimizations in this file.
73 */
74 static int* get_SIMD_level() {
75 int cpu_info[4] = { 0, 0, 0, 0 };
76 getcpuid(1, cpu_info);
77
78 int* level = new int;
79
80 if ((cpu_info[2] & (1<<20)) != 0) {
81 *level = SK_CPU_SSE_LEVEL_SSE42;
82 } else if ((cpu_info[2] & (1<<19)) != 0) {
83 *level = SK_CPU_SSE_LEVEL_SSE41;
84 } else if ((cpu_info[2] & (1<<9)) != 0) {
85 *level = SK_CPU_SSE_LEVEL_SSSE3;
86 } else if ((cpu_info[3] & (1<<26)) != 0) {
87 *level = SK_CPU_SSE_LEVEL_SSE2;
88 } else {
89 *level = 0;
90 }
91 return level;
92 }
93
94 SK_DECLARE_STATIC_ONCE_PTR(int, gSIMDLevel);
95
96 /* Verify that the requested SIMD level is supported in the build. 71 /* Verify that the requested SIMD level is supported in the build.
97 * If not, check if the platform supports it. 72 * If not, check if the platform supports it.
98 */ 73 */
99 static inline bool supports_simd(int minLevel) { 74 static inline bool supports_simd(int level) {
100 #if defined(SK_CPU_SSE_LEVEL) 75 #if defined(SK_CPU_SSE_LEVEL)
101 if (minLevel <= SK_CPU_SSE_LEVEL) { 76 if (level <= SK_CPU_SSE_LEVEL) {
102 return true; 77 return true;
103 } else 78 } else
104 #endif 79 #endif
105 { 80 {
106 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 81 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
107 /* For the Android framework we should always know at compile time if th e device 82 /* For the Android framework we should always know at compile time if th e device
108 * we are building for supports SSSE3. The one exception to this rule i s on the 83 * we are building for supports SSSE3. The one exception to this rule i s on the
109 * emulator where we are compiled without the -mssse3 option (so we have no 84 * emulator where we are compiled without the -mssse3 option (so we have no
110 * SSSE3 procs) but can be run on a host machine that supports SSSE3 85 * SSSE3 procs) but can be run on a host machine that supports SSSE3
111 * instructions. So for that particular case we disable our SSSE3 option s. 86 * instructions. So for that particular case we disable our SSSE3 option s.
112 */ 87 */
113 return false; 88 return false;
114 #else 89 #else
115 return minLevel <= *gSIMDLevel.get(get_SIMD_level); 90 static std::once_flag once;
91 static int maxLevel = 0;
92 std::call_once(once, [&]{
93 int cpu_info[4] = { 0, 0, 0, 0 };
94 getcpuid(1, cpu_info);
95
96 if (cpu_info[3] & (1<<26)) { maxLevel = SK_CPU_SSE_LEVEL_SSE2 ; }
97 if (cpu_info[2] & (1<< 9)) { maxLevel = SK_CPU_SSE_LEVEL_SSSE3; }
98 if (cpu_info[2] & (1<<19)) { maxLevel = SK_CPU_SSE_LEVEL_SSE41; }
99 if (cpu_info[2] & (1<<20)) { maxLevel = SK_CPU_SSE_LEVEL_SSE42; }
100 });
101 return level <= maxLevel;
116 #endif 102 #endif
117 } 103 }
118 } 104 }
119 105
120 //////////////////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////////////////
121 107
122 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) { 108 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) {
123 if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) { 109 if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) {
124 procs->fExtraHorizontalReads = 3; 110 procs->fExtraHorizontalReads = 3;
125 procs->fConvolveVertically = &convolveVertically_SSE2; 111 procs->fConvolveVertically = &convolveVertically_SSE2;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 245 }
260 } else { 246 } else {
261 return nullptr; 247 return nullptr;
262 } 248 }
263 249
264 } 250 }
265 251
266 SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkColorType, SkMask::Format, Ro wFlags) { 252 SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkColorType, SkMask::Format, Ro wFlags) {
267 return nullptr; 253 return nullptr;
268 } 254 }
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