Mercurial > hg > x
diff align8.h @ 1:6422640a802f
first upload
author | Wen X <xue.wen@elec.qmul.ac.uk> |
---|---|
date | Tue, 05 Oct 2010 10:45:57 +0100 |
parents | |
children | 5f3c32dc6e17 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/align8.h Tue Oct 05 10:45:57 2010 +0100 @@ -0,0 +1,39 @@ +//--------------------------------------------------------------------------- + +#ifndef align8H +#define align8H + +/* + align8.cpp - 8-byte (64-bit) alignment routines. + + This file provides tools for aligning boundaries of arrays, particularly of 64-byte units, e.g. double- + precision floating points, to physical addresses divisible by 8, including aligning dynamically + allocated memory block and aligning call stack. Currently stack alignment is disabled due to lack + of compiler support for Intel assembly. + + Further reading: "Double precision floating point alignment issue.pdf" +*/ + +//--stack alignment---------------------------------------------------------- +/* + These two macros are used to envelop a function call so that the function is called with a stack + pointer that is a multiple of 8. Aligning the stack does not automatically ensure that local double + -precision floating-point variables (or other variables one wants to align to 8-byte boundaries) are + aligned to 8-byte boundaries; one has to adjust the variable declaration order, using dummy variables + if necessary, to make the alignment happen. +*/ +//macro ALIGN_STACK_8 moves the current stack pointer to a multiple of 8 +#define ALIGN_STACK_8 {int alignstack; asm {mov alignstack, esp} asm {and esp, 0xFFFFFFF8} +//macro RESTORE_STACK moves the stack pointer back to where it was before ALIGN_STACK_8 +#define RESTORE_STACK asm {mov esp, alignstack}} + +//ALIGN8 ensures F is executed with a start stack pointer divisible by 8. Currently disabled. +#define ALIGN8(F) F +//uncomment the following line to enable stack alignment +//#define ALIGN8(F) ALIGN_STACK_8 F RESTORE_STACK + +//--64-bit aligned memory allocation routines-------------------------------- +void* malloc8(unsigned size); +void free8(void* buffer8); + +#endif