From f8d97b83ed6d65946570a2ec9d6aa1ac5ff7ce94 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Tue, 17 Oct 2017 20:47:14 -0400 Subject: Fix compile on old PowerPC This cleans up the compile on old PwerMac G5's. Our Altivec and Crypto code relies on Power7 and Power8 extensions. There's no need to shoehorn Altivec and Power4 into old platforms, so we disable Altivec and Crypto unless Power7 is available. The GNUmakefile sets CRYPTOPP_DISABLE_ALTIVEC if Power7 is not available. --- GNUmakefile | 17 +++++++++-------- config.h | 9 +++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index e013db84..dd87c888 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -339,11 +339,12 @@ ifeq ($(IS_ARMV8),1) endif # PowerPC and PowerPC-64 +# Altivec is available with Power4, but the library is tied to Power7 and unaligned loads/stores. ifneq ($(IS_PPC32)$(IS_PPC64)$(IS_AIX),000) # GCC and some compatibles - HAVE_ALTIVEC = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c '__ALTIVEC__') + HAVE_ALTIVEC = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mcpu=power7 -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c '__ALTIVEC__') ifneq ($(HAVE_ALTIVEC),0) - ALTIVEC_FLAG = -maltivec + ALTIVEC_FLAG = -mcpu=power7 -maltivec endif # GCC and some compatibles HAVE_CRYPTO = $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -mcpu=power8 -maltivec -dM -E - 2>/dev/null | $(GREP) -i -c -E '_ARCH_PWR8|_ARCH_PWR9|__CRYPTO') @@ -354,9 +355,9 @@ ifneq ($(IS_PPC32)$(IS_PPC64)$(IS_AIX),000) ALTIVEC_FLAG = -mcpu=power8 -maltivec endif # IBM XL C/C++ - HAVE_ALTIVEC = $(shell $(CXX) $(CXXFLAGS) -qshowmacros -qaltivec -E adhoc.cpp.proto 2>/dev/null | $(GREP) -i -c '__ALTIVEC__') + HAVE_ALTIVEC = $(shell $(CXX) $(CXXFLAGS) -qshowmacros -qarch=pwr7 -qaltivec -E adhoc.cpp.proto 2>/dev/null | $(GREP) -i -c '__ALTIVEC__') ifneq ($(HAVE_ALTIVEC),0) - ALTIVEC_FLAG = -qaltivec + ALTIVEC_FLAG = -qarch=pwr7 -qaltivec endif # IBM XL C/C++ HAVE_CRYPTO = $(shell $(CXX) $(CXXFLAGS) -qshowmacros -qarch=pwr8 -qaltivec -E adhoc.cpp.proto 2>/dev/null | $(GREP) -i -c -E '_ARCH_PWR8|_ARCH_PWR9|__CRYPTO') @@ -366,6 +367,10 @@ ifneq ($(IS_PPC32)$(IS_PPC64)$(IS_AIX),000) SHA_FLAG = -qarch=pwr8 -qaltivec ALTIVEC_FLAG = -qarch=pwr8 -qaltivec endif + # Fail safe to disable intrinsics on down level machines, like PowerMac G5 + ifeq ($(ALTIVEC_FLAG),) + CXXFLAGS += -DCRYPTOPP_DISABLE_ALTIVEC + endif endif # IBM XL C/C++ compiler @@ -378,10 +383,6 @@ ifeq ($(XLC_COMPILER),1) ifneq ($(findstring -fPIC,$(CXXFLAGS)),) CXXFLAGS := $(CXXFLAGS:-fPIC=-qpic) endif - # Warnings and intermittent failures on early IBM XL C/C++ - #ifneq ($(findstring -O3,$(CXXFLAGS)),) - # CXXFLAGS := $(CXXFLAGS:-O3=-O2) - #endif endif endif # IS_X86 diff --git a/config.h b/config.h index e106b698..de93c841 100644 --- a/config.h +++ b/config.h @@ -600,20 +600,21 @@ NAMESPACE_END #if (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) -// An old Apple G5 with GCC 4.01 has AltiVec. -#if !defined(CRYPTOPP_ALTIVEC_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) +// An old Apple G5 with GCC 4.01 has AltiVec, but its only Power4 or so. +// We need Power7 or above, so the makefile defines CRYPTOPP_DISABLE_ALTIVEC. +#if !defined(CRYPTOPP_ALTIVEC_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ALTIVEC) && !defined(CRYPTOPP_DISABLE_ASM) # if defined(__ALTIVEC__) || (CRYPTOPP_XLC_VERSION >= 100000) || (CRYPTOPP_GCC_VERSION >= 40000) # define CRYPTOPP_ALTIVEC_AVAILABLE 1 # endif #endif -#if !defined(CRYPTOPP_POWER8_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) +#if !defined(CRYPTOPP_POWER8_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) && defined(CRYPTOPP_ALTIVEC_AVAILABLE) # if defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800) # define CRYPTOPP_POWER8_AVAILABLE 1 # endif #endif -#if !defined(CRYPTOPP_POWER8_CRYPTO_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) +#if !defined(CRYPTOPP_POWER8_CRYPTO_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) && defined(CRYPTOPP_ALTIVEC_AVAILABLE) # if defined(__CRYPTO__) || defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800) # define CRYPTOPP_POWER8_AES_AVAILABLE 1 //# define CRYPTOPP_POWER8_SHA_AVAILABLE 1 -- cgit v1.2.1