double var = 0.;
for(int i = 0; i < 1000000 ; i++)
{
var += sqrt(2.0);
}
std::cout << var << std::endl;
在MSVC2012,是有可能,根据与优化导通,SQRT(2.0)的释放将被调用的值来代替,而不是把它称为1 * 10^6次?C++循环的编译器优化
ASM像她那样,不知道它的解释:
; Line 6
push ebp
mov ebp, esp
sub esp, 84 ; 00000054H
push ebx
push esi
push edi
; Line 8
movsd xmm0, QWORD PTR [email protected]
movsd QWORD PTR _var$[ebp], xmm0
; Line 9
mov DWORD PTR _i$1[ebp], 0
jmp SHORT [email protected]
[email protected]:
mov eax, DWORD PTR _i$1[ebp]
add eax, 1
mov DWORD PTR _i$1[ebp], eax
[email protected]:
cmp DWORD PTR _i$1[ebp], 1000000 ; 000f4240H
jge SHORT [email protected]
; Line 11
sub esp, 8
movsd xmm0, QWORD PTR [email protected]
movsd QWORD PTR [esp], xmm0
call _sqrt
add esp, 8
fstp QWORD PTR tv85[ebp]
movsd xmm0, QWORD PTR tv85[ebp]
addsd xmm0, QWORD PTR _var$[ebp]
movsd QWORD PTR _var$[ebp], xmm0
; Line 12
jmp SHORT [email protected]
编辑:
抱歉上面的调试版本....
; Line 7
push ebp
mov ebp, esp
and esp, -8 ; fffffff8H
; Line 11
movsd xmm0, QWORD PTR [email protected]
call __libm_sse2_sqrt_precise
movsd xmm2, QWORD PTR [email protected]@3NA
mov eax, 1000000 ; 000f4240H
[email protected]:
movapd xmm1, xmm0
addsd xmm2, xmm1
dec eax
jne SHORT [email protected]
movsd QWORD PTR [email protected]@3NA, xmm2
; Line 13
mov esp, ebp
pop ebp
ret 0
你有MSVS2012吗? –
只有快递版 – Guillaume07
可能吗?是的,当然!为什么不? –