diff options
| author | Jack O'Connor <[email protected]> | 2019-12-03 13:44:30 -0500 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2019-12-03 13:44:30 -0500 |
| commit | daad5a55b6e98fdd1b9ae42f311cc6532db630f6 (patch) | |
| tree | 32c16ed0b9a7455b4d3eca8c6297afaf3f5ec9f9 /src/platform.rs | |
| parent | ad97e2b1601c43cbd65e638e2664da2b5548c6d5 (diff) | |
add no_std support
Diffstat (limited to 'src/platform.rs')
| -rw-r--r-- | src/platform.rs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/platform.rs b/src/platform.rs index 439346f..5723e17 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -21,10 +21,10 @@ impl Platform { pub fn detect() -> Self { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { - if is_x86_feature_detected!("avx2") { + if avx2_detected() { return Platform::AVX2; } - if is_x86_feature_detected!("sse4.1") { + if sse41_detected() { return Platform::SSE41; } } @@ -114,3 +114,39 @@ impl Platform { } } } + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[inline(always)] +pub fn avx2_detected() -> bool { + // Static check, e.g. for building with target-cpu=native. + #[cfg(target_feature = "avx2")] + { + return true; + } + // Dyanmic check, if std is enabled. + #[cfg(feature = "std")] + { + if is_x86_feature_detected!("avx2") { + return true; + } + } + false +} + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[inline(always)] +pub fn sse41_detected() -> bool { + // Static check, e.g. for building with target-cpu=native. + #[cfg(target_feature = "sse4.1")] + { + return true; + } + // Dyanmic check, if std is enabled. + #[cfg(feature = "std")] + { + if is_x86_feature_detected!("sse4.1") { + return true; + } + } + false +} |
