Skip to content

Commit 3c3fd36

Browse files
committed
Fixup the generator and mostly finalize levels
1 parent bfda1c7 commit 3c3fd36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1220
-106
lines changed

fearless_simd_core/gen/src/main.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn generate_x86_level(
150150

151151
let level_struct_name = level.to_uppercase();
152152
// The target_feature(enable = "...") string.
153-
let lcd_contents = lcd.join(", ");
153+
let lcd_contents = lcd.join(",");
154154
// The fields of the new struct.
155155
let lcd_field_definitions = lcd
156156
.iter()
@@ -159,11 +159,13 @@ fn generate_x86_level(
159159
.iter()
160160
.find(|it| it.feature.feature_name == *feature)
161161
.unwrap();
162-
let type_path = format!(
163-
"crate::x86::{}::{}",
164-
normalized.feature.module, normalized.feature.struct_name
165-
);
166-
format!("{feature}: {type_path},\n")
162+
let type_path = format!("crate::x86::{level}::{}", normalized.feature.struct_name);
163+
let feature = feature.replace(".", "_");
164+
format!(
165+
"/// The contained proof that {} is available.\n\
166+
pub {feature}: {type_path},\n",
167+
normalized.feature.feature_docs_name
168+
)
167169
})
168170
.collect::<String>();
169171
// The enabled FEATURES.
@@ -180,14 +182,12 @@ fn generate_x86_level(
180182
.iter()
181183
.find(|it| it.feature.feature_name == *feature)
182184
.unwrap();
183-
let type_path = format!(
184-
"crate::x86::{}::{}",
185-
normalized.feature.module, normalized.feature.struct_name
186-
);
185+
let type_path = format!("crate::x86::{level}::{}", normalized.feature.struct_name);
186+
let feature = feature.replace(".", "_");
187187
format!("{type_path} = self.{feature}")
188188
})
189189
.collect::<Vec<_>>()
190-
.join(",");
190+
.join(", ");
191191
// The version of the struct initializer in `try_new`.
192192
let struct_initializer_try_new = lcd
193193
.iter()
@@ -196,10 +196,8 @@ fn generate_x86_level(
196196
.iter()
197197
.find(|it| it.feature.feature_name == *feature)
198198
.unwrap();
199-
let type_path = format!(
200-
"crate::x86::{}::{}",
201-
normalized.feature.module, normalized.feature.struct_name
202-
);
199+
let type_path = format!("crate::x86::{level}::{}", normalized.feature.struct_name);
200+
let feature = feature.replace(".", "_");
203201
// We rely on rustfmt to get the tab spacing right.
204202
format!("\t{feature}: {type_path}::try_new()?,\n")
205203
})
@@ -212,10 +210,8 @@ fn generate_x86_level(
212210
.iter()
213211
.find(|it| it.feature.feature_name == *feature)
214212
.unwrap();
215-
let type_path = format!(
216-
"crate::x86::{}::{}",
217-
normalized.feature.module, normalized.feature.struct_name
218-
);
213+
let type_path = format!("crate::x86::{level}::{}", normalized.feature.struct_name);
214+
let feature = feature.replace(".", "_");
219215
format!("\t{feature}: {type_path}::new(),\n")
220216
})
221217
.collect::<String>();
@@ -226,10 +222,7 @@ fn generate_x86_level(
226222
.iter()
227223
.find(|it| it.feature.feature_name == *child)
228224
.unwrap();
229-
let type_path = format!(
230-
"crate::x86::{}::{}",
231-
from_feature.feature.module, from_feature.feature.struct_name
232-
);
225+
let type_path = format!("crate::x86::{level}::{}", from_feature.feature.struct_name);
233226
write!(
234227
from_impls,
235228
"\n\
@@ -249,6 +242,9 @@ impl From<LEVEL_STRUCT_NAME> for {type_path} {{
249242
);
250243
// We replace the from impls first, as they use template variables from the rest of this.
251244
result = result.replace("/*{FROM_IMPLS}*/", &from_impls);
245+
result = result.replace("LEVEL_STRUCT_NAME", &level_struct_name);
246+
result = result.replace("{LEVEL_ID}", level);
247+
result = result.replace("{LEVEL_FEATURE_LCD_CONTENTS}", &lcd_contents);
252248
result = result.replace(
253249
"/*{LEVEL_FEATURE_LCD_FIELD_DEFINITIONS}*/",
254250
&lcd_field_definitions,

fearless_simd_core/gen/templates/x86_level.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ impl LEVEL_STRUCT_NAME {
8181
}
8282
}
8383
}
84+
// TODO: From impls to convert into lower x86 versions.
85+
8486
/*{FROM_IMPLS}*/
8587

