Skip to content

Commit 545c2b1

Browse files
authored
Add -mavx2 on Haswell only if the compiler supports it
1 parent 69d2064 commit 545c2b1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

kernel/Makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ endif
55
TOPDIR = ..
66
include $(TOPDIR)/Makefile.system
77

8+
AVX2OPT =
9+
ifeq ($(C_COMPILER), GCC)
10+
# AVX2 support was added in 4.7.0
11+
GCCVERSIONGTEQ4 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 4)
12+
GCCMINORVERSIONGTEQ7 := $(shell expr `$(CC) -dumpversion | cut -f2 -d.` \>= 7)
13+
ifeq ($(GCCVERSIONGTEQ4)$(GCCMINORVERSIONGTEQ7), 11)
14+
AVX2OPT = -mavx2
15+
endif
16+
endif
17+
ifeq ($(C_COMPILER), CLANG)
18+
# Any clang posing as gcc 4.2 should be new enough (3.4 or later)
19+
GCCVERSIONGTEQ4 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 4)
20+
GCCMINORVERSIONGTEQ2 := $(shell expr `$(CC) -dumpversion | cut -f2 -d.` \>= 2)
21+
ifeq ($(GCCVERSIONGTEQ4)$(GCCMINORVERSIONGTEQ2), 11)
22+
AVX2OPT -mavx2
23+
endif
24+
endif
25+
ifdef NO_AVX2
26+
AVX2OPT=
27+
endif
28+
829
ifdef TARGET_CORE
930
ifeq ($(TARGET_CORE), SKYLAKEX)
1031
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE) -march=skylake-avx512
@@ -17,9 +38,9 @@ ifeq ($(TARGET_CORE), SKYLAKEX)
1738
endif
1839
endif
1940
else ifeq($(TARGET_CORE), HASWELL)
20-
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE) -mavx2
41+
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE) $(AVX2OPT)
2142
else
22-
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE)
43+
override CFLAGS += -DBUILD_KERNEL -DTABLE_NAME=gotoblas_$(TARGET_CORE)
2344
endif
2445
BUILD_KERNEL = 1
2546
KDIR =

0 commit comments

Comments
 (0)