-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that allocated memory is in MEM1
- Loading branch information
Showing
2 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <type_traits> | ||
|
||
namespace Common | ||
{ | ||
template <typename T> | ||
constexpr T AlignUp(T value, size_t size) | ||
{ | ||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value."); | ||
return static_cast<T>(value + (size - value % size) % size); | ||
} | ||
|
||
template <typename T> | ||
constexpr T AlignDown(T value, size_t size) | ||
{ | ||
static_assert(std::is_unsigned<T>(), "T must be an unsigned value."); | ||
return static_cast<T>(value - value % size); | ||
} | ||
|
||
} // namespace Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters