Cleanup Altivec and Power7 code paths

This changes the dependency from Altivec to Power7. Internally we needed Power7 but it was cut-in as a pseudo Altivec dependency. Also see http://groups.google.com/forum/#!topic/cryptopp-users/fmEKOG41SG8
pull/531/head
Jeffrey Walton 2017-10-17 22:50:45 -04:00
parent f8d97b83ed
commit 7ba8c6bc81
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
5 changed files with 49 additions and 21 deletions

View File

@ -602,19 +602,21 @@ NAMESPACE_END
// An old Apple G5 with GCC 4.01 has AltiVec, but its only Power4 or so. // 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. // 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(CRYPTOPP_POWER7_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ALTIVEC) && !defined(CRYPTOPP_DISABLE_ASM)
# if defined(__ALTIVEC__) || (CRYPTOPP_XLC_VERSION >= 100000) || (CRYPTOPP_GCC_VERSION >= 40000) # if defined(_ARCH_PWR7) || (CRYPTOPP_XLC_VERSION >= 100000) || (CRYPTOPP_GCC_VERSION >= 40000)
# define CRYPTOPP_ALTIVEC_AVAILABLE 1 # define CRYPTOPP_ALTIVEC_AVAILABLE 1
# define CRYPTOPP_POWER7_AVAILABLE 1
# endif # endif
#endif #endif
#if !defined(CRYPTOPP_POWER8_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) && defined(CRYPTOPP_ALTIVEC_AVAILABLE) #if !defined(CRYPTOPP_POWER8_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ALTIVEC) && !defined(CRYPTOPP_DISABLE_ASM)
# if defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800) # if defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800)
# define CRYPTOPP_ALTIVEC_AVAILABLE 1
# define CRYPTOPP_POWER8_AVAILABLE 1 # define CRYPTOPP_POWER8_AVAILABLE 1
# endif # endif
#endif #endif
#if !defined(CRYPTOPP_POWER8_CRYPTO_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) && defined(CRYPTOPP_ALTIVEC_AVAILABLE) #if !defined(CRYPTOPP_POWER8_CRYPTO_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ALTIVEC) && !defined(CRYPTOPP_DISABLE_ASM)
# if defined(__CRYPTO__) || defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800) # if defined(__CRYPTO__) || defined(_ARCH_PWR8) || (CRYPTOPP_XLC_VERSION >= 130000) || (CRYPTOPP_GCC_VERSION >= 40800)
# define CRYPTOPP_POWER8_AES_AVAILABLE 1 # define CRYPTOPP_POWER8_AES_AVAILABLE 1
//# define CRYPTOPP_POWER8_SHA_AVAILABLE 1 //# define CRYPTOPP_POWER8_SHA_AVAILABLE 1

10
cpu.cpp
View File

