Use __BIGGEST_ALIGNMENT__ over sizeof(T), if __BIGGEST_ALIGNMENT__ is available

__BIGGEST_ALIGNMENT__ is provided by some compilers, like GCC and ICC (but not Clang). It is usually 16 on 64-bit platforms; and it is usually 8 on 32-bit platforms
pull/270/head
Jeffrey Walton 2016-09-12 06:34:00 -04:00
parent 28c3d685e3
commit 27b27475e9
1 changed files with 8 additions and 4 deletions

12
misc.h
View File

@ -872,10 +872,12 @@ inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
//! \brief Returns the minimum alignment requirements of a type //! \brief Returns the minimum alignment requirements of a type
//! \param dummy an unused Visual C++ 6.0 workaround //! \param dummy an unused Visual C++ 6.0 workaround
//! \returns the minimum alignment requirements of a type, in bytes //! \returns the minimum alignment requirements of a type, in bytes
//! \details Internally the function calls C++11's alignof if available. If not available, the //! \details Internally the function calls C++11's <tt>alignof</tt> if available. If not available,
//! function uses compiler specific extensions such as __alignof and _alignof_. sizeof(T) //! then the function uses compiler specific extensions such as <tt>__alignof</tt> and
//! is used if the others are not available. In all cases, if CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS //! <tt>_alignof_</tt>. If an extension is not available, then the function uses
//! is defined, then the function returns 1. //! <tt>__BIGGEST_ALIGNMENT__</tt>. <tt>sizeof(T)</tt> is used if the others are not available.
//! In <em>all</em> cases, if <tt>CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS</tt> is defined, then the
//! function returns 1.
template <class T> template <class T>
inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround
{ {
@ -891,6 +893,8 @@ inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround
return __alignof(T); return __alignof(T);
#elif defined(__GNUC__) #elif defined(__GNUC__)
return __alignof__(T); return __alignof__(T);
#elif __BIGGEST_ALIGNMENT__
return __BIGGEST_ALIGNMENT__;
#elif CRYPTOPP_BOOL_SLOW_WORD64 #elif CRYPTOPP_BOOL_SLOW_WORD64
return UnsignedMin(4U, sizeof(T)); return UnsignedMin(4U, sizeof(T));
#else #else