From 42340fc743aec49a5bebfc3969e24f070e436e06 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 17 Feb 2024 17:30:54 -0300
Subject: LightningJit: Add a limit on the number of instructions per function
 for Arm64 (#6328)

---
 src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Decoder.cs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'src')

diff --git a/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Decoder.cs b/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Decoder.cs
index 738b8a32..e9ba8ba2 100644
--- a/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Decoder.cs
+++ b/src/Ryujinx.Cpu/LightningJit/Arm64/Target/Arm64/Decoder.cs
@@ -8,7 +8,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64
 {
     static class Decoder
     {
-        private const int MaxInstructionsPerBlock = 1000;
+        private const int MaxInstructionsPerFunction = 10000;
 
         private const uint NzcvFlags = 0xfu << 28;
         private const uint CFlag = 0x1u << 29;
@@ -22,10 +22,11 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64
 
             bool hasHostCall = false;
             bool hasMemoryInstruction = false;
+            int totalInsts = 0;
 
             while (true)
             {
-                Block block = Decode(cpuPreset, memoryManager, address, ref useMask, ref hasHostCall, ref hasMemoryInstruction);
+                Block block = Decode(cpuPreset, memoryManager, address, ref totalInsts, ref useMask, ref hasHostCall, ref hasMemoryInstruction);
 
                 if (!block.IsTruncated && TryGetBranchTarget(block, out ulong targetAddress))
                 {
@@ -230,6 +231,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64
             CpuPreset cpuPreset,
             IMemoryManager memoryManager,
             ulong address,
+            ref int totalInsts,
             ref RegisterMask useMask,
             ref bool hasHostCall,
             ref bool hasMemoryInstruction)
@@ -272,7 +274,7 @@ namespace Ryujinx.Cpu.LightningJit.Arm64.Target.Arm64
 
                 uint tempGprUseMask = gprUseMask | instGprReadMask | instGprWriteMask;
 
-                if (CalculateAvailableTemps(tempGprUseMask) < CalculateRequiredGprTemps(tempGprUseMask) || insts.Count >= MaxInstructionsPerBlock)
+                if (CalculateAvailableTemps(tempGprUseMask) < CalculateRequiredGprTemps(tempGprUseMask) || totalInsts++ >= MaxInstructionsPerFunction)
                 {
                     isTruncated = true;
                     address -= 4UL;
-- 
cgit v1.2.3-70-g09d2