xue@1
|
1 //---------------------------------------------------------------------------
|
xue@1
|
2
|
xue@1
|
3 #ifndef align8H
|
xue@1
|
4 #define align8H
|
xue@1
|
5
|
Chris@5
|
6 /**
|
Chris@5
|
7 \file align8.h - 8-byte (64-bit) alignment routines.
|
xue@1
|
8
|
xue@1
|
9 This file provides tools for aligning boundaries of arrays, particularly of 64-byte units, e.g. double-
|
xue@1
|
10 precision floating points, to physical addresses divisible by 8, including aligning dynamically
|
xue@1
|
11 allocated memory block and aligning call stack. Currently stack alignment is disabled due to lack
|
xue@1
|
12 of compiler support for Intel assembly.
|
xue@1
|
13
|
xue@1
|
14 Further reading: "Double precision floating point alignment issue.pdf"
|
xue@1
|
15 */
|
xue@1
|
16
|
xue@1
|
17 //--stack alignment----------------------------------------------------------
|
xue@1
|
18 /*
|
xue@1
|
19 These two macros are used to envelop a function call so that the function is called with a stack
|
xue@1
|
20 pointer that is a multiple of 8. Aligning the stack does not automatically ensure that local double
|
xue@1
|
21 -precision floating-point variables (or other variables one wants to align to 8-byte boundaries) are
|
xue@1
|
22 aligned to 8-byte boundaries; one has to adjust the variable declaration order, using dummy variables
|
xue@1
|
23 if necessary, to make the alignment happen.
|
xue@1
|
24 */
|
xue@1
|
25 //macro ALIGN_STACK_8 moves the current stack pointer to a multiple of 8
|
xue@1
|
26 #define ALIGN_STACK_8 {int alignstack; asm {mov alignstack, esp} asm {and esp, 0xFFFFFFF8}
|
xue@1
|
27 //macro RESTORE_STACK moves the stack pointer back to where it was before ALIGN_STACK_8
|
xue@1
|
28 #define RESTORE_STACK asm {mov esp, alignstack}}
|
xue@1
|
29
|
xue@1
|
30 //ALIGN8 ensures F is executed with a start stack pointer divisible by 8. Currently disabled.
|
xue@1
|
31 #define ALIGN8(F) F
|
xue@1
|
32 //uncomment the following line to enable stack alignment
|
xue@1
|
33 //#define ALIGN8(F) ALIGN_STACK_8 F RESTORE_STACK
|
xue@1
|
34
|
xue@1
|
35 //--64-bit aligned memory allocation routines--------------------------------
|
xue@1
|
36 void* malloc8(unsigned size);
|
xue@1
|
37 void free8(void* buffer8);
|
xue@1
|
38
|
xue@1
|
39 #endif
|