X64对浮点参数的处理

编译:icl /EHa /Zi /Od icc64.c /link /debug

 

#include <stdio.h> double myfloat(double a,double b,double c,int d,int e,double g) { int tempInt=rand(); a=a+(double)tempInt; //1+41=42 b=a+1.0+(double)tempInt; //42+1+41=84 c=b+2.0*(double)tempInt; //84+82=166 return c; } int main() { double t; t=myfloat(1.0,2.0,3.0,3,10,2.0); printf("%lf /n",t); system("pause"); return 0; }

IDA: ; Attributes: bp-based frame fpd=20h ; int __cdecl main() main proc near var_30= dword ptr -30h var_28= qword ptr -28h var_20= qword ptr -20h var_18= qword ptr -18h var_10= dword ptr -10h var_C= dword ptr -0Ch push rbp sub rsp, 50h lea rbp, [rsp+30h] movsd xmm0, cs:qword_431BF8 movsd xmm1, cs:qword_431BE8 movsd xmm2, cs:qword_431BF0 mov eax, 3 mov [rsp+50h+var_30], 0Ah movsd xmm3, cs:qword_431BE8 movsd [rsp+50h+var_28], xmm3 mov r9d, eax ; d call j_myfloat movsd [rbp+20h+var_20], xmm0 movsd xmm0, [rbp+20h+var_20] movsd [rbp+20h+var_18], xmm0 lea rax, format ; "%lf /n" movsd xmm0, [rbp+20h+var_18] mov rcx, rax ; format movapd xmm1, xmm0 movq rdx, xmm1 call printf mov [rbp+20h+var_10], eax lea rax, command ; "pause" mov rcx, rax ; command call system mov [rbp+20h+var_C], eax mov eax, 0 lea rsp, [rbp+20h] pop rbp retn ; Attributes: bp-based frame fpd=10h ; long double __cdecl myfloat(long double a, long double b, long double c, int d, int e, long double g) myfloat proc near var_10= dword ptr -10h var_C= dword ptr -0Ch arg_0= qword ptr 10h arg_8= qword ptr 18h arg_10= qword ptr 20h arg_18= dword ptr 28h e= dword ptr 30h g= qword ptr 38h push rbp sub rsp, 30h lea rbp, [rsp+20h] movsd [rbp+10h+arg_0], xmm0 movsd [rbp+10h+arg_8], xmm1 movsd [rbp+10h+arg_10], xmm2 mov [rbp+10h+arg_18], r9d call rand mov [rbp+10h+var_10], eax mov eax, [rbp+10h+var_10] mov [rbp+10h+var_C], eax mov eax, [rbp+10h+var_C] cvtsi2sd xmm0, eax movsd xmm1, [rbp+10h+arg_0] addsd xmm1, xmm0 movsd [rbp+10h+arg_0], xmm1 movsd xmm0, cs:qword_431BE0 movsd xmm1, [rbp+10h+arg_0] addsd xmm1, xmm0 mov eax, [rbp+10h+var_C] cvtsi2sd xmm0, eax addsd xmm1, xmm0 movsd [rbp+10h+arg_8], xmm1 mov eax, [rbp+10h+var_C] cvtsi2sd xmm0, eax mov eax, [rbp+10h+var_C] cvtsi2sd xmm1, eax addsd xmm0, xmm1 movsd xmm1, [rbp+10h+arg_8] addsd xmm1, xmm0 movsd [rbp+10h+arg_10], xmm1 movsd xmm0, [rbp+10h+arg_10] lea rsp, [rbp+10h] pop rbp retn myfloat endp

编译:最大优化icl /EHa /Zi /Ox icc64.c /link /debug 这次直接在main中完成了所有计算,悲剧的优化太变态。 ; int __cdecl main() main proc near var_8= dword ptr -8 t= qword ptr 0 sub rsp, 28h mov ecx, 3 call __intel_new_proc_init stmxcsr [rsp+28h+var_8] or [rsp+28h+var_8], 8040h ldmxcsr [rsp+28h+var_8] call rand cvtsi2sd xmm1, eax movsd xmm0, cs:qword_434BE0 lea rcx, format ; "%lf /n" addsd xmm0, xmm1 addsd xmm1, xmm1 addsd xmm0, xmm0 addsd xmm1, xmm0 movq rdx, xmm1 ;//仍然是rdx与xmm1参数双保险 call printf lea rcx, command ; "pause" call system xor eax, eax add rsp, 28h retn ; long double __cdecl myfloat(long double a, long double b, long double c, int d, int e, long double g) myfloat proc near e= dword ptr 28h g= qword ptr 30h a = r9b b = r10b c = r11b d = r9 tempInt = rax sub rsp, 28h call rand cvtsi2sd xmm2, eax movsd xmm1, cs:qword_434BE8 movaps xmm0, xmm1 addsd xmm0, xmm2 addsd xmm0, xmm1 addsd xmm0, xmm2 addsd xmm0, xmm2 addsd xmm0, xmm2 add rsp, 28h retn

你可能感兴趣的:(c,优化,command,System,attributes)