| Index: src/opts/opts_check_x86.cpp
|
| diff --git a/src/opts/opts_check_x86.cpp b/src/opts/opts_check_x86.cpp
|
| index 23f30364a595aa18b1e57dd785ac83567204d6cd..3c817e1f0a4e529c0d9cf1212b2ed257f439ed3b 100644
|
| --- a/src/opts/opts_check_x86.cpp
|
| +++ b/src/opts/opts_check_x86.cpp
|
| @@ -13,8 +13,8 @@
|
| #include "SkBlitRow.h"
|
| #include "SkBlitRow_opts_SSE2.h"
|
| #include "SkBlitRow_opts_SSE4.h"
|
| +#include "SkOncePtr.h"
|
| #include "SkRTConf.h"
|
| -#include <mutex>
|
|
|
| #if defined(_MSC_VER) && defined(_WIN64)
|
| #include <intrin.h>
|
| @@ -68,12 +68,37 @@
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| +/* Fetch the SIMD level directly from the CPU, at run-time.
|
| + * Only checks the levels needed by the optimizations in this file.
|
| + */
|
| +static int* get_SIMD_level() {
|
| + int cpu_info[4] = { 0, 0, 0, 0 };
|
| + getcpuid(1, cpu_info);
|
| +
|
| + int* level = new int;
|
| +
|
| + if ((cpu_info[2] & (1<<20)) != 0) {
|
| + *level = SK_CPU_SSE_LEVEL_SSE42;
|
| + } else if ((cpu_info[2] & (1<<19)) != 0) {
|
| + *level = SK_CPU_SSE_LEVEL_SSE41;
|
| + } else if ((cpu_info[2] & (1<<9)) != 0) {
|
| + *level = SK_CPU_SSE_LEVEL_SSSE3;
|
| + } else if ((cpu_info[3] & (1<<26)) != 0) {
|
| + *level = SK_CPU_SSE_LEVEL_SSE2;
|
| + } else {
|
| + *level = 0;
|
| + }
|
| + return level;
|
| +}
|
| +
|
| +SK_DECLARE_STATIC_ONCE_PTR(int, gSIMDLevel);
|
| +
|
| /* Verify that the requested SIMD level is supported in the build.
|
| * If not, check if the platform supports it.
|
| */
|
| -static inline bool supports_simd(int level) {
|
| +static inline bool supports_simd(int minLevel) {
|
| #if defined(SK_CPU_SSE_LEVEL)
|
| - if (level <= SK_CPU_SSE_LEVEL) {
|
| + if (minLevel <= SK_CPU_SSE_LEVEL) {
|
| return true;
|
| } else
|
| #endif
|
| @@ -87,18 +112,7 @@
|
| */
|
| return false;
|
| #else
|
| - static std::once_flag once;
|
| - static int maxLevel = 0;
|
| - std::call_once(once, [&]{
|
| - int cpu_info[4] = { 0, 0, 0, 0 };
|
| - getcpuid(1, cpu_info);
|
| -
|
| - if (cpu_info[3] & (1<<26)) { maxLevel = SK_CPU_SSE_LEVEL_SSE2 ; }
|
| - if (cpu_info[2] & (1<< 9)) { maxLevel = SK_CPU_SSE_LEVEL_SSSE3; }
|
| - if (cpu_info[2] & (1<<19)) { maxLevel = SK_CPU_SSE_LEVEL_SSE41; }
|
| - if (cpu_info[2] & (1<<20)) { maxLevel = SK_CPU_SSE_LEVEL_SSE42; }
|
| - });
|
| - return level <= maxLevel;
|
| + return minLevel <= *gSIMDLevel.get(get_SIMD_level);
|
| #endif
|
| }
|
| }
|
|
|