ARMJIT: Use compile-time constant sized arrays

This commit is contained in:
Ameer J 2024-11-23 19:17:51 -05:00
parent 730b488fe3
commit ad114eb6e6
3 changed files with 14 additions and 12 deletions

View File

@ -472,7 +472,7 @@ ARMJIT::ARMJIT(melonDS::NDS& nds, std::optional<JITArgs> jit) noexcept :
NDS(nds), NDS(nds),
Memory(nds), Memory(nds),
JITCompiler(nds), JITCompiler(nds),
MaxBlockSize(jit.has_value() ? std::clamp(jit->MaxBlockSize, 1u, 32u) : 32), MaxBlockSize(jit.has_value() ? std::clamp(jit->MaxBlockSize, 1u, MaxSupportedBlockSize) : MaxSupportedBlockSize),
LiteralOptimizations(jit.has_value() ? jit->LiteralOptimizations : false), LiteralOptimizations(jit.has_value() ? jit->LiteralOptimizations : false),
BranchOptimizations(jit.has_value() ? jit->BranchOptimizations : false), BranchOptimizations(jit.has_value() ? jit->BranchOptimizations : false),
FastMemory((jit.has_value() ? jit->FastMemory : false) && ARMJIT_Memory::IsFastMemSupported()) FastMemory((jit.has_value() ? jit->FastMemory : false) && ARMJIT_Memory::IsFastMemSupported())
@ -495,7 +495,7 @@ void ARMJIT::RetireJitBlock(JitBlock* block) noexcept
void ARMJIT::SetJITArgs(JITArgs args) noexcept void ARMJIT::SetJITArgs(JITArgs args) noexcept
{ {
args.FastMemory = args.FastMemory && ARMJIT_Memory::IsFastMemSupported(); args.FastMemory = args.FastMemory && ARMJIT_Memory::IsFastMemSupported();
args.MaxBlockSize = std::clamp(args.MaxBlockSize, 1u, 32u); args.MaxBlockSize = std::clamp(args.MaxBlockSize, 1u, MaxSupportedBlockSize);
if (MaxBlockSize != args.MaxBlockSize if (MaxBlockSize != args.MaxBlockSize
|| LiteralOptimizations != args.LiteralOptimizations || LiteralOptimizations != args.LiteralOptimizations
@ -565,24 +565,24 @@ void ARMJIT::CompileBlock(ARM* cpu) noexcept
map.erase(existingBlockIt); map.erase(existingBlockIt);
} }
FetchedInstr instrs[MaxBlockSize]; FetchedInstr instrs[MaxSupportedBlockSize];
int i = 0; int i = 0;
u32 r15 = cpu->R[15]; u32 r15 = cpu->R[15];
u32 addressRanges[MaxBlockSize]; u32 addressRanges[MaxSupportedBlockSize];
u32 addressMasks[MaxBlockSize]; u32 addressMasks[MaxSupportedBlockSize] {};
memset(addressMasks, 0, MaxBlockSize * sizeof(u32));
u32 numAddressRanges = 0; u32 numAddressRanges = 0;
u32 numLiterals = 0; u32 numLiterals = 0;
u32 literalLoadAddrs[MaxBlockSize]; u32 literalLoadAddrs[MaxSupportedBlockSize];
// they are going to be hashed // they are going to be hashed
u32 literalValues[MaxBlockSize]; u32 literalValues[MaxSupportedBlockSize];
u32 instrValues[MaxBlockSize]; u32 instrValues[MaxSupportedBlockSize];
// due to instruction merging i might not reflect the amount of actual instructions // due to instruction merging i might not reflect the amount of actual instructions
u32 numInstrs = 0; u32 numInstrs = 0;
u32 writeAddrs[MaxBlockSize]; u32 writeAddrs[MaxSupportedBlockSize];
u32 numWriteAddrs = 0, writeAddrsTranslated = 0; u32 numWriteAddrs = 0, writeAddrsTranslated = 0;
cpu->FillPipeline(); cpu->FillPipeline();

View File

@ -67,8 +67,10 @@ public:
u32 LocaliseCodeAddress(u32 num, u32 addr) const noexcept; u32 LocaliseCodeAddress(u32 num, u32 addr) const noexcept;
ARMJIT_Memory Memory; ARMJIT_Memory Memory;
static constexpr u32 MaxSupportedBlockSize = 32;
private: private:
int MaxBlockSize {}; u32 MaxBlockSize {};
bool LiteralOptimizations = false; bool LiteralOptimizations = false;
bool BranchOptimizations = false; bool BranchOptimizations = false;
bool FastMemory = false; bool FastMemory = false;

View File

@ -58,7 +58,7 @@ constexpr std::array<u8, N> BrokenBIOS = []() constexpr {
/// Ignored in builds that don't have the JIT included. /// Ignored in builds that don't have the JIT included.
struct JITArgs struct JITArgs
{ {
unsigned MaxBlockSize = 32; u32 MaxBlockSize = 32;
bool LiteralOptimizations = true; bool LiteralOptimizations = true;
bool BranchOptimizations = true; bool BranchOptimizations = true;