更快的方法在C类型转换后复制阵列? [英] Faster method to copy arrays after typecasting in C?
问题描述
我有一两时二维整数数组 InArray [2] [60]
执行短
数据2 LS 2 MS字节字节和位字段数据。请提出一个快速的方法来提取短
数据,并将其复制到短
OutArray [60 ]
,东西就行了的memcpy()
。我presume的每个项目迭代是不这样做的最优化方法。
TIA
I have a two-dimesional integer array InArray[2][60]
carrying short
data in 2 LS bytes and bit field data in 2 MS bytes. Please suggest a faster method to extract short
data and copy it to a short
OutArray[60]
, something on the lines for memcpy()
. I presume iterating through each item is not the most optimal method of doing this.
TIA
编辑:添加code段
int InArray[2][60];
short OutArray[60];
for (int i=0; i < 60;i++)
{
OutArray[i] = (short)(InArray[0][i] & 0xffff);
}
是否有这样做的更好,更快的可能方式。
Is there a better and possibly faster way of doing this
推荐答案
如果你真的是复制60个元素的数组,那么也没关系。
If you really are copying a 60-element array, then it does not matter.
如果数组是更大和/或你正在做很多次,那么你会想看看的 SIMD 指令集:SSEx在Intel平台上,AltiVec技术在PPC ...
If the array is larger and/or you are doing it a lot of times, then you'll want to have a look at SIMD instruction sets: SSEx on Intel platforms, Altivec on PPC...
例如,使用SSE4,你可以使用_mm_packus_epi32(),它包(和饱和)2 * 4 32位操作数为8个16位操作数。
For instance, using SSE4, you may use _mm_packus_epi32() which packs (and saturates) 2*4 32-bit operands into 8 16-bit operands.
您的编译器可能有内在函数来使用这些: http://msdn.microsoft .COM / EN-US /库/ hh977022.aspx ,的http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/PowerPC-AltiVec-Built_002din-Functions.html...
Your compiler probably has intrinsics to use those: http://msdn.microsoft.com/en-us/library/hh977022.aspx, http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/PowerPC-AltiVec-Built_002din-Functions.html...
这篇关于更快的方法在C类型转换后复制阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!