Store __m256i to integer

2019-02-26 09:32发布

How can I store __m256i data type to integer?

I know that for floats there is :

_mm256_store_ps(float *a, __m256 b)

where the first argument is the output array.

For integers I found only :

_mm256_store_si256(__m256i *a, __m256i b)

where both arguments are __m256i data type.

Is it enough to do something like this:

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)

Inside function:

__m256i * Xmmtype = (__m256i*) X;

//fill output
_mm256_store_si256( &Xmmtype[ i ] , T ); //T is __m256i

Is this OK?

-----UPDATED -----------------------

Ok, so what if I have :

__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 );


    } 

} 

1条回答
太酷不给撩
2楼-- · 2019-02-26 09:55

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 );

or:

_mm256_store_si256( (__m256i *)&X[i], T );


Update based on the latest edit of your question:

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 );
查看更多
登录 后发表回答