@ -625,11 +625,12 @@ void DetectArmFeatures()
#elif (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) #elif (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64)
bool CRYPTOPP_SECTION_INIT g_PowerpcDetectionDone = false; bool CRYPTOPP_SECTION_INIT g_PowerpcDetectionDone = false;
bool CRYPTOPP_SECTION_INIT g_hasAltivec = false, CRYPTOPP_SECTION_INIT g_hasPower8 = false; bool CRYPTOPP_SECTION_INIT g_hasAltivec = false, CRYPTOPP_SECTION_INIT g_hasPower7 = false, CRYPTOPP_SECTION_INIT g_hasPower8 = false;
bool CRYPTOPP_SECTION_INIT g_hasAES = false, CRYPTOPP_SECTION_INIT g_hasSHA256 = false, CRYPTOPP_SECTION_INIT g_hasSHA512 = false; bool CRYPTOPP_SECTION_INIT g_hasAES = false, CRYPTOPP_SECTION_INIT g_hasSHA256 = false, CRYPTOPP_SECTION_INIT g_hasSHA512 = false;
word32 CRYPTOPP_SECTION_INIT g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE; word32 CRYPTOPP_SECTION_INIT g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
extern bool CPU_ProbeAltivec(); extern bool CPU_ProbeAltivec();
extern bool CPU_ProbePower7();
extern bool CPU_ProbePower8(); extern bool CPU_ProbePower8();
extern bool CPU_ProbeAES(); extern bool CPU_ProbeAES();
extern bool CPU_ProbeSHA256(); extern bool CPU_ProbeSHA256();
@ -657,17 +658,15 @@ inline bool CPU_QueryAltivec()
return false; return false;
} }
#if 0
inline bool CPU_QueryPower7() inline bool CPU_QueryPower7()
{ {
// Power7 and ISA 2.06 // Power7 and ISA 2.06
#if defined(__linux__) #if defined(__linux__)
if (getauxval(AT_HWCAP) & PPC_FEATURE_ARCH_2_06) if (getauxval(AT_HWCAP2) & PPC_FEATURE_ARCH_2_06)
return true; return true;
#endif #endif
return false; return false;
} }
#endif
inline bool CPU_QueryPower8() inline bool CPU_QueryPower8()
{ {
@ -722,6 +721,7 @@ void DetectPowerpcFeatures()
// The CPU_ProbeXXX's return false for OSes which // The CPU_ProbeXXX's return false for OSes which
// can't tolerate SIGILL-based probes, like Apple // can't tolerate SIGILL-based probes, like Apple
g_hasAltivec = CPU_QueryAltivec() || CPU_ProbeAltivec(); g_hasAltivec = CPU_QueryAltivec() || CPU_ProbeAltivec();
g_hasPower7 = CPU_QueryPower7() || CPU_ProbePower7();
g_hasPower8 = CPU_QueryPower8() || CPU_ProbePower8(); g_hasPower8 = CPU_QueryPower8() || CPU_ProbePower8();
//g_hasPMULL = CPU_QueryPMULL() || CPU_ProbePMULL(); //g_hasPMULL = CPU_QueryPMULL() || CPU_ProbePMULL();
g_hasAES = CPU_QueryAES() || CPU_ProbeAES(); g_hasAES = CPU_QueryAES() || CPU_ProbeAES();
@ -736,7 +736,7 @@ void DetectPowerpcFeatures()
g_cacheLineSize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); g_cacheLineSize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
#endif #endif
if (!g_cacheLineSize) if (g_cacheLineSize <= 0)
g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE; g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
g_PowerpcDetectionDone = true; g_PowerpcDetectionDone = true;

27
cpu.h
View File

@ -407,8 +407,11 @@ void CRYPTOPP_API DetectPowerpcFeatures();
//! \returns true if the hardware is capable of Altivec at runtime, false otherwise. //! \returns true if the hardware is capable of Altivec at runtime, false otherwise.
//! \details Altivec instructions are available under most modern PowerPCs. //! \details Altivec instructions are available under most modern PowerPCs.
//! \details Runtime support requires compile time support. When compiling with GCC, you may //! \details Runtime support requires compile time support. When compiling with GCC, you may
//! need to compile with <tt>-mcpu=power8</tt>; while IBM XL C/C++ compilers require //! need to compile with <tt>-mcpu=power7</tt>; while IBM XL C/C++ compilers require
//! <tt>-qarch=pwr8 -qaltivec</tt>. Also see PowerPC's <tt>_ALTIVEC_</tt> preprocessor macro. //! <tt>-qarch=pwr7 -qaltivec</tt>. Also see PowerPC's <tt>_ALTIVEC_</tt> preprocessor macro.
//! \details Atilvec was first available on Power4 platforms. However Crypto++ releies on unaligned
//! loads and stores which is a Power7 feature. If the platform lacks Power7 extensions, then the
//! GNUmakefile sets <tt>-DCRYPTOPP_DISABLE_ALTIVEC</tt>.
//! \note This function is only available on PowerPC and PowerPC-64 platforms //! \note This function is only available on PowerPC and PowerPC-64 platforms
inline bool HasAltivec() inline bool HasAltivec()
{ {
@ -423,6 +426,26 @@ inline bool HasAltivec()
//! \details Runtime support requires compile time support. When compiling with GCC, you may //! \details Runtime support requires compile time support. When compiling with GCC, you may
//! need to compile with <tt>-mcpu=power8</tt>; while IBM XL C/C++ compilers require //! need to compile with <tt>-mcpu=power8</tt>; while IBM XL C/C++ compilers require
//! <tt>-qarch=pwr8 -qaltivec</tt>. Also see PowerPC's <tt>_ALTIVEC_</tt> preprocessor macro. //! <tt>-qarch=pwr8 -qaltivec</tt>. Also see PowerPC's <tt>_ALTIVEC_</tt> preprocessor macro.
//! \details Atilvec was first available on Power4 platforms. However Crypto++ releies on unaligned
//! loads and stores which is a Power7 feature. If the platform lacks Power7 extensions, then the
//! GNUmakefile sets <tt>-DCRYPTOPP_DISABLE_ALTIVEC</tt>.
//! \note This function is only available on PowerPC and PowerPC-64 platforms
inline bool HasPower7()
{
if (!g_PowerpcDetectionDone)
DetectPowerpcFeatures();
return g_hasPower7;
}
//! \brief Determine if a PowerPC processor has Power8 available
//! \returns true if the hardware is capable of Power8 at runtime, false otherwise.
//! \details Altivec instructions are available under most modern PowerPCs.
//! \details Runtime support requires compile time support. When compiling with GCC, you may
//! need to compile with <tt>-mcpu=power8</tt>; while IBM XL C/C++ compilers require
//! <tt>-qarch=pwr8 -qaltivec</tt>. Also see PowerPC's <tt>_ALTIVEC_</tt> preprocessor macro.
//! \details Atilvec was first available on Power4 platforms. However Crypto++ releies on unaligned
//! loads and stores which is a Power7 feature. If the platform lacks Power7 extensions, then the
//! GNUmakefile sets <tt>-DCRYPTOPP_DISABLE_ALTIVEC</tt>.
//! \note This function is only available on PowerPC and PowerPC-64 platforms //! \note This function is only available on PowerPC and PowerPC-64 platforms
inline bool HasPower8() inline bool HasPower8()
{ {

View File

@ -97,12 +97,11 @@ bool CPU_ProbeAltivec()
#endif // CRYPTOPP_ALTIVEC_AVAILABLE #endif // CRYPTOPP_ALTIVEC_AVAILABLE
} }
#if 0
bool CPU_ProbePower7() bool CPU_ProbePower7()
{ {
#if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES) #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
return false; return false;
#elif (CRYPTOPP_POWER7_AVAILABLE) && 0 #elif (CRYPTOPP_POWER7_AVAILABLE)
# if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY) # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY)
// longjmp and clobber warnings. Volatile is required. // longjmp and clobber warnings. Volatile is required.
@ -121,7 +120,11 @@ bool CPU_ProbePower7()
result = false; result = false;
else else
{ {
// TODO byte b1[19] = {255, 255, 255, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, b2[17];
const uint8x16_p8 v1 = (uint8x16_p8)VectorLoad(0, b1+3);
VectorStore(v1, b2+1);
result = (0 == std::memcmp(b1+3, b2+1, 16));
} }
sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR); sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
@ -132,7 +135,6 @@ bool CPU_ProbePower7()
return false; return false;
#endif // CRYPTOPP_POWER7_AVAILABLE #endif // CRYPTOPP_POWER7_AVAILABLE
} }
#endif
bool CPU_ProbePower8() bool CPU_ProbePower8()
{ {

View File

@ -376,14 +376,15 @@ bool TestSettings()
std::cout << ", hasAES == " << hasAES << ", hasSHA1 == " << hasSHA1 << ", hasSHA2 == " << hasSHA2 << "\n"; std::cout << ", hasAES == " << hasAES << ", hasSHA1 == " << hasSHA1 << ", hasSHA2 == " << hasSHA2 << "\n";
#elif (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64) #elif (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64)
bool hasAltivec = HasAltivec(); const bool hasAltivec = HasAltivec();
bool hasPower8 = HasPower8(); const bool hasPower7 = HasPower7();
bool hasAES = HasAES(); const bool hasPower8 = HasPower8();
bool hasSHA256 = HasSHA256(); const bool hasAES = HasAES();
bool hasSHA512 = HasSHA512(); const bool hasSHA256 = HasSHA256();
const bool hasSHA512 = HasSHA512();
std::cout << "passed: "; std::cout << "passed: ";
std::cout << "hasAltivec == " << hasAltivec << ", hasPower8 == " << hasPower8; std::cout << "hasAltivec == " << hasAltivec << ", hasPower7 == " << hasPower7 << ", hasPower8 == " << hasPower8;
std::cout << ", hasAES == " << hasAES << ", hasSHA256 == " << hasSHA256 << ", hasSHA512 == " << hasSHA512 << "\n"; std::cout << ", hasAES == " << hasAES << ", hasSHA256 == " << hasSHA256 << ", hasSHA512 == " << hasSHA512 << "\n";
#endif #endif