aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrPurple666 <antoniosacramento666usa@gmail.com>2025-04-30 16:11:15 -0300
committerMrPurple666 <antoniosacramento666usa@gmail.com>2025-04-30 16:11:15 -0300
commitbb2f527b162372d6b63bbd5cc768f3e82dac0c5c (patch)
treef85a2e2476e200ad731032dc298f549c7bad290f
parentb5bec371ae9c117c1ebfcfd4d02dcee9b0a0a51a (diff)
Use a different approach for the LRU toggle
-rw-r--r--src/core/arm/nce/lru_cache.h3
-rw-r--r--src/core/arm/nce/patcher.cpp2
-rw-r--r--src/core/arm/nce/patcher.h27
3 files changed, 23 insertions, 9 deletions
diff --git a/src/core/arm/nce/lru_cache.h b/src/core/arm/nce/lru_cache.h
index 70f5163947..aacab368c4 100644
--- a/src/core/arm/nce/lru_cache.h
+++ b/src/core/arm/nce/lru_cache.h
@@ -3,6 +3,7 @@
#include <list>
#include <unordered_map>
#include <optional>
+#include "common/logging/log.h"
template<typename KeyType, typename ValueType>
class LRUCache {
@@ -15,6 +16,7 @@ private:
public:
explicit LRUCache(size_t capacity, bool enabled = true) : enabled(enabled), capacity(capacity) {
cache_map.reserve(capacity);
+ LOG_WARNING(Core, "LRU Cache initialized with state: {}", enabled ? "enabled" : "disabled");
}
// Returns pointer to value if found, nullptr otherwise
@@ -67,6 +69,7 @@ public:
// Enable or disable the LRU cache
void setEnabled(bool state) {
enabled = state;
+ LOG_WARNING(Core, "LRU Cache state changed to: {}", state ? "enabled" : "disabled");
if (!enabled) {
clear();
}
diff --git a/src/core/arm/nce/patcher.cpp b/src/core/arm/nce/patcher.cpp
index c7285e3a08..f6563bb20f 100644
--- a/src/core/arm/nce/patcher.cpp
+++ b/src/core/arm/nce/patcher.cpp
@@ -23,6 +23,8 @@ constexpr size_t MaxRelativeBranch = 128_MiB;
constexpr u32 ModuleCodeIndex = 0x24 / sizeof(u32);
Patcher::Patcher() : c(m_patch_instructions) {
+ LOG_WARNING(Core_ARM, "Patcher initialized with LRU cache {}",
+ patch_cache.isEnabled() ? "enabled" : "disabled");
// The first word of the patch section is always a branch to the first instruction of the
// module.
c.dw(0);
diff --git a/src/core/arm/nce/patcher.h b/src/core/arm/nce/patcher.h
index c8c2ac7326..8e6363b2d5 100644
--- a/src/core/arm/nce/patcher.h
+++ b/src/core/arm/nce/patcher.h
@@ -66,16 +66,25 @@ private:
LRUCache<uintptr_t, PatchTextAddress> patch_cache{CACHE_SIZE, Settings::values.lru_cache_enabled.GetValue()};
void BranchToPatch(uintptr_t module_dest) {
- // Try to get existing patch entry from cache
- if (auto* cached_patch = patch_cache.get(module_dest)) {
- curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), *cached_patch});
- return;
+ if (patch_cache.isEnabled()) {
+ LOG_DEBUG(Core_ARM, "LRU cache lookup for address {:#x}", module_dest);
+ // Try to get existing patch entry from cache
+ if (auto* cached_patch = patch_cache.get(module_dest)) {
+ LOG_DEBUG(Core_ARM, "LRU cache hit for address {:#x}", module_dest);
+ curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), *cached_patch});
+ return;
+ }
+ LOG_DEBUG(Core_ARM, "LRU cache miss for address {:#x}, creating new patch", module_dest);
+
+ // If not in cache, create new entry and cache it
+ const auto patch_addr = c.offset();
+ curr_patch->m_branch_to_patch_relocations.push_back({patch_addr, module_dest});
+ patch_cache.put(module_dest, patch_addr);
+ } else {
+ LOG_DEBUG(Core_ARM, "LRU cache disabled - creating direct patch for address {:#x}", module_dest);
+ // LRU disabled - use pre-LRU approach
+ curr_patch->m_branch_to_patch_relocations.push_back({c.offset(), module_dest});
}
-
- // If not in cache, create new entry and cache it
- const auto patch_addr = c.offset();
- curr_patch->m_branch_to_patch_relocations.push_back({patch_addr, module_dest});
- patch_cache.put(module_dest, patch_addr);
}
void BranchToModule(uintptr_t module_dest) {