X64對浮點參數的處理

來源:互聯網
上載者:User

編譯:icl /EHa /Zi /Od icc64.c /link /debug

 

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

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

編譯:最大最佳化icl /EHa /Zi /Ox icc64.c /link /debug 這次直接在main中完成了所有計算,悲劇的最佳化太變態。 ; int __cdecl main()<br />main proc near</p><p>var_8= dword ptr -8<br />t= qword ptr 0</p><p>sub rsp, 28h<br />mov ecx, 3<br />call __intel_new_proc_init<br />stmxcsr [rsp+28h+var_8]<br />or [rsp+28h+var_8], 8040h<br />ldmxcsr [rsp+28h+var_8]<br />call rand<br />cvtsi2sd xmm1, eax<br />movsd xmm0, cs:qword_434BE0<br />lea rcx, format ; "%lf /n"<br />addsd xmm0, xmm1<br />addsd xmm1, xmm1<br />addsd xmm0, xmm0<br />addsd xmm1, xmm0<br />movq rdx, xmm1 ;//仍然是rdx與xmm1參數雙保險<br />call printf<br />lea rcx, command ; "pause"<br />call system<br />xor eax, eax<br />add rsp, 28h<br />retn</p><p>; long double __cdecl myfloat(long double a, long double b, long double c, int d, int e, long double g)<br />myfloat proc near</p><p>e= dword ptr 28h<br />g= qword ptr 30h</p><p>a = r9b<br />b = r10b<br />c = r11b<br />d = r9<br />tempInt = rax<br />sub rsp, 28h<br />call rand<br />cvtsi2sd xmm2, eax<br />movsd xmm1, cs:qword_434BE8<br />movaps xmm0, xmm1<br />addsd xmm0, xmm2<br />addsd xmm0, xmm1<br />addsd xmm0, xmm2<br />addsd xmm0, xmm2<br />addsd xmm0, xmm2<br />add rsp, 28h<br />retn</p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.