| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 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 #define SkCpu_IMPL |
| 8 #include "SkCpu.h" | 9 #include "SkCpu.h" |
| 9 #include "SkOncePtr.h" | 10 #include "SkOnce.h" |
| 10 | 11 |
| 11 #if defined(SK_CPU_X86) | 12 #if defined(SK_CPU_X86) |
| 12 #if defined(SK_BUILD_FOR_WIN32) | 13 #if defined(SK_BUILD_FOR_WIN32) |
| 13 #include <intrin.h> | 14 #include <intrin.h> |
| 14 static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); } | 15 static void cpuid (uint32_t abcd[4]) { __cpuid ((int*)abcd, 1); } |
| 15 static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); } | 16 static void cpuid7(uint32_t abcd[4]) { __cpuidex((int*)abcd, 7, 0); } |
| 16 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); } | 17 static uint64_t xgetbv(uint32_t xcr) { return _xgetbv(xcr); } |
| 17 #else | 18 #else |
| 18 #include <cpuid.h> | 19 #include <cpuid.h> |
| 19 #if !defined(__cpuid_count) // Old Mac Clang doesn't have this defined. | 20 #if !defined(__cpuid_count) // Old Mac Clang doesn't have this defined. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return features; | 72 return features; |
| 72 } | 73 } |
| 73 | 74 |
| 74 #else | 75 #else |
| 75 static uint32_t read_cpu_features() { | 76 static uint32_t read_cpu_features() { |
| 76 return 0; | 77 return 0; |
| 77 } | 78 } |
| 78 | 79 |
| 79 #endif | 80 #endif |
| 80 | 81 |
| 81 #if defined(__GNUC__) || defined(__clang__) | 82 #if defined(_MSC_VER) |
| 82 SK_DECLARE_STATIC_ONCE_PTR(uint32_t, gCachedCpuFeatures); | 83 const uint32_t SkCpu::gCachedFeatures = read_cpu_features(); |
| 83 uint32_t SkCpu::RuntimeCpuFeatures() { | 84 |
| 84 return *gCachedCpuFeatures.get([]{ return new uint32_t{read_cpu_features
()}; }); | 85 void SkCpu::CacheRuntimeFeatures() {} |
| 86 |
| 87 #else |
| 88 uint32_t SkCpu::gCachedFeatures = 0; |
| 89 |
| 90 void SkCpu::CacheRuntimeFeatures() { |
| 91 static SkOnce once; |
| 92 once([] { gCachedFeatures = read_cpu_features(); }); |
| 85 } | 93 } |
| 86 | 94 |
| 87 #else | |
| 88 const uint32_t SkCpu::gCachedCpuFeatures = read_cpu_features(); | |
| 89 | |
| 90 #endif | 95 #endif |
| OLD | NEW |