[dynarmic] BACKPORT: remove RNG from regalloc, use incremental LRU

- Backported from Azahar's dynarmic <526227eebe>

> From: PabloMK7 <hackyglitch2@gmail.com>
> Date: Sun, 4 Jan 2026 13:57:44 +0100
> Subject: [PATCH] backend: Do not use random generator for reg allocation (#7)

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie
2026-01-29 06:52:05 +00:00
committed by Caio Oliveira
parent 8ed0ed5828
commit 4895f09678
3 changed files with 12 additions and 6 deletions

View File

@@ -286,6 +286,7 @@ Result FSP_SRV::OpenSaveDataFileSystem(OutInterface<IFileSystem> out_interface,
case FileSys::SaveDataSpaceId::Temporary:
case FileSys::SaveDataSpaceId::ProperSystem:
case FileSys::SaveDataSpaceId::SafeMode:
default:
ASSERT(false);
}

View File

@@ -433,9 +433,10 @@ int RegAlloc::AllocateRegister(const std::array<HostLocInfo, 32>& regs, const st
std::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) {

View File

@@ -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;
};