intnslib 0.1
A library to hold common functionality used across multiple projects.
Loading...
Searching...
No Matches
Alignment.hpp
1#ifndef INTNS_MEMORY_ALIGNMENT_HPP
2#define INTNS_MEMORY_ALIGNMENT_HPP
3
4#include <cstddef>
5#include <cstdint>
6
7namespace intns::memory {
8
16inline constexpr std::uintptr_t align_address(std::uintptr_t addr,
17 std::size_t alignment) noexcept {
18 return (addr + alignment - 1) & ~(alignment - 1);
19}
20
28inline constexpr bool is_aligned(std::uintptr_t addr,
29 std::size_t alignment) noexcept {
30 return (addr & (alignment - 1)) == 0;
31}
32
39inline constexpr bool is_power_of_two(std::size_t value) noexcept {
40 return value != 0 && (value & (value - 1)) == 0;
41}
42} // namespace intns::memory
43
44#endif