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?
65fn safe_avx_fn<P: Proof>(_: P) {
66 #[target_feature(enable = "avx")]
67 unsafe fn unsafe_avx_fn() {
68 println!("called an avx function")
69 }
70
71 // Future improvements to const generics might make it possible to assert this at compile time.
72 // Since P::TARGET is const, this assert disappears if the required features are present.
73 assert!(
74 P::TARGET.supports_feature_str("avx"),
75 "avx feature not supported"
76 );
77 unsafe { unsafe_avx_fn() }
78}
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.