Grok  9.7.5
foreach_target.h
Go to the documentation of this file.
1 // Copyright 2020 Google LLC
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef HIGHWAY_HWY_FOREACH_TARGET_H_
17 #define HIGHWAY_HWY_FOREACH_TARGET_H_
18 
19 // Re-includes the translation unit zero or more times to compile for any
20 // targets except HWY_STATIC_TARGET. Defines unique HWY_TARGET each time so that
21 // highway.h defines the corresponding macro/namespace.
22 
23 #include "hwy/detect_targets.h"
24 
25 // *_inl.h may include other headers, which requires include guards to prevent
26 // repeated inclusion. The guards must be reset after compiling each target, so
27 // the header is again visible. This is done by flipping HWY_TARGET_TOGGLE,
28 // defining it if undefined and vice versa. This macro is initially undefined
29 // so that IDEs don't gray out the contents of each header.
30 #ifdef HWY_TARGET_TOGGLE
31 #error "This macro must not be defined outside foreach_target.h"
32 #endif
33 
34 #ifdef HWY_HIGHWAY_INCLUDED // highway.h include guard
35 // Trigger fixup at the bottom of this header.
36 #define HWY_ALREADY_INCLUDED
37 
38 // The next highway.h must re-include set_macros-inl.h because the first
39 // highway.h chose the static target instead of what we will set below.
40 #undef HWY_SET_MACROS_PER_TARGET
41 #endif
42 
43 // Disable HWY_EXPORT in user code until we have generated all targets. Note
44 // that a subsequent highway.h will not override this definition.
45 #undef HWY_ONCE
46 #define HWY_ONCE (0 || HWY_IDE)
47 
48 // Avoid warnings on #include HWY_TARGET_INCLUDE by hiding them from the IDE;
49 // also skip if only 1 target defined (no re-inclusion will be necessary).
50 #if !HWY_IDE && (HWY_TARGETS != HWY_STATIC_TARGET)
51 
52 #if !defined(HWY_TARGET_INCLUDE)
53 #error ">1 target enabled => define HWY_TARGET_INCLUDE before foreach_target.h"
54 #endif
55 
56 #if (HWY_TARGETS & HWY_SCALAR) && (HWY_STATIC_TARGET != HWY_SCALAR)
57 #undef HWY_TARGET
58 #define HWY_TARGET HWY_SCALAR
59 #include HWY_TARGET_INCLUDE
60 #ifdef HWY_TARGET_TOGGLE
61 #undef HWY_TARGET_TOGGLE
62 #else
63 #define HWY_TARGET_TOGGLE
64 #endif
65 #endif
66 
67 #if (HWY_TARGETS & HWY_NEON) && (HWY_STATIC_TARGET != HWY_NEON)
68 #undef HWY_TARGET
69 #define HWY_TARGET HWY_NEON
70 #include HWY_TARGET_INCLUDE
71 #ifdef HWY_TARGET_TOGGLE
72 #undef HWY_TARGET_TOGGLE
73 #else
74 #define HWY_TARGET_TOGGLE
75 #endif
76 #endif
77 
78 #if (HWY_TARGETS & HWY_RVV) && (HWY_STATIC_TARGET != HWY_RVV)
79 #undef HWY_TARGET
80 #define HWY_TARGET HWY_RVV
81 #include HWY_TARGET_INCLUDE
82 #ifdef HWY_TARGET_TOGGLE
83 #undef HWY_TARGET_TOGGLE
84 #else
85 #define HWY_TARGET_TOGGLE
86 #endif
87 #endif
88 
89 #if (HWY_TARGETS & HWY_SVE) && (HWY_STATIC_TARGET != HWY_SVE)
90 #undef HWY_TARGET
91 #define HWY_TARGET HWY_SVE
92 #include HWY_TARGET_INCLUDE
93 #ifdef HWY_TARGET_TOGGLE
94 #undef HWY_TARGET_TOGGLE
95 #else
96 #define HWY_TARGET_TOGGLE
97 #endif
98 #endif
99 
100 #if (HWY_TARGETS & HWY_SVE2) && (HWY_STATIC_TARGET != HWY_SVE2)
101 #undef HWY_TARGET
102 #define HWY_TARGET HWY_SVE2
103 #include HWY_TARGET_INCLUDE
104 #ifdef HWY_TARGET_TOGGLE
105 #undef HWY_TARGET_TOGGLE
106 #else
107 #define HWY_TARGET_TOGGLE
108 #endif
109 #endif
110 
111 #if (HWY_TARGETS & HWY_SSSE3) && (HWY_STATIC_TARGET != HWY_SSSE3)
112 #undef HWY_TARGET
113 #define HWY_TARGET HWY_SSSE3
114 #include HWY_TARGET_INCLUDE
115 #ifdef HWY_TARGET_TOGGLE
116 #undef HWY_TARGET_TOGGLE
117 #else
118 #define HWY_TARGET_TOGGLE
119 #endif
120 #endif
121 
122 #if (HWY_TARGETS & HWY_SSE4) && (HWY_STATIC_TARGET != HWY_SSE4)
123 #undef HWY_TARGET
124 #define HWY_TARGET HWY_SSE4
125 #include HWY_TARGET_INCLUDE
126 #ifdef HWY_TARGET_TOGGLE
127 #undef HWY_TARGET_TOGGLE
128 #else
129 #define HWY_TARGET_TOGGLE
130 #endif
131 #endif
132 
133 #if (HWY_TARGETS & HWY_AVX2) && (HWY_STATIC_TARGET != HWY_AVX2)
134 #undef HWY_TARGET
135 #define HWY_TARGET HWY_AVX2
136 #include HWY_TARGET_INCLUDE
137 #ifdef HWY_TARGET_TOGGLE
138 #undef HWY_TARGET_TOGGLE
139 #else
140 #define HWY_TARGET_TOGGLE
141 #endif
142 #endif
143 
144 #if (HWY_TARGETS & HWY_AVX3) && (HWY_STATIC_TARGET != HWY_AVX3)
145 #undef HWY_TARGET
146 #define HWY_TARGET HWY_AVX3
147 #include HWY_TARGET_INCLUDE
148 #ifdef HWY_TARGET_TOGGLE
149 #undef HWY_TARGET_TOGGLE
150 #else
151 #define HWY_TARGET_TOGGLE
152 #endif
153 #endif
154 
155 #if (HWY_TARGETS & HWY_AVX3_DL) && (HWY_STATIC_TARGET != HWY_AVX3_DL)
156 #undef HWY_TARGET
157 #define HWY_TARGET HWY_AVX3_DL
158 #include HWY_TARGET_INCLUDE
159 #ifdef HWY_TARGET_TOGGLE
160 #undef HWY_TARGET_TOGGLE
161 #else
162 #define HWY_TARGET_TOGGLE
163 #endif
164 #endif
165 
166 #if (HWY_TARGETS & HWY_WASM2) && (HWY_STATIC_TARGET != HWY_WASM2)
167 #undef HWY_TARGET
168 #define HWY_TARGET HWY_WASM2
169 #include HWY_TARGET_INCLUDE
170 #ifdef HWY_TARGET_TOGGLE
171 #undef HWY_TARGET_TOGGLE
172 #else
173 #define HWY_TARGET_TOGGLE
174 #endif
175 #endif
176 
177 #if (HWY_TARGETS & HWY_WASM) && (HWY_STATIC_TARGET != HWY_WASM)
178 #undef HWY_TARGET
179 #define HWY_TARGET HWY_WASM
180 #include HWY_TARGET_INCLUDE
181 #ifdef HWY_TARGET_TOGGLE
182 #undef HWY_TARGET_TOGGLE
183 #else
184 #define HWY_TARGET_TOGGLE
185 #endif
186 #endif
187 
188 #if (HWY_TARGETS & HWY_PPC8) && (HWY_STATIC_TARGET != HWY_PPC8)
189 #undef HWY_TARGET
190 #define HWY_TARGET HWY_PPC8
191 #include HWY_TARGET_INCLUDE
192 #ifdef HWY_TARGET_TOGGLE
193 #undef HWY_TARGET_TOGGLE
194 #else
195 #define HWY_TARGET_TOGGLE
196 #endif
197 #endif
198 
199 #endif // !HWY_IDE && (HWY_TARGETS != HWY_STATIC_TARGET)
200 
201 // Now that all but the static target have been generated, re-enable HWY_EXPORT.
202 #undef HWY_ONCE
203 #define HWY_ONCE 1
204 
205 // If we re-include once per enabled target, the translation unit's
206 // implementation would have to be skipped via #if to avoid redefining symbols.
207 // We instead skip the re-include for HWY_STATIC_TARGET, and generate its
208 // implementation when resuming compilation of the translation unit.
209 #undef HWY_TARGET
210 #define HWY_TARGET HWY_STATIC_TARGET
211 
212 #ifdef HWY_ALREADY_INCLUDED
213 // Revert the previous toggle to prevent redefinitions for the static target.
214 #ifdef HWY_TARGET_TOGGLE
215 #undef HWY_TARGET_TOGGLE
216 #else
217 #define HWY_TARGET_TOGGLE
218 #endif
219 
220 // Force re-inclusion of set_macros-inl.h now that HWY_TARGET is restored.
221 #ifdef HWY_SET_MACROS_PER_TARGET
222 #undef HWY_SET_MACROS_PER_TARGET
223 #else
224 #define HWY_SET_MACROS_PER_TARGET
225 #endif
226 #endif
227 
228 #endif // HIGHWAY_HWY_FOREACH_TARGET_H_