Do not truncate to size_t while aligning.

Change-Id: If92e3b20c0ba08a6024116a44463c72ff4cfddce
This commit is contained in:
Piotr Fusik
2019-02-20 16:36:26 +01:00
committed by sys_ocldev
parent 98db6147d8
commit 3e2a2ec191
2 changed files with 20 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2018 Intel Corporation
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -24,7 +24,8 @@
template <typename T>
constexpr inline T alignUp(T before, size_t alignment) {
return static_cast<T>((static_cast<size_t>(before) + alignment - 1) & ~(alignment - 1));
T mask = static_cast<T>(alignment - 1);
return (before + mask) & ~mask;
}
template <typename T>
@@ -34,7 +35,8 @@ constexpr inline T *alignUp(T *ptrBefore, size_t alignment) {
template <typename T>
constexpr inline T alignDown(T before, size_t alignment) {
return static_cast<T>(static_cast<size_t>(before) & ~(alignment - 1));
T mask = static_cast<T>(alignment - 1);
return before & ~mask;
}
template <typename T>