Struct target_features::Target
source · pub struct Target { /* private fields */ }
Expand description
A target architecture with optional features.
Implementations§
source§impl Target
impl Target
sourcepub const fn suggested_simd_width<T: SimdType>(&self) -> Option<usize>
pub const fn suggested_simd_width<T: SimdType>(&self) -> Option<usize>
Returns a suggested number of elements for a SIMD vector of the provided type.
The returned value is an approximation and not necessarily indicative of the optimal vector width. A few caveats:
- Every instruction set is different, and this function doesn’t take into account any particular operations–it’s just a guess, and should be accurate at least for basic arithmetic.
- Variable length vector instruction sets (ARM SVE and RISC-V V) only return the minimum vector length.
source§impl Target
impl Target
sourcepub const fn new(architecture: Architecture) -> Self
pub const fn new(architecture: Architecture) -> Self
Create a target with no specified features.
sourcepub const fn from_cpu(
architecture: Architecture,
cpu: &str
) -> Result<Self, UnknownCpu>
pub const fn from_cpu( architecture: Architecture, cpu: &str ) -> Result<Self, UnknownCpu>
Create a target based on a particular CPU.
sourcepub const fn architecture(&self) -> Architecture
pub const fn architecture(&self) -> Architecture
Returns the target architecture.
sourcepub const fn features(&self) -> FeaturesIter ⓘ
pub const fn features(&self) -> FeaturesIter ⓘ
Returns an iterator over the features.
sourcepub const fn supports_feature(&self, feature: Feature) -> bool
pub const fn supports_feature(&self, feature: Feature) -> bool
Returns whether the target supports the specified feature.
sourcepub const fn supports_feature_str(&self, feature: &str) -> bool
pub const fn supports_feature_str(&self, feature: &str) -> bool
Returns whether the target supports the specified feature.
§Panics
Panics if the feature doesn’t belong to the target architecture.
Examples found in repository?
65 66 67 68 69 70 71 72 73 74 75 76 77 78
fn safe_avx_fn<P: Proof>(_: P) {
#[target_feature(enable = "avx")]
unsafe fn unsafe_avx_fn() {
println!("called an avx function")
}
// Future improvements to const generics might make it possible to assert this at compile time.
// Since P::TARGET is const, this assert disappears if the required features are present.
assert!(
P::TARGET.supports_feature_str("avx"),
"avx feature not supported"
);
unsafe { unsafe_avx_fn() }
}
sourcepub const fn with_feature(self, feature: Feature) -> Self
pub const fn with_feature(self, feature: Feature) -> Self
Add a feature to the target.
§Panics
Panics if the feature doesn’t belong to the target architecture.
sourcepub const fn with_feature_str(self, feature: &str) -> Self
pub const fn with_feature_str(self, feature: &str) -> Self
Add a feature to the target.
§Panics
Panics if the requested feature name doesn’t exist for the target architecture.