Skip to content

Commit

Permalink
Merge pull request #55 from jserv/refactor-cpus
Browse files Browse the repository at this point in the history
Check specific CPU features for build environment
  • Loading branch information
jserv committed Aug 6, 2018
2 parents 1c878ec + 0a374ef commit 93e6b89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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)

0 comments on commit 93e6b89

Please sign in to comment.