Grok 10.0.3
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_EMU128) && (HWY_STATIC_TARGET != HWY_EMU128)
57#undef HWY_TARGET
58#define HWY_TARGET HWY_EMU128
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_SCALAR) && (HWY_STATIC_TARGET != HWY_SCALAR)
68#undef HWY_TARGET
69#define HWY_TARGET HWY_SCALAR
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_NEON) && (HWY_STATIC_TARGET != HWY_NEON)
79#undef HWY_TARGET
80#define HWY_TARGET HWY_NEON
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_RVV) && (HWY_STATIC_TARGET != HWY_RVV)
90#undef HWY_TARGET
91#define HWY_TARGET HWY_RVV
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_SVE) && (HWY_STATIC_TARGET != HWY_SVE)
101#undef HWY_TARGET
102#define HWY_TARGET HWY_SVE
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_SVE2) && (HWY_STATIC_TARGET != HWY_SVE2)
112#undef HWY_TARGET
113#define HWY_TARGET HWY_SVE2
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_SVE_256) && (HWY_STATIC_TARGET != HWY_SVE_256)
123#undef HWY_TARGET
124#define HWY_TARGET HWY_SVE_256
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_SVE2_128) && (HWY_STATIC_TARGET != HWY_SVE2_128)
134#undef HWY_TARGET
135#define HWY_TARGET HWY_SVE2_128
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_SSSE3) && (HWY_STATIC_TARGET != HWY_SSSE3)
145#undef HWY_TARGET
146#define HWY_TARGET HWY_SSSE3
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_SSE4) && (HWY_STATIC_TARGET != HWY_SSE4)
156#undef HWY_TARGET
157#define HWY_TARGET HWY_SSE4
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_AVX2) && (HWY_STATIC_TARGET != HWY_AVX2)
167#undef HWY_TARGET
168#define HWY_TARGET HWY_AVX2
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_AVX3) && (HWY_STATIC_TARGET != HWY_AVX3)
178#undef HWY_TARGET
179#define HWY_TARGET HWY_AVX3
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_AVX3_DL) && (HWY_STATIC_TARGET != HWY_AVX3_DL)
189#undef HWY_TARGET
190#define HWY_TARGET HWY_AVX3_DL
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#if (HWY_TARGETS & HWY_WASM_EMU256) && (HWY_STATIC_TARGET != HWY_WASM_EMU256)
200#undef HWY_TARGET
201#define HWY_TARGET HWY_WASM_EMU256
202#include HWY_TARGET_INCLUDE
203#ifdef HWY_TARGET_TOGGLE
204#undef HWY_TARGET_TOGGLE
205#else
206#define HWY_TARGET_TOGGLE
207#endif
208#endif
209
210#if (HWY_TARGETS & HWY_WASM) && (HWY_STATIC_TARGET != HWY_WASM)
211#undef HWY_TARGET
212#define HWY_TARGET HWY_WASM
213#include HWY_TARGET_INCLUDE
214#ifdef HWY_TARGET_TOGGLE
215#undef HWY_TARGET_TOGGLE
216#else
217#define HWY_TARGET_TOGGLE
218#endif
219#endif
220
221#if (HWY_TARGETS & HWY_PPC8) && (HWY_STATIC_TARGET != HWY_PPC8)
222#undef HWY_TARGET
223#define HWY_TARGET HWY_PPC8
224#include HWY_TARGET_INCLUDE
225#ifdef HWY_TARGET_TOGGLE
226#undef HWY_TARGET_TOGGLE
227#else
228#define HWY_TARGET_TOGGLE
229#endif
230#endif
231
232#endif // !HWY_IDE && (HWY_TARGETS != HWY_STATIC_TARGET)
233
234// Now that all but the static target have been generated, re-enable HWY_EXPORT.
235#undef HWY_ONCE
236#define HWY_ONCE 1
237
238// If we re-include once per enabled target, the translation unit's
239// implementation would have to be skipped via #if to avoid redefining symbols.
240// We instead skip the re-include for HWY_STATIC_TARGET, and generate its
241// implementation when resuming compilation of the translation unit.
242#undef HWY_TARGET
243#define HWY_TARGET HWY_STATIC_TARGET
244
245#ifdef HWY_ALREADY_INCLUDED
246// Revert the previous toggle to prevent redefinitions for the static target.
247#ifdef HWY_TARGET_TOGGLE
248#undef HWY_TARGET_TOGGLE
249#else
250#define HWY_TARGET_TOGGLE
251#endif
252
253// Force re-inclusion of set_macros-inl.h now that HWY_TARGET is restored.
254#ifdef HWY_SET_MACROS_PER_TARGET
255#undef HWY_SET_MACROS_PER_TARGET
256#else
257#define HWY_SET_MACROS_PER_TARGET
258#endif
259#endif
260
261#endif // HIGHWAY_HWY_FOREACH_TARGET_H_