SpiecsEngine
 
Loading...
Searching...
No Matches
MemoryLibrary.h
Go to the documentation of this file.
1/**
2* @file MemoryLibrary.h
3* @brief The MemoryLibrary Class Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include "Core/Core.h"
9
10namespace Spices {
11
12 /**
13 * @brief Memory Static Function Library.
14 */
16 {
17 public:
18
19 /**
20 * @brief Determine is memory size aligned with specific value.
21 * @param[in] x memory size.
22 * @param[in] a aligned size.
23 * @return Returns true if is aligned.
24 */
25 template <class integral>
26 static constexpr bool is_aligned(integral x, size_t a) noexcept;
27
28 /**
29 * @brief Align up a memory size aligned with specific value.
30 * @param[in] x memory size.
31 * @param[in] a aligned size.
32 */
33 template <class integral>
34 static constexpr integral align_up(integral x, size_t a) noexcept;
35
36 /**
37 * @brief Align down a memory size aligned with specific value.
38 * @param[in] x memory size.
39 * @param[in] a aligned size.
40 */
41 template <class integral>
42 static constexpr integral align_down(integral x, size_t a) noexcept;
43 };
44
45 template<class integral>
46 inline constexpr bool MemoryLibrary::is_aligned(integral x, size_t a) noexcept
47 {
49
50 return (x & (integral(a) - 1)) == 0;
51 }
52
53 template<class integral>
54 inline constexpr integral MemoryLibrary::align_up(integral x, size_t a) noexcept
55 {
57
58 return integral((x + (integral(a) - 1)) & ~integral(a - 1));
59 }
60
61 template<class integral>
62 inline constexpr integral MemoryLibrary::align_down(integral x, size_t a) noexcept
63 {
65
66 return integral(x & ~integral(a - 1));
67 }
68}
#define SPICES_PROFILE_ZONE
static constexpr integral align_up(integral x, size_t a) noexcept
Align up a memory size aligned with specific value.
static constexpr integral align_down(integral x, size_t a) noexcept
Align down a memory size aligned with specific value.
static constexpr bool is_aligned(integral x, size_t a) noexcept
Determine is memory size aligned with specific value.
Memory Static Function Library.