rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
align.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include "../platform/attributes.hpp"
6#include "../platform/constexpr.hpp"
7
8#include <cstdint>
9#include <cstddef>
10
11namespace rexlib
12{
13
23template <typename T>
25std::size_t get_alignment(T* address) noexcept;
26
35REXLIB_NODISCARD REXLIB_CONSTEXPR
36std::size_t get_alignment(std::uintptr_t address) noexcept;
37
47template <typename T>
49bool is_aligned(T* address, std::size_t alignment) noexcept;
50
58REXLIB_NODISCARD REXLIB_CONSTEXPR
59bool is_aligned(std::uintptr_t address, std::size_t alignment) noexcept;
60
70template <typename T>
72T* align_floor(T* address, std::size_t alignment) noexcept;
73
82REXLIB_NODISCARD REXLIB_CONSTEXPR
83std::uintptr_t align_floor(std::uintptr_t address, std::size_t alignment) noexcept;
84
94REXLIB_CONSTEXPR
95std::uintptr_t& align_floor_inplace(std::uintptr_t& address, std::size_t alignment) noexcept;
96
107template <typename T>
109T* align_ceil(T* address, std::size_t alignment) noexcept;
110
119REXLIB_NODISCARD REXLIB_CONSTEXPR
120std::uintptr_t align_ceil(std::uintptr_t address, std::size_t alignment) noexcept;
121
131REXLIB_CONSTEXPR
132std::uintptr_t& align_ceil_inplace(std::uintptr_t& address, std::size_t alignment) noexcept;
133
146template <typename T>
148T* offset_bytes(T* address, std::ptrdiff_t count);
149
150} // namespace rexlib
151
152#include "align.inl"
#define REXLIB_NODISCARD
Indicates that the return value should be used.
Definition attributes.hpp:76
Container for multidimensional numeric data.
Definition array.hpp:31
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
REXLIB_NODISCARD T * align_ceil(T *address, std::size_t alignment) noexcept
Align a pointer to a higher or equal address that satisfies the provided alignment.
REXLIB_NODISCARD T * offset_bytes(T *address, std::ptrdiff_t count)
Offset an address by a given amount of bytes.
REXLIB_NODISCARD std::size_t get_alignment(T *address) noexcept
Get the alignment of a pointer.
REXLIB_CONSTEXPR std::uintptr_t & align_floor_inplace(std::uintptr_t &address, std::size_t alignment) noexcept
Align an address to a lower or equal address that satisfies the provided alignment.
REXLIB_CONSTEXPR std::uintptr_t & align_ceil_inplace(std::uintptr_t &address, std::size_t alignment) noexcept
Align an address to a higher or equal address that satisfies the provided alignment.
REXLIB_NODISCARD bool is_aligned(T *address, std::size_t alignment) noexcept
Check if a pointer is aligned to the provided boundary.
REXLIB_NODISCARD T * align_floor(T *address, std::size_t alignment) noexcept
Align a pointer to a lower or equal address that satisfies the provided alignment.