MdePkg/Base.h: Introduce ALIGN_VALUE_SUBTRAHEND

This commit is contained in:
Marvin Häuser 2023-03-30 16:12:39 +02:00 committed by Mikhail Krichanov
parent 623c955985
commit 9d65ea7b79
1 changed files with 12 additions and 1 deletions

View File

@ -907,6 +907,17 @@ STATIC_ASSERT (ALIGNOF (__VERIFY_INT32_ENUM_SIZE) == sizeof (__VERIFY_INT32_ENUM
**/
#define IS_POW2(Value) ((Value) != 0U && ((Value) & ((Value) - 1U)) == 0U)
/**
Determines the subtrahend to subtract from a value to round it down to the
previous boundary of a specified alignment.
@param Value The value to round down.
@param Alignment The alignment boundary used to return the subtrahend.
@return Subtrahend to round Value down to alignment boundary Alignment.
**/
#define ALIGN_VALUE_SUBTRAHEND(Value, Alignment) ((Value) & ((Alignment) - 1U))
/**
Checks whether a value is aligned by a specified alignment.
@ -916,7 +927,7 @@ STATIC_ASSERT (ALIGNOF (__VERIFY_INT32_ENUM_SIZE) == sizeof (__VERIFY_INT32_ENUM
@retval TRUE Value is aligned by Alignment.
@retval FALSE Value is not aligned by Alignment.
**/
#define IS_ALIGNED(Value, Alignment) (((Value) & ((Alignment) - 1U)) == 0U)
#define IS_ALIGNED(Value, Alignment) (ALIGN_VALUE_SUBTRAHEND (Value, Alignment) == 0U)
/**
Checks whether a pointer or address is aligned by a specified alignment.