Skip to content

Commit

Permalink
guard adx feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanting Zhang committed Jan 8, 2024
1 parent 0965aeb commit d0aad38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ portable = [ "blst/portable", "semolina/portable" ]
# Binary can be executed on Broadwell+ and Ryzen+ systems.
force-adx = [ "blst/force-adx", "semolina/force-adx" ]
cuda-mobile = []
# Build with __MSM_SORT_DONT_IMPLEMENT__ to prevent redefining
# symbols that breaks compilation during linking.
dont-implement-sort = []

[dependencies]
blst = "~0.3.11"
Expand Down
30 changes: 18 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,26 @@ fn common_build_configurations(cc: &mut cc::Build) {
}

fn determine_cc_def(target_arch: &str, default_def: &str) -> Option<String> {
match (cfg!(feature = "portable"), cfg!(feature = "force-adx")) {
(true, false) => Some(default_def.to_string()),
(false, true) if target_arch == "x86_64" => Some("__ADX__".to_string()),
(false, false)
if target_arch == "x86_64"
&& std::is_x86_feature_detected!("adx") =>
{
Some("__ADX__".to_string())
if cfg!(feature = "portable") && cfg!(feature = "force-adx") {
panic!("Cannot compile with both `portable` and `force-adx` features");
}

if cfg!(feature = "portable") {
return Some(default_def.to_string());
}

if cfg!(feature = "force-adx") && target_arch == "x86_64" {
return Some("__ADX__".to_string());
}

#[cfg(target_arch = "x86_64")]
{
if target_arch == "x86_64" && std::is_x86_feature_detected!("adx") {
return Some("__ADX__".to_string());
}
(true, true) => panic!(
"Cannot compile with both `portable` and `force-adx` features"
),
_ => None,
}

None
}

fn cuda_available() -> bool {
Expand Down

0 comments on commit d0aad38

Please sign in to comment.