From 1edea5a80fac65a4eeeb5f68af5d5516ec9d9bb7 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 21 Sep 2017 20:02:40 -0400 Subject: [PATCH] Vectorize tail of Rijndael_UncheckedSetKey_POWER8 --- rijndael-simd.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/rijndael-simd.cpp b/rijndael-simd.cpp index 3c61f99a..6b377752 100644 --- a/rijndael-simd.cpp +++ b/rijndael-simd.cpp @@ -1159,16 +1159,13 @@ void Rijndael_UncheckedSetKey_POWER8(const byte* userKey, size_t keyLen, word32* rk += keyLen/4; } - rk = rk_saved; - ConditionalByteReverse(BIG_ENDIAN_ORDER, rk, rk, (rounds+1)*16); - #if defined(IS_LITTLE_ENDIAN) - // VSX registers are big-endian. The entire subkey table must be byte - // reversed on little-endian systems to ensure it loads properly. - byte * ptr = reinterpret_cast(rk); - for (unsigned int i=0; i<=rounds; i++) - ReverseByteArrayLE(ptr+i*16); -#endif // IS_LITTLE_ENDIAN + rk = rk_saved; + const uint8x16_p8 mask = ((uint8x16_p8){12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3}); + const uint8x16_p8 zero = {0}; + for (unsigned int i=0; i<=rounds; ++i, rk+=4) + vec_vsx_st(vec_perm(vec_vsx_ld(0, (uint8_t*)rk), zero, mask), 0, (uint8_t*)rk); +#endif } }