[PATCH] toolchain: allow compiling with -march=native
Rui Salvaterra
rsalvaterra at gmail.com
Tue Nov 10 17:59:20 EST 2020
If the toolchain will only be executed on the system where it is built (or a
system with the exact same CPU), this will squeeze out the last few (single
digit) percent of performance.
Signed-off-by: Rui Salvaterra <rsalvaterra at gmail.com>
---
rules.mk | 2 +-
toolchain/Config.in | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/rules.mk b/rules.mk
index 3214395e1f..e416126030 100644
--- a/rules.mk
+++ b/rules.mk
@@ -249,7 +249,7 @@ export PKG_CONFIG
HOSTCC:=gcc
HOSTCXX:=g++
HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include)
-HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
+HOST_CFLAGS:=$(if $(CONFIG_BUILD_NATIVE_ARCH),-march=native) -O2 $(HOST_CPPFLAGS)
HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib)
ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
diff --git a/toolchain/Config.in b/toolchain/Config.in
index cb557d4ad3..3149d7bc66 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -164,6 +164,14 @@ menuconfig TOOLCHAINOPTS
bool "Toolchain Options" if DEVEL
depends on NEED_TOOLCHAIN
+config BUILD_NATIVE_ARCH
+ def_bool n
+ prompt "Build the toolchain with -march=native" if TOOLCHAINOPTS
+ help
+ When building the toolchain, optimize for the CPU in this specific machine.
+ Only choose Y if you're not going to run the compiled toolchain on any other
+ system.
+
menuconfig EXTRA_TARGET_ARCH
bool
prompt "Enable an extra toolchain target architecture" if TOOLCHAINOPTS
--
2.29.2
More information about the openwrt-devel
mailing list