1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
//! x86-v4 backend: AVX-512, parameterized by which AVX-512 sub-extensions the
//! target CPU actually has.
//!
//! AVX-512 is not one ISA. It is a foundation (F) plus a dozen optional
//! extensions that shipped in different years on different parts, so a single
//! `X86V4` backend would either target the lowest common denominator (Knights
//! Landing, 2016) or refuse to run on most AVX-512 hardware. Instead the
//! backend is generic over [`Avx512Features`]: one body of register code, with
//! `if const { F::AVX512VBMI }`-style forks selecting the best encoding the
//! instantiated tier allows. Everything folds at monomorphization, like the
//! `HAS_TRUE_FMA` / `HAS_APPROX_RCP` capability gates.
//!
//! The four rungs below are this crate's, not Intel's -- there is no official
//! "tier" concept. They match, exactly:
//!
//! - the `avx512-tier1..4` crate features,
//! - the `arch::tiers::tierN` intrinsic modules in [`crate::backend::x86`],
//! - [`Avx512Tier`] and `Features::avx512_tier`, which report what the
//! *hardware* reaches.
//!
//! | Tier | Struct | Adds | Silicon | SDE flag |
//! |---|---|---|---|---|
//! | 1 | [`Tier1`] | F + CD | Knights Landing/Mill (dead) | `-knl` |
//! | 2 | [`Tier2`] | + BW + DQ + VL | Skylake-SP, Cascade Lake | `-skx` |
//! | 3 | [`Tier3`] | + VBMI, VBMI2, VNNI, BITALG, VPOPCNTDQ, IFMA, GFNI, VAES, VPCLMULQDQ | Ice Lake, Tiger Lake, Zen 4 | `-icx` |
//! | 4 | [`Tier4`] | + BF16 | Sapphire Rapids, Granite Rapids, Zen 4/5 | `-spr` |
//!
//! Tier 2 is the one that matters most. VL is not new operations but the EVEX
//! encodings (masking, zero-masking, embedded broadcast, registers 16-31)
//! applied to XMM/YMM instead of ZMM only, which turns the `_c`/`_m`/`_z`
//! variants into single masked instructions at the register widths thermite
//! already uses, rather than only on new 512-bit ones.
//!
//! A const being `true` here does not make the intrinsic callable: the
//! `#[target_feature(enable = ...)]` set the dispatch macro emits for this
//! backend must enable the same feature, or the fork it guards fails to
//! compile. The two lists are maintained by hand, in
//! `thermite-macros/src/dispatch.rs` and here.
use crateAvx512Tier;
/// Which AVX-512 sub-extensions a given instantiation of the x86-v4 backend may
/// use.
///
/// Every const is a compile-time answer to "may I emit this instruction here?".
/// Register code reads them through `if const { ... }`, so a disabled feature
/// costs nothing at runtime -- the branch is gone before codegen.
///
/// Implementors are the ZSTs [`Tier1`]..[`Tier4`]. The supertraits mirror what
/// [`NativeIsa`](crate::simd::NativeIsa) demands of a backend marker, since
/// `X86V4` carries this one as a parameter.
/// Tier 1: F + CD only. Exactly the Knights Landing set (which also had the
/// long-dead ER and PF).
///
/// 512-bit or nothing: without VL there are no EVEX encodings at 128/256-bit,
/// so this tier cannot accelerate the `f32x4`/`f32x8` registers thermite
/// already has -- only new 512-bit ones. The hardware is extinct (Knights
/// Landing/Mill were discontinued in 2018-2019) and no other part ever shipped
/// F without BW/DQ/VL, so tier 2 is the realistic floor.
;
/// Tier 2: + BW + DQ + VL. The Skylake-SP set, and what nearly everyone means
/// by "has AVX-512".
///
/// The first tier that pays off for existing code: VL makes the `_c`/`_m`/`_z`
/// masked variants single instructions on the 128/256-bit registers, and BW
/// covers the 8/16-bit lane families.
;
/// Tier 3: + VBMI, VBMI2, VNNI, BITALG, VPOPCNTDQ, IFMA, GFNI, VAES,
/// VPCLMULQDQ. Ice Lake (2019) and later, and Zen 4 on the AMD side.
///
/// Adds lane-crossing byte permutes (VBMI), per-byte popcount (BITALG), 52-bit
/// integer FMA (IFMA), and GFNI's affine transform as a general bit permute.
;
/// Tier 4: + BF16. Sapphire Rapids, Granite Rapids, Zen 4/5.
///
/// Deliberately does **not** require AVX512-FP16 (see
/// [`Avx512Features::AVX512FP16`]) -- that would exclude every AMD part.
///
/// Watch out for Cooper Lake: it has BF16 *without* the tier-3 set, so it
/// reports [`Avx512Tier::Tier2`] and never selects this tier. That is the one
/// part the linear ladder cannot place.
;
;