From b16923a902322ed78e6502defdacdb7d43bc0f32 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 13 Jan 2024 07:58:09 -0300
Subject: Revert Apple hypervisor force ordered memory change (#6068)

---
 src/Ryujinx.Cpu/AppleHv/HvCodePatcher.cs   | 62 ------------------------------
 src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs | 12 ------
 2 files changed, 74 deletions(-)
 delete mode 100644 src/Ryujinx.Cpu/AppleHv/HvCodePatcher.cs

(limited to 'src')

diff --git a/src/Ryujinx.Cpu/AppleHv/HvCodePatcher.cs b/src/Ryujinx.Cpu/AppleHv/HvCodePatcher.cs
deleted file mode 100644
index 876597b7..00000000
--- a/src/Ryujinx.Cpu/AppleHv/HvCodePatcher.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-
-namespace Ryujinx.Cpu.AppleHv
-{
-    static class HvCodePatcher
-    {
-        private const uint XMask = 0x3f808000u;
-        private const uint XValue = 0x8000000u;
-
-        private const uint ZrIndex = 31u;
-
-        public static void RewriteUnorderedExclusiveInstructions(Span<byte> code)
-        {
-            Span<uint> codeUint = MemoryMarshal.Cast<byte, uint>(code);
-            Span<Vector128<uint>> codeVector = MemoryMarshal.Cast<byte, Vector128<uint>>(code);
-
-            Vector128<uint> mask = Vector128.Create(XMask);
-            Vector128<uint> value = Vector128.Create(XValue);
-
-            for (int index = 0; index < codeVector.Length; index++)
-            {
-                Vector128<uint> v = codeVector[index];
-
-                if (Vector128.EqualsAny(Vector128.BitwiseAnd(v, mask), value))
-                {
-                    int baseIndex = index * 4;
-
-                    for (int instIndex = baseIndex; instIndex < baseIndex + 4; instIndex++)
-                    {
-                        ref uint inst = ref codeUint[instIndex];
-
-                        if ((inst & XMask) != XValue)
-                        {
-                            continue;
-                        }
-
-                        bool isPair = (inst & (1u << 21)) != 0;
-                        bool isLoad = (inst & (1u << 22)) != 0;
-
-                        uint rt2 = (inst >> 10) & 0x1fu;
-                        uint rs = (inst >> 16) & 0x1fu;
-
-                        if (isLoad && rs != ZrIndex)
-                        {
-                            continue;
-                        }
-
-                        if (!isPair && rt2 != ZrIndex)
-                        {
-                            continue;
-                        }
-
-                        // Set the ordered flag.
-                        inst |= 1u << 15;
-                    }
-                }
-            }
-        }
-    }
-}
diff --git a/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs b/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs
index 947c3710..2f9743ab 100644
--- a/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs
+++ b/src/Ryujinx.Cpu/AppleHv/HvMemoryManager.cs
@@ -724,18 +724,6 @@ namespace Ryujinx.Cpu.AppleHv
         /// <inheritdoc/>
         public void Reprotect(ulong va, ulong size, MemoryPermission protection)
         {
-            if (protection.HasFlag(MemoryPermission.Execute))
-            {
-                // Some applications use unordered exclusive memory access instructions
-                // where it is not valid to do so, leading to memory re-ordering that
-                // makes the code behave incorrectly on some CPUs.
-                // To work around this, we force all such accesses to be ordered.
-
-                using WritableRegion writableRegion = GetWritableRegion(va, (int)size);
-
-                HvCodePatcher.RewriteUnorderedExclusiveInstructions(writableRegion.Memory.Span);
-            }
-
             // TODO
         }
 
-- 
cgit v1.2.3-70-g09d2