https://github.com/calebzulawski/arch-types
CPU feature detection types for Rust
https://github.com/calebzulawski/arch-types
cpu-detection cpu-features cpuid simd
Last synced: 7 months ago
JSON representation
CPU feature detection types for Rust
- Host: GitHub
- URL: https://github.com/calebzulawski/arch-types
- Owner: calebzulawski
- License: apache-2.0
- Created: 2020-05-11T04:46:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T16:54:59.000Z (over 5 years ago)
- Last Synced: 2025-01-18T02:40:40.126Z (9 months ago)
- Topics: cpu-detection, cpu-features, cpuid, simd
- Language: Rust
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
arch-types
==========
[](https://github.com/calebzulawski/arch-types/actions)
Type-level CPU feature detection using a tag dispatch model.
The following example uses a type that proves AVX support to make an AVX function safe to call:
```rust
use arch_types::{impl_features, new_features_type, Features};#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[target_feature(enable = "avx")]
unsafe fn foo_unsafe() {
println!("hello from AVX!");
}#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn foo_safe(_: impl_features!("avx")) {
unsafe { foo_unsafe() } // the trait bound ensures we support AVX
}#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn main() {
new_features_type! { Avx => "avx" }
if let Some(handle) = Avx::new() {
foo_safe(handle)
}
}
```The following fails to compile due to missing AVX support:
```rust
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn main() {
new_features_type! { NotAvx => "sse" }
if let Some(handle) = NotAvx::new() {
foo_safe(handle)
}
}
```
## License
arch-types is distributed under the terms of both the MIT license and the Apache License (Version 2.0).See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.