Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ fn build_avx512_c_intrinsics() {
// This is required on 32-bit x86 targets, since the assembly
// implementation doesn't support those.
println!("cargo:rustc-cfg=blake3_avx512_ffi");
println!("cargo:rustc-cfg=blake3_avx512_ffi_intrinsics");
let mut build = new_build();
build.file("c/blake3_avx512.c");
if is_windows_msvc() {
Expand All @@ -256,6 +257,7 @@ fn build_avx512_assembly() {
// only supports x86_64.
assert!(is_x86_64());
println!("cargo:rustc-cfg=blake3_avx512_ffi");
println!("cargo:rustc-cfg=blake3_avx512_ffi_assembly");
let mut build = new_build();
let mut is_msvc = false;
if is_windows_target() {
Expand All @@ -279,6 +281,7 @@ fn build_avx512_assembly() {
}

fn build_neon_c_intrinsics() {
println!("cargo:rustc-cfg=blake3_neon_ffi");
let mut build = new_build();
// Note that blake3_neon.c normally depends on the blake3_portable.c
// for the single-instance compression function, but we expose
Expand Down Expand Up @@ -310,7 +313,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"blake3_avx2_ffi",
"blake3_avx2_rust",
"blake3_avx512_ffi",
"blake3_neon",
"blake3_avx512_ffi_assembly",
"blake3_avx512_ffi_intrinsics",
"blake3_neon_ffi",
"blake3_wasm32_simd",
];
for cfg_name in all_cfgs {
Expand Down Expand Up @@ -353,7 +358,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if (is_arm() && is_neon())
|| (!is_no_neon() && !is_pure() && is_aarch64() && is_little_endian())
{
println!("cargo:rustc-cfg=blake3_neon");
build_neon_c_intrinsics();
}

Expand Down
4 changes: 4 additions & 0 deletions src/ffi_avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub unsafe fn hash_many<const N: usize>(
}

pub mod ffi {
#[cfg_attr(
blake3_avx2_ffi,
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
)]
extern "C" {
pub fn blake3_hash_many_avx2(
inputs: *const *const u8,
Expand Down
8 changes: 8 additions & 0 deletions src/ffi_avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ pub unsafe fn xof_many(
}

pub mod ffi {
#[cfg_attr(
blake3_avx512_ffi_assembly,
link(name = "blake3_avx512_assembly", kind = "static")
)]
#[cfg_attr(
blake3_avx512_ffi_intrinsics,
link(name = "blake3_avx512_intrinsics", kind = "static")
)]
extern "C" {
pub fn blake3_compress_in_place_avx512(
cv: *mut u32,
Expand Down
1 change: 1 addition & 0 deletions src/ffi_neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub extern "C" fn blake3_compress_in_place_portable(
}

pub mod ffi {
#[cfg_attr(blake3_neon_ffi, link(name = "blake3_neon", kind = "static"))]
extern "C" {
pub fn blake3_hash_many_neon(
inputs: *const *const u8,
Expand Down
4 changes: 4 additions & 0 deletions src/ffi_sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ pub unsafe fn hash_many<const N: usize>(
}

pub mod ffi {
#[cfg_attr(
blake3_sse2_ffi,
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these extensions have assembly implementations and intrinsics implementations, which we switch between with --feature prefer_intrinsics. Do they all need the same treatment as AVX-512?

More broadly, could you help me understand what the link(...) attribute actually means :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started digging into this and actually now I have questions about why the compiler seems to correctly forward native libraries dependencies through the crate graph if they come from #[link( but not if they come from command line arguments. I've poked some other compiler people, and I'll try to get back to you soon.

)]
extern "C" {
pub fn blake3_compress_in_place_sse2(
cv: *mut u32,
Expand Down
4 changes: 4 additions & 0 deletions src/ffi_sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ pub unsafe fn hash_many<const N: usize>(
}

pub mod ffi {
#[cfg_attr(
blake3_sse41_ffi,
link(name = "blake3_sse2_sse41_avx2_assembly", kind = "static")
)]
extern "C" {
pub fn blake3_compress_in_place_sse41(
cv: *mut u32,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod avx2;
#[cfg(blake3_avx512_ffi)]
#[path = "ffi_avx512.rs"]
mod avx512;
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
#[path = "ffi_neon.rs"]
mod neon;
mod portable;
Expand Down
18 changes: 9 additions & 9 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cfg_if::cfg_if! {
pub const MAX_SIMD_DEGREE: usize = 8;
}
}
} else if #[cfg(blake3_neon)] {
} else if #[cfg(blake3_neon_ffi)] {
pub const MAX_SIMD_DEGREE: usize = 4;
} else if #[cfg(blake3_wasm32_simd)] {
pub const MAX_SIMD_DEGREE: usize = 4;
Expand All @@ -32,7 +32,7 @@ cfg_if::cfg_if! {
pub const MAX_SIMD_DEGREE_OR_2: usize = 8;
}
}
} else if #[cfg(blake3_neon)] {
} else if #[cfg(blake3_neon_ffi)] {
pub const MAX_SIMD_DEGREE_OR_2: usize = 4;
} else if #[cfg(blake3_wasm32_simd)] {
pub const MAX_SIMD_DEGREE_OR_2: usize = 4;
Expand All @@ -53,7 +53,7 @@ pub enum Platform {
#[cfg(blake3_avx512_ffi)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
AVX512,
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
NEON,
#[cfg(blake3_wasm32_simd)]
#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Platform {
}
// We don't use dynamic feature detection for NEON. If the "neon"
// feature is on, NEON is assumed to be supported.
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
{
return Platform::NEON;
}
Expand All @@ -111,7 +111,7 @@ impl Platform {
#[cfg(blake3_avx512_ffi)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX512 => 16,
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
Platform::NEON => 4,
#[cfg(blake3_wasm32_simd)]
Platform::WASM32_SIMD => 4,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Platform {
crate::avx512::compress_in_place(cv, block, block_len, counter, flags)
},
// No NEON compress_in_place() implementation yet.
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
Platform::NEON => portable::compress_in_place(cv, block, block_len, counter, flags),
#[cfg(blake3_wasm32_simd)]
Platform::WASM32_SIMD => {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Platform {
crate::avx512::compress_xof(cv, block, block_len, counter, flags)
},
// No NEON compress_xof() implementation yet.
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
Platform::NEON => portable::compress_xof(cv, block, block_len, counter, flags),
#[cfg(blake3_wasm32_simd)]
Platform::WASM32_SIMD => {
Expand Down Expand Up @@ -282,7 +282,7 @@ impl Platform {
)
},
// Assumed to be safe if the "neon" feature is on.
#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
Platform::NEON => unsafe {
crate::neon::hash_many(
inputs,
Expand Down Expand Up @@ -390,7 +390,7 @@ impl Platform {
}
}

#[cfg(blake3_neon)]
#[cfg(blake3_neon_ffi)]
pub fn neon() -> Option<Self> {
// Assumed to be safe if the "neon" feature is on.
Some(Self::NEON)
Expand Down
Loading