diff mbox series

toolchain: allow compiling with -march=native

Message ID 20201110225920.1030302-1-rsalvaterra@gmail.com
State Under Review
Delegated to: Rui Salvaterra
Headers show
Series toolchain: allow compiling with -march=native | expand

Commit Message

Rui Salvaterra Nov. 10, 2020, 10:59 p.m. UTC
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@gmail.com>
---
 rules.mk            | 2 +-
 toolchain/Config.in | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

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