Mjolnir Core
Core functionality of the Mjolnir API

◆ is_aligned() [2/2]

auto is_aligned ( const volatile T_Type *  pointer,
UST  alignment 
) -> bool
inlinenoexcept

Check if a passed pointer is aligned.

Template Parameters
T_TypeThe pointer type
Parameters
[in]pointerPointer that should be checked
[in]alignmentRequired alignment
Returns
true or false
Remarks
Use the template version if the required alignment is known at compile-time. It is usually faster. Clang 10 with -O3 generates the following assembly for this function:
is_aligned(void const volatile*, unsigned long):
mov rax, rdi
xor edx, edx
div rsi
test rdx, rdx
sete al
ret
auto is_aligned(const volatile T_Type *pointer) noexcept -> bool
Check if a passed pointer is aligned.
Definition: pointer_operations.h:191
The output for the template version with 4 byte alignment looks like this:
bool is_aligned<4ul>(void const volatile*):
test dil, 3
sete al
ret
Note that it consists of less instructions and that the expensive div instruction is removed.