From 27b27475e9a46b5bd28a057ad0298dbbc9f96d01 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 12 Sep 2016 06:34:00 -0400 Subject: [PATCH] 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 --- misc.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/misc.h b/misc.h index 5120b96c..b44c8fe3 100644 --- a/misc.h +++ b/misc.h @@ -872,10 +872,12 @@ inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m) //! \brief Returns the minimum alignment requirements of a type //! \param dummy an unused Visual C++ 6.0 workaround //! \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 -//! function uses compiler specific extensions such as __alignof and _alignof_. sizeof(T) -//! is used if the others are not available. In all cases, if CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS -//! is defined, then the function returns 1. +//! \details Internally the function calls C++11's alignof if available. If not available, +//! then the function uses compiler specific extensions such as __alignof and +//! _alignof_. If an extension is not available, then the function uses +//! __BIGGEST_ALIGNMENT__. sizeof(T) is used if the others are not available. +//! In all cases, if CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS is defined, then the +//! function returns 1. template 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); #elif defined(__GNUC__) return __alignof__(T); +#elif __BIGGEST_ALIGNMENT__ + return __BIGGEST_ALIGNMENT__; #elif CRYPTOPP_BOOL_SLOW_WORD64 return UnsignedMin(4U, sizeof(T)); #else