From 3fef0f51d8600b2c5c9c8a53b8e26edf7484c0fd Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Wed, 10 Sep 2008 16:00:20 +0000 Subject: 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 --- MdePkg/Include/Base.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'MdePkg/Include/Base.h') diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index a103d93491..4bc80c17c8 100644 --- a/MdePkg/Include/Base.h +++ b/MdePkg/Include/Base.h @@ -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. -- cgit v1.2.3