AVX向量化学习(四)-INT类型转化成DOUBLE类型

AVX向量化学习(四)-INT类型转化成DOUBLE类型

使用AVX指令集把INT类型转化为DOUBLE类型

使用到的AVX函数介绍

1.

1
__m128i _mm_setr_epi32 (int e3, int e2, int e1, int e0)

Synopsis

__m128i _mm_setr_epi32 (int e3, int e2, int e1, int e0)
#include <emmintrin.h>
Instruction: Sequence
CPUID Flags: SSE2

Description

Set packed 32-bit integers in dst with the supplied values in reverse order.

Operation

1
2
3
4
dst[31:0] := e3 
dst[63:32] := e2
dst[95:64] := e1
dst[127:96] := e0

2.

1
__m256d _mm256_cvtepi32_pd (__m128i a)

Synopsis

m256d _mm256_cvtepi32_pd (m128i a)
#include <immintrin.h>
Instruction: vcvtdq2pd ymm, xmm
CPUID Flags: AVX

Description

Convert packed signed 32-bit integers in a to packed double-precision (64-bit) floating-point elements, and store the results in dst.

Operation

1
2
3
4
5
6
FOR j := 0 to 3 
i := j*32
m := j*64
dst[m+63:m] := Convert_Int32_To_FP64(a[i+31:i])
ENDFOR
dst[MAX:256] := 0

Performance

ArchitectureLatencyThroughput (CPI)
Icelake71
Skylake71
Broadwell61
Haswell61
Ivy Bridge41

程序运行平台

北京超级云计算中心A3分区

编译指令

g++ int_to_double.cpp -msse2 -mavx -o test01

运行指令

./test01

程序源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <immintrin.h>
using namespace std;
int main()
{
int a[4]={1,2,3,4};
double b[9]={0};
__m128i x = _mm_setr_epi32(a[0], a[1], a[2],a[3]); //load
__m256d v5=_mm256_cvtepi32_pd(x); //convert
_mm256_storeu_pd(b,v5);
for(int i=0;i<9;i++)
{
cout<<b[i]<<endl;
}

return 0;
}

程序输出

1
2
3
4
5
6
7
8
9
1
2
3
4
0
0
0
0
0

相关链接

[https://software.intel.com/sites/landingpage/IntrinsicsGuide/]: “ Intel® Intrinsics Guide”