Skip to content

Commit

Permalink
Bug 1659727 - Move makefile avx2 detection to config.mk. r=kjacobs
Browse files Browse the repository at this point in the history
Summary:
Current code base use CPU_ARCH to detect if avx2 is supported in arch.mk
However, when arch.mk included, CPU_ARCH haven't been initialised, CPU_ARCH
will be initialised by the OS specific code later on.

Move the AVX2 detection to config.mk, after all other initialisation done.

Reviewers: kjacobs

Reviewed By: kjacobs

Subscribers: kjacobs

Bug #: 1659727

Differential Revision: https://phabricator.services.mozilla.com/D88517

--HG--
extra : amend_source : f5cdac52bcc0d7484e7305386a6809bfb4779d31
  • Loading branch information
sgn committed Sep 11, 2020
1 parent 0ad7e68 commit 4028173
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 39 deletions.
29 changes: 0 additions & 29 deletions coreconf/arch.mk
Expand Up @@ -140,35 +140,6 @@ ifeq ($(OS_ARCH),OS_2)
OS_RELEASE := $(shell uname -v)
endif

#######################################################################
# Master "Core Components" macros for Hardware features #
#######################################################################

ifndef NSS_DISABLE_AVX2
ifneq ($(CPU_ARCH),x86_64)
# Disable AVX2 entirely on non-Intel platforms
NSS_DISABLE_AVX2 = 1
$(warning CPU_ARCH is not x86_64, disabling -mavx2)
else
ifdef CC_IS_CLANG
# Clang reports its version as an older gcc, but it's OK
NSS_DISABLE_AVX2 = 0
else
ifneq (,$(filter 4.8 4.9,$(word 1,$(GCC_VERSION)).$(word 2,$(GCC_VERSION))))
NSS_DISABLE_AVX2 = 0
endif
ifeq (,$(filter 0 1 2 3 4,$(word 1,$(GCC_VERSION))))
NSS_DISABLE_AVX2 = 0
endif
endif
ifndef NSS_DISABLE_AVX2
$(warning Unable to find gcc 4.8 or greater, disabling -Werror)
NSS_DISABLE_AVX2 = 1
endif
endif
export NSS_DISABLE_AVX2
endif #ndef NSS_DISABLE_AVX2

#######################################################################
# Master "Core Components" macros for getting the OS target #
#######################################################################
Expand Down
29 changes: 27 additions & 2 deletions coreconf/config.mk
Expand Up @@ -128,6 +128,33 @@ ifndef MK_RULESET
include $(CORE_DEPTH)/coreconf/ruleset.mk
endif

#######################################################################
# Master "Core Components" macros for Hardware features #
#######################################################################
ifndef NSS_DISABLE_AVX2
ifneq ($(CPU_ARCH),x86_64)
# Disable AVX2 entirely on non-Intel platforms
NSS_DISABLE_AVX2 = 1
$(warning CPU_ARCH is not x86_64, disabling -mavx2)
else
# Clang reports its version as an older gcc, but it's OK
ifndef CC_IS_CLANG
ifneq (,$(filter 0 1 2 3,$(word 1,$(GCC_VERSION))))
NSS_DISABLE_AVX2 = 1
endif
ifeq (4,$(word 1,$(GCC_VERSION)))
ifeq (,$(filter 8 9,$(word 2,$(GCC_VERSION))))
NSS_DISABLE_AVX2 = 1
endif
endif
endif
ifeq (1,$(NSS_DISABLE_AVX2))
$(warning Unable to find gcc 4.8 or greater, disabling avx2)
export NSS_DISABLE_AVX2
endif
endif
endif #ndef NSS_DISABLE_AVX2

#######################################################################
# [16.0] Global environ ment defines
#######################################################################
Expand All @@ -149,10 +176,8 @@ DEFINES += -DNSS_DISABLE_DBM
endif

ifdef NSS_DISABLE_AVX2
ifneq ($(NSS_DISABLE_AVX2),0)
DEFINES += -DNSS_DISABLE_AVX2
endif
endif

ifdef NSS_DISABLE_CHACHAPOLY
DEFINES += -DNSS_DISABLE_CHACHAPOLY
Expand Down
14 changes: 6 additions & 8 deletions lib/freebl/Makefile
Expand Up @@ -555,12 +555,16 @@ ifneq ($(shell $(CC) -? 2>&1 >/dev/null </dev/null | sed -e 's/:.*//;1q'),lcc)
HAVE_INT128_SUPPORT = 1
DEFINES += -DHAVE_INT128_SUPPORT
endif
ifneq (,$(filter 4.8 4.9,$(word 1,$(GCC_VERSION)).$(word 2,$(GCC_VERSION))))
ifneq (,$(filter 0 1 2 3,$(word 1,$(GCC_VERSION))))
NSS_DISABLE_AVX2 = 1
endif
ifeq (4,$(word 1,$(GCC_VERSION)))
ifeq (,$(filter 8 9,$(word 2,$(GCC_VERSION))))
NSS_DISABLE_AVX2 = 1
endif
endif
ifeq (,$(filter 0 1 2 3 4,$(word 1,$(GCC_VERSION))))
HAVE_INT128_SUPPORT = 1
NSS_DISABLE_AVX2 = 0
DEFINES += -DHAVE_INT128_SUPPORT
endif
endif
Expand All @@ -574,9 +578,6 @@ endif
ifndef NSS_DISABLE_CHACHAPOLY
ifeq ($(CPU_ARCH),x86_64)
ifndef NSS_DISABLE_AVX2
NSS_DISABLE_AVX2 = 0
endif
ifeq ($(NSS_DISABLE_AVX2),0)
EXTRA_SRCS += Hacl_Poly1305_256.c Hacl_Chacha20_Vec256.c Hacl_Chacha20Poly1305_256.c
endif # NSS_DISABLE_AVX2
EXTRA_SRCS += Hacl_Poly1305_128.c Hacl_Chacha20_Vec128.c Hacl_Chacha20Poly1305_128.c
Expand Down Expand Up @@ -766,9 +767,6 @@ $(OBJDIR)/$(PROG_PREFIX)Hacl_Chacha20Poly1305_128$(OBJ_SUFFIX): CFLAGS += -mssse
$(OBJDIR)/$(PROG_PREFIX)Hacl_Poly1305_128$(OBJ_SUFFIX): CFLAGS += -mssse3 -msse4.1 -msse4.2 -mavx -maes -mpclmul

ifndef NSS_DISABLE_AVX2
NSS_DISABLE_AVX2 = 0
endif
ifeq ($(NSS_DISABLE_AVX2),0)
$(OBJDIR)/$(PROG_PREFIX)Hacl_Chacha20Poly1305_256$(OBJ_SUFFIX): CFLAGS += -mssse3 -msse4.1 -msse4.2 -mavx2 -maes
$(OBJDIR)/$(PROG_PREFIX)Hacl_Chacha20_Vec256$(OBJ_SUFFIX): CFLAGS += -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -maes
$(OBJDIR)/$(PROG_PREFIX)Hacl_Poly1305_256$(OBJ_SUFFIX): CFLAGS += -mssse3 -msse4.1 -msse4.2 -mavx -mavx2 -maes -mpclmul
Expand Down

0 comments on commit 4028173

Please sign in to comment.