From 9f0cb9148f36724b32c6f607069391d962f254ee Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Sun, 17 Dec 2023 22:51:07 +0200 Subject: [PATCH] vm.h: Cleanup and fix some warnings --- rpcs3/Emu/Memory/vm.h | 66 +++++++++---------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/rpcs3/Emu/Memory/vm.h b/rpcs3/Emu/Memory/vm.h index b704f86a94..dbdeff9ae2 100644 --- a/rpcs3/Emu/Memory/vm.h +++ b/rpcs3/Emu/Memory/vm.h @@ -219,65 +219,27 @@ namespace vm return vm::addr_t{static_cast(uptr(ptr))}; } - template - struct cast_impl - { - static_assert(std::is_same::value, "vm::cast() error: unsupported type"); - }; - - template<> - struct cast_impl - { - static vm::addr_t cast(u32 addr, - u32, - u32, - const char*, - const char*) - { - return static_cast(addr); - } - }; - - template<> - struct cast_impl - { - static vm::addr_t cast(u64 addr, - u32 line, - u32 col, - const char* file, - const char* func) - { - return static_cast(::narrow(addr, line, col, file, func)); - } - }; - - template - struct cast_impl> - { - static vm::addr_t cast(const se_t& addr, - u32 line, - u32 col, - const char* file, - const char* func) - { - return cast_impl::cast(addr, line, col, file, func); - } - }; - - template + template requires (std::is_integral_v && (sizeof(+T{}) > 4 || std::is_signed_v)) vm::addr_t cast(const T& addr, u32 line = __builtin_LINE(), u32 col = __builtin_COLUMN(), const char* file = __builtin_FILE(), const char* func = __builtin_FUNCTION()) { - return cast_impl::cast(addr, line, col, file, func); + return vm::addr_t{::narrow(+addr, line, col, file, func)}; + } + + template requires (std::is_integral_v && (sizeof(+T{}) <= 4 && !std::is_signed_v)) + vm::addr_t cast(const T& addr, u32 = 0, u32 = 0, const char* = nullptr, const char* = nullptr) + { + return vm::addr_t{static_cast(+addr)}; } // Convert specified PS3/PSV virtual memory address to a pointer for common access - inline void* base(u32 addr) + template requires (std::is_integral_v) + inline void* base(T addr) { - return g_base_addr + addr; + return g_base_addr + static_cast(vm::cast(addr)); } inline const u8& read8(u32 addr) @@ -296,15 +258,15 @@ namespace vm inline namespace ps3_ { // Convert specified PS3 address to a pointer of specified (possibly converted to BE) type - template inline to_be_t* _ptr(u32 addr) + template inline to_be_t* _ptr(const U& addr) { return static_cast*>(base(addr)); } // Convert specified PS3 address to a reference of specified (possibly converted to BE) type - template inline to_be_t& _ref(u32 addr) + template inline to_be_t& _ref(const U& addr) { - return *_ptr(addr); + return *static_cast*>(base(addr)); } // Access memory bypassing memory protection