用于用户堆栈的单指令压入/弹出而不是辅助函数调用?

发布于 2024-12-28 11:18:54 字数 330 浏览 0 评论 0原文

在处理器堆栈上,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妞丶爷亲个 2025-01-04 11:18:54

听起来您想要做的就是从 getter/setter 中选择额外的 callret 。在这种情况下,您可以使用关键字 inline 告诉编译器内联该特定函数。另一种方法是使用 C 宏函数对 getter/setter 进行编码(如果它们不太复杂)。

Sounds like what you're trying to do is opt out the extra call and ret from your getters/setters. In this case, you can use the keyword inline 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文