OLD | NEW |
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" |
16 #include "SkRTConf.h" | 17 #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 Loading... |
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 |
71 /* Verify that the requested SIMD level is supported in the build. | 96 /* Verify that the requested SIMD level is supported in the build. |
72 * If not, check if the platform supports it. | 97 * If not, check if the platform supports it. |
73 */ | 98 */ |
74 static inline bool supports_simd(int level) { | 99 static inline bool supports_simd(int minLevel) { |
75 #if defined(SK_CPU_SSE_LEVEL) | 100 #if defined(SK_CPU_SSE_LEVEL) |
76 if (level <= SK_CPU_SSE_LEVEL) { | 101 if (minLevel <= SK_CPU_SSE_LEVEL) { |
77 return true; | 102 return true; |
78 } else | 103 } else |
79 #endif | 104 #endif |
80 { | 105 { |
81 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | 106 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
82 /* For the Android framework we should always know at compile time if th
e device | 107 /* For the Android framework we should always know at compile time if th
e device |
83 * we are building for supports SSSE3. The one exception to this rule i
s on the | 108 * we are building for supports SSSE3. The one exception to this rule i
s on the |
84 * emulator where we are compiled without the -mssse3 option (so we have
no | 109 * emulator where we are compiled without the -mssse3 option (so we have
no |
85 * SSSE3 procs) but can be run on a host machine that supports SSSE3 | 110 * SSSE3 procs) but can be run on a host machine that supports SSSE3 |
86 * instructions. So for that particular case we disable our SSSE3 option
s. | 111 * instructions. So for that particular case we disable our SSSE3 option
s. |
87 */ | 112 */ |
88 return false; | 113 return false; |
89 #else | 114 #else |
90 static std::once_flag once; | 115 return minLevel <= *gSIMDLevel.get(get_SIMD_level); |
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; | |
102 #endif | 116 #endif |
103 } | 117 } |
104 } | 118 } |
105 | 119 |
106 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
107 | 121 |
108 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) { | 122 void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) { |
109 if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) { | 123 if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) { |
110 procs->fExtraHorizontalReads = 3; | 124 procs->fExtraHorizontalReads = 3; |
111 procs->fConvolveVertically = &convolveVertically_SSE2; | 125 procs->fConvolveVertically = &convolveVertically_SSE2; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 259 } |
246 } else { | 260 } else { |
247 return nullptr; | 261 return nullptr; |
248 } | 262 } |
249 | 263 |
250 } | 264 } |
251 | 265 |
252 SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkColorType, SkMask::Format, Ro
wFlags) { | 266 SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkColorType, SkMask::Format, Ro
wFlags) { |
253 return nullptr; | 267 return nullptr; |
254 } | 268 } |
OLD | NEW |