Skip to main content

archmage/tokens/generated/
x86_avx512.rs

1//! Generated from token-registry.toml — DO NOT EDIT.
2//!
3//! Regenerate with: cargo xtask generate
4
5use super::x86::X64V2Token;
6use super::x86::X64V3Token;
7use crate::tokens::SimdToken;
8use crate::tokens::{Has128BitSimd, Has256BitSimd, Has512BitSimd, HasX64V2, HasX64V4};
9
10/// Proof that AVX-512 (F + CD + VL + DQ + BW) is available.
11///
12/// This is the complete x86-64-v4 AVX-512 feature set, available on:
13/// - Intel Skylake-X (2017+), Ice Lake, Sapphire Rapids
14/// - AMD Zen 4+ (2022+)
15///
16/// Note: Intel 12th-14th gen consumer CPUs do NOT have AVX-512.
17#[derive(Clone, Copy, Debug)]
18pub struct X64V4Token {
19    _private: (),
20}
21
22impl SimdToken for X64V4Token {
23    const NAME: &'static str = "AVX-512";
24
25    #[inline(always)]
26    fn try_new() -> Option<Self> {
27        if crate::is_x86_feature_available!("sse3")
28            && crate::is_x86_feature_available!("ssse3")
29            && crate::is_x86_feature_available!("sse4.1")
30            && crate::is_x86_feature_available!("sse4.2")
31            && crate::is_x86_feature_available!("popcnt")
32            && crate::is_x86_feature_available!("avx")
33            && crate::is_x86_feature_available!("avx2")
34            && crate::is_x86_feature_available!("fma")
35            && crate::is_x86_feature_available!("bmi1")
36            && crate::is_x86_feature_available!("bmi2")
37            && crate::is_x86_feature_available!("f16c")
38            && crate::is_x86_feature_available!("lzcnt")
39            && crate::is_x86_feature_available!("avx512f")
40            && crate::is_x86_feature_available!("avx512bw")
41            && crate::is_x86_feature_available!("avx512cd")
42            && crate::is_x86_feature_available!("avx512dq")
43            && crate::is_x86_feature_available!("avx512vl")
44        {
45            Some(unsafe { Self::forge_token_dangerously() })
46        } else {
47            None
48        }
49    }
50
51    #[inline(always)]
52    unsafe fn forge_token_dangerously() -> Self {
53        Self { _private: () }
54    }
55}
56
57impl X64V4Token {
58    /// Get a X64V3Token (AVX-512 implies x86-64-v3)
59    #[inline(always)]
60    pub fn v3(self) -> X64V3Token {
61        unsafe { X64V3Token::forge_token_dangerously() }
62    }
63    /// Get a X64V2Token (AVX-512 implies x86-64-v2)
64    #[inline(always)]
65    pub fn v2(self) -> X64V2Token {
66        unsafe { X64V2Token::forge_token_dangerously() }
67    }
68}
69
70/// Proof that modern AVX-512 features are available (Ice Lake / Zen 4 level).
71///
72/// This includes all of `X64V4Token` (F+CD+VL+DQ+BW) plus:
73/// - VPOPCNTDQ, IFMA, VBMI, VBMI2, BITALG, VNNI, BF16
74/// - VPCLMULQDQ, GFNI, VAES
75///
76/// Available on Intel Ice Lake (2019+), Sapphire Rapids, AMD Zen 4+.
77/// NOT available on Skylake-X (lacks VBMI2, VNNI, BF16, etc.).
78#[derive(Clone, Copy, Debug)]
79pub struct Avx512ModernToken {
80    _private: (),
81}
82
83impl SimdToken for Avx512ModernToken {
84    const NAME: &'static str = "AVX-512Modern";
85
86    #[inline(always)]
87    fn try_new() -> Option<Self> {
88        if crate::is_x86_feature_available!("sse3")
89            && crate::is_x86_feature_available!("ssse3")
90            && crate::is_x86_feature_available!("sse4.1")
91            && crate::is_x86_feature_available!("sse4.2")
92            && crate::is_x86_feature_available!("popcnt")
93            && crate::is_x86_feature_available!("avx")
94            && crate::is_x86_feature_available!("avx2")
95            && crate::is_x86_feature_available!("fma")
96            && crate::is_x86_feature_available!("bmi1")
97            && crate::is_x86_feature_available!("bmi2")
98            && crate::is_x86_feature_available!("f16c")
99            && crate::is_x86_feature_available!("lzcnt")
100            && crate::is_x86_feature_available!("avx512f")
101            && crate::is_x86_feature_available!("avx512bw")
102            && crate::is_x86_feature_available!("avx512cd")
103            && crate::is_x86_feature_available!("avx512dq")
104            && crate::is_x86_feature_available!("avx512vl")
105            && crate::is_x86_feature_available!("avx512vpopcntdq")
106            && crate::is_x86_feature_available!("avx512ifma")
107            && crate::is_x86_feature_available!("avx512vbmi")
108            && crate::is_x86_feature_available!("avx512vbmi2")
109            && crate::is_x86_feature_available!("avx512bitalg")
110            && crate::is_x86_feature_available!("avx512vnni")
111            && crate::is_x86_feature_available!("avx512bf16")
112            && crate::is_x86_feature_available!("vpclmulqdq")
113            && crate::is_x86_feature_available!("gfni")
114            && crate::is_x86_feature_available!("vaes")
115        {
116            Some(unsafe { Self::forge_token_dangerously() })
117        } else {
118            None
119        }
120    }
121
122    #[inline(always)]
123    unsafe fn forge_token_dangerously() -> Self {
124        Self { _private: () }
125    }
126}
127
128impl Avx512ModernToken {
129    /// Get a X64V4Token (AVX-512Modern implies AVX-512)
130    #[inline(always)]
131    pub fn v4(self) -> X64V4Token {
132        unsafe { X64V4Token::forge_token_dangerously() }
133    }
134
135    /// Get a X64V4Token (alias for `.v4()`)
136    #[inline(always)]
137    pub fn avx512(self) -> X64V4Token {
138        unsafe { X64V4Token::forge_token_dangerously() }
139    }
140    /// Get a X64V3Token (AVX-512Modern implies x86-64-v3)
141    #[inline(always)]
142    pub fn v3(self) -> X64V3Token {
143        unsafe { X64V3Token::forge_token_dangerously() }
144    }
145    /// Get a X64V2Token (AVX-512Modern implies x86-64-v2)
146    #[inline(always)]
147    pub fn v2(self) -> X64V2Token {
148        unsafe { X64V2Token::forge_token_dangerously() }
149    }
150}
151
152/// Proof that AVX-512 FP16 (half-precision) is available.
153///
154/// AVX-512 FP16 provides native 16-bit floating-point arithmetic in 512-bit
155/// vectors, enabling efficient ML inference and scientific computing.
156///
157/// Available on Intel Sapphire Rapids (2023+), Emerald Rapids.
158/// NOT available on Skylake-X, Ice Lake, AMD Zen 4.
159#[derive(Clone, Copy, Debug)]
160pub struct Avx512Fp16Token {
161    _private: (),
162}
163
164impl SimdToken for Avx512Fp16Token {
165    const NAME: &'static str = "AVX-512FP16";
166
167    #[inline(always)]
168    fn try_new() -> Option<Self> {
169        if crate::is_x86_feature_available!("sse3")
170            && crate::is_x86_feature_available!("ssse3")
171            && crate::is_x86_feature_available!("sse4.1")
172            && crate::is_x86_feature_available!("sse4.2")
173            && crate::is_x86_feature_available!("popcnt")
174            && crate::is_x86_feature_available!("avx")
175            && crate::is_x86_feature_available!("avx2")
176            && crate::is_x86_feature_available!("fma")
177            && crate::is_x86_feature_available!("bmi1")
178            && crate::is_x86_feature_available!("bmi2")
179            && crate::is_x86_feature_available!("f16c")
180            && crate::is_x86_feature_available!("lzcnt")
181            && crate::is_x86_feature_available!("avx512f")
182            && crate::is_x86_feature_available!("avx512bw")
183            && crate::is_x86_feature_available!("avx512cd")
184            && crate::is_x86_feature_available!("avx512dq")
185            && crate::is_x86_feature_available!("avx512vl")
186            && crate::is_x86_feature_available!("avx512fp16")
187        {
188            Some(unsafe { Self::forge_token_dangerously() })
189        } else {
190            None
191        }
192    }
193
194    #[inline(always)]
195    unsafe fn forge_token_dangerously() -> Self {
196        Self { _private: () }
197    }
198}
199
200impl Avx512Fp16Token {
201    /// Get a X64V4Token (AVX-512FP16 implies AVX-512)
202    #[inline(always)]
203    pub fn v4(self) -> X64V4Token {
204        unsafe { X64V4Token::forge_token_dangerously() }
205    }
206
207    /// Get a X64V4Token (alias for `.v4()`)
208    #[inline(always)]
209    pub fn avx512(self) -> X64V4Token {
210        unsafe { X64V4Token::forge_token_dangerously() }
211    }
212    /// Get a X64V3Token (AVX-512FP16 implies x86-64-v3)
213    #[inline(always)]
214    pub fn v3(self) -> X64V3Token {
215        unsafe { X64V3Token::forge_token_dangerously() }
216    }
217    /// Get a X64V2Token (AVX-512FP16 implies x86-64-v2)
218    #[inline(always)]
219    pub fn v2(self) -> X64V2Token {
220        unsafe { X64V2Token::forge_token_dangerously() }
221    }
222}
223
224/// Type alias for [`X64V4Token`].
225pub type Avx512Token = X64V4Token;
226
227/// Type alias for [`X64V4Token`].
228pub type Server64 = X64V4Token;
229
230impl Has128BitSimd for X64V4Token {}
231impl Has128BitSimd for Avx512ModernToken {}
232impl Has128BitSimd for Avx512Fp16Token {}
233impl Has256BitSimd for X64V4Token {}
234impl Has256BitSimd for Avx512ModernToken {}
235impl Has256BitSimd for Avx512Fp16Token {}
236impl Has512BitSimd for X64V4Token {}
237impl Has512BitSimd for Avx512ModernToken {}
238impl Has512BitSimd for Avx512Fp16Token {}
239impl HasX64V2 for X64V4Token {}
240impl HasX64V2 for Avx512ModernToken {}
241impl HasX64V2 for Avx512Fp16Token {}
242impl HasX64V4 for X64V4Token {}
243impl HasX64V4 for Avx512ModernToken {}
244impl HasX64V4 for Avx512Fp16Token {}