每个PUSH指令是否在x64上压入8字节的倍数? [英] Does each PUSH instruction push a multiple of 8 bytes on x64?

查看:412
本文介绍了每个PUSH指令是否在x64上压入8字节的倍数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x64上,每个PUSH指令是否压入8字节的倍数?如果没有,它将推动多少?

On x64, does each PUSH instruction push a multiple of 8 bytes? If not, how much does it push?

每个函数参数消耗多少堆栈空间?

Also, how much stack space does each function parameter consume?

推荐答案

否,但实际上,总是将8字节的值压入堆栈.

No, but in practice, one always pushes an 8 byte value onto the stack.

根据功能参数的大小以及是在堆栈中,在寄存器中传递还是通过引用传递,功能参数会占用不同的堆栈空间量.

Function parameters consuming varying amounts of stack space depending on the size of the function parameter and whether it is passed in the stack, in the registers, or passed by reference.

如果通过 pushing 在堆栈中传递了一个函数参数,则存在方便地推送8个字节的push指令这一事实表明,您将参数传递为一个8字节的值.对于指针,int64和普通双精度数,这显然很容易.对于char,bool,short和其他类型的内存较小的类型,大多数编译器所做的就是将值压入8个字节的块中.占用16或32字节的类型可能会由编译器通过多个推入指令推入.更大的价值往往无法通过推动获得通过.通常,编译器会尝试将指针传递给更大的值,而不是传递值本身. {我已经构建了一个可以传递任意大值的编译器,但它可以通过在堆栈中腾出空间,然后执行块移动指令来实现].各个编译器的详细信息各不相同,具体取决于正在编译的程序的语言语义.

If one passes a function parameter in the stack by pushing, then the fact that there are convenient push instructions that pushes 8 bytes strongly suggests that you pass the parameter as an 8 byte value. For pointers, int64 and plain doubles, this is obviously easy. For char, bool, short, and other types whose memory size is smaller, what most compilers do is push the value in an 8 byte chunk. Types that take 16 or 32 bytes might be pushed by the compiler with several push instructions. Bigger values tend not to get passed by pushing; often a compiler tries to pass a pointer to a bigger value rather than pass the value itself. {I've built a compiler that can pass arbitrarily big values, but it does so by making space in the stack, and then executing a block move instruction]. Details vary from compiler to compiler, and according to the language semantics of the program being compiled.

一个非常聪明的编译器可能会注意到几个参数很小,可以打包成一个8字节的数量,只需要一次按下即可.我还没有真正做到这一点,这可能是因为将这些值打包到一个寄存器中需要花很多精力,而推指令在设计和缓存方面已经非常快了.

A really clever compiler might notice that several arguments are small and can be packed into an 8 byte quantity that only requires a single push. I've not seen one actually do that, probably because it takes work to pack such values together into a register, and push instructions are already pretty fast by design and by cache.

可以将较小的值压入堆栈.根据体系结构,这是合法的,但是如果所推入的小值不是8字节的倍数,则可能会导致访问性能下降.然后必须小心地正确弹出非整数以恢复堆栈对齐.根据我的经验,该功能没有用(请参阅Peter Cordes撰写的代码高尔夫球评论).

It is possible to push smaller values onto the stack. This is legal according to the architecture, but is likely to cause a mis-aligned access performance hit if the set of small values pushed isn't a multiple of 8 bytes. And then one must be careful to pop off the non-multiple correctly to restore stack alignment. Not useful in my experience (see code golf comment by Peter Cordes).

如果将值传递到寄存器中,则不会推送任何内容:-}

If you pass the value in a register, nothing gets pushed :-}

可能会安排将参数值存储在堆栈中的一个众所周知的位置.然后就没有任何推送了:-}

One might arrange to store parameter values in a well known locations in the stack. Then there isn't any push :-}

这篇关于每个PUSH指令是否在x64上压入8字节的倍数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