SSE2 - comparing integers w/ float data types

Started by
2 comments, last by discman1028 16 years, 9 months ago
Greets, SSE defines the following type:

typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128 {
     float               m128_f32[4];
     unsigned __int64    m128_u64[2];
     __int8              m128_i8[16];
     __int16             m128_i16[8];
     __int32             m128_i32[4];
     __int64             m128_i64[2];
     unsigned __int8     m128_u8[16];
     unsigned __int16    m128_u16[8];
     unsigned __int32    m128_u32[4];
 } __m128;



SSE2 defines the following type:

typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128i {
    __int8              m128i_i8[16];
    __int16             m128i_i16[8];
    __int32             m128i_i32[4];    
    __int64             m128i_i64[2];
    unsigned __int8     m128i_u8[16];
    unsigned __int16    m128i_u16[8];
    unsigned __int32    m128i_u32[4];
    unsigned __int64    m128i_u64[2];
} __m128i;



I have two __m128's storing floating point values, but I'd like to do a bitwise compare. This can be done by doing a integer compare. This instruction was added in SSE2, so we are all good so far: __m128i _mm_cmpeq_epi32 (__m128i a, __m128i b); But I can't pass a __m128 to this function, it's the wrong type. But both unions have the raw data that I want to compare. How can I reinterpet-cast a __m128i to a __m128, or otherwise compare their integer representations, inexpensively? (I don't want to use any conversion intrinsics, b/c I don't want any rounding or converting -- just reinterpretation.) Thanks.
--== discman1028 ==--
Advertisement
I just realized I could _mm_xor_ps() them together, and if I got zero, then they were bitwise-equal.

But still... anyone know about the performance implications of the conversion I was talking about? Can I do that reinterpretation somehow, for free?
--== discman1028 ==--
No you can't do the conversion, the reason is that the value is probably stored in one of the SSE registers which keep track of weather the data is integer or floating point and raise some form of error if the wrong data type is used with the wrong instruction so the compiler would have to save the value to memory and reload it as an integer type in order to perform the conversion. Of coarse you can do that yourself, just copy the contents of the __m128 to a char[] and then from the char[] to a __m128i if you really need to.
Ok, thanks..

On a certain other vector platform / API, that uses Altivec, there is a vector type that is typeless... not float, int, or anything, but it performs all kind of int or float operations on that one type. As a user, I like that style. But perhaps there are performance hits I'm not seeing, such as you describe.

--== discman1028 ==--

This topic is closed to new replies.

Advertisement