Spaces:
Running
Running
Przemysław Pawełczyk
commited on
make : improve cpuinfo handling on x86 hosts (#1238)
Browse files* make : simplify and correct x86 ISA extensions detection on the host
It got broken in commit c5f9acf4b797 for Haiku and Mac OS (Intel),
which report CPU features in upper case.
Now we're finding the names in case-insensitive manner and as words.
SSE3 detection has been corrected for Linux, which uses PNI for that
(Prescott New Instructions).
* make : use dmesg.boot in FreeBSD/DragonFlyBSD to detect x86 ISA extensions on the host
* make : enable x86 ISA extensions on the host both in CFLAGS and CXXFLAGS
* make : correct AVX x86 ISA extension detection on macOS (Intel) host
It got broken in commit c5f9acf4b797. macOS calls it AVX1.0.
Makefile
CHANGED
|
@@ -65,57 +65,57 @@ endif
|
|
| 65 |
# Architecture specific
|
| 66 |
# TODO: probably these flags need to be tweaked on some architectures
|
| 67 |
# feel free to update the Makefile for your architecture and send a pull request or issue
|
| 68 |
-
ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686))
|
| 69 |
ifeq ($(UNAME_S),Darwin)
|
| 70 |
CPUINFO_CMD := sysctl machdep.cpu.features
|
| 71 |
else ifeq ($(UNAME_S),Linux)
|
| 72 |
CPUINFO_CMD := cat /proc/cpuinfo
|
| 73 |
else ifneq (,$(filter MINGW32_NT% MINGW64_NT%,$(UNAME_S)))
|
| 74 |
CPUINFO_CMD := cat /proc/cpuinfo
|
|
|
|
|
|
|
| 75 |
else ifeq ($(UNAME_S),Haiku)
|
| 76 |
CPUINFO_CMD := sysinfo -cpu
|
| 77 |
endif
|
| 78 |
|
| 79 |
-
ifdef CPUINFO_CMD
|
| 80 |
-
|
| 81 |
-
ifneq (,$(
|
| 82 |
-
CFLAGS
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
AVX2_M := $(shell $(CPUINFO_CMD) | grep -m 1 "avx2 ")
|
| 86 |
-
ifneq (,$(findstring avx2,$(AVX2_M)))
|
| 87 |
-
CFLAGS += -mavx2
|
| 88 |
endif
|
| 89 |
|
| 90 |
-
|
| 91 |
-
ifneq (,$(
|
| 92 |
-
CFLAGS
|
|
|
|
| 93 |
endif
|
| 94 |
|
| 95 |
-
|
| 96 |
-
ifneq (,$(
|
| 97 |
-
CFLAGS
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
endif
|
| 104 |
|
| 105 |
-
SSE3_M := $(shell $(CPUINFO_CMD) | grep -
|
| 106 |
-
ifneq (,$(
|
| 107 |
-
CFLAGS
|
|
|
|
| 108 |
endif
|
| 109 |
|
| 110 |
-
SSSE3_M := $(shell $(CPUINFO_CMD) | grep -
|
| 111 |
-
ifneq (,$(
|
| 112 |
-
CFLAGS
|
|
|
|
| 113 |
endif
|
| 114 |
endif
|
| 115 |
endif
|
| 116 |
-
ifeq ($(UNAME_M),amd64)
|
| 117 |
-
CFLAGS += -mavx -mavx2 -mfma -mf16c
|
| 118 |
-
endif
|
| 119 |
|
| 120 |
ifneq ($(filter ppc64%,$(UNAME_M)),)
|
| 121 |
POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
|
|
|
|
| 65 |
# Architecture specific
|
| 66 |
# TODO: probably these flags need to be tweaked on some architectures
|
| 67 |
# feel free to update the Makefile for your architecture and send a pull request or issue
|
| 68 |
+
ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
|
| 69 |
ifeq ($(UNAME_S),Darwin)
|
| 70 |
CPUINFO_CMD := sysctl machdep.cpu.features
|
| 71 |
else ifeq ($(UNAME_S),Linux)
|
| 72 |
CPUINFO_CMD := cat /proc/cpuinfo
|
| 73 |
else ifneq (,$(filter MINGW32_NT% MINGW64_NT%,$(UNAME_S)))
|
| 74 |
CPUINFO_CMD := cat /proc/cpuinfo
|
| 75 |
+
else ifneq (,$(filter DragonFly FreeBSD,$(UNAME_S)))
|
| 76 |
+
CPUINFO_CMD := grep Features /var/run/dmesg.boot
|
| 77 |
else ifeq ($(UNAME_S),Haiku)
|
| 78 |
CPUINFO_CMD := sysinfo -cpu
|
| 79 |
endif
|
| 80 |
|
| 81 |
+
ifdef CPUINFO_CMD
|
| 82 |
+
AVX_M := $(shell $(CPUINFO_CMD) | grep -iwE 'AVX|AVX1.0')
|
| 83 |
+
ifneq (,$(AVX_M))
|
| 84 |
+
CFLAGS += -mavx
|
| 85 |
+
CXXFLAGS += -mavx
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
endif
|
| 87 |
|
| 88 |
+
AVX2_M := $(shell $(CPUINFO_CMD) | grep -iw 'AVX2')
|
| 89 |
+
ifneq (,$(AVX2_M))
|
| 90 |
+
CFLAGS += -mavx2
|
| 91 |
+
CXXFLAGS += -mavx2
|
| 92 |
endif
|
| 93 |
|
| 94 |
+
FMA_M := $(shell $(CPUINFO_CMD) | grep -iw 'FMA')
|
| 95 |
+
ifneq (,$(FMA_M))
|
| 96 |
+
CFLAGS += -mfma
|
| 97 |
+
CXXFLAGS += -mfma
|
| 98 |
+
endif
|
| 99 |
|
| 100 |
+
F16C_M := $(shell $(CPUINFO_CMD) | grep -iw 'F16C')
|
| 101 |
+
ifneq (,$(F16C_M))
|
| 102 |
+
CFLAGS += -mf16c
|
| 103 |
+
CXXFLAGS += -mf16c
|
| 104 |
endif
|
| 105 |
|
| 106 |
+
SSE3_M := $(shell $(CPUINFO_CMD) | grep -iwE 'PNI|SSE3')
|
| 107 |
+
ifneq (,$(SSE3_M))
|
| 108 |
+
CFLAGS += -msse3
|
| 109 |
+
CXXFLAGS += -msse3
|
| 110 |
endif
|
| 111 |
|
| 112 |
+
SSSE3_M := $(shell $(CPUINFO_CMD) | grep -iw 'SSSE3')
|
| 113 |
+
ifneq (,$(SSSE3_M))
|
| 114 |
+
CFLAGS += -mssse3
|
| 115 |
+
CXXFLAGS += -mssse3
|
| 116 |
endif
|
| 117 |
endif
|
| 118 |
endif
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
ifneq ($(filter ppc64%,$(UNAME_M)),)
|
| 121 |
POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
|