Debian Codegraph @

src/opts/SkOpts_SetTarget.h

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright 2023 Google LLC
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 // Include guards are intentionally omitted
9
10 #include "include/private/base/SkFeatures.h"
11
12 #if !defined(SK_OPTS_TARGET)
13 #error Define SK_OPTS_TARGET before including SkOpts_SetTarget
14 #endif
15
16 #if defined(SK_OPTS_NS)
17 // For testing define SK_OPTS_NS before including.
18 #elif SK_OPTS_TARGET == SK_OPTS_TARGET_DEFAULT
19
20 #if defined(SK_ARM_HAS_NEON)
21 #define SK_OPTS_NS neon
22 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SKX
23 #define SK_OPTS_NS skx
24 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2
25 #define SK_OPTS_NS avx2
26 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX
27 #define SK_OPTS_NS avx
28 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42
29 #define SK_OPTS_NS sse42
30 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41
31 #define SK_OPTS_NS sse41
32 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
33 #define SK_OPTS_NS ssse3
34 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE3
35 #define SK_OPTS_NS sse3
36 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
37 #define SK_OPTS_NS sse2
38 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
39 #define SK_OPTS_NS sse
40 #elif SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LASX
41 #define SK_OPTS_NS lasx
42 #elif SK_CPU_LSX_LEVEL >= SK_CPU_LSX_LEVEL_LSX
43 #define SK_OPTS_NS lsx
44 #else
45 #define SK_OPTS_NS portable
46 #endif
47
48 #define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name
49
50 #else // SK_OPTS_TARGET != SK_OPTS_TARGET_DEFAULT
51
52 #if defined(SK_OLD_CPU_SSE_LEVEL)
53 #error Include SkOpts_RestoreTarget before re-including SkOpts_SetTarget
54 #endif
55
56 #define SK_OLD_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL
57 #undef SK_CPU_SSE_LEVEL
58 #undef SK_CPU_LSX_LEVEL
59
60 // NOTE: Below, we automatically include arch-specific intrinsic headers when we've detected
61 // that the compiler is clang-cl. Clang's headers skip including "unsupported" intrinsics (via
62 // defines like __AVX__ etc.), but only when _MSC_VER is also defined. To get around that, we
63 // directly include the headers for any intrinsics that ought to be present in each opts target.
64 //
65 // Each of the specific intrinsic headers also checks to ensure that immintrin.h has been
66 // included, so do that here, first.
67 #if defined(__clang__) && defined(_MSC_VER)
68 #define __RTMINTRIN_H // Workaround for https://github.com/llvm/llvm-project/issues/95133
69 #include <immintrin.h>
70 #endif
71
72 // Why not put the target string in a #define, and remove the boilerplate? Because GCC doesn't
73 // allow the target() option to be expanded by the preprocessor - it must be a literal string.
74 #if SK_OPTS_TARGET == SK_OPTS_TARGET_SSSE3
75
76 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3
77 #define SK_OPTS_NS ssse3
78
79 #if defined(__clang__)
80 #pragma clang attribute push(__attribute__((target("sse2,ssse3"))), apply_to=function)
81 #elif defined(__GNUC__)
82 #pragma GCC push_options
83 #pragma GCC target("sse2,ssse3")
84 #endif
85
86 #if defined(__clang__) && defined(_MSC_VER)
87 #include <pmmintrin.h>
88 #include <tmmintrin.h>
89 #endif
90
91 #elif SK_OPTS_TARGET == SK_OPTS_TARGET_AVX
92
93 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX
94 #define SK_OPTS_NS avx
95
96 #if defined(__clang__)
97 #pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,sse4.2,avx"))), apply_to=function)
98 #elif defined(__GNUC__)
99 #pragma GCC push_options
100 #pragma GCC target("sse2,ssse3,sse4.1,sse4.2,avx")
101 #endif
102
103 #if defined(__clang__) && defined(_MSC_VER)
104 #include <pmmintrin.h>
105 #include <tmmintrin.h>
106 #include <smmintrin.h>
107 #include <avxintrin.h>
108 #endif
109
110 #elif SK_OPTS_TARGET == SK_OPTS_TARGET_HSW
111
112 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2
113 #define SK_OPTS_NS hsw
114
115 #if defined(__clang__)
116 #pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,sse4.2,avx,avx2,bmi,bmi2,f16c,fma"))), apply_to=function)
117 #elif defined(__GNUC__)
118 #pragma GCC push_options
119 #pragma GCC target("sse2,ssse3,sse4.1,sse4.2,avx,avx2,bmi,bmi2,f16c,fma")
120 #endif
121
122 #if defined(__clang__) && defined(_MSC_VER)
123 #include <pmmintrin.h>
124 #include <tmmintrin.h>
125 #include <smmintrin.h>
126 #include <avxintrin.h>
127 #include <avx2intrin.h>
128 #include <f16cintrin.h>
129 #include <bmi2intrin.h>
130 #include <fmaintrin.h>
131 #endif
132
133 #elif SK_OPTS_TARGET == SK_OPTS_TARGET_LASX
134
135 #define SK_CPU_LSX_LEVEL SK_CPU_LSX_LEVEL_LASX
136 #define SK_OPTS_NS lasx
137 // The intrinsic from lasxintrin.h is wrapped by the __loongarch_asx macro, so we need to define it.
138 #define __loongarch_asx
139
140 #if defined(__clang__)
141 #pragma clang attribute push(__attribute__((target("lasx"))), apply_to=function)
•142 #elif defined(__GNUC__)
143 #pragma GCC push_options
144 #pragma GCC target("lsx,lasx")
145 #endif
146
147 #else
148 #error Unexpected value of SK_OPTS_TARGET
149
150 #endif
151
152 #endif // !SK_OPTS_TARGET_DEFAULT