Sign in to follow this  

SSE2 - comparing integers w/ float data types

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this