summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2008-09-10 16:00:20 +0000
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2008-09-10 16:00:20 +0000
commit3fef0f51d8600b2c5c9c8a53b8e26edf7484c0fd (patch)
treed09b2d5b6374a1bf45fcfaab450cf0e7f40d202e
parentaf1b10362dd41b88cb15c91953e986881a6387e6 (diff)
downloadedk2-platforms-3fef0f51d8600b2c5c9c8a53b8e26edf7484c0fd.tar.xz
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
-rw-r--r--MdePkg/Include/Base.h15
1 files changed, 8 insertions, 7 deletions
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
@@ -217,19 +217,20 @@ 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.