请这是我第一次使用AVX而我正试图对双精度数进行简单的乘法,但我没有得到所有结果。
我得到前4个结果,其他是行话。
#include <immintrin.h>
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
int main() {
double *a, *b; // data pointers
double *pA,*pB; // work pointer
__m256d rA_AVX, rB_AVX; // variables for AVX
const int vector_size = 8;
a = (double*) _mm_malloc (vector_size*sizeof(double),64);
b = (double*) _mm_malloc (vector_size*sizeof(double),64);
for(int i = 0; i < vector_size; i++) {
a[i] = (rand() % 48);
b[i] = 0.0f;
cout << a[i] << endl;
}
for (int i = 0; i < vector_size; i += 8)
{
pA = a;
pB = b;
rA_AVX = _mm256_load_pd(pA);
rB_AVX = _mm256_mul_pd(rA_AVX,rA_AVX);
_mm256_store_pd(pB,rB_AVX);
pA += 8;
pB += 8;
}
for (int i=0; i<vector_size; i++){
cout << endl << b[i] << endl;
}
_mm_free(a);
_mm_free(b);
system("PAUSE");
return 0;
}