如何在__m128i的特定位置加载字节
How to load bytes in a __m128i in a specific position
我需要加载 4 个字节连续存储在数组中的 __m128i 变量的特定位置,即能够执行许多int32_t和,一次 4 个,存储所有部分结果。
例如:
const unsigned int SIZE = 2000000;
const unsigned int STEP = 100;
unsigned char* inBuffer = new char[SIZE];
//Fill inBuffer
const unsigned char* a = inBuffer;
int32_t* outBuffer = new int32_t[SIZE/STEP*4];
int32_t* result = outBuffer;
__m128i sum = _mm_setzero_si128 ()
for (int i = 0; i < SIZE; i+=STEP) {
__m128i value = _mm_set_epi32 (a[3],a[2],a[1],a[0]);
sum = __mm_add_epi32(sum,value);
_mm_storeu_si128 ((__m128i*)result,sum);
a+=STEP;
result+=4;
}
//Print outBuffer
delete[] inBuffer;
delete[] outBuffer;
我想知道是否有更有效的方法可以做到这一点
这里的主要问题当然是这一行:
__m128i value = _mm_set_epi32 (a[3],a[2],a[1],a[0]);
但是,一个像样的编译器应该为此生成相当有效的代码。看看输出(gcc -O3 -S ...
) - 如果它不仅仅是几个指令,那么您可能需要考虑自己进行加载/解包操作。
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 无法获取webot::PositionSensor对象中位置传感器的值
- 非常量变量只读位置的赋值
- 如何定义更改car类中car位置的方法
- 使用迭代器时如何访问对象在向量中的位置?
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 求最大元素位置的分治算法
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 是与初始类同一内存位置的重新定位类
- 如何在使用网格布局时重叠qwidgets,并将重叠的widget定位在距离窗口边界特定距离的位置
- 我不知道如何定位最高随机数的位置
- 如何在MFC上设置窗口位置以将其定位到屏幕顶部
- 将QGraphicsSvgItem的中心定位在一个位置上。
- 如何定位WinRT异步方法调用中出现错误的位置
- 重定位表项在平面二进制文件中的存储位置