13.07.2015 Views

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

STACK ALIGNMENTExample D-2. Aligned ebp-based Stack Frames (Contd.)foo.aligned(5);add esp,-16 // aligned entry, this should// be a multiple of 16mov [esp],5call foo.alignedadd esp,12 // see Note B belowreturn j;movpopmovpopmovpopret 4}eax,[ebp-16]edxesp,ebpebpesp,ebxebx// NOTES:// (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, <strong>and</strong> thus the caller must account for the remaining adjustment.D.1.3Stack Frame <strong>Optimization</strong>sThe Intel C++ Compiler provides certain optimizations that may improve the wayaligned frames are set up <strong>and</strong> used. These optimizations are as follows:• If a procedure is defined to leave the stack frame 16-byte-aligned <strong>and</strong> it callsanother procedure that requires 16-byte alignment, then the callee’s alignedentry point is called, bypassing all of the unnecessary aligning code.• If a static function requires 16-byte alignment, <strong>and</strong> it can be proven to be calledonly by other functions that require 16-byte alignment, then that function will nothave any alignment code in it. That is, the compiler will not use EBX to point tothe argument block <strong>and</strong> it will not have alternate entry points, because thisfunction will never be entered with an unaligned frame.D-6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!