From 56a14db11371c71d7ba86b852abf955a3253b769 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 9 Sep 2024 18:53:51 +1000 Subject: [PATCH] Cheats: Prevent inlining of memory functions Clang is way too eager here and inlines the whole thing hundreds of times within CheatList::Apply(). --- src/common/types.h | 11 +++++++++-- src/core/cheats.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/common/types.h b/src/common/types.h index 4a63ddab1..9f973992b 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -10,7 +10,6 @@ #include // Force inline helper -#ifndef ALWAYS_INLINE #if defined(_MSC_VER) #define ALWAYS_INLINE __forceinline #elif defined(__GNUC__) || defined(__clang__) @@ -18,7 +17,6 @@ #else #define ALWAYS_INLINE inline #endif -#endif // Force inline in non-debug helper #ifdef _DEBUG @@ -27,6 +25,15 @@ #define ALWAYS_INLINE_RELEASE ALWAYS_INLINE #endif +// Prevent inlining +#if defined(_MSC_VER) +#define NEVER_INLINE __declspec(noinline) +#elif defined(__GNUC__) || defined(__clang__) +#define NEVER_INLINE __attribute__((noinline)) +#else +#define NEVER_INLINE +#endif + // unreferenced parameter macro #ifndef UNREFERENCED_VARIABLE #if defined(__GNUC__) || defined(__clang__) || defined(__EMSCRIPTEN__) diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 569729a63..d243d7390 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -44,7 +44,7 @@ static bool IsValidScanAddress(PhysicalMemoryAddress address) } template -static T DoMemoryRead(VirtualMemoryAddress address) +NEVER_INLINE static T DoMemoryRead(VirtualMemoryAddress address) { using UnsignedType = typename std::make_unsigned_t; static_assert(std::is_same_v || std::is_same_v || @@ -60,7 +60,7 @@ static T DoMemoryRead(VirtualMemoryAddress address) } template -static void DoMemoryWrite(PhysicalMemoryAddress address, T value) +NEVER_INLINE static void DoMemoryWrite(PhysicalMemoryAddress address, T value) { using UnsignedType = typename std::make_unsigned_t; static_assert(std::is_same_v || std::is_same_v || @@ -74,7 +74,7 @@ static void DoMemoryWrite(PhysicalMemoryAddress address, T value) CPU::SafeWriteMemoryWord(address, value); } -static u32 GetControllerButtonBits() +NEVER_INLINE static u32 GetControllerButtonBits() { static constexpr std::array button_mapping = {{ 0x0100, // Select @@ -115,7 +115,7 @@ static u32 GetControllerButtonBits() return translated_bits; } -static u32 GetControllerAnalogBits() +NEVER_INLINE static u32 GetControllerAnalogBits() { // 0x010000 - Right Thumb Up // 0x020000 - Right Thumb Right