Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check specific CPU features for build environment #55

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ else
CFLAGS += -Ofast
endif

SSE_S := $(shell grep -o sse /proc/cpuinfo | head -n 1)
# Check specific CPU features available on build host
include mk/cpu-features.mk

# FIXME: avoid hardcoded architecture flags. We might support advanced SIMD
# instructions for Intel and Arm later.
ifeq ("$(BUILD_AVX)","1")
CFLAGS += -mavx -mavx2 -DENABLE_AVX
else
ifeq ("$(BUILD_SSE)"_$(SSE_S),"1"_sse)
BUILD_SSE := $(call cpu_feature,SSE)
ifeq ("$(BUILD_SSE)","1")
CFLAGS += -msse2 -DENABLE_SSE
endif
endif
Expand All @@ -52,7 +52,7 @@ TESTS += \
pow_avx \
multi_pow_cpu
else
ifeq ("$(BUILD_SSE)"_$(SSE_S),"1"_sse)
ifeq ("$(BUILD_SSE)","1")
TESTS += \
pow_sse \
multi_pow_cpu
Expand Down Expand Up @@ -90,7 +90,7 @@ OBJS = \
ifeq ("$(BUILD_AVX)","1")
OBJS += pow_avx.o
else
ifeq ("$(BUILD_SSE)"_$(SSE_S),"1"_sse)
ifeq ("$(BUILD_SSE)","1")
OBJS += pow_sse.o
else
OBJS += pow_c.o
Expand Down
10 changes: 10 additions & 0 deletions mk/cpu-features.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
# macOS
FEATURES := sysctl machdep.cpu.features
else
# Linux
FEATURES := cat /proc/cpuinfo
endif

cpu_feature = $(shell $(FEATURES) | grep -oi $1 >/dev/null && echo 1 || echo 0)