From 47f9283a937092ba212ad7f3df6183dd7bf1c447 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Thu, 15 Aug 2024 16:22:55 -0700 Subject: [PATCH] mark blake3_xof_many_avx512 Unix-only in Rust and C --- c/blake3_c_rust_bindings/src/lib.rs | 1 + c/blake3_c_rust_bindings/src/test.rs | 1 + c/blake3_dispatch.c | 2 +- c/blake3_impl.h | 2 ++ src/ffi_avx512.rs | 3 +++ src/platform.rs | 1 + 6 files changed, 9 insertions(+), 1 deletion(-) diff --git a/c/blake3_c_rust_bindings/src/lib.rs b/c/blake3_c_rust_bindings/src/lib.rs index ac7880a52..31b7731bc 100644 --- a/c/blake3_c_rust_bindings/src/lib.rs +++ b/c/blake3_c_rust_bindings/src/lib.rs @@ -291,6 +291,7 @@ pub mod ffi { flags_end: u8, out: *mut u8, ); + #[cfg(unix)] pub fn blake3_xof_many_avx512( cv: *const u32, block: *const u8, diff --git a/c/blake3_c_rust_bindings/src/test.rs b/c/blake3_c_rust_bindings/src/test.rs index ec11219a2..da883677a 100644 --- a/c/blake3_c_rust_bindings/src/test.rs +++ b/c/blake3_c_rust_bindings/src/test.rs @@ -425,6 +425,7 @@ fn test_xof_many_portable() { } #[test] +#[cfg(unix)] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn test_xof_many_avx512() { if !crate::avx512_detected() { diff --git a/c/blake3_dispatch.c b/c/blake3_dispatch.c index 725f7ee18..a90c757cb 100644 --- a/c/blake3_dispatch.c +++ b/c/blake3_dispatch.c @@ -230,7 +230,7 @@ void blake3_xof_many(const uint32_t cv[8], uint8_t out[64], size_t outblocks) { #if defined(IS_X86) const enum cpu_feature features = get_cpu_features(); -#if !defined(BLAKE3_NO_AVX512) +#if defined(__unix__) && !defined(BLAKE3_NO_AVX512) if (features & AVX512VL) { blake3_xof_many_avx512(cv, block, block_len, counter, flags, out, outblocks); return; diff --git a/c/blake3_impl.h b/c/blake3_impl.h index 66a170791..abd754677 100644 --- a/c/blake3_impl.h +++ b/c/blake3_impl.h @@ -288,12 +288,14 @@ void blake3_hash_many_avx512(const uint8_t *const *inputs, size_t num_inputs, uint8_t flags, uint8_t flags_start, uint8_t flags_end, uint8_t *out); +#if defined(__unix__) void blake3_xof_many_avx512(const uint32_t cv[8], const uint8_t block[BLAKE3_BLOCK_LEN], uint8_t block_len, uint64_t counter, uint8_t flags, uint8_t* out, size_t outblocks); #endif #endif +#endif #if BLAKE3_USE_NEON == 1 void blake3_hash_many_neon(const uint8_t *const *inputs, size_t num_inputs, diff --git a/src/ffi_avx512.rs b/src/ffi_avx512.rs index d34e53c6c..679477463 100644 --- a/src/ffi_avx512.rs +++ b/src/ffi_avx512.rs @@ -61,6 +61,7 @@ pub unsafe fn hash_many( } // Unsafe because this may only be called on platforms supporting AVX-512. +#[cfg(unix)] pub unsafe fn xof_many( cv: &CVWords, block: &[u8; BLOCK_LEN], @@ -109,6 +110,7 @@ pub mod ffi { flags_end: u8, out: *mut u8, ); + #[cfg(unix)] pub fn blake3_xof_many_avx512( cv: *const u32, block: *const u8, @@ -141,6 +143,7 @@ mod test { crate::test::test_hash_many_fn(hash_many, hash_many); } + #[cfg(unix)] #[test] fn test_xof_many() { if !crate::platform::avx512_detected() { diff --git a/src/platform.rs b/src/platform.rs index 1858addc4..6e4ae2592 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -289,6 +289,7 @@ impl Platform { match self { // Safe because detect() checked for platform support. #[cfg(blake3_avx512_ffi)] + #[cfg(unix)] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] Platform::AVX512 => unsafe { crate::avx512::xof_many(cv, block, block_len, counter, flags, out)