Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

c - Store __m256i to integer

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


    } 

} 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...