native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
targets.h
1// SPDX-FileCopyrightText: 2026 Edward Kmett <ekmett@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
3#pragma once
4
5// Textual macros only: this header can precede or follow `import native;`.
6// Its expansions require the exported native ISA metadata. Clang is intentional.
7#ifndef __clang__
8#error native source target variants require Clang
9#endif
10
11// Register a custom source name with one literal, for example:
12// #define NATIVE_TARGET_compact "avx2,f16c"
13// The same literal drives compiler attributes, ISA values and admission.
14// Only positive feature names in native's registry are accepted; CPU names and
15// arbitrary C++ aliases cannot be reverse-engineered into compiler attributes.
16// The empty literal gives scalar metadata; its scope below deliberately applies
17// no target attribute. Clang reserves "default" for function multiversioning.
18#define NATIVE_TARGET_scalar ""
19#define NATIVE_TARGET_avx2 "avx2,fma"
20#define NATIVE_TARGET_avx512 "avx2,fma,avx512f,avx512dq,avx512bw,avx512vl"
21#define NATIVE_TARGET_avx512_bf16 "avx2,fma,avx512f,avx512dq,avx512bw,avx512vl,avx512bf16"
22#define NATIVE_TARGET_avx512_fp16 "avx2,fma,avx512f,avx512dq,avx512bw,avx512vl,avx512fp16"
23#define NATIVE_TARGET_neon "neon"
24#define NATIVE_TARGET_neon_fp16 "neon,fullfp16"
25#define NATIVE_TARGET_neon_bf16 "neon,bf16"
26
27#define NATIVE_DETAIL_TARGET_CAT_I(a,b) a##b
28#define NATIVE_DETAIL_TARGET_CAT(a,b) NATIVE_DETAIL_TARGET_CAT_I(a,b)
29#define NATIVE_DETAIL_TARGET_STRING_I(...) #__VA_ARGS__
30#define NATIVE_DETAIL_TARGET_STRING(...) NATIVE_DETAIL_TARGET_STRING_I(__VA_ARGS__)
31#define NATIVE_DETAIL_TARGET_PRAGMA(...) _Pragma(NATIVE_DETAIL_TARGET_STRING(__VA_ARGS__))
32#define NATIVE_TARGET_STRING(name) NATIVE_DETAIL_TARGET_CAT(NATIVE_TARGET_,name)
33#define NATIVE_TARGET_ISA(name) \
34 (::native::detail::source_isa<::native::target_features(NATIVE_TARGET_STRING(name))>)
35
36// The named pragma stack prevents accidentally popping an unrelated user's
37// clang attribute stack. This does not generate preprocessor #include lines.
38// Generate outside other ISA target scopes: Clang combines nested requirements,
39// which predefines cannot observe. Intentional nesting must record the outer
40// requirements in NATIVE_TARGET_EXTRA_MINIMUM for admission.
41#define NATIVE_DETAIL_TARGET_SECOND(a,b,...) b
42#define NATIVE_DETAIL_TARGET_PROBE() unused,1
43#define NATIVE_DETAIL_TARGET_SCALAR_scalar NATIVE_DETAIL_TARGET_PROBE()
44#define NATIVE_DETAIL_TARGET_IS_SCALAR_I(...) NATIVE_DETAIL_TARGET_SECOND(__VA_ARGS__,0)
45#define NATIVE_DETAIL_TARGET_IS_SCALAR(name) \
46 NATIVE_DETAIL_TARGET_IS_SCALAR_I(NATIVE_DETAIL_TARGET_CAT(NATIVE_DETAIL_TARGET_SCALAR_,name))
47#define NATIVE_DETAIL_TARGET_PUSH_0(name) \
48 NATIVE_DETAIL_TARGET_PRAGMA(clang attribute native_source_target.push(__attribute__((target(NATIVE_TARGET_STRING(name)))), apply_to=function))
49#define NATIVE_DETAIL_TARGET_PUSH_1(name) \
50 NATIVE_DETAIL_TARGET_PRAGMA(clang attribute native_source_target.push)
51#define NATIVE_TARGET_PUSH(name) \
52 NATIVE_DETAIL_TARGET_CAT(NATIVE_DETAIL_TARGET_PUSH_,NATIVE_DETAIL_TARGET_IS_SCALAR(name))(name)
53#define NATIVE_TARGET_POP() NATIVE_DETAIL_TARGET_PRAGMA(clang attribute native_source_target.pop)
54
55/*
56Context-aware adaptation of BAD_MAP in
57https://github.com/ekmett/bad/blob/main/include/bad/macros.hh
58Copyright (C) 2012 William Swanson, 2021 Edward Kmett.
59Permission is hereby granted, free of charge, to any person obtaining a copy of
60this software and associated documentation files (the "Software"), to deal in
61the Software without restriction, including without limitation the rights to
62use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
63the Software, and to permit persons to whom the Software is furnished to do so,
64subject to the following conditions:
65The above copyright notice and this permission notice shall be included in all
66copies or substantial portions of the Software.
67THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
71OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
72SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73Except as contained in this notice, the names of the authors or their
74institutions shall not be used in advertising or otherwise to promote the sale,
75use or other dealings in this Software without prior written authorization from
76the authors.
77*/
78// Pattern: [target-list mapping](../README.md#target-list-mapping).
79#define NATIVE_DETAIL_TARGET_EVAL0(...) __VA_ARGS__
80#define NATIVE_DETAIL_TARGET_EVAL1(...) \
81 NATIVE_DETAIL_TARGET_EVAL0(NATIVE_DETAIL_TARGET_EVAL0(NATIVE_DETAIL_TARGET_EVAL0(__VA_ARGS__)))
82#define NATIVE_DETAIL_TARGET_EVAL2(...) \
83 NATIVE_DETAIL_TARGET_EVAL1(NATIVE_DETAIL_TARGET_EVAL1(NATIVE_DETAIL_TARGET_EVAL1(__VA_ARGS__)))
84#define NATIVE_DETAIL_TARGET_EVAL3(...) \
85 NATIVE_DETAIL_TARGET_EVAL2(NATIVE_DETAIL_TARGET_EVAL2(NATIVE_DETAIL_TARGET_EVAL2(__VA_ARGS__)))
86#define NATIVE_DETAIL_TARGET_EVAL4(...) \
87 NATIVE_DETAIL_TARGET_EVAL3(NATIVE_DETAIL_TARGET_EVAL3(NATIVE_DETAIL_TARGET_EVAL3(__VA_ARGS__)))
88#define NATIVE_DETAIL_TARGET_EVAL(...) \
89 NATIVE_DETAIL_TARGET_EVAL4(NATIVE_DETAIL_TARGET_EVAL4(NATIVE_DETAIL_TARGET_EVAL4(__VA_ARGS__)))
90#define NATIVE_DETAIL_TARGET_MAP_END(...)
91#define NATIVE_DETAIL_TARGET_MAP_OUT
92#define NATIVE_DETAIL_TARGET_MAP_GET_END2() 0, NATIVE_DETAIL_TARGET_MAP_END
93#define NATIVE_DETAIL_TARGET_MAP_GET_END1(...) NATIVE_DETAIL_TARGET_MAP_GET_END2
94#define NATIVE_DETAIL_TARGET_MAP_GET_END(...) NATIVE_DETAIL_TARGET_MAP_GET_END1
95#define NATIVE_DETAIL_TARGET_MAP_NEXT0(test, next, ...) next NATIVE_DETAIL_TARGET_MAP_OUT
96#define NATIVE_DETAIL_TARGET_MAP_NEXT1(test, next) NATIVE_DETAIL_TARGET_MAP_NEXT0(test, next, 0)
97#define NATIVE_DETAIL_TARGET_MAP_NEXT(test, next) NATIVE_DETAIL_TARGET_MAP_NEXT1(NATIVE_DETAIL_TARGET_MAP_GET_END test, next)
98#define NATIVE_DETAIL_TARGET_MAP0(f, c, x, peek, ...) \
99 f(c, x) \
100 NATIVE_DETAIL_TARGET_MAP_NEXT(peek, NATIVE_DETAIL_TARGET_MAP1)(f, c, peek, __VA_ARGS__)
101
102#define NATIVE_DETAIL_TARGET_MAP1(f, c, x, peek, ...) \
103 f(c, x) \
104 NATIVE_DETAIL_TARGET_MAP_NEXT(peek, NATIVE_DETAIL_TARGET_MAP0)(f, c, peek, __VA_ARGS__)
105
106#define NATIVE_DETAIL_TARGET_MAP(f, c, ...) \
107 __VA_OPT__(NATIVE_DETAIL_TARGET_EVAL( \
108 NATIVE_DETAIL_TARGET_MAP1(f, c, __VA_ARGS__, ()()(), ()()(), ()()(), 0)))
109
110#define NATIVE_DETAIL_TARGET_UNPACK(...) __VA_ARGS__
111#define NATIVE_DETAIL_TARGET_ISA_ARG(unused,tag) ,NATIVE_TARGET_ISA(tag)
112
113// A list is a comma-separated sequence of registered target names:
114// #define targets avx512,avx2
115// body(name,ISA,...) receives the selected ISA followed by the full ISA pack.
116// Use target<A,__VA_ARGS__> == target<ISA,__VA_ARGS__> for disjoint overloads.
117// Keep local register types and instruction requirements within ISA, even when
118// A carries more features. Definitions need normal C++ ODR rules.
119// Expand the complete choice pack before mapping bodies, keeping the two uses
120// of the mapper separate during preprocessor rescanning.
121#define NATIVE_TARGET_VARIANTS(name,body,...) NATIVE_DETAIL_TARGET_VARIANTS(name,body,__VA_ARGS__)
122#define NATIVE_DETAIL_TARGET_VARIANTS(name,body,...) \
123 NATIVE_DETAIL_TARGET_EMIT_ALL(name,body, \
124 (NATIVE_DETAIL_TARGET_MAP(NATIVE_DETAIL_TARGET_ISA_ARG,unused,__VA_ARGS__)),__VA_ARGS__)
125#define NATIVE_DETAIL_TARGET_EMIT_ALL(name,body,choices,...) \
126 NATIVE_DETAIL_TARGET_MAP(NATIVE_DETAIL_TARGET_EMIT,(name,body,choices),__VA_ARGS__)
127#define NATIVE_DETAIL_TARGET_EMIT(context,tag) \
128 NATIVE_DETAIL_TARGET_EMIT_EXPAND(tag,NATIVE_DETAIL_TARGET_UNPACK context)
129#define NATIVE_DETAIL_TARGET_EMIT_EXPAND(...) NATIVE_DETAIL_TARGET_EMIT_IMPL(__VA_ARGS__)
130#define NATIVE_DETAIL_TARGET_EMIT_IMPL(tag,name,body,choices) \
131 NATIVE_TARGET_PUSH(tag) \
132 NATIVE_DETAIL_TARGET_EMIT_BODY(body,name,NATIVE_TARGET_ISA(tag) NATIVE_DETAIL_TARGET_UNPACK choices) \
133 NATIVE_TARGET_POP()
134#define NATIVE_DETAIL_TARGET_EMIT_BODY(body,...) body(__VA_ARGS__)
135
136// Snapshot inherited translation-unit features separately from the requested
137// ISA value. A target attribute adds features; it does not erase the project
138// minimum. An unregistered stronger minimum is rejected instead of under-admitted.
139#ifdef __MMX__
140#define NATIVE_DETAIL_MIN_MMX (::native::isa<>(::native::x86_feature::mmx))
141#else
142#define NATIVE_DETAIL_MIN_MMX (::native::isa<>{})
143#endif
144#ifdef __SSE__
145#define NATIVE_DETAIL_MIN_SSE (::native::isa<>(::native::x86_feature::sse))
146#else
147#define NATIVE_DETAIL_MIN_SSE (::native::isa<>{})
148#endif
149#ifdef __SSE2__
150#define NATIVE_DETAIL_MIN_SSE2 (::native::isa<>(::native::x86_feature::sse2))
151#else
152#define NATIVE_DETAIL_MIN_SSE2 (::native::isa<>{})
153#endif
154#ifdef __SSE3__
155#define NATIVE_DETAIL_MIN_SSE3 (::native::isa<>(::native::x86_feature::sse3))
156#else
157#define NATIVE_DETAIL_MIN_SSE3 (::native::isa<>{})
158#endif
159#ifdef __SSSE3__
160#define NATIVE_DETAIL_MIN_SSSE3 (::native::isa<>(::native::x86_feature::ssse3))
161#else
162#define NATIVE_DETAIL_MIN_SSSE3 (::native::isa<>{})
163#endif
164#ifdef __SSE4_1__
165#define NATIVE_DETAIL_MIN_SSE41 (::native::isa<>(::native::x86_feature::sse41))
166#else
167#define NATIVE_DETAIL_MIN_SSE41 (::native::isa<>{})
168#endif
169#ifdef __SSE4_2__
170#define NATIVE_DETAIL_MIN_SSE42 (::native::isa<>(::native::x86_feature::sse42))
171#else
172#define NATIVE_DETAIL_MIN_SSE42 (::native::isa<>{})
173#endif
174#ifdef __POPCNT__
175#define NATIVE_DETAIL_MIN_POPCNT (::native::isa<>(::native::x86_feature::popcnt))
176#else
177#define NATIVE_DETAIL_MIN_POPCNT (::native::isa<>{})
178#endif
179#ifdef __AVX__
180#define NATIVE_DETAIL_MIN_AVX (::native::isa<>(::native::x86_feature::avx))
181#else
182#define NATIVE_DETAIL_MIN_AVX (::native::isa<>{})
183#endif
184#ifdef __AVX2__
185#define NATIVE_DETAIL_MIN_AVX2 (::native::isa<>(::native::x86_feature::avx2))
186#else
187#define NATIVE_DETAIL_MIN_AVX2 (::native::isa<>{})
188#endif
189#ifdef __FMA__
190#define NATIVE_DETAIL_MIN_FMA (::native::isa<>(::native::x86_feature::fma))
191#else
192#define NATIVE_DETAIL_MIN_FMA (::native::isa<>{})
193#endif
194#ifdef __F16C__
195#define NATIVE_DETAIL_MIN_F16C (::native::isa<>(::native::x86_feature::f16c))
196#else
197#define NATIVE_DETAIL_MIN_F16C (::native::isa<>{})
198#endif
199#ifdef __BMI__
200#define NATIVE_DETAIL_MIN_BMI1 (::native::isa<>(::native::x86_feature::bmi1))
201#else
202#define NATIVE_DETAIL_MIN_BMI1 (::native::isa<>{})
203#endif
204#ifdef __BMI2__
205#define NATIVE_DETAIL_MIN_BMI2 (::native::isa<>(::native::x86_feature::bmi2))
206#else
207#define NATIVE_DETAIL_MIN_BMI2 (::native::isa<>{})
208#endif
209#ifdef __AVX512F__
210#define NATIVE_DETAIL_MIN_AVX512F (::native::isa<>(::native::x86_feature::avx512f))
211#else
212#define NATIVE_DETAIL_MIN_AVX512F (::native::isa<>{})
213#endif
214#ifdef __AVX512DQ__
215#define NATIVE_DETAIL_MIN_AVX512DQ (::native::isa<>(::native::x86_feature::avx512dq))
216#else
217#define NATIVE_DETAIL_MIN_AVX512DQ (::native::isa<>{})
218#endif
219#ifdef __AVX512BW__
220#define NATIVE_DETAIL_MIN_AVX512BW (::native::isa<>(::native::x86_feature::avx512bw))
221#else
222#define NATIVE_DETAIL_MIN_AVX512BW (::native::isa<>{})
223#endif
224#ifdef __AVX512VL__
225#define NATIVE_DETAIL_MIN_AVX512VL (::native::isa<>(::native::x86_feature::avx512vl))
226#else
227#define NATIVE_DETAIL_MIN_AVX512VL (::native::isa<>{})
228#endif
229#ifdef __AVX512BF16__
230#define NATIVE_DETAIL_MIN_AVX512BF16 (::native::isa<>(::native::x86_feature::avx512bf16))
231#else
232#define NATIVE_DETAIL_MIN_AVX512BF16 (::native::isa<>{})
233#endif
234#ifdef __AVX512FP16__
235#define NATIVE_DETAIL_MIN_AVX512FP16 (::native::isa<>(::native::x86_feature::avx512fp16))
236#else
237#define NATIVE_DETAIL_MIN_AVX512FP16 (::native::isa<>{})
238#endif
239#ifdef __AVX512VBMI__
240#define NATIVE_DETAIL_MIN_AVX512VBMI (::native::isa<>(::native::x86_feature::avx512vbmi))
241#else
242#define NATIVE_DETAIL_MIN_AVX512VBMI (::native::isa<>{})
243#endif
244#ifdef __AVX512VBMI2__
245#define NATIVE_DETAIL_MIN_AVX512VBMI2 (::native::isa<>(::native::x86_feature::avx512vbmi2))
246#else
247#define NATIVE_DETAIL_MIN_AVX512VBMI2 (::native::isa<>{})
248#endif
249#ifdef __AVX512BITALG__
250#define NATIVE_DETAIL_MIN_AVX512BITALG (::native::isa<>(::native::x86_feature::avx512bitalg))
251#else
252#define NATIVE_DETAIL_MIN_AVX512BITALG (::native::isa<>{})
253#endif
254#ifdef __AVX512VPOPCNTDQ__
255#define NATIVE_DETAIL_MIN_AVX512VPOPCNTDQ (::native::isa<>(::native::x86_feature::avx512vpopcntdq))
256#else
257#define NATIVE_DETAIL_MIN_AVX512VPOPCNTDQ (::native::isa<>{})
258#endif
259#ifdef __AVXVNNI__
260#define NATIVE_DETAIL_MIN_AVXVNNI (::native::isa<>(::native::x86_feature::avxvnni))
261#else
262#define NATIVE_DETAIL_MIN_AVXVNNI (::native::isa<>{})
263#endif
264#ifdef __AVX512VNNI__
265#define NATIVE_DETAIL_MIN_AVX512VNNI (::native::isa<>(::native::x86_feature::avx512vnni))
266#else
267#define NATIVE_DETAIL_MIN_AVX512VNNI (::native::isa<>{})
268#endif
269#ifdef __AVXVNNIINT8__
270#define NATIVE_DETAIL_MIN_AVXVNNIINT8 (::native::isa<>(::native::x86_feature::avxvnniint8))
271#else
272#define NATIVE_DETAIL_MIN_AVXVNNIINT8 (::native::isa<>{})
273#endif
274#ifdef __AVXVNNIINT16__
275#define NATIVE_DETAIL_MIN_AVXVNNIINT16 (::native::isa<>(::native::x86_feature::avxvnniint16))
276#else
277#define NATIVE_DETAIL_MIN_AVXVNNIINT16 (::native::isa<>{})
278#endif
279#ifdef __ARM_NEON
280#define NATIVE_DETAIL_MIN_NEON (::native::isa<>(::native::arm_feature::neon))
281#else
282#define NATIVE_DETAIL_MIN_NEON (::native::isa<>{})
283#endif
284#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) || defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC)
285#define NATIVE_DETAIL_MIN_NEON_FP16 (::native::isa<>(::native::arm_feature::neon_fp16))
286#else
287#define NATIVE_DETAIL_MIN_NEON_FP16 (::native::isa<>{})
288#endif
289#ifdef __ARM_FEATURE_BF16_VECTOR_ARITHMETIC
290#define NATIVE_DETAIL_MIN_NEON_BF16 (::native::isa<>(::native::arm_feature::neon_bf16))
291#else
292#define NATIVE_DETAIL_MIN_NEON_BF16 (::native::isa<>{})
293#endif
294#ifdef __AVXIFMA__
295#define NATIVE_DETAIL_MIN_AVXIFMA (::native::isa<>(::native::x86_feature::avxifma))
296#else
297#define NATIVE_DETAIL_MIN_AVXIFMA (::native::isa<>{})
298#endif
299#ifdef __SHA512__
300#define NATIVE_DETAIL_MIN_X86_SHA512 (::native::isa<>(::native::x86_feature::sha512))
301#else
302#define NATIVE_DETAIL_MIN_X86_SHA512 (::native::isa<>{})
303#endif
304#ifdef __SM3__
305#define NATIVE_DETAIL_MIN_X86_SM3 (::native::isa<>(::native::x86_feature::sm3))
306#else
307#define NATIVE_DETAIL_MIN_X86_SM3 (::native::isa<>{})
308#endif
309#ifdef __SM4__
310#define NATIVE_DETAIL_MIN_X86_SM4 (::native::isa<>(::native::x86_feature::sm4))
311#else
312#define NATIVE_DETAIL_MIN_X86_SM4 (::native::isa<>{})
313#endif
314#ifdef __AVXNECONVERT__
315#define NATIVE_DETAIL_MIN_X86_AVXNECONVERT (::native::isa<>(::native::x86_feature::avxneconvert))
316#else
317#define NATIVE_DETAIL_MIN_X86_AVXNECONVERT (::native::isa<>{})
318#endif
319#ifdef __ADX__
320#define NATIVE_DETAIL_MIN_ADX (::native::isa<>(::native::x86_feature::adx))
321#else
322#define NATIVE_DETAIL_MIN_ADX (::native::isa<>{})
323#endif
324#ifdef __SHA__
325#define NATIVE_DETAIL_MIN_SHA (::native::isa<>(::native::x86_feature::sha))
326#else
327#define NATIVE_DETAIL_MIN_SHA (::native::isa<>{})
328#endif
329#ifdef __VAES__
330#define NATIVE_DETAIL_MIN_VAES (::native::isa<>(::native::x86_feature::vaes))
331#else
332#define NATIVE_DETAIL_MIN_VAES (::native::isa<>{})
333#endif
334#ifdef __AES__
335#define NATIVE_DETAIL_MIN_AES (::native::isa<>(::native::x86_feature::aes))
336#else
337#define NATIVE_DETAIL_MIN_AES (::native::isa<>{})
338#endif
339#ifdef __VPCLMULQDQ__
340#define NATIVE_DETAIL_MIN_VPCLMULQDQ (::native::isa<>(::native::x86_feature::vpclmulqdq))
341#else
342#define NATIVE_DETAIL_MIN_VPCLMULQDQ (::native::isa<>{})
343#endif
344#ifdef __PCLMUL__
345#define NATIVE_DETAIL_MIN_PCLMUL (::native::isa<>(::native::x86_feature::pclmul))
346#else
347#define NATIVE_DETAIL_MIN_PCLMUL (::native::isa<>{})
348#endif
349#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) && (defined(__x86_64__) || defined(_M_X64))
350#define NATIVE_DETAIL_MIN_CX16 (::native::isa<>(::native::x86_feature::cx16))
351#else
352#define NATIVE_DETAIL_MIN_CX16 (::native::isa<>{})
353#endif
354#ifdef __AVX512CD__
355#define NATIVE_DETAIL_MIN_AVX512CD (::native::isa<>(::native::x86_feature::avx512cd))
356#else
357#define NATIVE_DETAIL_MIN_AVX512CD (::native::isa<>{})
358#endif
359#ifdef __AVX512IFMA__
360#define NATIVE_DETAIL_MIN_AVX512IFMA (::native::isa<>(::native::x86_feature::avx512ifma))
361#else
362#define NATIVE_DETAIL_MIN_AVX512IFMA (::native::isa<>{})
363#endif
364
365#ifdef __LZCNT__
366#define NATIVE_DETAIL_MIN_LZCNT (::native::isa<>(::native::x86_feature::lzcnt))
367#else
368#define NATIVE_DETAIL_MIN_LZCNT (::native::isa<>{})
369#endif
370#ifdef __MOVBE__
371#define NATIVE_DETAIL_MIN_MOVBE (::native::isa<>(::native::x86_feature::movbe))
372#else
373#define NATIVE_DETAIL_MIN_MOVBE (::native::isa<>{})
374#endif
375#ifdef __LAHF_SAHF__
376#define NATIVE_DETAIL_MIN_SAHF (::native::isa<>(::native::x86_feature::sahf))
377#else
378#define NATIVE_DETAIL_MIN_SAHF (::native::isa<>{})
379#endif
380#ifdef __MWAITX__
381#define NATIVE_DETAIL_MIN_MWAITX (::native::isa<>(::native::x86_feature::mwaitx))
382#else
383#define NATIVE_DETAIL_MIN_MWAITX (::native::isa<>{})
384#endif
385#ifdef __WAITPKG__
386#define NATIVE_DETAIL_MIN_WAITPKG (::native::isa<>(::native::x86_feature::waitpkg))
387#else
388#define NATIVE_DETAIL_MIN_WAITPKG (::native::isa<>{})
389#endif
390#ifdef __CRC32__
391#define NATIVE_DETAIL_MIN_CRC32 (::native::isa<>(::native::x86_feature::crc32))
392#else
393#define NATIVE_DETAIL_MIN_CRC32 (::native::isa<>{})
394#endif
395#ifdef __GFNI__
396#define NATIVE_DETAIL_MIN_GFNI (::native::isa<>(::native::x86_feature::gfni))
397#else
398#define NATIVE_DETAIL_MIN_GFNI (::native::isa<>{})
399#endif
400#ifdef __ARM_FEATURE_AES
401#define NATIVE_DETAIL_MIN_ARM_AES (::native::arm_feature::aes&::native::arm_feature::pmull)
402#else
403#define NATIVE_DETAIL_MIN_ARM_AES (::native::isa<>{})
404#endif
405#ifdef __ARM_FEATURE_SHA2
406#define NATIVE_DETAIL_MIN_ARM_SHA2 (::native::arm_feature::sha1&::native::arm_feature::sha2)
407#else
408#define NATIVE_DETAIL_MIN_ARM_SHA2 (::native::isa<>{})
409#endif
410#ifdef __ARM_FEATURE_SHA3
411#define NATIVE_DETAIL_MIN_ARM_SHA3 (::native::isa<>(::native::arm_feature::sha3))
412#else
413#define NATIVE_DETAIL_MIN_ARM_SHA3 (::native::isa<>{})
414#endif
415#ifdef __ARM_FEATURE_SHA512
416#define NATIVE_DETAIL_MIN_ARM_SHA512 (::native::arm_feature::sha1&::native::arm_feature::sha2&::native::arm_feature::sha512)
417#else
418#define NATIVE_DETAIL_MIN_ARM_SHA512 (::native::isa<>{})
419#endif
420#ifdef __ARM_FEATURE_SM3
421#define NATIVE_DETAIL_MIN_ARM_SM3 (::native::isa<>(::native::arm_feature::sm3))
422#else
423#define NATIVE_DETAIL_MIN_ARM_SM3 (::native::isa<>{})
424#endif
425#ifdef __ARM_FEATURE_SM4
426#define NATIVE_DETAIL_MIN_ARM_SM4 (::native::isa<>(::native::arm_feature::sm4))
427#else
428#define NATIVE_DETAIL_MIN_ARM_SM4 (::native::isa<>{})
429#endif
430#ifdef __ARM_FEATURE_CRC32
431#define NATIVE_DETAIL_MIN_ARM_CRC (::native::isa<>(::native::arm_feature::crc))
432#else
433#define NATIVE_DETAIL_MIN_ARM_CRC (::native::isa<>{})
434#endif
435#ifdef __ARM_FEATURE_ATOMICS
436#define NATIVE_DETAIL_MIN_ARM_LSE (::native::isa<>(::native::arm_feature::lse))
437#else
438#define NATIVE_DETAIL_MIN_ARM_LSE (::native::isa<>{})
439#endif
440#ifdef __ARM_FEATURE_QRDMX
441#define NATIVE_DETAIL_MIN_ARM_RDM (::native::isa<>(::native::arm_feature::rdm))
442#else
443#define NATIVE_DETAIL_MIN_ARM_RDM (::native::isa<>{})
444#endif
445#ifdef __ARM_FEATURE_FP16_FML
446#define NATIVE_DETAIL_MIN_ARM_FP16FML (::native::isa<>(::native::arm_feature::fp16fml))
447#else
448#define NATIVE_DETAIL_MIN_ARM_FP16FML (::native::isa<>{})
449#endif
450#ifdef __ARM_FEATURE_DOTPROD
451#define NATIVE_DETAIL_MIN_ARM_DOTPROD (::native::isa<>(::native::arm_feature::dotprod))
452#else
453#define NATIVE_DETAIL_MIN_ARM_DOTPROD (::native::isa<>{})
454#endif
455#ifdef __ARM_FEATURE_COMPLEX
456#define NATIVE_DETAIL_MIN_ARM_COMPLEX (::native::isa<>(::native::arm_feature::complxnum))
457#else
458#define NATIVE_DETAIL_MIN_ARM_COMPLEX (::native::isa<>{})
459#endif
460#ifdef __ARM_FEATURE_JCVT
461#define NATIVE_DETAIL_MIN_ARM_JSCVT (::native::isa<>(::native::arm_feature::jsconv))
462#else
463#define NATIVE_DETAIL_MIN_ARM_JSCVT (::native::isa<>{})
464#endif
465#ifdef __ARM_FEATURE_RCPC
466#define NATIVE_DETAIL_MIN_ARM_RCPC (::native::isa<>(::native::arm_feature::rcpc))
467#else
468#define NATIVE_DETAIL_MIN_ARM_RCPC (::native::isa<>{})
469#endif
470#ifdef __ARM_FEATURE_MATMUL_INT8
471#define NATIVE_DETAIL_MIN_ARM_I8MM (::native::isa<>(::native::arm_feature::i8mm))
472#else
473#define NATIVE_DETAIL_MIN_ARM_I8MM (::native::isa<>{})
474#endif
475#ifdef __ARM_FEATURE_PAUTH
476#define NATIVE_DETAIL_MIN_ARM_PAUTH (::native::isa<>(::native::arm_feature::pauth))
477#else
478#define NATIVE_DETAIL_MIN_ARM_PAUTH (::native::isa<>{})
479#endif
480
481#ifdef __wasm_simd128__
482#define NATIVE_DETAIL_MIN_WASM_SIMD128 (::native::isa<>(::native::wasm_feature::simd128))
483#else
484#define NATIVE_DETAIL_MIN_WASM_SIMD128 (::native::isa<>{})
485#endif
486#ifdef __wasm_relaxed_simd__
487#define NATIVE_DETAIL_MIN_WASM_RELAXED_SIMD (::native::isa<>(::native::wasm_feature::relaxed_simd))
488#else
489#define NATIVE_DETAIL_MIN_WASM_RELAXED_SIMD (::native::isa<>{})
490#endif
491
492#if defined(__SSE4A__) || defined(__XOP__) || defined(__FMA4__) || \
493 defined(__AVX512VP2INTERSECT__) || \
494 defined(__AMX_TILE__) || defined(__AMX_INT8__) || defined(__AMX_BF16__) || \
495 defined(__ARM_FEATURE_SVE) || defined(__ARM_FEATURE_SME)
496#define NATIVE_DETAIL_MIN_UNREGISTERED (::native::target_features("unregistered"))
497#else
498#define NATIVE_DETAIL_MIN_UNREGISTERED (::native::isa<>{})
499#endif
500
501// Optional additional project contract. This is an ISA value/expression (for
502// example ::native::target_features("avx2,f16c")), never a CPU-name guess. The ordinary
503// executable's minimum remains a startup precondition: the selector itself must
504// already be safe to run. Compiler CPU models can enable features not represented
505// by predefines; this macro is not an inference engine for arbitrary -mcpu flags.
506#ifndef NATIVE_TARGET_EXTRA_MINIMUM
507#define NATIVE_TARGET_EXTRA_MINIMUM (::native::isa<>{})
508#endif
509// The current translation unit's known enabled instruction features. Clang has
510// already resolved command-line implications and explicit negative flags. Do not
511// apply feature_closure here: it could re-enable a deliberately disabled feature.
512// This textual expression belongs to the consumer, not a precompiled module.
513// Function target attributes and target pragmas do not change this snapshot.
514#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
515#define NATIVE_DETAIL_BASELINE_NEON_FP16 (::native::isa<>(::native::arm_feature::neon_fp16))
516#else
517#define NATIVE_DETAIL_BASELINE_NEON_FP16 (::native::isa<>{})
518#endif
519// Some architecture-version macros survive -mgeneral-regs-only. SIMD
520// operations are available only when the vector register target is enabled.
521#define NATIVE_DETAIL_MIN_ARM_SIMD_EXTRAS (NATIVE_DETAIL_MIN_NEON_BF16& \
522 NATIVE_DETAIL_MIN_ARM_AES&NATIVE_DETAIL_MIN_ARM_SHA2&NATIVE_DETAIL_MIN_ARM_SHA3&NATIVE_DETAIL_MIN_ARM_SHA512& \
523 NATIVE_DETAIL_MIN_ARM_SM3&NATIVE_DETAIL_MIN_ARM_SM4& \
524 NATIVE_DETAIL_MIN_ARM_RDM&NATIVE_DETAIL_MIN_ARM_FP16FML&NATIVE_DETAIL_MIN_ARM_DOTPROD& \
525 NATIVE_DETAIL_MIN_ARM_COMPLEX&NATIVE_DETAIL_MIN_ARM_I8MM)
526#ifdef __ARM_NEON
527#define NATIVE_DETAIL_BASELINE_ARM_SIMD_EXTRAS NATIVE_DETAIL_MIN_ARM_SIMD_EXTRAS
528#else
529#define NATIVE_DETAIL_BASELINE_ARM_SIMD_EXTRAS (::native::isa<>{})
530#endif
531#if defined(__ARM_FP) && (__ARM_FP & 8)
532#define NATIVE_DETAIL_BASELINE_ARM_JSCVT NATIVE_DETAIL_MIN_ARM_JSCVT
533#else
534#define NATIVE_DETAIL_BASELINE_ARM_JSCVT (::native::isa<>{})
535#endif
536#define NATIVE_BASELINE (\
537 NATIVE_DETAIL_MIN_MMX&NATIVE_DETAIL_MIN_SSE&NATIVE_DETAIL_MIN_SSE2&NATIVE_DETAIL_MIN_SSE3& \
538 NATIVE_DETAIL_MIN_SSSE3&NATIVE_DETAIL_MIN_SSE41&NATIVE_DETAIL_MIN_SSE42&NATIVE_DETAIL_MIN_POPCNT& \
539 NATIVE_DETAIL_MIN_AVX&NATIVE_DETAIL_MIN_AVX2&NATIVE_DETAIL_MIN_FMA&NATIVE_DETAIL_MIN_F16C& \
540 NATIVE_DETAIL_MIN_BMI1&NATIVE_DETAIL_MIN_BMI2&NATIVE_DETAIL_MIN_AVX512F&NATIVE_DETAIL_MIN_AVX512DQ& \
541 NATIVE_DETAIL_MIN_AVX512BW&NATIVE_DETAIL_MIN_AVX512VL&NATIVE_DETAIL_MIN_AVX512BF16&NATIVE_DETAIL_MIN_AVX512FP16& \
542 NATIVE_DETAIL_MIN_AVX512VBMI&NATIVE_DETAIL_MIN_AVX512VBMI2& \
543 NATIVE_DETAIL_MIN_AVX512BITALG&NATIVE_DETAIL_MIN_AVX512VPOPCNTDQ& \
544 NATIVE_DETAIL_MIN_AVXVNNI&NATIVE_DETAIL_MIN_AVX512VNNI&NATIVE_DETAIL_MIN_AVXVNNIINT8&NATIVE_DETAIL_MIN_AVXVNNIINT16& \
545 NATIVE_DETAIL_MIN_NEON&NATIVE_DETAIL_BASELINE_NEON_FP16&NATIVE_DETAIL_BASELINE_ARM_SIMD_EXTRAS& \
546 NATIVE_DETAIL_MIN_AES&NATIVE_DETAIL_MIN_SHA&NATIVE_DETAIL_MIN_VAES&NATIVE_DETAIL_MIN_AVXIFMA&NATIVE_DETAIL_MIN_ADX&NATIVE_DETAIL_MIN_X86_SHA512&NATIVE_DETAIL_MIN_X86_SM3&NATIVE_DETAIL_MIN_X86_SM4&NATIVE_DETAIL_MIN_X86_AVXNECONVERT&NATIVE_DETAIL_MIN_PCLMUL&NATIVE_DETAIL_MIN_VPCLMULQDQ&NATIVE_DETAIL_MIN_CX16&NATIVE_DETAIL_MIN_AVX512CD& \
547 NATIVE_DETAIL_MIN_AVX512IFMA&NATIVE_DETAIL_MIN_LZCNT&NATIVE_DETAIL_MIN_MOVBE&NATIVE_DETAIL_MIN_SAHF& \
548 NATIVE_DETAIL_MIN_MWAITX&NATIVE_DETAIL_MIN_WAITPKG&NATIVE_DETAIL_MIN_CRC32&NATIVE_DETAIL_MIN_GFNI& \
549 NATIVE_DETAIL_MIN_ARM_CRC&NATIVE_DETAIL_MIN_ARM_LSE&NATIVE_DETAIL_BASELINE_ARM_JSCVT& \
550 NATIVE_DETAIL_MIN_ARM_RCPC&NATIVE_DETAIL_MIN_ARM_PAUTH& \
551 NATIVE_DETAIL_MIN_WASM_SIMD128&NATIVE_DETAIL_MIN_WASM_RELAXED_SIMD)
552
553// Source-variant admission retains its conservative inherited minimum and any
554// additional deployment requirements, separately from the exact known baseline.
555#define NATIVE_TARGET_MINIMUM (::native::feature_closure(NATIVE_TARGET_EXTRA_MINIMUM& \
556 NATIVE_BASELINE&NATIVE_DETAIL_MIN_NEON_FP16&NATIVE_DETAIL_MIN_ARM_SIMD_EXTRAS& \
557 NATIVE_DETAIL_MIN_ARM_JSCVT&NATIVE_DETAIL_MIN_UNREGISTERED))
558
559// Admission follows the same order as the compile-time choice pack.
560#define NATIVE_DETAIL_TARGET_LIST(unused,tag) \
561 +::native::isa_list<::native::target_entry{NATIVE_TARGET_ISA(tag),NATIVE_TARGET_MINIMUM}>{}
562#define NATIVE_TARGET_LIST(...) \
563 (::native::isa_list<>{} NATIVE_DETAIL_TARGET_MAP(NATIVE_DETAIL_TARGET_LIST,unused,__VA_ARGS__))