mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-05-11 09:36:09 +02:00
add no_std support
This commit is contained in:
parent
ad97e2b160
commit
daad5a55b6
|
@ -432,7 +432,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_transpose() {
|
||||
if !is_x86_feature_detected!("avx2") {
|
||||
if !crate::platform::avx2_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -464,7 +464,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_parents() {
|
||||
if !is_x86_feature_detected!("avx2") {
|
||||
if !crate::platform::avx2_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -519,7 +519,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_chunks() {
|
||||
if !is_x86_feature_detected!("avx2") {
|
||||
if !crate::platform::avx2_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -596,7 +596,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_hash_many() {
|
||||
if !is_x86_feature_detected!("avx2") {
|
||||
if !crate::platform::avx2_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use arrayref::{array_refs, mut_array_refs};
|
||||
use arrayvec::ArrayString;
|
||||
use core::fmt;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
14
src/sse41.rs
14
src/sse41.rs
|
@ -670,7 +670,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_transpose() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -702,7 +702,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_compress() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -737,7 +737,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_parents() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -784,7 +784,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_chunks() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -853,7 +853,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_hash1_1() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -893,7 +893,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_hash1_3() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -934,7 +934,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_hash_many() {
|
||||
if !is_x86_feature_detected!("sse4.1") {
|
||||
if !crate::platform::sse41_detected() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue