-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime SIMD detection? #84
Comments
I believe it should be possible. The aes crate uses cpufeatures to detect simd support. |
I spent a good amount of time working on this. First using rust's nightly feature |
Yes, that's a bit annoying, but you can still do something like: foo() {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
if is_x86_feature_detected!("avx2") {
return foo_avx2();
}
}
foo_fallback()
}
#[target_feature(enable = "avx2")]
unsafe fn foo_avx2() {
bar();
baz();
}
#[inline(always)]
fn bar() {
unsafe {
let clr_mask = _mm256_set1_epi8(0x0f);
[...]
}
}
#[inline(always)]
fn baz() { ... }
That's the approach I've taken with the Reed-Solomon library I just published: https://crates.io/crates/reed-solomon-simd Feel free to draw some inspiration from that implementation. The relevant code is here: https://github.com/AndersTrier/reed-solomon-simd/tree/master/src/engine |
Yeah looking at your code it looks possible. We'd need to change the architecture here to something similar to yours. Where there is an underlying abstraction at the highest level (basically as soon as your create a |
Is it possible for this crate to implement runtime SIMD detection, so that portable binaries with SIMD code inside can be published?
The text was updated successfully, but these errors were encountered: