Skip to content

Commit

Permalink
mark blake3_xof_many_avx512 Unix-only in Rust and C
Browse files Browse the repository at this point in the history
  • Loading branch information
oconnor663 committed Aug 15, 2024
1 parent bb2c530 commit 47f9283
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions c/blake3_c_rust_bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions c/blake3_c_rust_bindings/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion c/blake3_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions c/blake3_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/ffi_avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub unsafe fn hash_many<const N: usize>(
}

// 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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 47f9283

Please sign in to comment.