简体   繁体   English

make gcc通过寄存器传递参数

[英]make gcc pass the arguments by register

On my 32bit x86 Ubuntu11.10, gcc4.6.3 pass the arguments by stack. 在我的32位x86 Ubuntu11.10上,gcc4.6.3通过堆栈传递参数。 Is there any gcc optimization that force gcc to pass arguments by registers? 是否存在强制gcc通过寄存器传递参数的gcc优化? And how gcc do that? 那gcc怎么做到的? I want some details, please. 我想要一些细节。

The relevant attribute is __attribute__((fastcall)) . 相关属性是__attribute__((fastcall)) Functions declared with this attribute are called with their first eligible argument in ECX and the second in EDX. 使用此属性声明的函数将在ECX中使用第一个符合条件的参数进行调用,在EDX中调用第二个参数。

(I'm assuming x86. You just said 32 bits, but that covers many architectures such as ARM). (我假设是x86。你刚才说了32位,但它涵盖了很多架构,比如ARM)。

GCC passes arguments on stack in your case because the Linux-x86 ABI specifies that. GCC在你的情况下传递堆栈上的参数,因为Linux-x86 ABI指定了。 With the fastcall function attribute you can change that, which of course breaks the ABI and causes all kinds of problems due to that. 使用fastcall函数属性,您可以更改它,这当然会破坏ABI并导致由此引起的各种问题。

A solution could be to swith to x86-64, where the ABI specifies that (some) arguments are passed by registers. 解决方案可以是切换到x86-64,其中ABI指定(某些)参数由寄存器传递。 Or if you like bleeding edge stuff, the newish x32 ABI is similar to the x86-64 ABI but with 32-bit pointers. 或者如果你喜欢前沿的东西,新的x32 ABI类似于x86-64 ABI,但有32位指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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