-
Notifications
You must be signed in to change notification settings - Fork 287
XSAVE, CPUID, Runtime AVX-512 and ARM support #175
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c197560
[stdsimd-test] testing conditional on more than one feature
gnzlbg 400c50e
[x86] implement xsave intrinsics
gnzlbg 8503aca
[x86] implement __read/write eflags
gnzlbg 111b367
[x86] implement cpuid intrinsics
gnzlbg 10f430f
[x86] cleanup run-time; add SSE4a, AVX-512, and xsave
gnzlbg 65d597b
[cpuid] Improve docs, implement __get_cpuid_max
gnzlbg 582758a
[ci] add intel_sde feature
gnzlbg 2aa0e81
[arm] runtime-detection support
gnzlbg 8d92d15
[clippy] fix missing doc on pub item
gnzlbg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! Run-time feature detection on ARM Aarch64. | ||
use super::{bit, linux}; | ||
|
||
#[macro_export] | ||
#[doc(hidden)] | ||
macro_rules! __unstable_detect_feature { | ||
("neon") => { | ||
// FIXME: this should be removed once we rename Aarch64 neon to asimd | ||
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::asimd{}) | ||
}; | ||
("asimd") => { | ||
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::asimd{}) | ||
}; | ||
("pmull") => { | ||
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::pmull{}) | ||
}; | ||
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) }; | ||
} | ||
|
||
/// ARM Aarch64 CPU Feature enum. Each variant denotes a position in a bitset | ||
/// for a particular feature. | ||
/// | ||
/// PLEASE: do not use this, it is an implementation detail subject to change. | ||
#[doc(hidden)] | ||
#[allow(non_camel_case_types)] | ||
#[repr(u8)] | ||
pub enum __Feature { | ||
/// ARM Advanced SIMD (ASIMD) - Aarch64 | ||
asimd, | ||
/// Polynomial Multiply | ||
pmull, | ||
} | ||
|
||
pub fn detect_features<T: linux::FeatureQuery>(mut x: T) -> usize { | ||
let value: usize = 0; | ||
{ | ||
let mut enable_feature = |f| { | ||
if x.has_feature(&f) { | ||
bit::set(value, f as u32); | ||
} | ||
}; | ||
enable_feature(__Feature::asimd); | ||
enable_feature(__Feature::pmull); | ||
} | ||
value | ||
} | ||
|
||
impl linux::FeatureQuery for linux::CpuInfo { | ||
fn has_feature(&mut self, x: &__Feature) -> bool { | ||
use self::__Feature::*; | ||
match *x { | ||
asimd => self.field("Features").has("asimd"), | ||
pmull => self.field("Features").has("pmull"), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Run-time feature detection on ARM Aarch32. | ||
|
||
use super::{bit, linux}; | ||
|
||
#[macro_export] | ||
#[doc(hidden)] | ||
macro_rules! __unstable_detect_feature { | ||
("neon") => { | ||
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::neon{}) | ||
}; | ||
("pmull") => { | ||
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::pmull{}) | ||
}; | ||
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) }; | ||
} | ||
|
||
/// ARM CPU Feature enum. Each variant denotes a position in a bitset for a | ||
/// particular feature. | ||
/// | ||
/// PLEASE: do not use this, it is an implementation detail subject to change. | ||
#[doc(hidden)] | ||
#[allow(non_camel_case_types)] | ||
#[repr(u8)] | ||
pub enum __Feature { | ||
/// ARM Advanced SIMD (NEON) - Aarch32 | ||
neon, | ||
/// Polynomial Multiply | ||
pmull, | ||
} | ||
|
||
pub fn detect_features<T: linux::FeatureQuery>(mut x: T) -> usize { | ||
let value: usize = 0; | ||
{ | ||
let mut enable_feature = |f| { | ||
if x.has_feature(&f) { | ||
bit::set(value, f as u32); | ||
} | ||
}; | ||
enable_feature(__Feature::neon); | ||
enable_feature(__Feature::pmull); | ||
} | ||
value | ||
} | ||
|
||
/// Is the CPU known to have a broken NEON unit? | ||
/// | ||
/// See https://crbug.com/341598. | ||
fn has_broken_neon(cpuinfo: &linux::CpuInfo) -> bool { | ||
cpuinfo.field("CPU implementer") == "0x51" | ||
&& cpuinfo.field("CPU architecture") == "7" | ||
&& cpuinfo.field("CPU variant") == "0x1" | ||
&& cpuinfo.field("CPU part") == "0x04d" | ||
&& cpuinfo.field("CPU revision") == "0" | ||
} | ||
|
||
impl linux::FeatureQuery for linux::CpuInfo { | ||
fn has_feature(&mut self, x: &__Feature) -> bool { | ||
use self::__Feature::*; | ||
match *x { | ||
neon => { | ||
self.field("Features").has("neon") && !has_broken_neon(self) | ||
} | ||
pmull => self.field("Features").has("pmull"), | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Bit manipulation utilities | ||
|
||
/// Sets the `bit` of `x`. | ||
pub const fn set(x: usize, bit: u32) -> usize { | ||
x | 1 << bit | ||
} | ||
|
||
/// Tests the `bit` of `x`. | ||
pub const fn test(x: usize, bit: u32) -> bool { | ||
x & (1 << bit) != 0 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! Cache of run-time feature detection | ||
|
||
use super::bit; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
/// This global variable is a bitset used to cache the features supported by | ||
/// the | ||
/// CPU. | ||
static CACHE: AtomicUsize = AtomicUsize::new(::std::usize::MAX); | ||
|
||
/// Test the `bit` of the storage. If the storage has not been initialized, | ||
/// initializes it with the result of `f()`. | ||
/// | ||
/// On its first invocation, it detects the CPU features and caches them in the | ||
/// `FEATURES` global variable as an `AtomicUsize`. | ||
/// | ||
/// It uses the `__Feature` variant to index into this variable as a bitset. If | ||
/// the bit is set, the feature is enabled, and otherwise it is disabled. | ||
/// | ||
/// PLEASE: do not use this, it is an implementation detail subject to change. | ||
pub fn test<F>(bit: u32, f: F) -> bool | ||
where | ||
F: FnOnce() -> usize, | ||
{ | ||
if CACHE.load(Ordering::Relaxed) == ::std::usize::MAX { | ||
CACHE.store(f(), Ordering::Relaxed); | ||
} | ||
bit::test(CACHE.load(Ordering::Relaxed), bit) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you get a chance, could you add documentation here for what
intel_sde
is?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll add a comment to the Cargo.toml.