Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/psprecomp/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,15 @@ class Runtime : public CorpusRuntime {
std::unordered_map<std::string, HleLibrary,
TransparentStringHash, std::equal_to<>> hle_;
std::unordered_map<std::uint32_t, NativeFastPath> native_fast_paths_;
std::vector<const HleFunction *> import_bindings_;
// Import slots are per-corpus ordinals: two corpora reuse the same slot
// numbers for different imports, so a cached entry names the (library,
// nid) it was resolved for and is only reused for that pair.
struct ImportBinding {
const HleFunction *function{};
std::string library;
std::uint32_t nid{};
};
std::vector<ImportBinding> import_bindings_;
std::filesystem::path game_root_;
bool stopped_{};
std::string stop_reason_;
Expand Down
12 changes: 8 additions & 4 deletions src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Runtime::Runtime(std::uint32_t ram_size)
// Most commercial PSP titles use a few hundred import stubs. Seed a small
// binding table so first use of a late-numbered import does not reallocate
// in the middle of guest execution; larger profiles can still grow it.
import_bindings_.resize(256u, nullptr);
import_bindings_.resize(256u);
hle_histogram_enabled_ = std::getenv("PSPRECOMP_HLE_HISTOGRAM") != nullptr;
#if defined(PSPRECOMP_AOT_PRODUCTION_FASTPATHS)
track_dispatch_counters_ = false;
Expand Down Expand Up @@ -1276,7 +1276,11 @@ void Runtime::invoke_import_cached(std::uint32_t slot, std::string_view library,
std::uint32_t nid, AllegrexContext &ctx) {
if (hle_histogram_enabled_) ++hle_histogram_[hle_key(library, nid)];

const HleFunction *bound = slot < import_bindings_.size() ? import_bindings_[slot] : nullptr;
const HleFunction *bound = nullptr;
if (slot < import_bindings_.size()) {
const ImportBinding &cached = import_bindings_[slot];
if (cached.function != nullptr && cached.nid == nid && cached.library == library) bound = cached.function;
}
if (bound == nullptr) {
const auto library_it = hle_.find(library);
const auto function_it = library_it != hle_.end()
Expand All @@ -1287,9 +1291,9 @@ void Runtime::invoke_import_cached(std::uint32_t slot, std::string_view library,
stop("Missing HLE import " + library_name + "::" + name);
return;
}
if (slot >= import_bindings_.size()) import_bindings_.resize(static_cast<std::size_t>(slot) + 1u, nullptr);
if (slot >= import_bindings_.size()) import_bindings_.resize(static_cast<std::size_t>(slot) + 1u);
bound = &function_it->second;
import_bindings_[slot] = bound;
import_bindings_[slot] = ImportBinding{bound, std::string(library), nid};
}

(*bound)(*this, ctx);
Expand Down