Skip to content

Commit b7162dd

Browse files
committed
Add the generated x86 code
1 parent 9ccc7b5 commit b7162dd

Some content is hidden

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

65 files changed

+7455
-6
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// This file is automatically generated by `fearless_simd_core_gen`.
2+
// Its template can be found in `fearless_simd_core/gen/templates`.
3+
4+
//! The ADX target feature.
5+
6+
use crate::{TargetFeatureToken, trampoline};
7+
8+
use core::fmt::Debug;
9+
10+
/// [ADX] --- Multi-Precision Add-Carry Instruction Extensions
11+
///
12+
/// [ADX]: https://en.wikipedia.org/wiki/Intel_ADX
13+
///
14+
/// A token indicating that the current CPU has the `adx` target feature.
15+
///
16+
/// # Example
17+
///
18+
/// This can be used to [`trampoline!`] into functions like:
19+
///
20+
/// ```rust
21+
/// #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
22+
/// #[target_feature(enable = "adx")]
23+
/// fn uses_adx() {
24+
/// // ...
25+
/// }
26+
/// ```
27+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
28+
pub struct Adx {
29+
// We don't use non_exhaustive because we don't want this struct to be constructible.
30+
// in different modules in this crate.
31+
_private: (),
32+
}
33+
34+
impl Debug for Adx {
35+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36+
write!(f, r#""adx" enabled."#)
37+
}
38+
}
39+
40+
unsafe impl TargetFeatureToken for Adx {
41+
const FEATURES: &[&str] = &["adx"];
42+
43+
#[inline(always)]
44+
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
45+
// Because we want this constant to be eagerly evaluated.
46+
trampoline!([Adx = self] => "adx", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
47+
}
48+
}
49+
50+
impl Adx {
51+
#[cfg(feature = "std")]
52+
/// Create a new token if the `"adx"` target feature is detected as enabled.
53+
///
54+
/// This does not do any caching internally, although note that the standard
55+
/// library does internally cache the features it detects.
56+
// TODO: Consider a manual override feature/env var?
57+
pub fn try_new() -> Option<Self> {
58+
// Feature flag required to make docs compile.
59+
// TODO: Extract into a (private) crate::x86::is_x86_feature_detected?
60+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
61+
if std::arch::is_x86_feature_detected!("adx") {
62+
// Safety: The required CPU feature was detected.
63+
unsafe { Some(Self::new()) }
64+
} else {
65+
None
66+
}
67+
}
68+
69+
#[target_feature(enable = "adx")]
70+
/// Create a new token for the "adx" target feature.
71+
///
72+
/// This method is useful to get a new token if you have an external proof that
73+
/// ADX is available. This could happen if you are in a target feature
74+
/// function called by an external library user.
75+
///
76+
/// # Safety
77+
///
78+
/// No conditions other than those inherited from the target feature attribute,
79+
/// i.e. that the "adx" target feature is available.
80+
///
81+
/// [implicitly enables]: https://doc.rust-lang.org/beta/reference/attributes/codegen.html?highlight=implicitly%20enabled#r-attributes.codegen.target_feature.safety-restrictions
82+
pub fn new() -> Self {
83+
Self { _private: () }
84+
}
85+
}
86+
87+
const _: () = {
88+
assert!(
89+
core::mem::size_of::<Adx>() == 0,
90+
"Target feature tokens should be zero sized."
91+
);
92+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! The "adx" target feature.
2+
3+
#[expect(
4+
clippy::module_inception,
5+
reason = "The inner module is automatically generated."
6+
)]
7+
mod adx;
8+
pub use adx::Adx;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// This file is automatically generated by `fearless_simd_core_gen`.
2+
// Its template can be found in `fearless_simd_core/gen/templates`.
3+
4+
//! The AVX target feature.
5+
6+
use crate::{TargetFeatureToken, trampoline};
7+
8+
use core::fmt::Debug;
9+
10+
/// [AVX] --- Advanced Vector Extensions
11+
///
12+
/// [AVX]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
13+
///
14+
/// A token indicating that the current CPU has the `avx` target feature.
15+
///
16+
/// # Example
17+
///
18+
/// This can be used to [`trampoline!`] into functions like:
19+
///
20+
/// ```rust
21+
/// #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
22+
/// #[target_feature(enable = "avx")]
23+
/// fn uses_avx() {
24+
/// // ...
25+
/// }
26+
/// ```
27+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
28+
pub struct Avx {
29+
// We don't use non_exhaustive because we don't want this struct to be constructible.
30+
// in different modules in this crate.
31+
_private: (),
32+
}
33+
34+
impl Debug for Avx {
35+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36+
write!(f, r#""avx" enabled."#)
37+
}
38+
}
39+
40+
unsafe impl TargetFeatureToken for Avx {
41+
const FEATURES: &[&str] = &["avx", "sse", "sse2", "sse3", "sse4.1", "sse4.2", "ssse3"];
42+
43+
#[inline(always)]
44+
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
45+
// Because we want this constant to be eagerly evaluated.
46+
trampoline!([Avx = self] => "avx", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
47+
}
48+
}
49+
50+
impl Avx {
51+
#[cfg(feature = "std")]
52+
/// Create a new token if the `"avx"` target feature is detected as enabled.
53+
///
54+
/// This does not do any caching internally, although note that the standard
55+
/// library does internally cache the features it detects.
56+
// TODO: Consider a manual override feature/env var?
57+
pub fn try_new() -> Option<Self> {
58+
// Feature flag required to make docs compile.
59+
// TODO: Extract into a (private) crate::x86::is_x86_feature_detected?
60+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
61+
if std::arch::is_x86_feature_detected!("avx") {
62+
// Safety: The required CPU feature was detected.
63+
unsafe { Some(Self::new()) }
64+
} else {
65+
None
66+
}
67+
}
68+
69+
#[target_feature(enable = "avx")]
70+
/// Create a new token for the "avx" target feature.
71+
///
72+
/// This method is useful to get a new token if you have an external proof that
73+
/// AVX is available. This could happen if you are in a target feature
74+
/// function called by an external library user.
75+
///
76+
/// # Safety
77+
///
78+
/// No conditions other than those inherited from the target feature attribute,
79+
/// i.e. that the "avx" target feature is available.
80+
///
81+
/// [implicitly enables]: https://doc.rust-lang.org/beta/reference/attributes/codegen.html?highlight=implicitly%20enabled#r-attributes.codegen.target_feature.safety-restrictions
82+
pub fn new() -> Self {
83+
Self { _private: () }
84+
}
85+
}
86+
87+
impl From<Avx> for crate::x86::sse::Sse {
88+
fn from(value: Avx) -> Self {
89+
// This also serves as a correctness check of the implicitly enabled features.
90+
trampoline!([Avx = value] => "avx", fn() -> crate::x86::sse::Sse { crate::x86::sse::Sse::new() })
91+
}
92+
}
93+
94+
impl From<Avx> for crate::x86::sse::Sse2 {
95+
fn from(value: Avx) -> Self {
96+
// This also serves as a correctness check of the implicitly enabled features.
97+
trampoline!([Avx = value] => "avx", fn() -> crate::x86::sse::Sse2 { crate::x86::sse::Sse2::new() })
98+
}
99+
}
100+
101+
impl From<Avx> for crate::x86::sse::Sse3 {
102+
fn from(value: Avx) -> Self {
103+
// This also serves as a correctness check of the implicitly enabled features.
104+
trampoline!([Avx = value] => "avx", fn() -> crate::x86::sse::Sse3 { crate::x86::sse::Sse3::new() })
105+
}
106+
}
107+
108+
impl From<Avx> for crate::x86::sse::Sse4_1 {
109+
fn from(value: Avx) -> Self {
110+
// This also serves as a correctness check of the implicitly enabled features.
111+
trampoline!([Avx = value] => "avx", fn() -> crate::x86::sse::Sse4_1 { crate::x86::sse::Sse4_1::new() })
112+
}
113+
}
114+
115+
impl From<Avx> for crate::x86::sse::Sse4_2 {
116+
fn from(value: Avx) -> Self {
117+
// This also serves as a correctness check of the implicitly enabled features.
118+
trampoline!([Avx = value] => "avx", fn() -> crate::x86::sse::Sse4_2 { crate::x86::sse::Sse4_2::new() })
119+
}
120+
}
121+
122+
impl From<Avx> for crate::x86::sse::SupplementalSse3 {
123+
fn from(value: Avx) -> Self {
124+
// This also serves as a correctness check of the implicitly enabled features.
125+
trampoline!([Avx = value] => "avx", fn() -> crate::x86::sse::SupplementalSse3 { crate::x86::sse::SupplementalSse3::new() })
126+
}
127+
}
128+
129+
const _: () = {
130+
assert!(
131+
core::mem::size_of::<Avx>() == 0,
132+
"Target feature tokens should be zero sized."
133+
);
134+
};
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// This file is automatically generated by `fearless_simd_core_gen`.
2+
// Its template can be found in `fearless_simd_core/gen/templates`.
3+
4+
//! The AVX2 target feature.
5+
6+
use crate::{TargetFeatureToken, trampoline};
7+
8+
use core::fmt::Debug;
9+
10+
/// [AVX2] --- Advanced Vector Extensions 2
11+
///
12+
/// [AVX2]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#AVX2
13+
///
14+
/// A token indicating that the current CPU has the `avx2` target feature.
15+
///
16+
/// # Example
17+
///
18+
/// This can be used to [`trampoline!`] into functions like:
19+
///
20+
/// ```rust
21+
/// #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
22+
/// #[target_feature(enable = "avx2")]
23+
/// fn uses_avx2() {
24+
/// // ...
25+
/// }
26+
/// ```
27+
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
28+
pub struct Avx2 {
29+
// We don't use non_exhaustive because we don't want this struct to be constructible.
30+
// in different modules in this crate.
31+
_private: (),
32+
}
33+
34+
impl Debug for Avx2 {
35+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36+
write!(f, r#""avx2" enabled."#)
37+
}
38+
}
39+
40+
unsafe impl TargetFeatureToken for Avx2 {
41+
const FEATURES: &[&str] = &[
42+
"avx2", "avx", "sse", "sse2", "sse3", "sse4.1", "sse4.2", "ssse3",
43+
];
44+
45+
#[inline(always)]
46+
fn vectorize<R>(self, f: impl FnOnce() -> R) -> R {
47+
// Because we want this constant to be eagerly evaluated.
48+
trampoline!([Avx2 = self] => "avx2", <(R)> fn<(R)>(f: impl FnOnce() -> R = f) -> R { f() })
49+
}
50+
}
51+
52+
impl Avx2 {
53+
#[cfg(feature = "std")]
54+
/// Create a new token if the `"avx2"` target feature is detected as enabled.
55+
///
56+
/// This does not do any caching internally, although note that the standard
57+
/// library does internally cache the features it detects.
58+
// TODO: Consider a manual override feature/env var?
59+
pub fn try_new() -> Option<Self> {
60+
// Feature flag required to make docs compile.
61+
// TODO: Extract into a (private) crate::x86::is_x86_feature_detected?
62+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
63+
if std::arch::is_x86_feature_detected!("avx2") {
64+
// Safety: The required CPU feature was detected.
65+
unsafe { Some(Self::new()) }
66+
} else {
67+
None
68+
}
69+
}
70+
71+
#[target_feature(enable = "avx2")]
72+
/// Create a new token for the "avx2" target feature.
73+
///
74+
/// This method is useful to get a new token if you have an external proof that
75+
/// AVX2 is available. This could happen if you are in a target feature
76+
/// function called by an external library user.
77+
///
78+
/// # Safety
79+
///
80+
/// No conditions other than those inherited from the target feature attribute,
81+
/// i.e. that the "avx2" target feature is available.
82+
///
83+
/// [implicitly enables]: https://doc.rust-lang.org/beta/reference/attributes/codegen.html?highlight=implicitly%20enabled#r-attributes.codegen.target_feature.safety-restrictions
84+
pub fn new() -> Self {
85+
Self { _private: () }
86+
}
87+
}
88+
89+
impl From<Avx2> for crate::x86::avx::Avx {
90+
fn from(value: Avx2) -> Self {
91+
// This also serves as a correctness check of the implicitly enabled features.
92+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::avx::Avx { crate::x86::avx::Avx::new() })
93+
}
94+
}
95+
96+
impl From<Avx2> for crate::x86::sse::Sse {
97+
fn from(value: Avx2) -> Self {
98+
// This also serves as a correctness check of the implicitly enabled features.
99+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::sse::Sse { crate::x86::sse::Sse::new() })
100+
}
101+
}
102+
103+
impl From<Avx2> for crate::x86::sse::Sse2 {
104+
fn from(value: Avx2) -> Self {
105+
// This also serves as a correctness check of the implicitly enabled features.
106+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::sse::Sse2 { crate::x86::sse::Sse2::new() })
107+
}
108+
}
109+
110+
impl From<Avx2> for crate::x86::sse::Sse3 {
111+
fn from(value: Avx2) -> Self {
112+
// This also serves as a correctness check of the implicitly enabled features.
113+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::sse::Sse3 { crate::x86::sse::Sse3::new() })
114+
}
115+
}
116+
117+
impl From<Avx2> for crate::x86::sse::Sse4_1 {
118+
fn from(value: Avx2) -> Self {
119+
// This also serves as a correctness check of the implicitly enabled features.
120+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::sse::Sse4_1 { crate::x86::sse::Sse4_1::new() })
121+
}
122+
}
123+
124+
impl From<Avx2> for crate::x86::sse::Sse4_2 {
125+
fn from(value: Avx2) -> Self {
126+
// This also serves as a correctness check of the implicitly enabled features.
127+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::sse::Sse4_2 { crate::x86::sse::Sse4_2::new() })
128+
}
129+
}
130+
131+
impl From<Avx2> for crate::x86::sse::SupplementalSse3 {
132+
fn from(value: Avx2) -> Self {
133+
// This also serves as a correctness check of the implicitly enabled features.
134+
trampoline!([Avx2 = value] => "avx2", fn() -> crate::x86::sse::SupplementalSse3 { crate::x86::sse::SupplementalSse3::new() })
135+
}
136+
}
137+
138+
const _: () = {
139+
assert!(
140+
core::mem::size_of::<Avx2>() == 0,
141+
"Target feature tokens should be zero sized."
142+
);
143+
};

0 commit comments

Comments
 (0)