Is something like
__m128 a = something;
__m128i b = reinterpret_cast<__m128i>(a);
safe or undefined? If it is undefined, will it at least work on all of the major compilers (gcc,clang,msvc,icc)? I tested it on my computer with gcc and it works, but I'm not sure if its portable. I know that I can use _mm_castps_si128()
, but because of templates, the first way happens to be more convenient.
The reinterpret_cast operator can be used for conversions such as char* to int* , or One_class* to Unrelated_class* , which are inherently unsafe. The result of a reinterpret_cast cannot safely be used for anything other than being cast back to its original type.
No. It is a purely compile-time construct.
No it's not portable and the behavior is undefined; __m128
is for float
and __m128i
is for integer types, these are not compatible types.
In fact, it doesn't even compile in MSVC 2017:
error C2440: 'reinterpret_cast': cannot convert from '__m128' to '__m128i'
Use the cast intrinsic:
__m128 a = something;
__m128i b = _mm_castps_si128(a);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With