Skip to content

Commit

Permalink
Fix issue #26 CPU optimization flag detection does not work on aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Sep 17, 2024
1 parent 4dde7ad commit 45e1311
Showing 1 changed file with 56 additions and 34 deletions.
90 changes: 56 additions & 34 deletions Ratatouille/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# check on which OS we build
UNAME_S := $(shell uname -s)
# check which architecture we build on
UNAME_M := $(shell uname -m)
# check which architecture we build for
TARGET_ARCH = UNKNOWN
# check if user is root
user = $(shell whoami)
ifeq ($(user),root)
Expand All @@ -9,32 +13,56 @@
INSTALL_DIR = ~/.lv2
endif


# check if clang is available
ifeq ($(TARGET), Linux)
CXX_VERSION = $(shell clang++ --version 2>/dev/null)
ifneq ($(CXX_VERSION),)
CXX := clang++
endif
endif

# check which architecture we build for
TARGET_ARCH = $(shell $(CXX) -dumpmachine | sed 's/-.*//')

# get flags supported by CPU
ifeq ($(UNAME_S), FreeBSD)
CPU_INFO = dmesg | grep Features | tr A-Z a-z
ifeq ($(UNAME_M), amd64)
UNAME_M = x86_64
endif
else
CPU_INFO = cat /proc/cpuinfo | grep flags
endif

# check for sse optimisation level
ifneq ($$(filter $(CPU_INFO) | grep sse3 ) , )
SSE_CFLAGS = -msse3 -mfpmath=sse -mfxsr
FFT_FLAG = -DFFTCONVOLVER_USE_SSE=1
else ifneq ($$(filter $(CPU_INFO) | grep sse2 ) , )
SSE_CFLAGS = -msse2 -mfpmath=sse -mfxsr
FFT_FLAG = -DFFTCONVOLVER_USE_SSE=1
else ifneq ($$(filter $(CPU_INFO) | grep sse ) , )
SSE_CFLAGS = -msse -mfpmath=sse -mfxsr
FFT_FLAG = -DFFTCONVOLVER_USE_SSE=1
else ifneq ($$(filter $(CPU_INFO) | grep ARM ) , )
ifneq ($$(filter $(CPU_INFO) | grep ARMv7 ) , )
ifneq ($$(filter $(CPU_INFO) | grep vfpd32 ) , )
SSE_CFLAGS = -march=armv7-a -mfpu=vfpv3
else ifneq ($$(filter $(CPU_INFO) | grep vfpv3 ) , )
SSE_CFLAGS = -march=armv7-a -mfpu=vfpv3
ifneq ($(UNAME_M),$(TARGET_ARCH))
CROSS_COMPILING = 1
$(info $(yellow) INFO: $(reset)Cross Compile $(blue)$(UNAME_M)$(reset) to $(blue)$(TARGET_ARCH)$(reset))
endif

# avoid optimisation for x86_64 arch when we cross compile
#ifneq ($(CROSS_COMPILING), 1)
# check for sse optimisation level only on x86_64 architecture
ifeq ($(TARGET_ARCH), x86_64)
ifneq ($$(filter $(CPU_INFO) | grep sse3 ) , )
SSE_CFLAGS = -msse3 -mfpmath=sse -mfxsr
FFT_FLAG = -DFFTCONVOLVER_USE_SSE=1
else ifneq ($$(filter $(CPU_INFO) | grep sse2 ) , )
SSE_CFLAGS = -msse2 -mfpmath=sse -mfxsr
FFT_FLAG = -DFFTCONVOLVER_USE_SSE=1
else ifneq ($$(filter $(CPU_INFO) | grep sse ) , )
SSE_CFLAGS = -msse -mfpmath=sse -mfxsr
FFT_FLAG = -DFFTCONVOLVER_USE_SSE=1
else ifneq ($$(filter $(CPU_INFO) | grep ARM ) , )
ifneq ($$(filter $(CPU_INFO) | grep ARMv7 ) , )
ifneq ($$(filter $(CPU_INFO) | grep vfpd32 ) , )
SSE_CFLAGS = -march=armv7-a -mfpu=vfpv3
else ifneq ($$(filter $(CPU_INFO) | grep vfpv3 ) , )
SSE_CFLAGS = -march=armv7-a -mfpu=vfpv3
endif
else
ARMCPU = "YES"
endif
else
ARMCPU = "YES"
endif
else
SSE_CFLAGS =
Expand All @@ -47,7 +75,7 @@ FLAGS_v2 := cx16 lahf_lm popcnt sse4_1 sse4_2 ssse3
FLAGS := $(shell $(CPU_INFO))


NO_x86_64 = -v0
NO_x86_64 =
define LOOPBODY
ifneq ($$(filter $(v),$(FLAGS)),)
YES_x86_64 = $(x86_64_LEVEL)
Expand All @@ -65,35 +93,29 @@ endif
ifeq ($(NO_x86_64), $(x86_64_LEVEL))
x86_64_LEVEL :=
endif
#endif

CXX_v = $(shell $(CXX) -dumpversion)
ifneq ($(MAKECMDGOALS),install)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(NO_x86_64), $(x86_64_LEVEL))
ifeq ($(shell awk -v a="$(CXX_v)" -v b="11" 'BEGIN{print(a<b)}'), 1)
SSE_CFLAGS += -march=native
$(info $(yellow) INFO: $(reset)optimised for $(blue)$(SSE_CFLAGS)$(reset))
else
$(info $(yellow) INFO: $(reset)optimised for $(blue)$(SSE_CFLAGS)$(reset))
else ifeq ($(TARGET_ARCH), x86_64)
SSE_CFLAGS += -march=x86-64$(x86_64_LEVEL)
$(info $(yellow) INFO: $(reset)optimised for $(blue)$(SSE_CFLAGS)$(reset))
else ifeq ($(TARGET_ARCH), aarch64)
CXXFLAGS += -march=armv8-a
$(info $(yellow) INFO: $(reset)optimised for $(blue)-march=armv8-a $(SSE_CFLAGS)$(reset))
else
SSE_CFLAGS += -march=native
$(info $(yellow) INFO: $(reset)optimised for $(blue)$(SSE_CFLAGS)$(reset))
endif
else ifeq ($(shell arch), aarch64)
CXXFLAGS += -march=armv8-a
$(info $(yellow) INFO: $(reset)optimised for $(blue)-march=armv8 $(SSE_CFLAGS)$(reset))
endif
endif
endif

# check if clang is available

ifeq ($(TARGET), Linux)
CXX_VERSION = $(shell clang++ --version 2>/dev/null)
ifneq ($(CXX_VERSION),)
CXX := clang++
endif
endif


# check for c++ level
ifeq (,$(filter clean,$(MAKECMDGOALS)))
ifeq (,$(filter install,$(MAKECMDGOALS)))
Expand Down

1 comment on commit 45e1311

@38github
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Please sign in to comment.