From 5e0f8e873857ce3ca3f532aff0936beb28e412c8 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 10 Jan 2023 19:16:59 -0300 Subject: Implement JIT Arm64 backend (#4114) * Implement JIT Arm64 backend * PPTC version bump * Address some feedback from Arm64 JIT PR * Address even more PR feedback * Remove unused IsPageAligned function * Sync Qc flag before calls * Fix comment and remove unused enum * Address riperiperi PR feedback * Delete Breakpoint IR instruction that was only implemented for Arm64 --- Ryujinx.Memory/MemoryBlock.cs | 70 +++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 40 deletions(-) (limited to 'Ryujinx.Memory/MemoryBlock.cs') diff --git a/Ryujinx.Memory/MemoryBlock.cs b/Ryujinx.Memory/MemoryBlock.cs index 6b9d852d..e1f19c27 100644 --- a/Ryujinx.Memory/MemoryBlock.cs +++ b/Ryujinx.Memory/MemoryBlock.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Concurrent; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Threading; namespace Ryujinx.Memory @@ -13,10 +13,9 @@ namespace Ryujinx.Memory private readonly bool _usesSharedMemory; private readonly bool _isMirror; private readonly bool _viewCompatible; + private readonly bool _forJit; private IntPtr _sharedMemory; private IntPtr _pointer; - private ConcurrentDictionary _viewStorages; - private int _viewCount; /// /// Pointer to the memory block data. @@ -40,24 +39,27 @@ namespace Ryujinx.Memory if (flags.HasFlag(MemoryAllocationFlags.Mirrorable)) { _sharedMemory = MemoryManagement.CreateSharedMemory(size, flags.HasFlag(MemoryAllocationFlags.Reserve)); - _pointer = MemoryManagement.MapSharedMemory(_sharedMemory, size); + + if (!flags.HasFlag(MemoryAllocationFlags.NoMap)) + { + _pointer = MemoryManagement.MapSharedMemory(_sharedMemory, size); + } + _usesSharedMemory = true; } else if (flags.HasFlag(MemoryAllocationFlags.Reserve)) { _viewCompatible = flags.HasFlag(MemoryAllocationFlags.ViewCompatible); - _pointer = MemoryManagement.Reserve(size, _viewCompatible); + _forJit = flags.HasFlag(MemoryAllocationFlags.Jit); + _pointer = MemoryManagement.Reserve(size, _forJit, _viewCompatible); } else { - _pointer = MemoryManagement.Allocate(size); + _forJit = flags.HasFlag(MemoryAllocationFlags.Jit); + _pointer = MemoryManagement.Allocate(size, _forJit); } Size = size; - - _viewStorages = new ConcurrentDictionary(); - _viewStorages.TryAdd(this, 0); - _viewCount = 1; } /// @@ -104,7 +106,7 @@ namespace Ryujinx.Memory /// Throw when either or are out of range public bool Commit(ulong offset, ulong size) { - return MemoryManagement.Commit(GetPointerInternal(offset, size), size); + return MemoryManagement.Commit(GetPointerInternal(offset, size), size, _forJit); } /// @@ -138,11 +140,6 @@ namespace Ryujinx.Memory throw new ArgumentException("The source memory block is not mirrorable, and thus cannot be mapped on the current block."); } - if (_viewStorages.TryAdd(srcBlock, 0)) - { - srcBlock.IncrementViewCount(); - } - MemoryManagement.MapView(srcBlock._sharedMemory, srcOffset, GetPointerInternal(dstOffset, size), size, this); } @@ -403,33 +400,16 @@ namespace Ryujinx.Memory { MemoryManagement.Free(ptr, Size); } - - foreach (MemoryBlock viewStorage in _viewStorages.Keys) - { - viewStorage.DecrementViewCount(); - } - - _viewStorages.Clear(); } - } - - /// - /// Increments the number of views that uses this memory block as storage. - /// - private void IncrementViewCount() - { - Interlocked.Increment(ref _viewCount); - } - /// - /// Decrements the number of views that uses this memory block as storage. - /// - private void DecrementViewCount() - { - if (Interlocked.Decrement(ref _viewCount) == 0 && _sharedMemory != IntPtr.Zero && !_isMirror) + if (!_isMirror) { - MemoryManagement.DestroySharedMemory(_sharedMemory); - _sharedMemory = IntPtr.Zero; + IntPtr sharedMemory = Interlocked.Exchange(ref _sharedMemory, IntPtr.Zero); + + if (sharedMemory != IntPtr.Zero) + { + MemoryManagement.DestroySharedMemory(sharedMemory); + } } } @@ -453,6 +433,16 @@ namespace Ryujinx.Memory return true; } + public static ulong GetPageSize() + { + if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + return 1UL << 14; + } + + return 1UL << 12; + } + private static void ThrowInvalidMemoryRegionException() => throw new InvalidMemoryRegionException(); } } -- cgit v1.2.3