Update documentation

Remove typedefs
Whitespace check-in
pull/548/head
Jeffrey Walton 2017-12-12 09:22:03 -05:00
parent 2c79be7a54
commit 57e3ae309b
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 67 additions and 82 deletions

View File

@ -1,7 +1,7 @@
// ppc-simd.h - written and placed in public domain by Jeffrey Walton // ppc-simd.h - written and placed in public domain by Jeffrey Walton
/// \file ppc-simd.h /// \file ppc-simd.h
/// \brief Support functions for PowerPC and Power8 vector operations /// \brief Support functions for PowerPC and vector operations
/// \details This header provides an agnostic interface into GCC and /// \details This header provides an agnostic interface into GCC and
/// IBM XL C/C++ compilers modulo their different built-in functions /// IBM XL C/C++ compilers modulo their different built-in functions
/// for accessing vector intructions. /// for accessing vector intructions.
@ -31,26 +31,12 @@ NAMESPACE_BEGIN(CryptoPP)
typedef __vector unsigned char uint8x16_p; typedef __vector unsigned char uint8x16_p;
typedef __vector unsigned int uint32x4_p; typedef __vector unsigned int uint32x4_p;
#if defined(CRYPTOPP_POWER5_AVAILABLE) #if defined(CRYPTOPP_POWER5_AVAILABLE)
typedef __vector unsigned long long uint64x2_p; typedef __vector unsigned long long uint64x2_p;
#endif #endif
// Use 8x16 for documentation because it is used frequently /// \brief Default vector type
#if defined(CRYPTOPP_XLC_VERSION) typedef uint32x4_p VectorType;
typedef uint8x16_p VectorType;
#elif defined(CRYPTOPP_GCC_VERSION)
typedef uint64x2_p VectorType;
#endif
#if defined(CRYPTOPP_DOXYGEN_PROCESSING)
/// \brief Default vector typedef
/// \details IBM XL C/C++ provides equally good support for all vector types,
/// including <tt>uint8x16_p</tt>. GCC provides good support for
/// <tt>uint64x2_p</tt>. <tt>VectorType</tt> is typedef'd accordingly to
/// minimize casting to and from buit-in function calls.
# define VectorType ...
#endif
#endif // CRYPTOPP_ALTIVEC_AVAILABLE #endif // CRYPTOPP_ALTIVEC_AVAILABLE
@ -82,8 +68,7 @@ template <class T>
inline T Reverse(const T& src) inline T Reverse(const T& src)
{ {
const uint8x16_p mask = {15,14,13,12, 11,10,9,8, 7,6,5,4, 3,2,1,0}; const uint8x16_p mask = {15,14,13,12, 11,10,9,8, 7,6,5,4, 3,2,1,0};
const uint8x16_p zero = {0}; return vec_perm(src, src, mask);
return vec_perm(src, zero, mask);
} }
/// \brief Loads a vector from a byte array /// \brief Loads a vector from a byte array
@ -93,15 +78,15 @@ inline T Reverse(const T& src)
/// \note VectorLoadBE() does not require an aligned array. /// \note VectorLoadBE() does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoadBE(const uint8_t src[16]) inline uint32x4_p VectorLoadBE(const uint8_t src[16])
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl_be(0, (uint8_t*)src); return (uint32x4_p)vec_xl_be(0, (uint8_t*)src);
#else #else
# if defined(CRYPTOPP_LITTLE_ENDIAN) # if defined(CRYPTOPP_LITTLE_ENDIAN)
return (VectorType)Reverse(vec_vsx_ld(0, (uint8_t*)src)); return (uint32x4_p)Reverse(vec_vsx_ld(0, (uint8_t*)src));
# else # else
return (VectorType)vec_vsx_ld(0, (uint8_t*)src); return (uint32x4_p)vec_vsx_ld(0, (uint8_t*)src);
# endif # endif
#endif #endif
} }
@ -114,15 +99,15 @@ inline VectorType VectorLoadBE(const uint8_t src[16])
/// \note VectorLoadBE does not require an aligned array. /// \note VectorLoadBE does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoadBE(int off, const uint8_t src[16]) inline uint32x4_p VectorLoadBE(int off, const uint8_t src[16])
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl_be(off, (uint8_t*)src); return (uint32x4_p)vec_xl_be(off, (uint8_t*)src);
#else #else
# if defined(CRYPTOPP_LITTLE_ENDIAN) # if defined(CRYPTOPP_LITTLE_ENDIAN)
return (VectorType)Reverse(vec_vsx_ld(off, (uint8_t*)src)); return (uint32x4_p)Reverse(vec_vsx_ld(off, (uint8_t*)src));
# else # else
return (VectorType)vec_vsx_ld(off, (uint8_t*)src); return (uint32x4_p)vec_vsx_ld(off, (uint8_t*)src);
# endif # endif
#endif #endif
} }
@ -134,9 +119,9 @@ inline VectorType VectorLoadBE(int off, const uint8_t src[16])
/// \note VectorLoad does not require an aligned array. /// \note VectorLoad does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoad(const byte src[16]) inline uint32x4_p VectorLoad(const byte src[16])
{ {
return (VectorType)VectorLoadBE((uint8_t*)src); return (uint32x4_p)VectorLoadBE((uint8_t*)src);
} }
/// \brief Loads a vector from a byte array /// \brief Loads a vector from a byte array
@ -147,9 +132,9 @@ inline VectorType VectorLoad(const byte src[16])
/// \note VectorLoad does not require an aligned array. /// \note VectorLoad does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoad(int off, const byte src[16]) inline uint32x4_p VectorLoad(int off, const byte src[16])
{ {
return (VectorType)VectorLoadBE(off, (uint8_t*)src); return (uint32x4_p)VectorLoadBE(off, (uint8_t*)src);
} }
/// \brief Loads a vector from a byte array /// \brief Loads a vector from a byte array
@ -159,12 +144,12 @@ inline VectorType VectorLoad(int off, const byte src[16])
/// \note VectorLoadKey does not require an aligned array. /// \note VectorLoadKey does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoadKey(const byte src[16]) inline uint32x4_p VectorLoadKey(const byte src[16])
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl(0, (uint8_t*)src); return (uint32x4_p)vec_xl(0, (uint8_t*)src);
#else #else
return (VectorType)vec_vsx_ld(0, (uint8_t*)src); return (uint32x4_p)vec_vsx_ld(0, (uint8_t*)src);
#endif #endif
} }
@ -175,12 +160,12 @@ inline VectorType VectorLoadKey(const byte src[16])
/// \note VectorLoadKey does not require an aligned array. /// \note VectorLoadKey does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoadKey(const word32 src[4]) inline uint32x4_p VectorLoadKey(const word32 src[4])
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl(0, (uint8_t*)src); return (uint32x4_p)vec_xl(0, (uint8_t*)src);
#else #else
return (VectorType)vec_vsx_ld(0, (uint8_t*)src); return (uint32x4_p)vec_vsx_ld(0, (uint8_t*)src);
#endif #endif
} }
@ -192,12 +177,12 @@ inline VectorType VectorLoadKey(const word32 src[4])
/// \note VectorLoadKey does not require an aligned array. /// \note VectorLoadKey does not require an aligned array.
/// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() /// \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
/// \since Crypto++ 6.0 /// \since Crypto++ 6.0
inline VectorType VectorLoadKey(int off, const byte src[16]) inline uint32x4_p VectorLoadKey(int off, const byte src[16])
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl(off, (uint8_t*)src); return (uint32x4_p)vec_xl(off, (uint8_t*)src);
#else #else
return (VectorType)vec_vsx_ld(off, (uint8_t*)src); return (uint32x4_p)vec_vsx_ld(off, (uint8_t*)src);
#endif #endif
} }
@ -387,9 +372,9 @@ template <class T1, class T2>
inline T1 VectorEncrypt(const T1& state, const T2& key) inline T1 VectorEncrypt(const T1& state, const T2& key)
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (T1)__vcipher((VectorType)state, (VectorType)key); return (T1)__vcipher((uint32x4_p)state, (uint32x4_p)key);
#elif defined(CRYPTOPP_GCC_VERSION) #elif defined(CRYPTOPP_GCC_VERSION)
return (T1)__builtin_crypto_vcipher((VectorType)state, (VectorType)key); return (T1)__builtin_crypto_vcipher((uint32x4_p)state, (uint32x4_p)key);
#else #else
CRYPTOPP_ASSERT(0); CRYPTOPP_ASSERT(0);
#endif #endif
@ -407,9 +392,9 @@ template <class T1, class T2>
inline T1 VectorEncryptLast(const T1& state, const T2& key) inline T1 VectorEncryptLast(const T1& state, const T2& key)
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (T1)__vcipherlast((VectorType)state, (VectorType)key); return (T1)__vcipherlast((uint32x4_p)state, (uint32x4_p)key);
#elif defined(CRYPTOPP_GCC_VERSION) #elif defined(CRYPTOPP_GCC_VERSION)
return (T1)__builtin_crypto_vcipherlast((VectorType)state, (VectorType)key); return (T1)__builtin_crypto_vcipherlast((uint32x4_p)state, (uint32x4_p)key);
#else #else
CRYPTOPP_ASSERT(0); CRYPTOPP_ASSERT(0);
#endif #endif
@ -427,9 +412,9 @@ template <class T1, class T2>
inline T1 VectorDecrypt(const T1& state, const T2& key) inline T1 VectorDecrypt(const T1& state, const T2& key)
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (T1)__vncipher((VectorType)state, (VectorType)key); return (T1)__vncipher((uint32x4_p)state, (uint32x4_p)key);
#elif defined(CRYPTOPP_GCC_VERSION) #elif defined(CRYPTOPP_GCC_VERSION)
return (T1)__builtin_crypto_vncipher((VectorType)state, (VectorType)key); return (T1)__builtin_crypto_vncipher((uint32x4_p)state, (uint32x4_p)key);
#else #else
CRYPTOPP_ASSERT(0); CRYPTOPP_ASSERT(0);
#endif #endif
@ -447,9 +432,9 @@ template <class T1, class T2>
inline T1 VectorDecryptLast(const T1& state, const T2& key) inline T1 VectorDecryptLast(const T1& state, const T2& key)
{ {
#if defined(CRYPTOPP_XLC_VERSION) #if defined(CRYPTOPP_XLC_VERSION)
return (T1)__vncipherlast((VectorType)state, (VectorType)key); return (T1)__vncipherlast((uint32x4_p)state, (uint32x4_p)key);
#elif defined(CRYPTOPP_GCC_VERSION) #elif defined(CRYPTOPP_GCC_VERSION)
return (T1)__builtin_crypto_vncipherlast((VectorType)state, (VectorType)key); return (T1)__builtin_crypto_vncipherlast((uint32x4_p)state, (uint32x4_p)key);
#else #else
CRYPTOPP_ASSERT(0); CRYPTOPP_ASSERT(0);
#endif #endif