請問"__fastcall"的使用時機 |
答題得分者是:CoffeeX
|
remmurds
一般會員 發表:17 回覆:14 積分:16 註冊:2006-10-29 發送簡訊給我 |
||||
CoffeeX
中階會員 發表:18 回覆:121 積分:72 註冊:2005-02-18 發送簡訊給我 |
請善用help檔喔!
不過我還沒研讀過@@,... <basefont></basefont> Use the __fastcall modifier to declare functions that expect parameters to be passed in registers. The first three parameters are passed (from left to right) in EAX, EDX, and ECX, if they fit in the register. The registers are not used if the parameter is a floating-point or struct type. All form class member functions must use the __fastcall convention. The compiler treats this calling convention as a new language specifier, along the lines of _cdecl and _pascal Functions declared using _cdecl or _pascal cannot have the _fastcall modifier because they use the stack to pass parameters. Likewise, the __fastcall modifier cannot be used together with _export. The compiler prefixes the __fastcall function name with an at-sign ("@"). This prefix applies to both unmangled C function names and to mangled C function names. For Microsoft C style __fastcall implementation, see __msfastcall and __msreturn. <basefont></basefont> Note: The __fastcall modifier is subject to name mangling. See the description of the -VC option.
------
=.=??? |
|||
rogan321
高階會員 發表:21 回覆:307 積分:200 註冊:2003-05-15 發送簡訊給我 |
||||
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
||||
CoffeeX
中階會員 發表:18 回覆:121 積分:72 註冊:2005-02-18 發送簡訊給我 |
補充一下...
主題: When to use fastcall http://bcbjournal.com/articles/vol4/0004/When_to_use___fastcall.htm 請自行閱讀, 懂翻譯的麻煩一下了...^^ 大意上, 說明的很詳細, 無需自己加上_fastcall, 該加的BCB會自己加, 實測中(_fastcall)並不會有更高的效率, 說錯的話麻煩指正一下,在下的英文不是很好...
------
=.=??? |
|||
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
其實。你只要寫一段下去測試。看它的 asm 就知道了。
比方說我寫個簡單的測試如下 [code] int __fastcall TForm1::f1(int i1, int i2, int i3, int i4) 004016C0 55 push ebp 004016C1 8BEC mov ebp,esp 004016C3 83C4F0 add esp,-0x10 004016C6 894DF4 mov [ebp-0x0c],ecx 004016C9 8955F8 mov [ebp-0x08],edx 004016CC 8945FC mov [ebp-0x04],eax i = i1 i2 i3 i4; 004016CF 8B45F8 mov eax,[ebp-0x08] 004016D2 0345F4 add eax,[ebp-0x0c] 004016D5 03450C add eax,[ebp 0x0c] 004016D8 034508 add eax,[ebp 0x08] 004016DB 8945F0 mov [ebp-0x10],eax return i; 004016DE 8B45F0 mov eax,[ebp-0x10] } }004016E1 8BE5 mov esp,ebp 004016E3 5D pop ebp 004016E4 C20800 ret 0x0008 004016E7 90 nop int TForm1::f1(int i1, int i2, int i3, int i4) { 004016E8 55 push ebp 004016E9 8BEC mov ebp,esp 004016EB 51 push ecx i = i1 i2 i3 i4; 004016EC 8B450C mov eax,[ebp 0x0c] 004016EF 034510 add eax,[ebp 0x10] 004016F2 034514 add eax,[ebp 0x14] 004016F5 034518 add eax,[ebp 0x18] 004016F8 8945FC mov [ebp-0x04],eax return i; 004016FB 8B45FC mov eax,[ebp-0x04] } 004016FE 59 pop ecx 004016FF 5D pop ebp 00401700 C3 ret [/code]這樣看起來。是不是就有所差別了? 它們對於參數的處理方式就不同了。 我所舉的例子為固定參數。也就是沒有像 printf 那種不定個數的參數。 在 C 跟 pascal 不同的處理,應是在不定參數上面。__fastcall 應在那上面有更大的不同。 而我只做了固定參數的測試。你可以測一下不定參數時的情況。 而你所提的那個網頁,我也去看了。 它的測試方法有幾個問題。 1.並沒有考慮到不定參數時的情況。 2.它並沒有考慮到 cache 的情況。 也就是說程式太小。根本還沒被移出 cpu 的 level 1 cache . 由我寫的那一段可以看到指令沒幾個。 所以那樣的測試並不準確。 3.再者。所謂的 fastcall 並不是說它呼叫起來會比較”快”。 這個感覺應是翻譯的問題。 因為 pascal 在傳參數跟 C 不同。 詳細的操作過程你可以去看它的 CPU VIEW 慢慢看就能體會。 太久沒玩這麼低階的東西了。你可以試著去看它的 asm code 應該就可以了解它的差異 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |