OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkCpu_DEFINED | |
9 #define SkCpu_DEFINED | |
10 | |
11 #include "SkTypes.h" | |
12 | |
13 struct SkCpu { | |
14 enum { | |
15 SSE1 = 1 << 0, | |
16 SSE2 = 1 << 1, | |
17 SSE3 = 1 << 2, | |
18 SSSE3 = 1 << 3, | |
19 SSE41 = 1 << 4, | |
20 SSE42 = 1 << 5, | |
21 AVX = 1 << 6, | |
22 F16C = 1 << 7, | |
23 FMA = 1 << 8, | |
24 AVX2 = 1 << 9, | |
25 }; | |
26 enum { | |
27 NEON = 1 << 0, | |
28 NEON_FMA = 1 << 1, | |
29 VFP_FP16 = 1 << 2, | |
30 }; | |
31 | |
32 static void CacheRuntimeFeatures(); | |
33 static bool Supports(uint32_t); | |
34 private: | |
35 #if defined(_MSC_VER) || !defined(SkCpu_IMPL) | |
36 static const uint32_t gCachedFeatures; | |
37 #else | |
38 static uint32_t gCachedFeatures; | |
39 #endif | |
40 }; | |
41 | |
42 inline bool SkCpu::Supports(uint32_t mask) { | |
43 uint32_t features = gCachedFeatures; | |
44 | |
45 // If we mask in compile-time known lower limits, the compiler can | |
46 // often compile away this entire function. | |
47 #if SK_CPU_X86 | |
48 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1 | |
49 features |= SSE1; | |
50 #endif | |
51 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | |
52 features |= SSE2; | |
53 #endif | |
54 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE3 | |
55 features |= SSE3; | |
56 #endif | |
57 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 | |
58 features |= SSSE3; | |
59 #endif | |
60 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41 | |
61 features |= SSE41; | |
62 #endif | |
63 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42 | |
64 features |= SSE42; | |
65 #endif | |
66 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX | |
67 features |= AVX; | |
68 #endif | |
69 // F16C goes here if we add SK_CPU_SSE_LEVEL_F16C | |
70 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 | |
71 features |= AVX2; | |
72 #endif | |
73 // FMA doesn't fit neatly into this total ordering. | |
74 // It's available on Haswell+ just like AVX2, but it's technically a differe
nt bit. | |
75 // TODO: circle back on this if we find ourselves limited by lack of compile
-time FMA | |
76 | |
77 #else | |
78 #if defined(SK_ARM_HAS_NEON) | |
79 features |= NEON; | |
80 #endif | |
81 | |
82 #if defined(SK_CPU_ARM64) | |
83 features |= NEON|NEON_FMA|VFP_FP16; | |
84 #endif | |
85 | |
86 #endif | |
87 return (features & mask) == mask; | |
88 } | |
89 | |
90 #endif//SkCpu_DEFINED | |
OLD | NEW |