将 __m256i 存储为整数 [英] Store __m256i to integer

查看:39
本文介绍了将 __m256i 存储为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 __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.

做这样的事情就足够了:

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)

内部函数:

__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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