Implement r_pod_cast function

Related-To: NEO-6210
Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwolinski
2021-10-11 17:50:20 +02:00
committed by Compute-Runtime-Automation
parent 4286b3a55c
commit 9276f689f8
3 changed files with 32 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
#include "shared/source/compiler_interface/compiler_cache.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/casts.h"
#include "shared/source/helpers/file_io.h"
#include "shared/source/helpers/hash.h"
#include "shared/source/helpers/hw_info.h"
@@ -36,9 +37,9 @@ const std::string CompilerCache::getCachedFileName(const HardwareInfo &hwInfo, c
hash.update(&*internalOptions.begin(), internalOptions.size());
hash.update("----", 4);
hash.update(reinterpret_cast<const char *>(&hwInfo.platform), sizeof(hwInfo.platform));
hash.update(r_pod_cast<const char *>(&hwInfo.platform), sizeof(hwInfo.platform));
hash.update("----", 4);
hash.update(reinterpret_cast<const char *>(&hwInfo.featureTable.packed), sizeof(hwInfo.featureTable.packed));
hash.update(r_pod_cast<const char *>(&hwInfo.featureTable.packed), sizeof(hwInfo.featureTable.packed));
hash.update("----", 4);
hash.update(reinterpret_cast<const char *>(&hwInfo.workaroundTable), sizeof(hwInfo.workaroundTable));

View File

@@ -27,6 +27,7 @@ set(NEO_CORE_HELPERS
${CMAKE_CURRENT_SOURCE_DIR}/cache_flush.inl
${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.h
${CMAKE_CURRENT_SOURCE_DIR}/casts.h
${CMAKE_CURRENT_SOURCE_DIR}/common_types.h
${CMAKE_CURRENT_SOURCE_DIR}/compiler_hw_info_config.h
${CMAKE_CURRENT_SOURCE_DIR}/compiler_hw_info_config.cpp

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <type_traits>
namespace NEO {
template <typename To, typename From>
constexpr To r_pod_cast(From *f) {
typedef typename std::remove_pointer<From>::type FromType;
typedef typename std::remove_pointer<To>::type ToType;
static_assert(std::is_trivially_copyable<FromType>::value &&
std::is_standard_layout<FromType>::value,
"Original cast type is not POD");
static_assert(std::is_trivially_copyable<ToType>::value &&
std::is_standard_layout<ToType>::value,
"Target cast type is not POD");
return reinterpret_cast<To>(f);
}
} // namespace NEO