用于用户堆栈的单指令压入/弹出而不是辅助函数调用?
在处理器堆栈上,push、mov 和 pop 等都是单个指令。
编译源代码时,编译器生成单个机器指令版本,但在运行时,假设堆栈是......好吧,一个常规堆栈容器,在运行时访问存储在堆栈上的值需要函数调用,这会转换为大量的函数调用机器代码。
动态运行时对象是否可以达到相同水平的效率,而不是使用比单个机器指令长得多的 setter 和 getter 成员函数?
我的想法是使用标记指针,但我不知道如何在运行时将其值逐字推入内存位置或从内存位置推入,而无需诉诸函数调用。
内联汇编可能是一种选择,如果可能的话我想避免这种选择。但我想我仍然需要将它放在函数体内,这样它就不会是一条指令。
On the processor stack push mov and pop and so on are single instructions.
When compiling source code the compiler generates the single machine instruction version, but during run-time, assuming the stack is ... well a regular stack container, accessing values stored on the stack during run-time takes function calls which translate into tons of machine code.
It is possible to achieve the same level of efficiency for dynamic run-time objects instead of using setter and getter member functions which are way longer than a single machine instruction?
My idea is of using a mark pointer, but I don't know how to literally push its value into a memory location or in from a memory location during run-time without resorting to function calls.
Inlining assembly is probably an option, one I would like to avoid if possible. But I guess I would still have to put it inside a function body so it won't be a single instruction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想要做的就是从 getter/setter 中选择额外的
call
和ret
。在这种情况下,您可以使用关键字inline
告诉编译器内联该特定函数。另一种方法是使用 C 宏函数对 getter/setter 进行编码(如果它们不太复杂)。Sounds like what you're trying to do is opt out the extra
call
andret
from your getters/setters. In this case, you can use the keywordinline
to tell your compiler to inline that particular function. Another way would be to code your getters/setters using C macro function if they are not too complex.