简体   繁体   中英

make gcc pass the arguments by register

On my 32bit x86 Ubuntu11.10, gcc4.6.3 pass the arguments by stack. Is there any gcc optimization that force gcc to pass arguments by registers? And how gcc do that? I want some details, please.

The relevant attribute is __attribute__((fastcall)) . Functions declared with this attribute are called with their first eligible argument in ECX and the second in EDX.

(I'm assuming x86. You just said 32 bits, but that covers many architectures such as ARM).

GCC passes arguments on stack in your case because the Linux-x86 ABI specifies that. With the fastcall function attribute you can change that, which of course breaks the ABI and causes all kinds of problems due to that.

A solution could be to swith to x86-64, where the ABI specifies that (some) arguments are passed by registers. Or if you like bleeding edge stuff, the newish x32 ABI is similar to the x86-64 ABI but with 32-bit pointers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM