如何使用 AVX 打乱数组中的值并将打乱后的值存储到不同的数组中

问题描述

在此先感谢您的帮助。我需要能够在具有 uint16_t 数据的数组中执行以下洗牌模式。我未处理的数组将如下所示

0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 

我已经用_mm512_permutexvar_epi16 将我未处理的数据转换成下面的格式

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 

然后将 AVX 寄存器的内容存储到 4 个不同的数组中,这是我不确定最佳方法的部分。

next eight values of arrayofZero's 0 0 0 0 0 0 0 0 
next eight values of arrayofOne's 1 1 1 1 1 1 1 1 
next eight values of arrayofTwo's 2 2 2 2 2 2 2 2
next eight values of arrayofThree's 3 3 3 3 3 3 3

我需要遍历我未处理的数据,并用我的 1、2 和 3 值填充零值数组,依此类推。 注意:我的实际数据不是硬编码的 0,1,2,3。它是计算数据,我需要把

1st value in the 1st array,2nd value in the 2nd array,3rd value in the 3rd processed data array,and 4th value in the 4th processed data array

该模式对整个未处理的数据数组重复。这样就完成了所有的处理

1st Array holds all the 0 values
2nd Array holds all the 1 values
3rd array holds all the 2 values
4th array holds all the 3 values

我一直在查看 _mm512_permutexvar_epi16 以将我未处理的数据转换为格式。

下面是我已经开始的代码

#include <immintrin.h>
#include <array>
#include <iostream>

int main()
{
    alignas(64) std::array<uint16_t,128> unprocessedData;
    alignas(64) std::array<uint16_t,32> processedData0,processedData1,processedData2,processedData3; 
    alignas(64) constexpr std::array<uint16_t,32> shuffleMask {
         0,4,8,12,16,20,24,28,5,9,13,17,21,25,29,6,10,14,18,22,26,30,3,7,11,15,19,23,27,31,};
    //prepare sample data
    for (uint16_t i {0}; i < unprocessedData.size(); i+=4)
    {
        unprocessedData[i] = 0;
        unprocessedData[i+1] = 1;
        unprocessedData[i+2] = 2;
        unprocessedData[i+3] = 3;
    } 
    for (size_t i {0}; i < unprocessedData.size(); i+=32)
    {
            auto v {_mm512_loadu_epi16(&unprocessedData[i]) };
            _mm512_storeu_epi16(&unprocessedData[i],_mm512_permutexvar_epi16(_mm512_load_si512((__m512i*)shuffleMask.data()),v));
        //Somehow Store values 0-7 of permuted array into processedData0
        //Store values 8-15 of permuted array into processedData1
        //Store values 16-23 of permuted array into processedData2
        //Store values 24-31 of permuted array into processedData3
    }
    return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)