native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
isa.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#include "native/config.h"
5#include <array>
6#include <concepts>
7#include <cstddef>
8#include <cstdint>
9#include <string_view>
10#include <type_traits>
11#include <utility>
12
13namespace native {
15 enum class x86_feature : std::uint64_t {
16 mmx, sse, sse2, sse3, ssse3, sse41,
17 sse42, popcnt, avx, avx2, fma, f16c,
18 bmi1, bmi2, avx512f, avx512dq, avx512bw, avx512vl,
19 avx512bf16, avx512fp16, aes, pclmul, cx16, avx512cd,
20 avx512ifma, lzcnt, movbe, sahf, mwaitx, waitpkg, crc32, gfni, avx512vpopcntdq,
21 vpclmulqdq, avxvnni, avx512vnni, avxvnniint8, avxvnniint16, avx512bitalg, avx512vbmi, avx512vbmi2, sha, vaes, avxifma, adx, sha512, sm3, sm4, avxneconvert
22 };
23
24 enum class arm_feature : std::uint64_t {
25 neon, neon_fp16, neon_bf16, aes, sha2, sha3,
26 crc, lse, rdm, fp16fml, dotprod, complxnum,
27 jsconv, rcpc, pauth, i8mm, pmull, sha1, sha512, ebf16, sm3, sm4
28 };
29
30 enum class wasm_feature : std::uint64_t { simd128, relaxed_simd };
32 inline constexpr std::size_t wasm_feature_count=std::size_t(wasm_feature::relaxed_simd)+1;
34 inline constexpr std::size_t x86_feature_count=std::size_t(x86_feature::avxneconvert)+1;
36 inline constexpr std::size_t arm_feature_count=std::size_t(arm_feature::sm4)+1;
37
40 struct polyfill_t {};
43 inline constexpr polyfill_t polyfill{};
44
46 template<architecture Family=target_arch> struct isa;
47
48 namespace detail {
49 template<class T> concept instruction_feature=
50 std::same_as<T,x86_feature> || std::same_as<T,arm_feature> || std::same_as<T,wasm_feature>;
51 template<instruction_feature E> inline constexpr std::size_t feature_count=
52 std::same_as<E,x86_feature> ? x86_feature_count :
53 std::same_as<E,arm_feature> ? arm_feature_count : wasm_feature_count;
54 template<instruction_feature E> inline constexpr architecture family_of=
55 std::same_as<E,x86_feature> ? x86 : std::same_as<E,arm_feature> ? arm : wasm;
56 template<architecture Family> struct feature_traits;
57 template<> struct feature_traits<x86> { using type=x86_feature; static constexpr auto count=x86_feature_count; };
58 template<> struct feature_traits<arm> { using type=arm_feature; static constexpr auto count=arm_feature_count; };
59 template<> struct feature_traits<wasm> { using type=wasm_feature; static constexpr auto count=wasm_feature_count; };
60 enum class unknown_feature : std::uint64_t {};
61 template<> struct feature_traits<architecture::unknown> { using type=unknown_feature; static constexpr std::size_t count=0; };
62 }
63
65 template<architecture Family> struct isa {
67 using feature_type=typename detail::feature_traits<Family>::type;
69 static constexpr architecture family=Family;
71 static constexpr auto feature_count=detail::feature_traits<Family>::count;
73 std::array<std::uint64_t,(feature_count+1+63)/64> flags{};
75 bool allow_polyfill=false;
77 constexpr isa(polyfill_t) noexcept : allow_polyfill(true) {}
79 constexpr bool has(polyfill_t) const noexcept { return allow_polyfill; }
81 constexpr isa() noexcept=default;
83 constexpr isa(feature_type f) noexcept { set(f,true); }
85 constexpr bool get(feature_type f) const noexcept {
86 auto i=std::uint64_t(f);
87 return i<feature_count && ((flags[i/64]>>(i%64))&1);
88 }
89
91 constexpr void set(feature_type f,bool value) noexcept {
92 auto i=std::uint64_t(f);
93 if(i>=feature_count) {
94 if(!value) return;
96 }
97 auto mask=std::uint64_t{1}<<(i%64);
98 auto & word=flags[i/64];
99 word=(word&~mask)|(value?mask:0);
100 }
101
102 constexpr bool has(feature_type f) const noexcept { return get(f); }
105 constexpr bool has(isa other) const noexcept {
106 for(std::size_t i=0;i<flags.size();++i)
107 if((flags[i]&other.flags[i])!=other.flags[i]) return false;
108 return true;
109 }
110
111 constexpr bool valid() const noexcept {
112 constexpr auto used=feature_count%64;
113 constexpr auto mask=used ? (std::uint64_t{1}<<used)-1 : 0;
114 return (flags.back()&~mask)==0;
115 }
116
117 constexpr bool operator==(isa const &) const=default;
118 };
119
121 template<> struct isa<x86> {
123 using feature_type=typename detail::feature_traits<x86>::type;
125 static constexpr architecture family=x86;
127 static constexpr auto feature_count=detail::feature_traits<x86>::count;
129 std::array<std::uint64_t,(feature_count+1+63)/64> flags{};
131 bool allow_polyfill=false;
133 constexpr isa(polyfill_t) noexcept : allow_polyfill(true) {}
135 constexpr bool has(polyfill_t) const noexcept { return allow_polyfill; }
137 constexpr isa() noexcept=default;
139 constexpr isa(feature_type f) noexcept { set(f,true); }
141 constexpr bool get(feature_type f) const noexcept {
142 auto i=std::uint64_t(f);
143 return i<feature_count && ((flags[i/64]>>(i%64))&1);
144 }
145
147 constexpr void set(feature_type f,bool value) noexcept {
148 auto i=std::uint64_t(f);
149 if(i>=feature_count) {
150 if(!value) return;
152 }
153 auto mask=std::uint64_t{1}<<(i%64);
154 auto & word=flags[i/64];
155 word=(word&~mask)|(value?mask:0);
156 }
157
158 constexpr bool has(feature_type f) const noexcept { return get(f); }
161 constexpr bool has(isa other) const noexcept {
162 for(std::size_t i=0;i<flags.size();++i)
163 if((flags[i]&other.flags[i])!=other.flags[i]) return false;
164 return true;
165 }
166
167 constexpr bool valid() const noexcept {
168 constexpr auto used=feature_count%64;
169 constexpr auto mask=used ? (std::uint64_t{1}<<used)-1 : 0;
170 return (flags.back()&~mask)==0;
171 }
172
173 constexpr bool operator==(isa const &) const=default;
174 __declspec(property(get=get_mmx,put=set_mmx)) bool mmx;
175 __declspec(property(get=get_sse,put=set_sse)) bool sse;
176 __declspec(property(get=get_sse2,put=set_sse2)) bool sse2;
177 __declspec(property(get=get_sse3,put=set_sse3)) bool sse3;
178 __declspec(property(get=get_ssse3,put=set_ssse3)) bool ssse3;
179 __declspec(property(get=get_sse41,put=set_sse41)) bool sse41;
180 __declspec(property(get=get_sse42,put=set_sse42)) bool sse42;
181 __declspec(property(get=get_popcnt,put=set_popcnt)) bool popcnt;
182 __declspec(property(get=get_avx,put=set_avx)) bool avx;
183 __declspec(property(get=get_avx2,put=set_avx2)) bool avx2;
184 __declspec(property(get=get_fma,put=set_fma)) bool fma;
185 __declspec(property(get=get_f16c,put=set_f16c)) bool f16c;
186 __declspec(property(get=get_bmi1,put=set_bmi1)) bool bmi1;
187 __declspec(property(get=get_bmi2,put=set_bmi2)) bool bmi2;
188 __declspec(property(get=get_avx512f,put=set_avx512f)) bool avx512f;
189 __declspec(property(get=get_avx512dq,put=set_avx512dq)) bool avx512dq;
190 __declspec(property(get=get_avx512bw,put=set_avx512bw)) bool avx512bw;
191 __declspec(property(get=get_avx512vl,put=set_avx512vl)) bool avx512vl;
192 __declspec(property(get=get_avx512bf16,put=set_avx512bf16)) bool avx512bf16;
193 __declspec(property(get=get_avx512fp16,put=set_avx512fp16)) bool avx512fp16;
194 __declspec(property(get=get_aes,put=set_aes)) bool aes;
195 __declspec(property(get=get_pclmul,put=set_pclmul)) bool pclmul;
196 __declspec(property(get=get_cx16,put=set_cx16)) bool cx16;
197 __declspec(property(get=get_avx512cd,put=set_avx512cd)) bool avx512cd;
198 __declspec(property(get=get_avx512ifma,put=set_avx512ifma)) bool avx512ifma;
199 __declspec(property(get=get_lzcnt,put=set_lzcnt)) bool lzcnt;
200 __declspec(property(get=get_movbe,put=set_movbe)) bool movbe;
201 __declspec(property(get=get_sahf,put=set_sahf)) bool sahf;
202 __declspec(property(get=get_mwaitx,put=set_mwaitx)) bool mwaitx;
203 __declspec(property(get=get_waitpkg,put=set_waitpkg)) bool waitpkg;
204 __declspec(property(get=get_crc32,put=set_crc32)) bool crc32;
205 __declspec(property(get=get_gfni,put=set_gfni)) bool gfni;
206 __declspec(property(get=get_vpclmulqdq,put=set_vpclmulqdq)) bool vpclmulqdq;
207 __declspec(property(get=get_avx512vpopcntdq,put=set_avx512vpopcntdq)) bool avx512vpopcntdq;
208 __declspec(property(get=get_avxvnni,put=set_avxvnni)) bool avxvnni;
209 __declspec(property(get=get_avx512vnni,put=set_avx512vnni)) bool avx512vnni;
210 __declspec(property(get=get_avxvnniint8,put=set_avxvnniint8)) bool avxvnniint8;
211 __declspec(property(get=get_avxvnniint16,put=set_avxvnniint16)) bool avxvnniint16;
212 __declspec(property(get=get_avx512bitalg,put=set_avx512bitalg)) bool avx512bitalg;
213 __declspec(property(get=get_avx512vbmi,put=set_avx512vbmi)) bool avx512vbmi;
214 __declspec(property(get=get_avx512vbmi2,put=set_avx512vbmi2)) bool avx512vbmi2;
215 __declspec(property(get=get_sha,put=set_sha)) bool sha;
216 __declspec(property(get=get_vaes,put=set_vaes)) bool vaes;
217 __declspec(property(get=get_avxifma,put=set_avxifma)) bool avxifma;
218 __declspec(property(get=get_adx,put=set_adx)) bool adx;
219 __declspec(property(get=get_sha512,put=set_sha512)) bool sha512;
220 __declspec(property(get=get_sm3,put=set_sm3)) bool sm3;
221 __declspec(property(get=get_sm4,put=set_sm4)) bool sm4;
222 __declspec(property(get=get_avxneconvert,put=set_avxneconvert)) bool avxneconvert;
223 };
224
226 template<> struct isa<arm> {
228 using feature_type=typename detail::feature_traits<arm>::type;
230 static constexpr architecture family=arm;
232 static constexpr auto feature_count=detail::feature_traits<arm>::count;
234 std::array<std::uint64_t,(feature_count+1+63)/64> flags{};
236 bool allow_polyfill=false;
238 constexpr isa(polyfill_t) noexcept : allow_polyfill(true) {}
240 constexpr bool has(polyfill_t) const noexcept { return allow_polyfill; }
242 constexpr isa() noexcept=default;
244 constexpr isa(feature_type f) noexcept { set(f,true); }
246 constexpr bool get(feature_type f) const noexcept {
247 auto i=std::uint64_t(f);
248 return i<feature_count && ((flags[i/64]>>(i%64))&1);
249 }
250
252 constexpr void set(feature_type f,bool value) noexcept {
253 auto i=std::uint64_t(f);
254 if(i>=feature_count) {
255 if(!value) return;
257 }
258 auto mask=std::uint64_t{1}<<(i%64);
259 auto & word=flags[i/64];
260 word=(word&~mask)|(value?mask:0);
261 }
262
263 constexpr bool has(feature_type f) const noexcept { return get(f); }
266 constexpr bool has(isa other) const noexcept {
267 for(std::size_t i=0;i<flags.size();++i)
268 if((flags[i]&other.flags[i])!=other.flags[i]) return false;
269 return true;
270 }
271
272 constexpr bool valid() const noexcept {
273 constexpr auto used=feature_count%64;
274 constexpr auto mask=used ? (std::uint64_t{1}<<used)-1 : 0;
275 return (flags.back()&~mask)==0;
276 }
277
278 constexpr bool operator==(isa const &) const=default;
279 __declspec(property(get=get_neon,put=set_neon)) bool neon;
280 __declspec(property(get=get_neon_fp16,put=set_neon_fp16)) bool neon_fp16;
281 __declspec(property(get=get_neon_bf16,put=set_neon_bf16)) bool neon_bf16;
282 __declspec(property(get=get_pmull,put=set_pmull)) bool pmull;
283 __declspec(property(get=get_sha1,put=set_sha1)) bool sha1;
284 __declspec(property(get=get_sha512,put=set_sha512)) bool sha512;
285 __declspec(property(get=get_ebf16,put=set_ebf16)) bool ebf16;
288 __declspec(property(get=get_sm3,put=set_sm3)) bool sm3;
291 __declspec(property(get=get_sm4,put=set_sm4)) bool sm4;
292 __declspec(property(get=get_aes,put=set_aes)) bool aes;
293 __declspec(property(get=get_sha2,put=set_sha2)) bool sha2;
294 __declspec(property(get=get_sha3,put=set_sha3)) bool sha3;
295 __declspec(property(get=get_crc,put=set_crc)) bool crc;
296 __declspec(property(get=get_lse,put=set_lse)) bool lse;
297 __declspec(property(get=get_rdm,put=set_rdm)) bool rdm;
298 __declspec(property(get=get_fp16fml,put=set_fp16fml)) bool fp16fml;
299 __declspec(property(get=get_dotprod,put=set_dotprod)) bool dotprod;
300 __declspec(property(get=get_complxnum,put=set_complxnum)) bool complxnum;
301 __declspec(property(get=get_jsconv,put=set_jsconv)) bool jsconv;
302 __declspec(property(get=get_rcpc,put=set_rcpc)) bool rcpc;
303 __declspec(property(get=get_pauth,put=set_pauth)) bool pauth;
304 __declspec(property(get=get_i8mm,put=set_i8mm)) bool i8mm;
305 };
306
308 template<> struct isa<wasm> {
310 using feature_type=typename detail::feature_traits<wasm>::type;
312 static constexpr architecture family=wasm;
314 static constexpr auto feature_count=detail::feature_traits<wasm>::count;
316 std::array<std::uint64_t,(feature_count+1+63)/64> flags{};
318 bool allow_polyfill=false;
320 constexpr isa(polyfill_t) noexcept : allow_polyfill(true) {}
322 constexpr bool has(polyfill_t) const noexcept { return allow_polyfill; }
324 constexpr isa() noexcept=default;
326 constexpr isa(feature_type f) noexcept { set(f,true); }
328 constexpr bool get(feature_type f) const noexcept {
329 auto i=std::uint64_t(f);
330 return i<feature_count && ((flags[i/64]>>(i%64))&1);
331 }
332
334 constexpr void set(feature_type f,bool value) noexcept {
335 auto i=std::uint64_t(f);
336 if(i>=feature_count) {
337 if(!value) return;
339 }
340 auto mask=std::uint64_t{1}<<(i%64);
341 auto & word=flags[i/64];
342 word=(word&~mask)|(value?mask:0);
343 }
344
345 constexpr bool has(feature_type f) const noexcept { return get(f); }
348 constexpr bool has(isa other) const noexcept {
349 for(std::size_t i=0;i<flags.size();++i)
350 if((flags[i]&other.flags[i])!=other.flags[i]) return false;
351 return true;
352 }
353
354 constexpr bool valid() const noexcept {
355 constexpr auto used=feature_count%64;
356 constexpr auto mask=used ? (std::uint64_t{1}<<used)-1 : 0;
357 return (flags.back()&~mask)==0;
358 }
359
360 constexpr bool operator==(isa const &) const=default;
361 __declspec(property(get=get_simd128,put=set_simd128)) bool simd128;
362 __declspec(property(get=get_relaxed_simd,put=set_relaxed_simd)) bool relaxed_simd;
363 };
364
366 template<detail::instruction_feature E> isa(E)->isa<detail::family_of<E>>;
367
368 namespace detail {
369 template<class T> inline constexpr bool is_isa=false;
370 template<architecture Family> inline constexpr bool is_isa<isa<Family>> = true;
371 template<class T> struct arch_family;
372 template<instruction_feature E> struct arch_family<E> : std::integral_constant<architecture,family_of<E>> {};
373 template<architecture Family> struct arch_family<isa<Family>> : std::integral_constant<architecture,Family> {};
374 }
376 template<class T> concept arch=detail::instruction_feature<T> || detail::is_isa<T>;
377 namespace detail {
378 template<arch T> inline constexpr architecture arch_family_v=arch_family<T>::value;
379 template<class A,class B> concept same_arch=arch<A> && arch<B> && arch_family_v<A> == arch_family_v<B>;
380 }
381
383 template<arch A,arch B> requires detail::same_arch<A,B>
384 constexpr auto operator&(A left,B right) noexcept {
385 isa<detail::arch_family_v<A>> result=left, other=right;
386 for(std::size_t i=0;i<result.flags.size();++i) result.flags[i]|=other.flags[i];
387 result.allow_polyfill=result.allow_polyfill || other.allow_polyfill;
388 return result;
389 }
390
391 template<arch A>
392 constexpr auto operator|(A requirements,polyfill_t) noexcept {
393 isa<detail::arch_family_v<A>> result=requirements;
394 result.allow_polyfill=true;
395 return result;
396 }
397
398 template<arch A>
399 constexpr auto operator|(polyfill_t,A requirements) noexcept { return requirements|polyfill; }
401 constexpr polyfill_t operator|(polyfill_t,polyfill_t) noexcept { return {}; }
402
403 // Concrete enum overloads prevent built-in ordinal comparisons from winning.
405 constexpr bool operator<(x86_feature,x86_feature) noexcept { return false; }
407 constexpr bool operator>(x86_feature,x86_feature) noexcept { return false; }
409 constexpr bool operator<=(x86_feature a,x86_feature b) noexcept { return a==b; }
411 constexpr bool operator>=(x86_feature a,x86_feature b) noexcept { return a==b; }
413 constexpr bool operator<(arm_feature,arm_feature) noexcept { return false; }
415 constexpr bool operator>(arm_feature,arm_feature) noexcept { return false; }
417 constexpr bool operator<=(arm_feature a,arm_feature b) noexcept { return a==b; }
419 constexpr bool operator>=(arm_feature a,arm_feature b) noexcept { return a==b; }
421 constexpr bool operator<(wasm_feature,wasm_feature) noexcept { return false; }
423 constexpr bool operator>(wasm_feature,wasm_feature) noexcept { return false; }
425 constexpr bool operator<=(wasm_feature a,wasm_feature b) noexcept { return a==b; }
427 constexpr bool operator>=(wasm_feature a,wasm_feature b) noexcept { return a==b; }
429 template<arch A,arch B> requires detail::same_arch<A,B>
430 constexpr bool operator<=(A a,B b) noexcept { return isa<detail::arch_family_v<A>>(b).has(a); }
432 template<arch A,arch B> requires detail::same_arch<A,B>
433 constexpr bool operator>=(A a,B b) noexcept { return b<=a; }
435 template<arch A,arch B> requires detail::same_arch<A,B>
436 constexpr bool operator<(A a,B b) noexcept { return a<=b && !(b<=a); }
438 template<arch A,arch B> requires detail::same_arch<A,B>
439 constexpr bool operator>(A a,B b) noexcept { return b<a; }
440
442 // Explicit constraints let Clang merge the header with an imported declaration.
443 template<auto A,auto... Choices>
444 requires arch<decltype(A)> && ((detail::same_arch<decltype(A),decltype(Choices)>) && ...)
445 inline constexpr int target=[]() consteval {
446 using value_type=isa<detail::arch_family_v<decltype(A)>>;
447 constexpr std::array<value_type,sizeof...(Choices)> choices{value_type(Choices)...};
448 static_assert([&] {
449 for(std::size_t i=0;i<choices.size();++i)
450 for(std::size_t j=i+1;j<choices.size();++j)
451 if(choices[i]<=choices[j]) return false;
452 return true;
453 }(),"a later target is shadowed by an earlier one");
454 for(std::size_t i=0;i<choices.size();++i)
455 if(choices[i]<=value_type(A)) return int(i);
456 return -1;
457 }();
458
459 namespace detail {
460 template<architecture Family>
461 constexpr isa<Family> intersection(isa<Family> a,isa<Family> b) noexcept {
462 for(std::size_t i=0;i<a.flags.size();++i) a.flags[i]&=b.flags[i];
463 a.allow_polyfill=a.allow_polyfill && b.allow_polyfill;
464 return a;
465 }
466 enum class feature_register { leaf1_ecx, leaf1_edx, leaf7_ebx, leaf7_ecx, leaf7_edx, leaf7_1_eax, leaf7_1_edx, extended1_ecx, arm, wasm };
467 template<architecture Family> struct feature_record {
468 isa<Family> value;
469 std::string_view spelling;
470 isa<Family> implies;
471 feature_register location;
472 static constexpr architecture family=Family;
473 unsigned bit;
474 std::size_t index;
475 isa<Family> target_implies;
476 bool targetable;
477 constexpr feature_record(typename feature_traits<Family>::type f,std::string_view spelling,isa<Family> implies,
478 feature_register location,unsigned bit,isa<Family> target_implies={},bool targetable=true) noexcept:
479 value(f),spelling(spelling),implies(implies),location(location),bit(bit),index(std::size_t(f)),
480 target_implies(target_implies),targetable(targetable) {}
481 };
482 // Hardware prerequisites and compiler bundles are recorded separately.
483 template<architecture Family> inline constexpr auto feature_registry=std::array<feature_record<Family>,0>{};
484 template<> inline constexpr auto feature_registry<x86> = std::to_array<feature_record<x86>>({
485 {x86_feature::mmx,"mmx",{},feature_register::leaf1_edx,23},
486 {x86_feature::sse,"sse",isa(x86_feature::mmx),feature_register::leaf1_edx,25},
487 {x86_feature::sse2,"sse2",isa(x86_feature::sse),feature_register::leaf1_edx,26},
488 {x86_feature::sse3,"sse3",isa(x86_feature::sse2),feature_register::leaf1_ecx,0},
489 {x86_feature::ssse3,"ssse3",isa(x86_feature::sse3),feature_register::leaf1_ecx,9},
490 {x86_feature::sse41,"sse4.1",isa(x86_feature::ssse3),feature_register::leaf1_ecx,19},
491 {x86_feature::sse42,"sse4.2",x86_feature::sse41&x86_feature::popcnt&x86_feature::crc32,feature_register::leaf1_ecx,20},
492 {x86_feature::popcnt,"popcnt",{},feature_register::leaf1_ecx,23},
493 {x86_feature::avx,"avx",isa(x86_feature::sse42),feature_register::leaf1_ecx,28},
494 {x86_feature::avx2,"avx2",isa(x86_feature::avx),feature_register::leaf7_ebx,5},
495 {x86_feature::fma,"fma",isa(x86_feature::avx),feature_register::leaf1_ecx,12},
496 {x86_feature::f16c,"f16c",isa(x86_feature::avx),feature_register::leaf1_ecx,29},
497 {x86_feature::bmi1,"bmi",{},feature_register::leaf7_ebx,3},
498 {x86_feature::bmi2,"bmi2",{},feature_register::leaf7_ebx,8},
499 {x86_feature::mwaitx,"mwaitx",{},feature_register::extended1_ecx,29},
500 {x86_feature::waitpkg,"waitpkg",{},feature_register::leaf7_ecx,5},
501 {x86_feature::crc32,"crc32",{},feature_register::leaf1_ecx,20},
502 {x86_feature::gfni,"gfni",isa(x86_feature::sse2),feature_register::leaf7_ecx,8},
503 {x86_feature::avx512f,"avx512f",x86_feature::avx2&x86_feature::f16c&x86_feature::fma,feature_register::leaf7_ebx,16},
504 {x86_feature::avx512dq,"avx512dq",isa(x86_feature::avx512f),feature_register::leaf7_ebx,17},
505 {x86_feature::avx512bw,"avx512bw",isa(x86_feature::avx512f),feature_register::leaf7_ebx,30},
506 {x86_feature::avx512vl,"avx512vl",isa(x86_feature::avx512f),feature_register::leaf7_ebx,31},
507 {x86_feature::avx512bf16,"avx512bf16",isa(x86_feature::avx512bw),feature_register::leaf7_1_eax,5},
508 {x86_feature::avx512fp16,"avx512fp16",isa(x86_feature::avx512bw),feature_register::leaf7_edx,23},
509 {x86_feature::avx512vbmi,"avx512vbmi",isa(x86_feature::avx512bw),feature_register::leaf7_ecx,1},
510 {x86_feature::avx512vbmi2,"avx512vbmi2",isa(x86_feature::avx512bw),feature_register::leaf7_ecx,6},
511 {x86_feature::avx512bitalg,"avx512bitalg",isa(x86_feature::avx512bw),feature_register::leaf7_ecx,12},
512 {x86_feature::avx512vpopcntdq,"avx512vpopcntdq",isa(x86_feature::avx512f),feature_register::leaf7_ecx,14},
513 {x86_feature::avxvnni,"avxvnni",isa(x86_feature::avx2),feature_register::leaf7_1_eax,4},
514 {x86_feature::avx512vnni,"avx512vnni",isa(x86_feature::avx512f),feature_register::leaf7_ecx,11},
515 {x86_feature::avxvnniint8,"avxvnniint8",isa(x86_feature::avx2),feature_register::leaf7_1_edx,4},
516 {x86_feature::avxvnniint16,"avxvnniint16",isa(x86_feature::avx2),feature_register::leaf7_1_edx,10},
517 {x86_feature::aes,"aes",isa(x86_feature::sse2),feature_register::leaf1_ecx,25},
518 {x86_feature::pclmul,"pclmul",isa(x86_feature::sse2),feature_register::leaf1_ecx,1},
519 {x86_feature::sha,"sha",isa(x86_feature::sse2),feature_register::leaf7_ebx,29},
520 {x86_feature::vaes,"vaes",isa(x86_feature::avx),feature_register::leaf7_ecx,9,
521 x86_feature::aes&x86_feature::avx2},
522 {x86_feature::vpclmulqdq,"vpclmulqdq",x86_feature::avx&x86_feature::pclmul,feature_register::leaf7_ecx,10},
523 {x86_feature::cx16,"cx16",{},feature_register::leaf1_ecx,13},
524 {x86_feature::avx512cd,"avx512cd",isa(x86_feature::avx512f),feature_register::leaf7_ebx,28},
525 {x86_feature::avx512ifma,"avx512ifma",isa(x86_feature::avx512f),feature_register::leaf7_ebx,21},
526 {x86_feature::avxifma,"avxifma",isa(x86_feature::avx),feature_register::leaf7_1_eax,23,isa(x86_feature::avx2)},
527 {x86_feature::adx,"adx",{},feature_register::leaf7_ebx,19},
528 {x86_feature::sha512,"sha512",isa(x86_feature::avx),feature_register::leaf7_1_eax,0,isa(x86_feature::avx2)},
529 {x86_feature::sm3,"sm3",isa(x86_feature::avx),feature_register::leaf7_1_eax,1},
530 {x86_feature::sm4,"sm4",isa(x86_feature::avx),feature_register::leaf7_1_eax,2,isa(x86_feature::avx2)},
531 {x86_feature::avxneconvert,"avxneconvert",isa(x86_feature::avx),feature_register::leaf7_1_edx,5,isa(x86_feature::avx2)},
532 {x86_feature::lzcnt,"lzcnt",{},feature_register::extended1_ecx,5},
533 {x86_feature::movbe,"movbe",{},feature_register::leaf1_ecx,22},
534 {x86_feature::sahf,"sahf",{},feature_register::extended1_ecx,0}
535 });
536 template<> inline constexpr auto feature_registry<arm> = std::to_array<feature_record<arm>>({
537 {arm_feature::neon,"neon",{},feature_register::arm,0},
538 {arm_feature::neon_fp16,"fullfp16",isa(arm_feature::neon),feature_register::arm,1},
539 {arm_feature::neon_bf16,"bf16",isa(arm_feature::neon),feature_register::arm,2},
540 {arm_feature::aes,"aes",isa(arm_feature::neon),feature_register::arm,3,isa(arm_feature::pmull)},
541 {arm_feature::sha2,"sha2",isa(arm_feature::neon),feature_register::arm,4,isa(arm_feature::sha1)},
542 {arm_feature::sha3,"sha3",isa(arm_feature::neon),feature_register::arm,5,arm_feature::sha1&arm_feature::sha2&arm_feature::sha512},
543 {arm_feature::crc,"crc",{},feature_register::arm,6},
544 {arm_feature::lse,"lse",isa(arm_feature::neon),feature_register::arm,7},
545 {arm_feature::rdm,"rdm",isa(arm_feature::neon),feature_register::arm,8},
546 {arm_feature::fp16fml,"fp16fml",isa(arm_feature::neon_fp16),feature_register::arm,9},
547 {arm_feature::dotprod,"dotprod",isa(arm_feature::neon),feature_register::arm,10},
548 {arm_feature::complxnum,"complxnum",isa(arm_feature::neon),feature_register::arm,11},
549 {arm_feature::jsconv,"jsconv",isa(arm_feature::neon),feature_register::arm,12},
550 {arm_feature::rcpc,"rcpc",isa(arm_feature::neon),feature_register::arm,13},
551 {arm_feature::pauth,"pauth",isa(arm_feature::neon),feature_register::arm,14},
552 {arm_feature::i8mm,"i8mm",isa(arm_feature::neon),feature_register::arm,15},
553 {arm_feature::pmull,"pmull",isa(arm_feature::neon),feature_register::arm,16,{},false},
554 {arm_feature::sha1,"sha1",isa(arm_feature::neon),feature_register::arm,17,{},false},
555 {arm_feature::sha512,"sha512",isa(arm_feature::neon),feature_register::arm,18,{},false},
556 {arm_feature::ebf16,"ebf16",isa(arm_feature::neon_bf16),feature_register::arm,19,{},false},
557 {arm_feature::sm3,"sm3",isa(arm_feature::neon),feature_register::arm,20,{},false},
558 {arm_feature::sm4,"sm4",isa(arm_feature::neon),feature_register::arm,21,isa(arm_feature::sm3)}
559 });
560 template<> inline constexpr auto feature_registry<wasm> = std::to_array<feature_record<wasm>>({
561 {wasm_feature::simd128,"simd128",{},feature_register::wasm,0},
562 {wasm_feature::relaxed_simd,"relaxed-simd",isa(wasm_feature::simd128),feature_register::wasm,1}
563 });
564 template<architecture Family> inline constexpr isa<Family> known_features=[] {
565 isa<Family> result;
566 for(auto const & entry:feature_registry<Family>) result=result&entry.value;
567 return result;
568 }();
569 template<instruction_feature E> inline constexpr auto family_features=known_features<family_of<E>>;
570 inline constexpr auto arm_features=known_features<arm>;
571 inline constexpr auto x86_features=known_features<x86>;
572 inline constexpr auto wasm_features=known_features<wasm>;
573 template<architecture Family> inline constexpr isa<Family> invalid_features=[] {
574 isa<Family> result;
575 constexpr auto index=feature_traits<Family>::count;
576 result.flags[index/64]|=std::uint64_t{1}<<(index%64);
577 return result;
578 }();
579 // Shared source constraints remain equivalent across repeated declarations.
580 template<isa<> A> inline constexpr isa<> source_isa=[]() consteval {
581 static_assert(A<=known_features<target_arch>,"source target contains an unregistered ISA feature");
582 return A;
583 }();
584 }
585
588 template<arch A> constexpr auto feature_closure(A input) noexcept {
589 constexpr auto family=detail::arch_family_v<A>;
590 isa<family> bits=input, previous;
591 do {
592 previous=bits;
593 for(auto const & entry:detail::feature_registry<family>)
594 if(bits.has(entry.value)) bits=bits&entry.implies;
595 } while(previous!=bits);
596 return bits;
597 }
598
599 inline constexpr isa<> scalar{};
600 inline constexpr auto avx2=feature_closure(x86_feature::avx2&x86_feature::fma);
601 inline constexpr auto avx512=feature_closure(avx2&x86_feature::avx512f&x86_feature::avx512dq&x86_feature::avx512bw&x86_feature::avx512vl);
602 inline constexpr auto avx512_bf16=feature_closure(avx512&x86_feature::avx512bf16);
603 inline constexpr auto avx512_fp16=feature_closure(avx512&x86_feature::avx512fp16);
604 inline constexpr auto neon=feature_closure(arm_feature::neon);
605 inline constexpr auto neon_fp16=feature_closure(arm_feature::neon_fp16);
606 inline constexpr auto neon_bf16=feature_closure(arm_feature::neon_bf16);
607
610 template<architecture Family=target_arch>
611 constexpr isa<Family> target_features(std::string_view text) noexcept {
612 if(text.empty()) return {};
613 isa<Family> bits;
614 while(!text.empty()) {
615 auto comma=text.find(',');
616 auto token=text.substr(0,comma);
617 bool found=false;
618 for(auto const & entry:detail::feature_registry<Family>) if(entry.targetable && token.compare(entry.spelling)==0) {
619 bits=bits&entry.value&entry.target_implies; found=true; break;
620 }
621 if(!found) return detail::invalid_features<Family>;
622 if(comma==std::string_view::npos) break;
623 text.remove_prefix(comma+1);
624 if(text.empty()) return detail::invalid_features<Family>;
625 }
626 return feature_closure(bits);
627 }
628
629 template<architecture Family=target_arch> struct isa_admission {
630 isa<Family> missing_features{};
631 std::uint64_t missing_xcr0=0;
632 bool invalid_features=false;
633 bool missing_xcr0_observation=false;
635 constexpr bool admitted() const noexcept {
636 return missing_features==isa<Family>{} && !missing_xcr0 && !invalid_features && !missing_xcr0_observation;
637 }
638
641 constexpr char const * reason() const noexcept {
642 if(invalid_features) return "invalid ISA features";
643 for(auto const & entry:detail::feature_registry<Family>)
644 if(missing_features.has(entry.value)) return entry.spelling.data();
645 if(missing_xcr0_observation) return "XCR0 unavailable";
646 if(missing_xcr0 & (1ull<<1)) return "XMM state unavailable";
647 if(missing_xcr0 & (1ull<<2)) return "YMM state unavailable";
648 if(missing_xcr0 & (1ull<<5)) return "opmask state unavailable";
649 if(missing_xcr0 & (1ull<<6)) return "ZMM high state unavailable";
650 if(missing_xcr0 & (1ull<<7)) return "high ZMM registers unavailable";
651 return admitted() ? "admitted" : "ISA requirements unavailable";
652 }
653 };
654
655 namespace detail {
656 template<class C> concept x86_observation=requires(C const & c) {
657 c.max_basic_leaf; c.leaf1_ecx; c.leaf1_edx; c.leaf7_ebx;
658 c.max_leaf7_subleaf; c.leaf7_1_eax; c.leaf7_edx;
659 };
660 template<class C> concept arm_observation=requires(C const & c) {
661 c.baseline_observed; c.fp; c.asimd;
662 c.fp16_observed; c.scalar_fp16; c.vector_fp16;
663 c.bf16_observed; c.bf16;
664 };
665 template<class C,architecture Family> concept normalized_features=requires(C const & c) {
666 { c.present } -> std::same_as<isa<Family> const &>;
667 { c.observed } -> std::same_as<isa<Family> const &>;
668 };
669 template<class C> concept has_feature_observation=requires(C const & c) { c.present; c.observed; };
670 template<architecture Family> struct feature_observation {
671 isa<Family> present{},observed{};
672 };
673 template<x86_observation C>
674 constexpr feature_observation<x86> decode_x86_features(C const & cpu) noexcept {
675 feature_observation<x86> result;
676 for(auto const & entry:feature_registry<x86>) {
677 std::uint32_t word=0;
678 bool observed=false;
679 switch(entry.location) {
680 case feature_register::leaf1_ecx: observed=cpu.max_basic_leaf>=1; word=cpu.leaf1_ecx; break;
681 case feature_register::leaf1_edx: observed=cpu.max_basic_leaf>=1; word=cpu.leaf1_edx; break;
682 case feature_register::leaf7_ebx: observed=cpu.max_basic_leaf>=7; word=cpu.leaf7_ebx; break;
683 case feature_register::leaf7_ecx:
684 if constexpr(requires { cpu.leaf7_ecx; }) {
685 observed=cpu.max_basic_leaf>=7; word=cpu.leaf7_ecx;
686 }
687 break;
688 case feature_register::leaf7_edx: observed=cpu.max_basic_leaf>=7; word=cpu.leaf7_edx; break;
689 case feature_register::leaf7_1_eax:
690 observed=cpu.max_basic_leaf>=7 && cpu.max_leaf7_subleaf>=1; word=cpu.leaf7_1_eax; break;
691 case feature_register::leaf7_1_edx:
692 if constexpr(requires { cpu.leaf7_1_edx; }) {
693 observed=cpu.max_basic_leaf>=7 && cpu.max_leaf7_subleaf>=1; word=cpu.leaf7_1_edx;
694 }
695 break;
696 case feature_register::extended1_ecx:
697 if constexpr(requires { cpu.max_extended_leaf; cpu.extended1_ecx; }) {
698 observed=cpu.max_extended_leaf>=0x80000001u; word=cpu.extended1_ecx;
699 }
700 break;
701 case feature_register::arm: case feature_register::wasm: continue;
702 }
703 auto f=static_cast<x86_feature>(entry.index);
704 result.observed.set(f,observed);
705 result.present.set(f,observed && (word&(std::uint32_t{1}<<entry.bit)));
706 }
707 return result;
708 }
709 template<arm_observation C>
710 constexpr feature_observation<arm> decode_arm_features(C const & cpu) noexcept {
711 feature_observation<arm> result;
712 result.observed.set(arm_feature::neon,cpu.baseline_observed);
713 result.present.set(arm_feature::neon,cpu.baseline_observed && cpu.fp && cpu.asimd);
714 result.observed.set(arm_feature::neon_fp16,cpu.fp16_observed);
715 result.present.set(arm_feature::neon_fp16,cpu.fp16_observed && cpu.scalar_fp16 && cpu.vector_fp16);
716 result.observed.set(arm_feature::neon_bf16,cpu.bf16_observed);
717 result.present.set(arm_feature::neon_bf16,cpu.bf16_observed && cpu.bf16);
718 if constexpr(requires { cpu.ebf16_observed; cpu.ebf16; }) {
719 result.observed.set(arm_feature::ebf16,cpu.ebf16_observed);
720 result.present.set(arm_feature::ebf16,cpu.ebf16_observed && cpu.ebf16);
721 }
722 constexpr auto baseline=arm_feature::neon&arm_feature::neon_fp16&arm_feature::neon_bf16&arm_feature::ebf16;
723 if constexpr(requires { cpu.extra_observed; cpu.extra_features; })
724 for(auto const & entry:feature_registry<arm>) {
725 if(baseline.has(entry.value)) continue;
726 auto f=static_cast<arm_feature>(entry.index);
727 auto observed=cpu.extra_observed.has(f);
728 result.observed.set(f,observed);
729 result.present.set(f,observed && cpu.extra_features.has(f));
730 }
731 return result;
732 }
733 template<architecture Family>
734 constexpr isa_admission<Family> classify_features(isa<Family> present,isa<Family> observed,isa<Family> bits) noexcept {
735 isa_admission<Family> result;
736 auto known=known_features<Family>;
737 result.invalid_features=!present.valid() || !observed.valid() || !(bits<=known);
738 auto available=intersection(present,observed);
739 result.missing_features=intersection(bits,known);
740 for(std::size_t i=0;i<available.flags.size();++i)
741 result.missing_features.flags[i]&=~available.flags[i];
742 return result;
743 }
744 constexpr isa_admission<x86> classify_x86_features(isa<x86> present,
745 isa<x86> observed,std::uint64_t xcr0,bool readable,isa<x86> bits) noexcept {
746 auto result=classify_features(present,observed,bits);
747 if(bits.has(x86_feature::avx)) {
748 result.missing_xcr0_observation=!readable;
749 result.missing_xcr0=(bits.has(x86_feature::avx512f)?0xe6ull:0x6ull)&~(readable?xcr0:0ull);
750 }
751 return result;
752 }
753 }
754
758 template<class C> requires detail::normalized_features<C,x86> && requires(C const & c) { c.xcr0; c.xcr0_observed; }
759 constexpr isa_admission<x86> classify_isa(C const & cpu,isa<x86> requested,isa<x86> minimum={}) noexcept {
760 return detail::classify_x86_features(cpu.present,cpu.observed,cpu.xcr0,cpu.xcr0_observed,
761 feature_closure(requested&minimum));
762 }
763
766 template<class C> requires detail::normalized_features<C,arm>
767 constexpr isa_admission<arm> classify_isa(C const & cpu,isa<arm> requested,isa<arm> minimum={}) noexcept {
768 return detail::classify_features(cpu.present,cpu.observed,feature_closure(requested&minimum));
769 }
770
773 template<class C> requires detail::normalized_features<C,wasm>
774 constexpr isa_admission<wasm> classify_isa(C const & runtime,isa<wasm> requested,isa<wasm> minimum={}) noexcept {
775 return detail::classify_features(runtime.present,runtime.observed,feature_closure(requested&minimum));
776 }
777
780 template<detail::x86_observation C> requires (!detail::has_feature_observation<C>) && requires(C const & c) { c.xcr0; c.xcr0_observed; }
781 constexpr isa_admission<x86> classify_isa(C const & cpu,isa<x86> requested,isa<x86> minimum={}) noexcept {
782 auto features=detail::decode_x86_features(cpu);
783 bool readable=cpu.max_basic_leaf>=1 && (cpu.leaf1_ecx&(1u<<26)) &&
784 (cpu.leaf1_ecx&(1u<<27)) && cpu.xcr0_observed;
785 return detail::classify_x86_features(features.present,features.observed,cpu.xcr0,readable,
786 feature_closure(requested&minimum));
787 }
788
791 template<detail::arm_observation C> requires (!detail::has_feature_observation<C>)
792 constexpr isa_admission<arm> classify_isa(C const & cpu,isa<arm> requested,isa<arm> minimum={}) noexcept {
793 auto features=detail::decode_arm_features(cpu);
794 return detail::classify_features(features.present,features.observed,feature_closure(requested&minimum));
795 }
796
798 template<architecture Family=target_arch> struct target_entry {
799 isa<Family> architecture;
800 isa<Family> minimum{};
802 constexpr bool operator==(target_entry const &) const = default;
803 };
804
805 template<architecture Family> target_entry(isa<Family>,isa<Family> = {})->target_entry<Family>;
807 template<detail::instruction_feature E> target_entry(E)->target_entry<detail::family_of<E>>;
809 template<arch A,arch B> requires detail::same_arch<A,B>
810 target_entry(A,B)->target_entry<detail::arch_family_v<A>>;
811 template<auto... Entries> struct isa_list {};
813 template<auto... A,auto... B>
814 constexpr isa_list<A...,B...> operator+(isa_list<A...>,isa_list<B...>) noexcept { return {}; }
815
816 namespace detail {
817 template<auto E,int I> struct abi_match {
818 static constexpr auto entry=[] {
819 if constexpr(arch<std::remove_cv_t<decltype(E)>>) return target_entry<arch_family_v<std::remove_cv_t<decltype(E)>>>{E};
820 else return E;
821 }();
822 static constexpr auto architecture=entry.architecture;
823 static constexpr auto minimum=entry.minimum;
824 static_assert(architecture<=known_features<decltype(architecture)::family>,"ABI policy contains an unregistered ISA feature");
825 static_assert(minimum<=known_features<decltype(minimum)::family>,"ABI policy minimum contains an unregistered ISA feature");
826 static constexpr auto required_features=feature_closure(architecture&minimum);
827 static constexpr bool matched=true;
828 static constexpr int index=I;
829 };
830 template<isa A,int I,auto... Entries> struct abi_lookup_impl {
831 static constexpr bool matched=false;
832 static constexpr int index=-1;
833 static constexpr decltype(A) architecture{},minimum{},required_features{};
834 };
835 template<isa A,int I,auto E,auto... Rest>
836 struct abi_lookup_impl<A,I,E,Rest...> : std::conditional_t<
837 abi_match<E,I>::required_features<=A,
838 abi_match<E,I>,abi_lookup_impl<A,I+1,Rest...>> {};
839 }
842 template<isa A,class List> struct abi_lookup;
843 template<isa A,auto... Entries>
844 requires ((decltype(detail::abi_match<Entries,0>::architecture)::family==decltype(A)::family) && ...)
845 struct abi_lookup<A,isa_list<Entries...>> : detail::abi_lookup_impl<A,0,Entries...> {};
846
847 namespace detail {
848 template<class C> concept capability_observation=
849 normalized_features<C,x86> || normalized_features<C,arm> || normalized_features<C,wasm> ||
850 x86_observation<C> || arm_observation<C>;
851 template<capability_observation C> inline constexpr architecture observation_family=[] {
852 if constexpr(normalized_features<C,x86>) return x86;
853 else if constexpr(normalized_features<C,arm>) return arm;
854 else if constexpr(normalized_features<C,wasm>) return wasm;
855 else if constexpr(x86_observation<C>) return x86;
856 else return arm;
857 }();
858 }
860 template<auto... Entries,detail::capability_observation C,class F>
861 requires ((decltype(detail::abi_match<Entries,0>::architecture)::family==detail::observation_family<C>) && ...)
862 constexpr bool with_isa(isa_list<Entries...>,C const & cpu,F && callback,isa<detail::observation_family<C>> minimum={}) {
863 bool selected=false;
864 auto try_entry=[&]<auto E>() {
865 using entry=detail::abi_match<E,0>;
866 if(!selected && classify_isa(cpu,entry::architecture,minimum&entry::minimum).admitted()) {
867 selected=true;
868 std::forward<F>(callback).template operator()<entry::architecture>();
869 }
870 };
871 (try_entry.template operator()<Entries>(),...);
872 return selected;
873 }
874}
A feature enum or an ISA value from one architecture family.
Definition isa.h:376
constexpr std::uint32_t crc32(std::uint32_t accumulator, std::uint8_t value) noexcept
Update the CRC32 accumulator with exactly 8 input bits.
Definition crc.h:29
constexpr simd< std::uint64_t, 2, Arch > pmull(std::uint64_t a, std::uint64_t b) noexcept
std::string_view const type
typename mask_traits< std::remove_cvref_t< T > >::type mask
Definition mask_traits.h:22
constexpr std::uint16_t lzcnt(std::uint16_t value) noexcept
Definition lzcnt.h:24
constexpr std::uint16_t popcnt(std::uint16_t value) noexcept
Definition popcnt.h:24
constexpr simd< std::uint64_t, 2, Arch > vpclmulqdq(simd< std::uint64_t, 2, Arch > a, simd< std::uint64_t, 2, Arch > b) noexcept
Multiply selected halves of one 128-bit lane using PCLMUL and AVX.
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
constexpr std::size_t arm_feature_count
Number of named ARM feature values.
Definition isa.h:36
constexpr architecture arm
Select ARM feature metadata independently of the compilation target.
Definition config.h:28
constexpr architecture x86
Select x86 feature metadata independently of the compilation target.
Definition config.h:26
void operator>=(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
void operator>(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
x86_feature
Architecture-specific instruction features, represented by local bit indices.
Definition isa.h:15
architecture
Instruction-set families; an ISA value belongs to exactly one family.
Definition config.h:24
void operator|(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
target_entry(isa< Family >, isa< Family >={}) -> target_entry< Family >
Deduce a source record from same-family ISA values.
constexpr auto feature_closure(A input) noexcept
Definition isa.h:588
constexpr architecture wasm
Select WebAssembly feature metadata independently of the compilation target.
Definition config.h:30
constexpr simd< fp16, 32, Arch > fma(simd< fp16, 32, Arch > a, simd< fp16, 32, Arch > b, simd< fp16, 32, Arch > c) noexcept
void operator<=(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
constexpr std::size_t x86_feature_count
Number of named x86 feature values.
Definition isa.h:34
constexpr isa_admission< x86 > classify_isa(C const &cpu, isa< x86 > requested, isa< x86 > minimum={}) noexcept
Definition isa.h:759
@ unknown
Any other vendor string.
constexpr int target
First matching requirement, with every later choice checked for shadowing.
Definition isa.h:445
void operator&(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
void operator+(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
constexpr isa< Family > target_features(std::string_view text) noexcept
Definition isa.h:611
wasm_feature
WebAssembly validation capabilities, using local bit indices.
Definition isa.h:30
void operator<(simd< T, N, A >, simd< U, M, B >)=delete
Reject mixed architectures and mismatched short-vector widths before native conversions can participa...
constexpr std::size_t wasm_feature_count
Number of named Wasm feature values.
Definition isa.h:32
constexpr polyfill_t polyfill
Compose this permission with an ISA using A | polyfill. Used alone, it selects scalar emulation in th...
Definition isa.h:43
arm_feature
Independently observable ARM instruction features, using local bit indices.
Definition isa.h:24
isa(E) -> isa< detail::family_of< E > >
Deduce the family from a feature enum; explicit isa<> always names the host family.
bool neon
Read or update the neon feature bit through flags.
Definition isa.h:279
constexpr bool has(isa other) const noexcept
Definition isa.h:266
typename detail::feature_traits< arm >::type feature_type
Feature enum accepted by this ISA family.
Definition isa.h:228
static constexpr auto feature_count
Number of registered features in this family.
Definition isa.h:232
bool lse
Read or update the lse feature bit through flags.
Definition isa.h:296
bool i8mm
Read or update the i8mm feature bit through flags.
Definition isa.h:304
constexpr bool has(polyfill_t) const noexcept
True when semantic emulation or storage decomposition is permitted.
Definition isa.h:240
bool fp16fml
Read or update the fp16fml feature bit through flags.
Definition isa.h:298
std::array< std::uint64_t,(feature_count+1+63)/64 > flags
Public structural bits; invalid enum values and padding fail validation.
Definition isa.h:234
constexpr bool valid() const noexcept
True when no invalid marker or unregistered padding bit is set.
Definition isa.h:272
static constexpr architecture family
Architecture family, independent of the compiler target.
Definition isa.h:230
bool neon_bf16
Read or update the neon_bf16 feature bit through flags.
Definition isa.h:281
bool sha1
Read or update the sha1 feature bit through flags.
Definition isa.h:283
constexpr bool get(feature_type f) const noexcept
Read one feature; out-of-range values are absent.
Definition isa.h:246
bool pauth
Read or update the pauth feature bit through flags.
Definition isa.h:303
constexpr bool has(feature_type f) const noexcept
True when the feature is present.
Definition isa.h:263
bool aes
Read or update the aes feature bit through flags.
Definition isa.h:292
constexpr void set(feature_type f, bool value) noexcept
Definition isa.h:252
bool sha3
Read or update the sha3 feature bit through flags.
Definition isa.h:294
bool jsconv
Read or update the jsconv feature bit through flags.
Definition isa.h:301
constexpr isa() noexcept=default
Construct the empty requirement set.
constexpr isa(polyfill_t) noexcept
Construct an empty hardware requirement with emulation permitted.
Definition isa.h:238
bool crc
Read or update the crc feature bit through flags.
Definition isa.h:295
bool sha512
Read or update the sha512 feature bit through flags.
Definition isa.h:284
bool rcpc
Read or update the rcpc feature bit through flags.
Definition isa.h:302
bool sm4
Read or update the sm4 feature bit through flags.
Definition isa.h:291
bool allow_polyfill
Structural emulation permission; hardware feature tests do not read it.
Definition isa.h:236
bool sha2
Read or update the sha2 feature bit through flags.
Definition isa.h:293
bool neon_fp16
Read or update the neon_fp16 feature bit through flags.
Definition isa.h:280
bool complxnum
Read or update the complxnum feature bit through flags.
Definition isa.h:300
bool pmull
Read or update the pmull feature bit through flags.
Definition isa.h:282
bool dotprod
Read or update the dotprod feature bit through flags.
Definition isa.h:299
constexpr bool operator==(isa const &) const =default
Compare hardware bits and emulation permission, retaining NTTP identity.
bool rdm
Read or update the rdm feature bit through flags.
Definition isa.h:297
constexpr void set(feature_type f, bool value) noexcept
Definition isa.h:334
constexpr isa() noexcept=default
Construct the empty requirement set.
bool simd128
Read or update the simd128 feature bit through flags.
Definition isa.h:361
constexpr bool has(polyfill_t) const noexcept
True when semantic emulation or storage decomposition is permitted.
Definition isa.h:322
constexpr bool has(feature_type f) const noexcept
True when the feature is present.
Definition isa.h:345
constexpr bool operator==(isa const &) const =default
Compare hardware bits and emulation permission, retaining NTTP identity.
std::array< std::uint64_t,(feature_count+1+63)/64 > flags
Public structural bits; invalid enum values and padding fail validation.
Definition isa.h:316
bool allow_polyfill
Structural emulation permission; hardware feature tests do not read it.
Definition isa.h:318
constexpr bool valid() const noexcept
True when no invalid marker or unregistered padding bit is set.
Definition isa.h:354
constexpr isa(polyfill_t) noexcept
Construct an empty hardware requirement with emulation permitted.
Definition isa.h:320
static constexpr architecture family
Architecture family, independent of the compiler target.
Definition isa.h:312
typename detail::feature_traits< wasm >::type feature_type
Feature enum accepted by this ISA family.
Definition isa.h:310
static constexpr auto feature_count
Number of registered features in this family.
Definition isa.h:314
constexpr bool get(feature_type f) const noexcept
Read one feature; out-of-range values are absent.
Definition isa.h:328
bool relaxed_simd
Read or update the relaxed_simd feature bit through flags.
Definition isa.h:362
constexpr bool has(isa other) const noexcept
Definition isa.h:348
bool lzcnt
Read or update the lzcnt feature bit through flags.
Definition isa.h:199
bool sse42
Read or update the sse42 feature bit through flags.
Definition isa.h:180
bool sha512
Read or update the sha512 feature bit through flags.
Definition isa.h:219
bool avx512bw
Read or update the avx512bw feature bit through flags.
Definition isa.h:190
bool bmi1
Read or update the bmi1 feature bit through flags.
Definition isa.h:186
bool avx512dq
Read or update the avx512dq feature bit through flags.
Definition isa.h:189
typename detail::feature_traits< x86 >::type feature_type
Feature enum accepted by this ISA family.
Definition isa.h:123
bool crc32
Read or update the crc32 feature bit through flags.
Definition isa.h:204
bool allow_polyfill
Structural emulation permission; hardware feature tests do not read it.
Definition isa.h:131
bool sse2
Read or update the sse2 feature bit through flags.
Definition isa.h:176
bool avx512f
Read or update the avx512f feature bit through flags.
Definition isa.h:188
bool sse
Read or update the sse feature bit through flags.
Definition isa.h:175
bool f16c
Read or update the f16c feature bit through flags.
Definition isa.h:185
static constexpr auto feature_count
Number of registered features in this family.
Definition isa.h:127
bool avx512bitalg
Read or update the avx512bitalg feature bit through flags.
Definition isa.h:212
constexpr bool has(polyfill_t) const noexcept
True when semantic emulation or storage decomposition is permitted.
Definition isa.h:135
bool ssse3
Read or update the ssse3 feature bit through flags.
Definition isa.h:178
bool sm3
Read or update the sm3 feature bit through flags.
Definition isa.h:220
bool avxifma
Read or update the avxifma feature bit through flags.
Definition isa.h:217
bool avx512fp16
Read or update the avx512fp16 feature bit through flags.
Definition isa.h:193
bool popcnt
Read or update the popcnt feature bit through flags.
Definition isa.h:181
bool avxneconvert
Read or update the avxneconvert feature bit through flags.
Definition isa.h:222
bool adx
Read or update the adx feature bit through flags.
Definition isa.h:218
bool avx
Read or update the avx feature bit through flags.
Definition isa.h:182
bool sha
Read or update the sha feature bit through flags.
Definition isa.h:215
bool avx512vl
Read or update the avx512vl feature bit through flags.
Definition isa.h:191
bool avx512bf16
Read or update the avx512bf16 feature bit through flags.
Definition isa.h:192
bool avxvnniint8
Read or update the avxvnniint8 feature bit through flags.
Definition isa.h:210
bool avx512ifma
Read or update the avx512ifma feature bit through flags.
Definition isa.h:198
bool fma
Read or update the fma feature bit through flags.
Definition isa.h:184
bool avx512vbmi2
Read or update the avx512vbmi2 feature bit through flags.
Definition isa.h:214
bool avx2
Read or update the avx2 feature bit through flags.
Definition isa.h:183
constexpr bool operator==(isa const &) const =default
Compare hardware bits and emulation permission, retaining NTTP identity.
constexpr isa() noexcept=default
Construct the empty requirement set.
bool aes
Read or update the aes feature bit through flags.
Definition isa.h:194
constexpr bool valid() const noexcept
True when no invalid marker or unregistered padding bit is set.
Definition isa.h:167
bool avxvnniint16
Read or update the avxvnniint16 feature bit through flags.
Definition isa.h:211
bool cx16
Read or update the cx16 feature bit through flags.
Definition isa.h:196
bool sm4
Read or update the sm4 feature bit through flags.
Definition isa.h:221
bool mmx
Read or update the mmx feature bit through flags.
Definition isa.h:174
constexpr bool has(feature_type f) const noexcept
True when the feature is present.
Definition isa.h:158
bool vpclmulqdq
Read or update the vpclmulqdq feature bit through flags.
Definition isa.h:206
constexpr bool has(isa other) const noexcept
Definition isa.h:161
bool sse41
Read or update the sse41 feature bit through flags.
Definition isa.h:179
std::array< std::uint64_t,(feature_count+1+63)/64 > flags
Public structural bits; invalid enum values and padding fail validation.
Definition isa.h:129
bool avx512vnni
Read or update the avx512vnni feature bit through flags.
Definition isa.h:209
bool gfni
Read or update the gfni feature bit through flags.
Definition isa.h:205
static constexpr architecture family
Architecture family, independent of the compiler target.
Definition isa.h:125
bool mwaitx
Read or update the mwaitx feature bit through flags.
Definition isa.h:202
bool sahf
Read or update the sahf feature bit through flags.
Definition isa.h:201
constexpr bool get(feature_type f) const noexcept
Read one feature; out-of-range values are absent.
Definition isa.h:141
bool avx512vbmi
Read or update the avx512vbmi feature bit through flags.
Definition isa.h:213
bool avx512vpopcntdq
Read or update the avx512vpopcntdq feature bit through flags.
Definition isa.h:207
constexpr void set(feature_type f, bool value) noexcept
Definition isa.h:147
bool waitpkg
Read or update the waitpkg feature bit through flags.
Definition isa.h:203
constexpr isa(polyfill_t) noexcept
Construct an empty hardware requirement with emulation permitted.
Definition isa.h:133
bool pclmul
Read or update the pclmul feature bit through flags.
Definition isa.h:195
bool vaes
Read or update the vaes feature bit through flags.
Definition isa.h:216
bool avx512cd
Read or update the avx512cd feature bit through flags.
Definition isa.h:197
bool sse3
Read or update the sse3 feature bit through flags.
Definition isa.h:177
bool avxvnni
Read or update the avxvnni feature bit through flags.
Definition isa.h:208
bool movbe
Read or update the movbe feature bit through flags.
Definition isa.h:200
bool bmi2
Read or update the bmi2 feature bit through flags.
Definition isa.h:187
Admission result for requirements from one architecture family.
Definition isa.h:629
constexpr char const * reason() const noexcept
Definition isa.h:641
constexpr bool admitted() const noexcept
True only when every requested feature and OS state component is present.
Definition isa.h:635
A structural set of one family's features, without prerequisite closure.
Definition isa.h:65
static constexpr auto feature_count
Definition isa.h:71
constexpr bool has(polyfill_t) const noexcept
True when semantic emulation or storage decomposition is permitted.
Definition isa.h:79
constexpr bool has(feature_type f) const noexcept
True when the feature is present.
Definition isa.h:102
constexpr isa(polyfill_t) noexcept
Construct an empty hardware requirement with emulation permitted.
Definition isa.h:77
constexpr isa() noexcept=default
Construct the empty requirement set.
static constexpr architecture family
Definition isa.h:69
constexpr bool operator==(isa const &) const =default
Compare hardware bits and emulation permission, retaining NTTP identity.
bool allow_polyfill
Definition isa.h:75
std::array< std::uint64_t,(feature_count+1+63)/64 > flags
Definition isa.h:73
constexpr void set(feature_type f, bool value) noexcept
Definition isa.h:91
typename detail::feature_traits< Family >::type feature_type
Definition isa.h:67
constexpr bool has(isa other) const noexcept
Definition isa.h:105
constexpr bool get(feature_type f) const noexcept
Read one feature; out-of-range values are absent.
Definition isa.h:85
constexpr bool valid() const noexcept
True when no invalid marker or unregistered padding bit is set.
Definition isa.h:111
waiter using the MONITORX/MWAITX instruction feature
Permission to emulate operations or decompose unsupported SIMD shapes. This is policy,...
Definition isa.h:40
A source variant retains its requested ISA and inherited compiler minimum.
Definition isa.h:798
constexpr bool operator==(target_entry const &) const =default
Compare the requested ISA and inherited compiler minimum exactly.