Intel IA-32 Computer Accessories User Manual


 
Stack Alignment D
D-9
Stack Frame Optimizations
The Intel C++ Compiler provides certain optimizations that may
improve the way aligned frames are set up and used. These
optimizations are as follows:
If a procedure is defined to leave the stack frame 16-byte-aligned
and it calls another procedure that requires 16-byte alignment, then
the callee’s aligned entry point is called, bypassing all of the
unnecessary aligning code.
If a static function requires 16-byte alignment, and it can be proven
to be called only by other functions that require 16-byte alignment,
then that function will not have any alignment code in it. That is, the
compiler will not use
ebx to point to the argument block and it will
not have alternate entry points, because this function will never be
entered with an unaligned frame.
NOTE. A. Here we allow for local variables. However,
this value should be adjusted so that, after pushing the
saved registers, esp is 0 mod 16.
B. Just prior to the call, esp is 0 mod 16. To
maintain alignment, esp should be adjusted by 16.
When a callee uses the stdcall calling sequence, the
stack pointer is restored by the callee. The final
addition of 12 compensates for the fact that only 4
bytes were passed, rather than 16, and thus the caller
must account for the remaining adjustment.