Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitwise cast from __m128 to __m128i on MSVC

On Linux and Mac, one can do

__m128 x;
__m128i n = (__m128i)x;

This operation copies the bit representation of x to n, and is useful for implementing various branch-free conditional operations operating on SSE floating point registers. On MSVC 11, it gives

eikonal-generated.h(1228) : error C2440: 'type cast' : cannot convert from '__m128' to '__m128i'; No constructor could take the source type, or constructor overload resolution was ambiguous

What is the equivalent in Microsoft Visual Studio?

Note that I am not asking for the standard float-to-int conversion function _mm_cvtepi32_ps, which does numerically meaningful conversion.

like image 728
Geoffrey Irving Avatar asked Nov 29 '12 18:11

Geoffrey Irving


1 Answers

With MSVC you need to use:

_mm_castsi128_ps for bitwise cast from __m128i to __m128

and

_mm_castps_si128 for bitwise cast from __m128 to __m128i

For other compilers (gcc, ICC, et al) you can just use normal casts.

like image 154
Paul R Avatar answered Nov 12 '22 10:11

Paul R