diff options
author | noloader <noloader@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2015-07-14 02:57:13 +0000 |
---|---|---|
committer | noloader <noloader@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2015-07-14 02:57:13 +0000 |
commit | 51dd45a78501d37d02fea9ffa504d2e609ad8672 (patch) | |
tree | 79997d63ec3bcfc521fbc6b058d6405c90884787 /misc.h | |
parent | 47e5a4d4ea89c7f236bfc55df01c052efc3059e1 (diff) | |
download | cryptopp-51dd45a78501d37d02fea9ffa504d2e609ad8672.tar.gz |
Cleared crash with GCC 4.8 and above and -O3. In a nutshell, it was due to vectorization and alignment violations agains the vmovdqa instruction
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@583 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'misc.h')
-rw-r--r-- | misc.h | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -382,21 +382,26 @@ inline T1 RoundDownToMultipleOf(const T1 &n, const T2 &m) template <class T1, class T2> inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m) { + // TODO: undefined behavior here... if (n+m-1 < n) throw InvalidArgument("RoundUpToMultipleOf: integer overflow"); return RoundDownToMultipleOf(n+m-1, m); } +// Influenced by CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS; may cause +// problems at -O3 and GCC vectorization. template <class T> inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround { #ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS if (sizeof(T) < 16) - return 1; + return 1; #endif - + #if (_MSC_VER >= 1300) return __alignof(T); +#elif defined(__clang__) + return __alignof(T); #elif defined(__GNUC__) return __alignof__(T); #elif CRYPTOPP_BOOL_SLOW_WORD64 @@ -406,17 +411,43 @@ inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround #endif } +// Not influenced by CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS; will not +// cause problems with -O3 and GCC vectorization. +template <class T> +inline unsigned int GetStrictAlignmentOf(T *dummy=NULL) // VC60 workaround +{ +#if (_MSC_VER >= 1300) + return __alignof(T); +#elif defined(__clang__) + return __alignof(T); +#elif defined(__GNUC__) + return __alignof__(T); +#else + return sizeof(T); +#endif +} + inline bool IsAlignedOn(const void *p, unsigned int alignment) { return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2((size_t)p, alignment) == 0 : (size_t)p % alignment == 0); } +// Influenced by CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS; may cause +// problems at -O3 and GCC vectorization. template <class T> inline bool IsAligned(const void *p, T *dummy=NULL) // VC60 workaround { return IsAlignedOn(p, GetAlignmentOf<T>()); } +// Not influenced by CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS; will not +// cause problems with -O3 and GCC vectorization. +template <class T> +inline bool IsStrictAligned(const void *p, T *dummy=NULL) // VC60 workaround +{ + return IsAlignedOn(p, GetStrictAlignmentOf<T>()); +} + #ifdef IS_LITTLE_ENDIAN typedef LittleEndian NativeByteOrder; #else |