汇编优化问题,谁能给段优化算法加分200
准备写SSE汇编算法优化,可以刚开始就遇到问题了
下面这段C代码
QueryPerformanceCounter((LARGE_INTEGER*)&start_time);
QueryPerformanceCounter((LARGE_INTEGER*)&end_time);
cout<<"time is : "<<double(end_time-start_time)<<"\n" ;
用此方法测的基本时间是4
cout<<"time is : "<<double(end_time-start_time)<<"\n" ;
QueryPerformanceCounter((LARGE_INTEGER*)&start_time);
for(z=0;z<MAXZ;z++)
for(i=0;i<MAX;i++){
}
QueryPerformanceCounter((LARGE_INTEGER*)&end_time);
cout<<"time is : "<<double(end_time-start_time)<<"\n" ;
测得使用时间是4,说明
for(z=0;z<MAXZ;z++)
for(i=0;i<MAX;i++)
{
}
使用时间约等于0
我用VC内联汇编
void __stdcall SSE(TEMP* dest, TEMP *sou, int max,int maxz)
{
//空函数花费时间约等于0
__asm
{
mov edi, dest
mov esi, sou
mov ebx, maxz
mov edx, max //以上参数传递花费时间2
mov eax, 0 //i=0
a: cmp eax, ebx //以下是上面C语言中的for循环.使用时间10-11真夸张
jb b
jmp end
b: mov ecx, 0 //z=0
c: cmp ecx, edx
jb d //去SSE加速代码
inc eax
jmp a
d:
inc ecx
jmp c
end: nop
}
return ;
}
QueryPerformanceCounter((LARGE_INTEGER*)&start_time);
SSE(mytmp2,mytmp,MAX,MAXZ);
QueryPerformanceCounter((LARGE_INTEGER*)&end_time);
cout<<"time is : "<<double(end_time-start_time)<<"\n" ;
测得时间是17,晕死,本想用汇编优化结果越搞越慢