Skip to content

Commit

Permalink
Merge pull request #2179 from Sonicadvance1/tsl_maps
Browse files Browse the repository at this point in the history
Core: Replace a couple maps with tsl robin_map
  • Loading branch information
Sonicadvance1 authored Nov 29, 2022
2 parents 0841ff5 + 1fb3a2e commit 57c5761
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions External/FEXCore/Source/Interface/Core/LookupCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>
#include <vector>
#include <mutex>
#include <tsl/robin_map.h>

namespace FEXCore {
namespace Context {
Expand All @@ -17,7 +18,7 @@ namespace Context {
class LookupCache {
public:

struct LookupCacheEntry {
struct LookupCacheEntry {
uintptr_t HostCode;
uintptr_t GuestCode;
};
Expand Down Expand Up @@ -54,15 +55,15 @@ class LookupCache {
return L1Entry.HostCode;
}
}

// Try L3
auto HostCode = BlockList.find(Address);

if (HostCode != BlockList.end()) {
CacheBlockMapping(Address, HostCode->second);
return HostCode->second;
}

// Failed to find
return 0;
}
Expand All @@ -73,7 +74,7 @@ class LookupCache {
// Returns true if new pages are marked as containing code
bool AddBlockExecutableRange(uint64_t Address, uint64_t Start, uint64_t Length) {
std::lock_guard<std::recursive_mutex> lk(WriteLock);

bool rv = false;

for (auto CurrentPage = Start >> 12, EndPage = (Start + Length -1) >> 12; CurrentPage <= EndPage; CurrentPage++) {
Expand All @@ -88,7 +89,7 @@ class LookupCache {
// Adds to Guest -> Host code mapping
void AddBlockMapping(uint64_t Address, void *HostCode) {
std::lock_guard<std::recursive_mutex> lk(WriteLock);

[[maybe_unused]] auto Inserted = BlockList.emplace(Address, (uintptr_t)HostCode).second;
LOGMAN_THROW_AA_FMT(Inserted, "Duplicate block mapping added");

Expand Down Expand Up @@ -158,7 +159,7 @@ class LookupCache {
constexpr static size_t L1_ENTRIES_MASK = L1_ENTRIES - 1;

// This needs to be taken before reads or writes to L2, L3, CodePages, Thread::DebugStore,
// and before writes to L1. Concurrent access from a thread that this LookupCache doesn't belong to
// and before writes to L1. Concurrent access from a thread that this LookupCache doesn't belong to
// may only happen during cross thread invalidation (::Erase).
// All other operations must be done from the owning thread.
// Some care is taken so that L1 lookups can be done without locks, and even tearing is unlikely to lead to a crash.
Expand All @@ -167,7 +168,7 @@ class LookupCache {
std::recursive_mutex WriteLock;

private:
void CacheBlockMapping(uint64_t Address, uintptr_t HostCode) {
void CacheBlockMapping(uint64_t Address, uintptr_t HostCode) {
std::lock_guard<std::recursive_mutex> lk(WriteLock);

// Do L1
Expand Down Expand Up @@ -239,7 +240,7 @@ class LookupCache {


std::map<BlockLinkTag, std::function<void()>> BlockLinks;
std::map<uint64_t, uint64_t> BlockList;
tsl::robin_map<uint64_t, uint64_t> BlockList;

constexpr static size_t CODE_SIZE = 128 * 1024 * 1024;
constexpr static size_t SIZE_PER_PAGE = 4096 * sizeof(LookupCacheEntry);
Expand Down
8 changes: 4 additions & 4 deletions External/FEXCore/include/FEXCore/Debug/InternalThreadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <FEXCore/Utils/InterruptableConditionVariable.h>
#include <FEXCore/Utils/Threads.h>

#include <map>
#include <unordered_map>
#include <tsl/robin_map.h>

#include <shared_mutex>

namespace FEXCore {
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace FEXCore::Core {
std::unique_ptr<FEXCore::CPU::CPUBackend> CPUBackend;
std::unique_ptr<FEXCore::LookupCache> LookupCache;

std::unordered_map<uint64_t, LocalIREntry> DebugStore;
tsl::robin_map<uint64_t, LocalIREntry> DebugStore;

std::unique_ptr<FEXCore::Frontend::Decoder> FrontendDecoder;
std::unique_ptr<FEXCore::IR::PassManager> PassManager;
Expand All @@ -115,7 +115,7 @@ namespace FEXCore::Core {

std::shared_mutex ObjectCacheRefCounter{};
bool DestroyedByParent{false}; // Should the parent destroy this thread, or it destory itself

alignas(16) FEXCore::Core::CpuStateFrame BaseFrameState{};

};
Expand Down

0 comments on commit 57c5761

Please sign in to comment.