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

爱⌒轻易说出口 提交于 2019-12-03 07:07:26

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!