How does the frame-Pointer work?

Asked

Viewed 687 times

3

In the official GCC documentation there is a option that allows you to remove the frame-Pointer when it is not necessary.

  • What the frame-Pointer ago?
  • How removing this pointer can improve performance?

1 answer

4


I don’t know how much you know about these low-level things and how memory works. This can help if you don’t know much.

The frame Pointer, or inter-base as it is also called, it is a sub-stack of the stack where it has the data of a function.

Pilha de chamadas

FP is the address where the current function begins. It is used to easily return to the original location in the call as soon as the execution of this function ends, especially in the occurrence of an exception (unwinding). It is also used as the base address for the calculation of the various elements that the function allocates, so the code can have relative addresses.

There are some rare situations where it is not necessary to keep this number in a register by librating it for another task. It is more rare to still have the need to use this register for something else, so the optimization is almost innocuous or of very rare advantage.

The debug usually use this register for your control. Omitting it prevents its use, but then optimization is discarded even.

Architectures with frames fixed size do not need this and architectures that have their own treatment for the stack frame cannot receive this optimization.

The conclusion is that this optimization is almost unnecessary.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.