cbase 1.46.11
C/C++ Static Template
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).
#define SHIFT8(T, x, s)
 Shifts a byte value to a specific bit position.
#define PACK_U32_LE(a, b, c, d)
 Packs 4 bytes into a 32-bit unsigned integer (little-endian order).

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 359 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 351 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 366 of file base_macros.h.

◆ PACK_U32_LE

#define PACK_U32_LE ( a,
b,
c,
d )
Value:
(SHIFT8(U32, a, 0) | SHIFT8(U32, b, 8) | SHIFT8(U32, c, 16) | SHIFT8(U32, d, 24))
#define SHIFT8(T, x, s)
Shifts a byte value to a specific bit position.

Packs 4 bytes into a 32-bit unsigned integer (little-endian order).

Parameters
aLeast significant byte.
bSecond byte.
cThird byte.
dMost significant byte.
Returns
A packed U32 value.

Definition at line 384 of file base_macros.h.

◆ SHIFT8

#define SHIFT8 ( T,
x,
s )
Value:
((T)(x) << (s))

Shifts a byte value to a specific bit position.

Parameters
TTarget type (e.g., U32).
xValue to shift.
sBit position (0, 8, 16, 24).

Definition at line 374 of file base_macros.h.