From 373e50250139f4cc6fb7496a3d53c583f8cb7ea6 Mon Sep 17 00:00:00 2001 From: oltolm Date: Sat, 19 Aug 2023 12:30:46 +0200 Subject: [PATCH] Workaround for Clang: move bless to its own header file --- Utilities/lockless.h | 2 +- rpcs3/emucore.vcxproj | 1 + rpcs3/emucore.vcxproj.filters | 3 +++ rpcs3/util/asm.hpp | 17 ----------------- rpcs3/util/bless.hpp | 21 +++++++++++++++++++++ rpcs3/util/shared_ptr.hpp | 2 +- 6 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 rpcs3/util/bless.hpp diff --git a/Utilities/lockless.h b/Utilities/lockless.h index 7bd0133346..87e726ee3c 100644 --- a/Utilities/lockless.h +++ b/Utilities/lockless.h @@ -2,7 +2,7 @@ #include "util/types.hpp" #include "util/atomic.hpp" -#include "util/asm.hpp" +#include "util/bless.hpp" //! Simple unshrinkable array base for concurrent access. Only growths automatically. //! There is no way to know the current size. The smaller index is, the faster it's accessed. diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 17051eb305..4aaaf7ef2d 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -611,6 +611,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 0adf76dedf..fb5bda5d41 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -2371,6 +2371,9 @@ Emu\GPU\RSX\Common + + Utilities + diff --git a/rpcs3/util/asm.hpp b/rpcs3/util/asm.hpp index 6afc032390..da0be9f1f6 100644 --- a/rpcs3/util/asm.hpp +++ b/rpcs3/util/asm.hpp @@ -410,23 +410,6 @@ namespace utils return factor1 > 0 && T{umax} / factor1 < factor2 ? T{umax} : static_cast(factor1 * factor2); } - // Hack. Pointer cast util to workaround UB. Use with extreme care. - template - [[nodiscard]] T* bless(U* ptr) - { -#ifdef _MSC_VER - return (T*)ptr; -#elif defined(ARCH_X64) - T* result; - __asm__("movq %1, %0;" : "=r" (result) : "r" (ptr) : "memory"); - return result; -#elif defined(ARCH_ARM64) - T* result; - __asm__("mov %0, %1" : "=r" (result) : "r" (ptr) : "memory"); - return result; -#endif - } - inline void trap() { #ifdef _M_X64 diff --git a/rpcs3/util/bless.hpp b/rpcs3/util/bless.hpp new file mode 100644 index 0000000000..49ffa8facb --- /dev/null +++ b/rpcs3/util/bless.hpp @@ -0,0 +1,21 @@ +#pragma once + +namespace utils +{ + // Hack. Pointer cast util to workaround UB. Use with extreme care. + template + [[nodiscard]] T* bless(U* ptr) + { +#ifdef _MSC_VER + return (T*)ptr; +#elif defined(ARCH_X64) + T* result; + __asm__("movq %1, %0;" : "=r" (result) : "r" (ptr) : "memory"); + return result; +#elif defined(ARCH_ARM64) + T* result; + __asm__("mov %0, %1" : "=r" (result) : "r" (ptr) : "memory"); + return result; +#endif + } +} diff --git a/rpcs3/util/shared_ptr.hpp b/rpcs3/util/shared_ptr.hpp index 23d4bfd974..109e28216a 100644 --- a/rpcs3/util/shared_ptr.hpp +++ b/rpcs3/util/shared_ptr.hpp @@ -3,7 +3,7 @@ #include #include #include "atomic.hpp" -#include "asm.hpp" +#include "bless.hpp" namespace stx {