Single instruction push/pop for user stack instead accessory function calls?

495 views Asked by At

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.

1

There are 1 answers

0
Quentin Casasnovas On

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.