aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2024-01-20 11:11:28 -0300
committerGitHub <noreply@github.com>2024-01-20 11:11:28 -0300
commit427b7d06b5ab6d2b06784a9d283eaf836a04c27e (patch)
treeb69b500432626c89f6a4b7171a948b46c46b3723 /src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs
parent331c07807fd0db5d4452d6ef02962a6d19a56d7f (diff)
Implement a new JIT for Arm devices (#6057)1.1.1117
* Implement a new JIT for Arm devices * Auto-format * Make a lot of Assembler members read-only * More read-only * Fix more warnings * ObjectDisposedException.ThrowIf * New JIT cache for platforms that enforce W^X, currently unused * Remove unused using * Fix assert * Pass memory manager type around * Safe memory manager mode support + other improvements * Actual safe memory manager mode masking support * PR feedback
Diffstat (limited to 'src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs')
-rw-r--r--src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs b/src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs
new file mode 100644
index 00000000..60e13de9
--- /dev/null
+++ b/src/Ryujinx.Cpu/LightningJit/TranslatorCache.cs
@@ -0,0 +1,96 @@
+using ARMeilleure.Translation;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+
+namespace Ryujinx.Cpu.LightningJit
+{
+ internal class TranslatorCache<T>
+ {
+ private readonly IntervalTree<ulong, T> _tree;
+ private readonly ReaderWriterLockSlim _treeLock;
+
+ public int Count => _tree.Count;
+
+ public TranslatorCache()
+ {
+ _tree = new IntervalTree<ulong, T>();
+ _treeLock = new ReaderWriterLockSlim();
+ }
+
+ public bool TryAdd(ulong address, ulong size, T value)
+ {
+ return AddOrUpdate(address, size, value, null);
+ }
+
+ public bool AddOrUpdate(ulong address, ulong size, T value, Func<ulong, T, T> updateFactoryCallback)
+ {
+ _treeLock.EnterWriteLock();
+ bool result = _tree.AddOrUpdate(address, address + size, value, updateFactoryCallback);
+ _treeLock.ExitWriteLock();
+
+ return result;
+ }
+
+ public T GetOrAdd(ulong address, ulong size, T value)
+ {
+ _treeLock.EnterWriteLock();
+ value = _tree.GetOrAdd(address, address + size, value);
+ _treeLock.ExitWriteLock();
+
+ return value;
+ }
+
+ public bool Remove(ulong address)
+ {
+ _treeLock.EnterWriteLock();
+ bool removed = _tree.Remove(address) != 0;
+ _treeLock.ExitWriteLock();
+
+ return removed;
+ }
+
+ public void Clear()
+ {
+ _treeLock.EnterWriteLock();
+ _tree.Clear();
+ _treeLock.ExitWriteLock();
+ }
+
+ public bool ContainsKey(ulong address)
+ {
+ _treeLock.EnterReadLock();
+ bool result = _tree.ContainsKey(address);
+ _treeLock.ExitReadLock();
+
+ return result;
+ }
+
+ public bool TryGetValue(ulong address, out T value)
+ {
+ _treeLock.EnterReadLock();
+ bool result = _tree.TryGet(address, out value);
+ _treeLock.ExitReadLock();
+
+ return result;
+ }
+
+ public int GetOverlaps(ulong address, ulong size, ref ulong[] overlaps)
+ {
+ _treeLock.EnterReadLock();
+ int count = _tree.Get(address, address + size, ref overlaps);
+ _treeLock.ExitReadLock();
+
+ return count;
+ }
+
+ public List<T> AsList()
+ {
+ _treeLock.EnterReadLock();
+ List<T> list = _tree.AsList();
+ _treeLock.ExitReadLock();
+
+ return list;
+ }
+ }
+}