From 10f85d65967bbe15ad807ee214fdf4babec1a991 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 15 Nov 2018 02:11:00 -0500 Subject: Make Altivec vector wraps friendly to downgrades The way the existing ppc_simd.h is written makes it hard to to switch between the old Altivec loads and stores and the new POWER7 loads and stores. This checkin rewrites the wrappers to use _ALTIVEC_, _ARCH_PWR7 and _ARCH_PWR8. The wrappers in this file now honor -maltivec, -mcpu-power7 and -mcpu=power8. It allows users to compile a source file, like chacha_simd.cpp, with a lower ISA and things just work for them. --- chacha.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'chacha.cpp') diff --git a/chacha.cpp b/chacha.cpp index 333a58a6..a89fa016 100644 --- a/chacha.cpp +++ b/chacha.cpp @@ -24,7 +24,7 @@ extern void ChaCha_OperateKeystream_SSE2(const word32 *state, const byte* input, extern void ChaCha_OperateKeystream_AVX2(const word32 *state, const byte* input, byte *output, unsigned int rounds); #endif -#if (CRYPTOPP_POWER7_AVAILABLE) +#if (CRYPTOPP_ALTIVEC_AVAILABLE) extern void ChaCha_OperateKeystream_POWER7(const word32 *state, const byte* input, byte *output, unsigned int rounds); #endif @@ -85,6 +85,11 @@ std::string ChaCha_Policy::AlgorithmProvider() const if (HasPower7()) return "Power7"; else +#endif +#if (CRYPTOPP_ALTIVEC_AVAILABLE) + if (HasAltivec()) + return "Altivec"; + else #endif return "C++"; } @@ -139,8 +144,8 @@ unsigned int ChaCha_Policy::GetAlignment() const return 16; else #endif -#if (CRYPTOPP_POWER7_AVAILABLE) - if (HasPower7()) +#if (CRYPTOPP_ALTIVEC_AVAILABLE) + if (HasAltivec()) return 16; else #endif @@ -164,8 +169,8 @@ unsigned int ChaCha_Policy::GetOptimalBlockSize() const return 4*BYTES_PER_ITERATION; else #endif -#if (CRYPTOPP_POWER7_AVAILABLE) - if (HasPower7()) +#if (CRYPTOPP_ALTIVEC_AVAILABLE) + if (HasAltivec()) return 4*BYTES_PER_ITERATION; else #endif @@ -245,8 +250,8 @@ void ChaCha_Policy::OperateKeystream(KeystreamOperation operation, } #endif -#if (CRYPTOPP_POWER7_AVAILABLE) - if (HasPower7()) +#if (CRYPTOPP_ALTIVEC_AVAILABLE) + if (HasAltivec()) { while (iterationCount >= 4 && MultiBlockSafe(4)) { -- cgit v1.2.1