8688
const _: () = {

fearless_simd_core/src/x86/adx/adx.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ impl Debug for Adx {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Adx {
4143
const FEATURES: &[&str] = &["adx"];
4244

4345
#[inline(always)]
4446
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
45-
// Because we want this constant to be eagerly evaluated.
47+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
48+
// This means we can't use `Self = self` here, unfortunately.
4649
trampoline!([Adx = self] => "adx", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
4750
}
4851
}

fearless_simd_core/src/x86/avx/avx.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ impl Debug for Avx {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avx {
4143
const FEATURES: &[&str] = &["avx", "sse", "sse2", "sse3", "sse4.1", "sse4.2", "ssse3"];
4244

4345
#[inline(always)]
4446
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
45-
// Because we want this constant to be eagerly evaluated.
47+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
48+
// This means we can't use `Self = self` here, unfortunately.
4649
trampoline!([Avx = self] => "avx", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
4750
}
4851
}

fearless_simd_core/src/x86/avx/avx2.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ impl Debug for Avx2 {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avx2 {
4143
const FEATURES: &[&str] = &[
4244
"avx2", "avx", "sse", "sse2", "sse3", "sse4.1", "sse4.2", "ssse3",
4345
];
4446

4547
#[inline(always)]
4648
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
47-
// Because we want this constant to be eagerly evaluated.
49+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
50+
// This means we can't use `Self = self` here, unfortunately.
4851
trampoline!([Avx2 = self] => "avx2", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
4952
}
5053
}

fearless_simd_core/src/x86/avx/avxifma.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ impl Debug for Avxifma {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avxifma {
4143
const FEATURES: &[&str] = &[
4244
"avxifma", "avx", "avx2", "sse", "sse2", "sse3", "sse4.1", "sse4.2", "ssse3",
4345
];
4446

4547
#[inline(always)]
4648
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
47-
// Because we want this constant to be eagerly evaluated.
49+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
50+
// This means we can't use `Self = self` here, unfortunately.
4851
trampoline!([Avxifma = self] => "avxifma", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
4952
}
5053
}

fearless_simd_core/src/x86/avx/avxneconvert.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ impl Debug for Avxneconvert {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avxneconvert {
4143
const FEATURES: &[&str] = &[
4244
"avxneconvert",
@@ -52,7 +54,8 @@ unsafe impl TargetFeatureToken for Avxneconvert {
5254

5355
#[inline(always)]
5456
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
55-
// Because we want this constant to be eagerly evaluated.
57+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
58+
// This means we can't use `Self = self` here, unfortunately.
5659
trampoline!([Avxneconvert = self] => "avxneconvert", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
5760
}
5861
}

fearless_simd_core/src/x86/avx/avxvnni.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ impl Debug for Avxvnni {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avxvnni {
4143
const FEATURES: &[&str] = &[
4244
"avxvnni", "avx", "avx2", "sse", "sse2", "sse3", "sse4.1", "sse4.2", "ssse3",
4345
];
4446

4547
#[inline(always)]
4648
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
47-
// Because we want this constant to be eagerly evaluated.
49+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
50+
// This means we can't use `Self = self` here, unfortunately.
4851
trampoline!([Avxvnni = self] => "avxvnni", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
4952
}
5053
}

fearless_simd_core/src/x86/avx/avxvnniint16.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ impl Debug for Avxvnniint16 {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avxvnniint16 {
4143
const FEATURES: &[&str] = &[
4244
"avxvnniint16",
@@ -52,7 +54,8 @@ unsafe impl TargetFeatureToken for Avxvnniint16 {
5254

5355
#[inline(always)]
5456
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
55-
// Because we want this constant to be eagerly evaluated.
57+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
58+
// This means we can't use `Self = self` here, unfortunately.
5659
trampoline!([Avxvnniint16 = self] => "avxvnniint16", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
5760
}
5861
}

fearless_simd_core/src/x86/avx/avxvnniint8.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ impl Debug for Avxvnniint8 {
3737
}
3838
}
3939

40+
// Safety: This token can only be constructed if you have proof that all the requisite
41+
// target feature is enabled.
4042
unsafe impl TargetFeatureToken for Avxvnniint8 {
4143
const FEATURES: &[&str] = &[
4244
"avxvnniint8",
@@ -52,7 +54,8 @@ unsafe impl TargetFeatureToken for Avxvnniint8 {
5254

5355
#[inline(always)]
5456
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
55-
// Because we want this constant to be eagerly evaluated.
57+
// Because we need the safety check to be eagerly evaluated, it uses an constant item.
58+
// This means we can't use `Self = self` here, unfortunately.
5659
trampoline!([Avxvnniint8 = self] => "avxvnniint8", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
5760
}
5861
}

0 commit comments

Comments
 (0)