performance: Correct alignment checks

Only use checks in debug builds.

Resolves: HSD-18039597713

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2024-09-09 13:06:28 +00:00
committed by Compute-Runtime-Automation
parent fa61b92cfb
commit 7d16521c7b
2 changed files with 4 additions and 4 deletions

View File

@@ -22,7 +22,7 @@
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
constexpr inline TNoRef alignUp(T before, size_t alignment) {
UNRECOVERABLE_IF(!Math::isPow2(alignment));
OPTIONAL_UNRECOVERABLE_IF(!Math::isPow2(alignment));
TNoRef mask = static_cast<TNoRef>(alignment - 1);
return (before + mask) & ~mask;
}
@@ -43,7 +43,7 @@ constexpr inline T *alignUp(T *ptrBefore, size_t alignment) {
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
constexpr inline TNoRef alignDown(T before, size_t alignment) {
UNRECOVERABLE_IF(!Math::isPow2(alignment));
OPTIONAL_UNRECOVERABLE_IF(!Math::isPow2(alignment));
TNoRef mask = static_cast<TNoRef>(alignment - 1);
return before & ~mask;
}
@@ -108,7 +108,7 @@ inline bool isAligned(T *ptr) {
template <typename T1, typename T2>
inline bool isAligned(T1 ptr, T2 alignment) {
UNRECOVERABLE_IF(!Math::isPow2(alignment));
OPTIONAL_UNRECOVERABLE_IF(!Math::isPow2(alignment));
return ((static_cast<size_t>(ptr)) & (static_cast<size_t>(alignment) - 1u)) == 0;
}

View File

@@ -15,7 +15,7 @@
#define UNREACHABLE(...) std::abort()
#ifdef MOCKABLE
#if defined(MOCKABLE) || defined(_DEBUG)
#define OPTIONAL_UNRECOVERABLE_IF(expression) UNRECOVERABLE_IF(expression)
#else
#define OPTIONAL_UNRECOVERABLE_IF(expression) (void)0