mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
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:
committed by
Compute-Runtime-Automation
parent
fa61b92cfb
commit
7d16521c7b
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
|
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
|
||||||
constexpr inline TNoRef alignUp(T before, size_t alignment) {
|
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);
|
TNoRef mask = static_cast<TNoRef>(alignment - 1);
|
||||||
return (before + mask) & ~mask;
|
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>
|
template <typename T, typename TNoRef = typename std::remove_reference<T>::type>
|
||||||
constexpr inline TNoRef alignDown(T before, size_t alignment) {
|
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);
|
TNoRef mask = static_cast<TNoRef>(alignment - 1);
|
||||||
return before & ~mask;
|
return before & ~mask;
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ inline bool isAligned(T *ptr) {
|
|||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
inline bool isAligned(T1 ptr, T2 alignment) {
|
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;
|
return ((static_cast<size_t>(ptr)) & (static_cast<size_t>(alignment) - 1u)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#define UNREACHABLE(...) std::abort()
|
#define UNREACHABLE(...) std::abort()
|
||||||
|
|
||||||
#ifdef MOCKABLE
|
#if defined(MOCKABLE) || defined(_DEBUG)
|
||||||
#define OPTIONAL_UNRECOVERABLE_IF(expression) UNRECOVERABLE_IF(expression)
|
#define OPTIONAL_UNRECOVERABLE_IF(expression) UNRECOVERABLE_IF(expression)
|
||||||
#else
|
#else
|
||||||
#define OPTIONAL_UNRECOVERABLE_IF(expression) (void)0
|
#define OPTIONAL_UNRECOVERABLE_IF(expression) (void)0
|
||||||
|
|||||||
Reference in New Issue
Block a user