Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert 'long long' (or __int64) to __m64

What is the proper way to convert an __int64 value to an __m64 value for use with SSE?

like image 377
user541686 Avatar asked Jan 30 '12 08:01

user541686


1 Answers

With gcc you can just use _mm_set_pi64x:

#include <mmintrin.h>

__int64 i = 0x123456LL; 
__m64 v = _mm_set_pi64x(i);

Note that not all compilers have _mm_set_pi64x defined in mmintrin.h. For gcc it's defined like this:

extern __inline __m64  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_set_pi64x (long long __i)
{
  return (__m64) __i;
}

which suggests that you could probably just use a cast if you prefer, e.g.

__int64 i = 0x123456LL; 
__m64 v = (__m64)i;

Failing that, if you're stuck with an overly picky compiler such as Visual C/C++, as a last resort you can just use a union and implement your own intrinsic:

#ifdef _MSC_VER // if Visual C/C++
__inline __m64 _mm_set_pi64x (const __int64 i) {
    union {
        __int64 i;
        __m64 v;
    } u;

    u.i = i;
    return u.v;
}
#endif

Note that strictly speaking this is UB, since we are writing to one variant of a union and reading from another, but it should work in this instance.

like image 125
Paul R Avatar answered Nov 07 '22 00:11

Paul R