2020-08-06 18:18:34 +08:00
|
|
|
// AMD AMDUtils code
|
2021-09-08 10:54:22 +08:00
|
|
|
//
|
2020-08-06 18:18:34 +08:00
|
|
|
// Copyright(c) 2020 Advanced Micro Devices, Inc.All rights reserved.
|
2020-07-31 11:31:32 +08:00
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files(the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions :
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
2021-09-08 10:54:22 +08:00
|
|
|
#include "misc.h"
|
2020-07-31 11:31:32 +08:00
|
|
|
|
2021-09-08 10:54:22 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <chrono>
|
|
|
|
static std::chrono::time_point<std::chrono::steady_clock> misc_start = std::chrono::steady_clock::now();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
double MillisecondsNow() {
|
|
|
|
#ifdef _WIN32
|
2020-08-06 18:18:34 +08:00
|
|
|
static LARGE_INTEGER s_frequency;
|
|
|
|
static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency);
|
|
|
|
double milliseconds = 0;
|
|
|
|
|
2021-09-08 10:54:22 +08:00
|
|
|
if (s_use_qpc) {
|
2020-08-06 18:18:34 +08:00
|
|
|
LARGE_INTEGER now;
|
|
|
|
QueryPerformanceCounter(&now);
|
|
|
|
milliseconds = double(1000.0 * now.QuadPart) / s_frequency.QuadPart;
|
2021-09-08 10:54:22 +08:00
|
|
|
} else {
|
2020-08-06 18:18:34 +08:00
|
|
|
milliseconds = double(GetTickCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
return milliseconds;
|
2021-09-08 10:54:22 +08:00
|
|
|
#else
|
|
|
|
std::chrono::duration<double, std::milli> diff = std::chrono::steady_clock::now() - misc_start;
|
|
|
|
return diff.count();
|
|
|
|
#endif
|
2020-08-06 18:18:34 +08:00
|
|
|
}
|
|
|
|
|
2021-09-08 10:54:22 +08:00
|
|
|
#ifdef _WIN32
|
2020-08-06 18:18:34 +08:00
|
|
|
// align uLocation to the next multiple of uAlign
|
2021-09-08 10:54:22 +08:00
|
|
|
SIZE_T Align(SIZE_T uOffset, SIZE_T uAlign) {
|
|
|
|
if ((0 == uAlign) || (uAlign & (uAlign - 1))) {
|
2020-08-06 18:18:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2020-07-31 11:31:32 +08:00
|
|
|
|
2020-08-06 18:18:34 +08:00
|
|
|
return ((uOffset + (uAlign - 1)) & ~(uAlign - 1));
|
|
|
|
}
|
2020-07-31 11:31:32 +08:00
|
|
|
|
2021-09-08 10:54:22 +08:00
|
|
|
#endif
|