WinTer 0.1.1
Windows Terminal Emulator
Loading...
Searching...
No Matches
Memory Alignment

Fast, bitwise macros for aligning pointers and sizes to powers of 2. More...

Macros

#define ALIGN_UP_POW2(x, p)
 Aligns a value UP to the nearest power of 2.
#define ALIGN_DOWN_POW2(x, p)
 Aligns a value DOWN to the nearest power of 2.
#define IS_POW2_OR_ZERO(x)
 Checks if a given integer is a power of 2 (or zero).

Detailed Description

Fast, bitwise macros for aligning pointers and sizes to powers of 2.

Macro Definition Documentation

◆ ALIGN_DOWN_POW2

#define ALIGN_DOWN_POW2 ( x,
p )
Value:
((x) & ~((p) - 1))

Aligns a value DOWN to the nearest power of 2.

Parameters
xThe value to align.
pThe alignment boundary (must be a power of 2).
Returns
The aligned value.

Definition at line 340 of file base_macros.h.

◆ ALIGN_UP_POW2

#define ALIGN_UP_POW2 ( x,
p )
Value:
(((x) + (p) - 1) & ~((p) - 1))

Aligns a value UP to the nearest power of 2.

Parameters
xThe value to align.
pThe alignment boundary (must be a power of 2).
Returns
The aligned value.

Definition at line 332 of file base_macros.h.

◆ IS_POW2_OR_ZERO

#define IS_POW2_OR_ZERO ( x)
Value:
(((x) & ((x) - 1)) == 0)

Checks if a given integer is a power of 2 (or zero).

Parameters
xThe value to check.
Returns
1 (true) if it is a power of 2, 0 (false) otherwise.

Definition at line 347 of file base_macros.h.