ChibiOS 21.11.4
Memory Alignment

Detailed Description

Memory Alignment services.

Collaboration diagram for Memory Alignment:

Memory alignment support macros

#define MEM_ALIGN_MASK(a)
 Alignment mask constant.
#define MEM_ALIGN_PREV(p, a)
 Aligns to the previous aligned memory address.
#define MEM_ALIGN_NEXT(p, a)
 Aligns to the next aligned memory address.
#define MEM_IS_ALIGNED(p, a)
 Returns whatever a pointer or memory size is aligned.
#define MEM_IS_VALID_ALIGNMENT(a)
 Returns whatever a constant is a valid alignment.

Macro Definition Documentation

◆ MEM_ALIGN_MASK

#define MEM_ALIGN_MASK ( a)
Value:
((size_t)(a) - 1U)

Alignment mask constant.

Parameters
[in]aalignment, must be a power of two

Definition at line 61 of file chalign.h.

◆ MEM_ALIGN_PREV

#define MEM_ALIGN_PREV ( p,
a )
Value:
/*lint -save -e9033 [10.8] The cast is safe.*/ \
((size_t)(p) & ~MEM_ALIGN_MASK(a)) \
/*lint -restore*/
#define MEM_ALIGN_MASK(a)
Alignment mask constant.
Definition chalign.h:61

Aligns to the previous aligned memory address.

Parameters
[in]pvariable to be aligned
[in]aalignment, must be a power of two

Definition at line 69 of file chalign.h.

Referenced by chCoreAllocFromTopI().

◆ MEM_ALIGN_NEXT

#define MEM_ALIGN_NEXT ( p,
a )
Value:
/*lint -save -e9033 [10.8] The cast is safe.*/ \
MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK(a), (a)) \
/*lint -restore*/

Aligns to the next aligned memory address.

Parameters
[in]pvariable to be aligned
[in]aalignment, must be a power of two

Definition at line 80 of file chalign.h.

Referenced by chCoreAllocFromBaseI(), chFactoryCreateObjectsFIFO(), chHeapAllocAligned(), chHeapFree(), chHeapObjectInit(), chThdCreateStatic(), and chThdCreateSuspendedI().

◆ MEM_IS_ALIGNED

#define MEM_IS_ALIGNED ( p,
a )
Value:
(((size_t)(p) & MEM_ALIGN_MASK(a)) == 0U)

Returns whatever a pointer or memory size is aligned.

Parameters
[in]pvariable to be aligned
[in]aalignment, must be a power of two

Definition at line 91 of file chalign.h.

Referenced by chHeapFree(), chPoolAllocI(), chPoolFreeI(), chThdCreateI(), chThdCreateStatic(), and chThdCreateSuspendedI().

◆ MEM_IS_VALID_ALIGNMENT

#define MEM_IS_VALID_ALIGNMENT ( a)
Value:
(((size_t)(a) != 0U) && (((size_t)(a) & ((size_t)(a) - 1U)) == 0U))

Returns whatever a constant is a valid alignment.

Valid alignments are powers of two.

Parameters
[in]aalignment to be checked, must be a constant

Definition at line 99 of file chalign.h.

Referenced by chCoreAllocFromBaseI(), chCoreAllocFromTopI(), chHeapAllocAligned(), and chPoolObjectInitAligned().