1. Add new macro: ALIGN_VALUE to round up a value to the next boundary of a given alignment.

2. Update ALIGN_POINTER to use the new macro
3. Drop the second parameter of ALIGN_VARIABLE for simplicity. It can also directly use the new macro ALIGN_VALUE. 

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5869 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2008-09-10 16:00:20 +00:00
parent af1b10362d
commit 3fef0f51d8
1 changed files with 8 additions and 7 deletions

View File

@ -216,20 +216,21 @@ typedef CHAR8 *VA_LIST;
///
#define _CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
///
/// ALIGN_VALUE - aligns a value up to the next boundary of the given alignment.
///
#define ALIGN_VALUE(Value, Alignment) ((Value) + (((Alignment) - (Value)) & ((Alignment) - 1)))
///
/// ALIGN_POINTER - aligns a pointer to the lowest boundry
///
#define ALIGN_POINTER(p, s) ((VOID *) ((UINTN)(p) + (((s) - ((UINTN) (p))) & ((s) - 1))))
#define ALIGN_POINTER(Pointer, Alignment) ((VOID *) (ALIGN_VALUE ((UINTN)(Pointer), (Alignment))))
///
/// ALIGN_VARIABLE - aligns a variable up to the next natural boundry for int size of a processor
///
#define ALIGN_VARIABLE(Value, Adjustment) \
Adjustment = 0U; \
if ((UINTN) (Value) % sizeof (UINTN)) { \
(Adjustment) = (UINTN)(sizeof (UINTN) - ((UINTN) (Value) % sizeof (UINTN))); \
} \
(Value) = (UINTN)((UINTN) (Value) + (UINTN) (Adjustment))
#define ALIGN_VARIABLE(Value) ALIGN_VALUE ((Value), sizeof (UINTN))
//
// Return the maximum of two operands.