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

Unified 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 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/opts_check_x86.cpp
diff --git a/src/opts/opts_check_x86.cpp b/src/opts/opts_check_x86.cpp
index 3c817e1f0a4e529c0d9cf1212b2ed257f439ed3b..23f30364a595aa18b1e57dd785ac83567204d6cd 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,37 +68,12 @@ static inline void getcpuid(int info_type, int info[4]) {
////////////////////////////////////////////////////////////////////////////////
-/* 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 minLevel) {
+static inline bool supports_simd(int level) {
#if defined(SK_CPU_SSE_LEVEL)
- if (minLevel <= SK_CPU_SSE_LEVEL) {
+ if (level <= SK_CPU_SSE_LEVEL) {
return true;
} else
#endif
@@ -112,7 +87,18 @@ static inline bool supports_simd(int minLevel) {
*/
return false;
#else
- return minLevel <= *gSIMDLevel.get(get_SIMD_level);
+ 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;
#endif
}
}
« 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