VERY experimental Nintendo Switch 2 emulator
C++
[dynarmic] remove RNG from ARM64 regalloc, use incremental LRU (#3416)
lizziebd7d0e0466d9
diff --git a/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.cpp b/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.cppindex 3bd5ed90e4..e98a2f6e71 100644--- a/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.cpp+++ b/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.cpp@@ -433,9 +433,10 @@ int RegAlloc::AllocateRegister(const std::array<HostLocInfo, 32>& regs, const ststd::vector<int> candidates;std::copy_if(order.begin(), order.end(), std::back_inserter(candidates), [&](int i) { return regs[i].MaybeAllocatable(); });- // TODO: LRU- std::uniform_int_distribution<size_t> dis{0, candidates.size() - 1};- return candidates[dis(rand_gen)];+ // TODO: The candidate was chosen randomly before, and a LRU was+ // suggested as an improvement. However, using an incrementing index+ // seems to be close enough. Determine if an LRU is still needed.+ return candidates[alloc_candidate_index++ % candidates.size()];}void RegAlloc::SpillGpr(int index) {diff --git a/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.h b/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.hindex a8395a068d..87446a240b 100644--- a/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.h+++ b/src/dynarmic/src/dynarmic/backend/arm64/reg_alloc.h@@ -160,8 +160,12 @@ class RegAlloc final {public:using ArgumentInfo = std::array<Argument, IR::max_arg_count>;- explicit RegAlloc(oaknut::CodeGenerator& code, FpsrManager& fpsr_manager, std::vector<int> gpr_order, std::vector<int> fpr_order)- : code{code}, fpsr_manager{fpsr_manager}, gpr_order{gpr_order}, fpr_order{fpr_order}, rand_gen{std::random_device{}()} {}+ explicit RegAlloc(oaknut::CodeGenerator& code, FpsrManager& fpsr_manager, std::vector<int> gpr_order, std::vector<int> fpr_order) noexcept+ : code{code}+ , fpsr_manager{fpsr_manager}+ , gpr_order{gpr_order}+ , fpr_order{fpr_order}+ {}ArgumentInfo GetArgumentInfo(IR::Inst* inst);bool WasValueDefined(IR::Inst* inst) const;@@ -331,7 +335,7 @@ private:HostLocInfo flags;std::array<HostLocInfo, SpillCount> spills;- mutable std::mt19937 rand_gen;+ mutable size_t alloc_candidate_index = 0;ankerl::unordered_dense::set<const IR::Inst*> defined_insts;};