将4个SSE整数提取为4个字符 [英] Extract 4 SSE integers to 4 chars
本文介绍了将4个SSE整数提取为4个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个__m128i
,其中包含4个32位整数值.
Suppose I have a __m128i
containing 4 32-bit integer values.
是否可以通过某种方式将其存储在char[4]
内,其中每个int
值的低位字符都存储在char
值中?
Is there some way I can store it inside a char[4]
, where the lower char from each int
value is stored in a char
value?
所需结果:
r1 r2 r3 r4
__m128i 0x00000012 0x00000034 0x00000056 0x00000078
|
V
char[4] 0x12 0x34 0x56 0x78
SSE2及以下版本是首选. 在MSVC ++上编译.
SSE2 and below is preferred. Compiling on MSVC++.
推荐答案
使用SSE2,您可以使用以下代码:
With SSE2 you can use the following code:
char[4] array;
x = _mm_packs_epi32(x, x);
x = _mm_packus_epi16(x, x);
*((int*)array) = _mm_cvtsi128_si32(x);
这篇关于将4个SSE整数提取为4个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文