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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPENDIX DSTACK ALIGNMENTThis appendix details on the alignment of the stacks of data for Streaming SIMDExtensions <strong>and</strong> Streaming SIMD Extensions 2.D.1 STACK FRAMESThis section describes the stack alignment conventions for both ESP-based (normal),<strong>and</strong> EDP-based (debug) stack frames. A stack frame is a contiguous block of memoryallocated to a function for its local memory needs. It contains space for the function’sparameters, return address, local variables, register spills, parameters needing to bepassed to other functions that a stack frame may call, <strong>and</strong> possibly others. It is typicallydelineated in memory by a stack frame pointer (ESP) that points to the base ofthe frame for the function <strong>and</strong> from which all data are referenced via appropriateoffsets. The convention on Intel <strong>64</strong> <strong>and</strong> <strong>IA</strong>-<strong>32</strong> is to use the ESP register as the stackframe pointer for normal optimized code, <strong>and</strong> to use EDP in place of ESP when debuginformation must be kept. Debuggers use the EDP register to find the informationabout the function via the stack frame.It is important to ensure that the stack frame is aligned to a 16-byte boundary uponfunction entry to keep local __m128 data, parameters, <strong>and</strong> XMM register spill locationsaligned throughout a function invocation.The Intel C++ Compiler for Win<strong>32</strong>*Systems supports conventions presented here help to prevent memory referencesfrom incurring penalties due to misaligned data by keeping them aligned to 16-byteboundaries. In addition, this scheme supports improved alignment for __m<strong>64</strong> <strong>and</strong>double type data by enforcing that these <strong>64</strong>-bit data items are at least eight-bytealigned (they will now be 16-byte aligned).For variables allocated in the stack frame, the compiler cannot guarantee the base ofthe variable is aligned unless it also ensures that the stack frame itself is 16-bytealigned. Previous software conventions, as implemented in most compilers, onlyensure that individual stack frames are 4-byte aligned. Therefore, a function calledfrom a Microsoft-compiled function, for example, can only assume that the framepointer it used is 4-byte aligned.Earlier versions of the Intel C++ Compiler for Win<strong>32</strong> Systems have attempted toprovide 8-byte aligned stack frames by dynamically adjusting the stack framepointer in the prologue of main <strong>and</strong> preserving 8-byte alignment of the functions itcompiles. This technique is limited in its applicability for the following reasons:• The main function must be compiled by the Intel C++ Compiler.• There may be no functions in the call tree compiled by some other compiler (asmight be the case for routines registered as callbacks).• Support is not provided for proper alignment of parameters.D-1

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

Saved successfully!

Ooh no, something went wrong!