From 33249c872fce5171e29b985959c03b217fd031d0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 12 Nov 2023 11:41:41 +0530 Subject: [PATCH] Use a better default march for binary builds x86-64-v2 implies SSE4.2 which should be available everywhere by now. We will see if we get errors with it. https://developers.redhat.com/blog/2021/01/05/building-red-hat-enterprise-linux-9-for-the-x86-64-v2-microarchitecture-level#architectural_considerations_for_rhel_9 --- setup.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index a56bf9f12..be67cddde 100755 --- a/setup.py +++ b/setup.py @@ -416,10 +416,6 @@ def init_env( vcs_rev: str = '', ) -> Env: native_optimizations = native_optimizations and not sanitize - if native_optimizations and is_macos and is_arm: - # see https://github.com/kovidgoyal/kitty/issues/3126 - # -march=native is not supported when targeting Apple Silicon - native_optimizations = False cc, ccver = cc_version() if verbose: print('CC:', cc, ccver) @@ -447,7 +443,6 @@ def init_env( werror = '' if ignore_compiler_warnings else '-pedantic-errors -Werror' std = '' if is_openbsd else '-std=c11' sanitize_flag = ' '.join(sanitize_args) - march = '-march=native' if native_optimizations else '' # Using -mbranch-protection=standard causes crashes on Linux ARM, reported # in https://github.com/kovidgoyal/kitty/issues/6845#issuecomment-1835886938 arm_control_flow_protection = '-mbranch-protection=standard' if is_macos else '' @@ -459,6 +454,16 @@ def init_env( env_ldflags = shlex.split(os.environ.get('LDFLAGS', '')) if control_flow_protection and not test_compile(cc, control_flow_protection, *env_cppflags, *env_cflags, ldflags=env_ldflags): control_flow_protection = '' + march = '' + if is_macos and is_arm: + # see https://github.com/kovidgoyal/kitty/issues/3126 + # -march=native is not supported when targeting Apple Silicon + pass + else: + if native_optimizations: + march = '-march=native -mtune=native' + elif sys.maxsize > 2**32 and not is_arm: # 64 bit Intel + march = '-march=x86-64-v2 -mtune=generic' cflags_ = os.environ.get( 'OVERRIDE_CFLAGS', ( f'-Wextra {float_conversion} -Wno-missing-field-initializers -Wall -Wstrict-prototypes {std}'