性能和SSE代码

时间:2013-03-08 07:38:04

标签: c++ performance assembly x86 sse

我的SSE代码性能有问题。我尝试计算Pi数,然后使用http://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80。因此,当我进行1 * 10 ^ 11次迭代时,我的性能(-100%)比没有SSE的代码差。如果我做1 * 10 ^ 10次迭代,我的性能会比没有SSE的代码好。

我使用Visual Studio C ++编译器和英特尔编译器(没有优化!)。当然我可以使用编译器进行优化(我会得到完美的结果),但我想了解什么是错的。

我尝试对齐数据(你可以看到它)并且我使用VS C ++编译器获得了更好的性能(-40%而不是-100%),但是使用英特尔编译器的性能我获得了-85%而不是-100 :) 我使用getTickCount来测量时间。

我的处理器是AMD Turon X2双核移动RM74。可能是有道理的:))

我的SSE代码

    double *a = (double*) _mm_malloc(4 * sizeof(double  ), 16);
double *i = (double*) _mm_malloc(sizeof(double), 64); //good point
double *k = (double*) _mm_malloc(sizeof(double), 64);
double *result = (double*) _mm_malloc(sizeof(double), 64);
double *temp = (double*) _mm_malloc(sizeof(double), 64);
*temp = 0.0;
*result = 0.0;
*k = 1.0;
a[0] = 1;
a[1] = -1;
for (*i = 1; *i < 100000000000; *i += 2, *k += 4.0) {
        a[2] = *k;
        a[3] = *k + 2;
    __asm {
        mov eax, dword ptr a

        movapd XMM0, xmmword ptr [eax ]
        movapd XMM1, xmmword ptr [eax + 16]

        divpd XMM0, XMM1

        movapd XMM1, XMM0

        psrldq XMM1,8

        addpd   XMM0,XMM1  
        mov eax, dword ptr temp;

        movsd [eax], XMM0
    }

    *result += *temp;
}

*result = *result * 4.0;

计时 getTickcount。毫秒。

intel + O       | 942901
intel - O       | 1273139
intel + sse + O | 948096 
intel + sse - O | 2354382 |(unaligned data)
VS + O          | 949079
VS - O          | 1106749
VS + SSE + O    | 968189
VS + SSE - O    | 2180067 | (unaligned data)
VS + SSE - O    | 1674201 | (aligned data)
intel + sse - O | 1921437 |(aligned data)

0 个答案:

没有答案