1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <windows.h>
#include <iostream>
#include <cmath>
#include "xmmintrin.h"
#define LENGTH 100000000
void TestInvSqrt()
{
double d = 0;
for(int i = 1 ; i < LENGTH ; i++)
{
d += 1/sqrt((double)i);
}
printf("%f\n", d);
}
void TestInvSqrt2()
{
double d = 0;
for(int i = 1 ; i < LENGTH ; i+=4)
{
__declspec(align(16)) float tab[4] = {i, i +1, i+2, i+3};
__m128* m128 = (__m128*)tab;
*m128 = _mm_rsqrt_ps(*m128);
d += tab[0] + tab[1] + tab[2] + tab[3];
}
printf("%f\n", d);
}
int main()
{
int time = GetTickCount();
TestInvSqrt();
std::cout << GetTickCount() - time << std::endl;
time = GetTickCount();
TestInvSqrt2();
std::cout << GetTickCount() - time << std::endl;
} |
Partager