Prefer union access over pointer cast

Also see http://stackoverflow.com/a/38547909/608639
pull/239/head
Jeffrey Walton 2016-07-24 00:34:55 -04:00
parent ef4f185d9b
commit 32e6276baf
1 changed files with 5 additions and 5 deletions

View File

@ -14,7 +14,7 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
// Uncomment for benchmarking C++ against SSE2 or NEON // Uncomment for benchmarking C++ against SSE2 or NEON
// #undef CRYPTOPP_BOOL_SSE4_INTRINSICS_AVAILABLE #undef CRYPTOPP_BOOL_SSE4_INTRINSICS_AVAILABLE
// #undef CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE // #undef CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE
// Visual Studio needs both VS2005 (1400) and _M_64 for SSE2 and _mm_set_epi64x() // Visual Studio needs both VS2005 (1400) and _M_64 for SSE2 and _mm_set_epi64x()
@ -40,14 +40,14 @@ NAMESPACE_BEGIN(CryptoPP)
#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5130) #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5130)
inline __m128i _mm_set_epi64x(const uint64_t a, const uint64_t b) inline __m128i _mm_set_epi64x(const uint64_t a, const uint64_t b)
{ {
union INT_128_64 { union INT_128_64x2 {
__m128i v128; __m128i v128;
uint64_t v64[2]; uint64_t v64[2];
}; };
INT_128_64 v; INT_128_64x2 val;
v.v64[0] = b; v.v64[1] = a; val.v64[0] = b; val.v64[1] = a;
return *(reinterpret_cast<__m128i*>(v.v64)); return val.v128;
} }
#endif #endif