Add safety for SSSE4.1 and SSE4.2 intructions

They are giving ARIA and BLAKE2 trouble. It looks like SSE4  support appeared in the GCC compiler around 4.1 or 4.2. It looks like SHA support appeared in the GNU assembler around 2.18
This commit is contained in:
Jeffrey Walton 2017-04-23 06:37:03 -04:00
parent 96cc3522ce
commit 89176e51cd
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 27 additions and 7 deletions

View File

@ -45,6 +45,7 @@ endif()
option(DISABLE_ASM "Disable ASM" OFF)
option(DISABLE_SSSE3 "Disable SSSE3" OFF)
option(DISABLE_SSE4 "Disable SSE4" OFF)
option(DISABLE_AESNI "Disable AES-NI" OFF)
option(DISABLE_SHA "Disable SHA" OFF)
option(DISABLE_NATIVE_ARCH "Disable the addition of -march=native" OFF)
@ -151,6 +152,15 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(DISABLE_NATIVE_ARCH 1)
endif()
# OpenBSD, CentOS 5 needed this one due to ARIA and BLAKE2
execute_process(COMMAND echo ${GAS_STRING}
COMMAND ${GREP_CMD} "GNU assembler version (2\\.1[8-9]|2\\.[2-9]|[3-9])"
OUTPUT_VARIABLE GAS218_OR_LATER)
if (GAS218_OR_LATER EQUAL 0)
add_definitions(-DCRYPTOPP_DISABLE_SSE4)
set(DISABLE_NATIVE_ARCH 1)
endif()
execute_process(COMMAND echo ${GAS_STRING}
COMMAND ${GREP_CMD} "GNU assembler version (2\\.19|2\\.[2-9]|[3-9])"
OUTPUT_VARIABLE GAS219_OR_LATER)
@ -159,6 +169,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(DISABLE_NATIVE_ARCH 1)
endif()
# Ubuntu 10 and Ubuntu 12 needed this one
execute_process(COMMAND echo ${GAS_STRING}
COMMAND ${GREP_CMD} "GNU assembler version (2\\.2[3-9]|2\\.[3-9]|[3-9])"
OUTPUT_VARIABLE GAS223_OR_LATER)

View File

@ -147,6 +147,7 @@ endif
ifneq ($(HAVE_GAS),0)
GAS210_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.[1-9][0-9]|[3-9])")
GAS217_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.1[7-9]|2\.[2-9]|[3-9])")
GAS218_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.1[8-9]|2\.[2-9]|[3-9])")
GAS219_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.19|2\.[2-9]|[3-9])")
GAS223_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(EGREP) -c "GNU assembler version (2\.2[3-9]|2\.[3-9]|[3-9])")
endif
@ -163,13 +164,19 @@ endif
# .intel_syntax wasn't supported until GNU assembler 2.10
# No DISABLE_NATIVE_ARCH with CRYPTOPP_DISABLE_ASM for now
# See http://github.com/weidai11/cryptopp/issues/395
ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
ifeq ($(HAVE_GAS)$(GAS210_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
DISABLE_NATIVE_ARCH := 1
else
ifeq ($(HAVE_GAS)$(GAS217_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
DISABLE_NATIVE_ARCH := 1
else
ifeq ($(HAVE_GAS)$(GAS218_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSE4
DISABLE_NATIVE_ARCH := 1
else
ifeq ($(HAVE_GAS)$(GAS219_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
DISABLE_NATIVE_ARCH := 1
@ -177,15 +184,17 @@ else
ifeq ($(HAVE_GAS)$(GAS223_OR_LATER),10)
CXXFLAGS += -DCRYPTOPP_DISABLE_SHA
DISABLE_NATIVE_ARCH := 1
endif
endif
endif
endif
endif # -DCRYPTOPP_DISABLE_SHA
endif # -DCRYPTOPP_DISABLE_AESNI
endif # -DCRYPTOPP_DISABLE_SSE4
endif # -DCRYPTOPP_DISABLE_SSSE3
endif # -DCRYPTOPP_DISABLE_ASM
endif # CXXFLAGS
# BEGIN NATIVE_ARCH
# BEGIN_NATIVE_ARCH
# Guard use of -march=native (or -m{32|64} on some platforms)
# Don't add anything if -march=XXX or -mtune=XXX is specified
ifneq ($(DISABLE_NATIVE_ARCH),1)
ifeq ($(DISABLE_NATIVE_ARCH),0)
ifeq ($(findstring -march,$(CXXFLAGS)),)
ifeq ($(findstring -mtune,$(CXXFLAGS)),)
ifeq ($(GCC42_OR_LATER)$(IS_NETBSD),10)
@ -206,7 +215,7 @@ ifeq ($(findstring -mtune,$(CXXFLAGS)),)
endif # -mtune
endif # -march
endif # DISABLE_NATIVE_ARCH
# END NATIVE_ARCH
# END_NATIVE_ARCH
# Aligned access required for -O3 and above due to vectorization
UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h)