2023-08-19 12:30:46 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
namespace utils
|
|
|
|
|
{
|
|
|
|
|
// Hack. Pointer cast util to workaround UB. Use with extreme care.
|
|
|
|
|
template <typename T, typename U>
|
|
|
|
|
[[nodiscard]] T* bless(U* ptr)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
return (T*)ptr;
|
|
|
|
|
#elif defined(ARCH_X64)
|
|
|
|
|
T* result;
|
2025-04-05 21:50:45 +02:00
|
|
|
__asm__("movq %1, %0;" : "=r"(result) : "r"(ptr) : "memory");
|
2023-08-19 12:30:46 +02:00
|
|
|
return result;
|
|
|
|
|
#elif defined(ARCH_ARM64)
|
|
|
|
|
T* result;
|
2025-04-05 21:50:45 +02:00
|
|
|
__asm__("mov %0, %1" : "=r"(result) : "r"(ptr) : "memory");
|
2023-08-19 12:30:46 +02:00
|
|
|
return result;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2025-04-05 21:50:45 +02:00
|
|
|
} // namespace utils
|