-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linux-aarch64 doesn't seem to have -march=native either #95
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me
Hmm, my rpi4 builds fine with
This feels a little clunky to disable |
Using is_like_clang() looked promising to filter out |
How about something like this in build.rs? diff --git a/build.rs b/build.rs
index 431f5fb..7bf7016 100644
--- a/build.rs
+++ b/build.rs
@@ -158,12 +158,7 @@ fn write_tables() {
not(any(target_os = "android", target_os = "ios"))
))]
fn compile_simd_c() {
- let mut build = cc::Build::new();
- build.opt_level(3);
-
- // `-march=native` is not supported on Apple M1
- #[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
- {
+ let flag_arch = {
fn guess_target_cpu() -> String {
// Copied and adapted from https://github.com/alexcrichton/proc-macro2/blob/4173a21dc497c67326095e438ff989cc63cd9279/build.rs#L115
// Licensed under Apache-2.0 + MIT (compatible because we're MIT)
@@ -181,7 +176,37 @@ fn compile_simd_c() {
"native".to_string()
}
- build.flag(&format!("-march={}", guess_target_cpu()));
+ format!("-march={}", guess_target_cpu())
+ };
+
+ let build_arch_test_c =
+ std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("build-arch-test.c");
+
+ std::fs::OpenOptions::new()
+ .create(true)
+ .write(true)
+ .open(&build_arch_test_c)
+ .unwrap();
+
+ let mut build = cc::Build::new();
+ build.opt_level(3).flag("-std=c11").file(&build_arch_test_c);
+
+ let mut build_with_arch = build.clone();
+ build_with_arch.flag(&flag_arch);
+
+ // Test if the `-march` flag works for this compiler
+ let use_build_arch = if build_with_arch.try_compile("build-arch-test").is_ok() {
+ true
+ } else if build.try_compile("build-arch-test").is_ok() {
+ false
+ } else {
+ panic!("Unable to compile test file");
+ };
+
+ let mut build = cc::Build::new();
+ build.opt_level(3);
+ if use_build_arch {
+ build.flag(&flag_arch);
}
build
.flag("-std=c11") |
I'm wondering how much does it actually help in terms of performance. Maybe we can place it under feature flag or remove instead? |
thanks for the opportunity to learn more :) I really wonder if there's a reason why |
I'm not sure how the codegen differs on aarch64 with/without I'm not overly opposed to this PR as is, the simplicity of it is nice. aarch64 for my usage is development only, so potentially less optimal code for this architecture wouldn't bother me, we only use x86_86 in production currently.
Seems that this is ultimately just a |
Why? Did you benchmark that it is significantly slower without that? |
No, because I didn’t benchmark it so I don’t know! |
OK, I did some quick testing. Removing Though using Since there is code that already checks Every app developer has to decide which flags they want and since performance is so different, if we were to remove this behavior, new major version would be needed and a section in readme about optimizations users might want to apply to get the best performance. |
@mvines let's go with the test approach you suggested above for now |
closes #94
and yep, it lets me build solana on my overdrive box.