将__m256i存储为整数 [英] Store __m256i to integer
问题描述
如何将__m256i数据类型存储为整数?
How can I store __m256i data type to integer?
我知道对于花车来说:
_mm256_store_ps(float *a, __m256 b)
第一个参数是输出数组.
where the first argument is the output array.
对于仅发现的整数:
_mm256_store_si256(__m256i *a, __m256i b)
其中两个参数均为__m256i数据类型.
where both arguments are __m256i data type.
做这样的事情够了吗
int * X = (int*) _mm_malloc( N * sizeof (*X) ,32 );
(我正在使用它作为函数的参数,我想获取它的值)
( I am using this as an argument to a function and I want to obtain it's values)
内部功能:
__m256i * Xmmtype = (__m256i*) X;
//fill output
_mm256_store_si256( &Xmmtype[ i ] , T ); //T is __m256i
这样可以吗?
-----更新-----------------------
-----UPDATED -----------------------
好的,如果我有:
__m256i T;
for ( y = 0; y < h; y++ )
{
for ( x = 0; x < w; x++ )
{
for ( int i = 0; i < N; i+=8 )
{
//calculate here the T
}
//write result
_mm256_store_si256( &Xmmtype[ x + y * w ] , T );
}
}
推荐答案
您已完成,但您无需创建临时指针-您可以直接应用强制类型转换,例如:
What you've done is OK, but you don't need to create a temporary pointer - you can just apply the cast directly, e.g.:
_mm256_store_si256( (__m256i *)X, T );
或:
_mm256_store_si256( (__m256i *)&X[i], T );
根据您问题的最新编辑进行更新:
Update based on the latest edit of your question:
您似乎在以不符合AVX对齐要求的方式为X
编制索引,即X[i]
不能保证是32字节对齐,因此您应该使用未对齐的存储区:
It looks like you are indexing X
in a way that does not meet AVX alignment requirements, i.e. X[i]
is not guaranteed to be 32 byte aligned, so you should use an unaligned store:
_mm256_storeu_si256( (__m256i *)&X[i], T );
这篇关于将__m256i存储为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!