From cb31d79164ddad8d857fd1e84f04185d15c22b30 Mon Sep 17 00:00:00 2001
From: Evan Husted <gr33m11@gmail.com>
Date: Sat, 12 Oct 2024 21:39:30 -0500
Subject: [PATCH] misc: Collapse XXHash128 into Hash128.

---
 src/ARMeilleure/Translation/PTC/Ptc.cs        | 26 +++++++++----------
 .../Translation/PTC/PtcProfiler.cs            |  8 +++---
 .../Engine/MME/MacroHLETable.cs               |  2 +-
 .../Threed/Blender/AdvancedBlendFunctions.cs  |  2 +-
 .../Threed/Blender/AdvancedBlendManager.cs    |  2 +-
 .../Shader/DiskCache/DiskCacheGuestStorage.cs |  2 +-
 6 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/ARMeilleure/Translation/PTC/Ptc.cs b/src/ARMeilleure/Translation/PTC/Ptc.cs
index c2eed7a55..5aa464310 100644
--- a/src/ARMeilleure/Translation/PTC/Ptc.cs
+++ b/src/ARMeilleure/Translation/PTC/Ptc.cs
@@ -309,7 +309,7 @@ namespace ARMeilleure.Translation.PTC
                     ReadOnlySpan<byte> infosBytes = new(stream.PositionPointer, innerHeader.InfosLength);
                     stream.Seek(innerHeader.InfosLength, SeekOrigin.Current);
 
-                    Hash128 infosHash = XXHash128.ComputeHash(infosBytes);
+                    Hash128 infosHash = Hash128.ComputeHash(infosBytes);
 
                     if (innerHeader.InfosHash != infosHash)
                     {
@@ -321,7 +321,7 @@ namespace ARMeilleure.Translation.PTC
                     ReadOnlySpan<byte> codesBytes = (int)innerHeader.CodesLength > 0 ? new(stream.PositionPointer, (int)innerHeader.CodesLength) : ReadOnlySpan<byte>.Empty;
                     stream.Seek(innerHeader.CodesLength, SeekOrigin.Current);
 
-                    Hash128 codesHash = XXHash128.ComputeHash(codesBytes);
+                    Hash128 codesHash = Hash128.ComputeHash(codesBytes);
 
                     if (innerHeader.CodesHash != codesHash)
                     {
@@ -333,7 +333,7 @@ namespace ARMeilleure.Translation.PTC
                     ReadOnlySpan<byte> relocsBytes = new(stream.PositionPointer, innerHeader.RelocsLength);
                     stream.Seek(innerHeader.RelocsLength, SeekOrigin.Current);
 
-                    Hash128 relocsHash = XXHash128.ComputeHash(relocsBytes);
+                    Hash128 relocsHash = Hash128.ComputeHash(relocsBytes);
 
                     if (innerHeader.RelocsHash != relocsHash)
                     {
@@ -345,7 +345,7 @@ namespace ARMeilleure.Translation.PTC
                     ReadOnlySpan<byte> unwindInfosBytes = new(stream.PositionPointer, innerHeader.UnwindInfosLength);
                     stream.Seek(innerHeader.UnwindInfosLength, SeekOrigin.Current);
 
-                    Hash128 unwindInfosHash = XXHash128.ComputeHash(unwindInfosBytes);
+                    Hash128 unwindInfosHash = Hash128.ComputeHash(unwindInfosBytes);
 
                     if (innerHeader.UnwindInfosHash != unwindInfosHash)
                     {
@@ -478,10 +478,10 @@ namespace ARMeilleure.Translation.PTC
 
                 Debug.Assert(stream.Position == stream.Length);
 
-                innerHeader.InfosHash = XXHash128.ComputeHash(infosBytes);
-                innerHeader.CodesHash = XXHash128.ComputeHash(codesBytes);
-                innerHeader.RelocsHash = XXHash128.ComputeHash(relocsBytes);
-                innerHeader.UnwindInfosHash = XXHash128.ComputeHash(unwindInfosBytes);
+                innerHeader.InfosHash = Hash128.ComputeHash(infosBytes);
+                innerHeader.CodesHash = Hash128.ComputeHash(codesBytes);
+                innerHeader.RelocsHash = Hash128.ComputeHash(relocsBytes);
+                innerHeader.UnwindInfosHash = Hash128.ComputeHash(unwindInfosBytes);
 
                 innerHeader.SetHeaderHash();
 
@@ -907,7 +907,7 @@ namespace ARMeilleure.Translation.PTC
 
         public static Hash128 ComputeHash(IMemoryManager memory, ulong address, ulong guestSize)
         {
-            return XXHash128.ComputeHash(memory.GetSpan(address, checked((int)(guestSize))));
+            return Hash128.ComputeHash(memory.GetSpan(address, checked((int)(guestSize))));
         }
 
         public void WriteCompiledFunction(ulong address, ulong guestSize, Hash128 hash, bool highCq, CompiledFunction compiledFunc)
@@ -1036,14 +1036,14 @@ namespace ARMeilleure.Translation.PTC
             {
                 Span<OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
 
-                HeaderHash = XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]);
+                HeaderHash = Hash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]);
             }
 
             public bool IsHeaderValid()
             {
                 Span<OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
 
-                return XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]) == HeaderHash;
+                return Hash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]) == HeaderHash;
             }
         }
 
@@ -1071,14 +1071,14 @@ namespace ARMeilleure.Translation.PTC
             {
                 Span<InnerHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
 
-                HeaderHash = XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<InnerHeader>() - Unsafe.SizeOf<Hash128>())]);
+                HeaderHash = Hash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<InnerHeader>() - Unsafe.SizeOf<Hash128>())]);
             }
 
             public bool IsHeaderValid()
             {
                 Span<InnerHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
 
-                return XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<InnerHeader>() - Unsafe.SizeOf<Hash128>())]) == HeaderHash;
+                return Hash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<InnerHeader>() - Unsafe.SizeOf<Hash128>())]) == HeaderHash;
             }
         }
 
diff --git a/src/ARMeilleure/Translation/PTC/PtcProfiler.cs b/src/ARMeilleure/Translation/PTC/PtcProfiler.cs
index 0fe78edab..8e95c5e4b 100644
--- a/src/ARMeilleure/Translation/PTC/PtcProfiler.cs
+++ b/src/ARMeilleure/Translation/PTC/PtcProfiler.cs
@@ -209,7 +209,7 @@ namespace ARMeilleure.Translation.PTC
 
                 Hash128 expectedHash = DeserializeStructure<Hash128>(stream);
 
-                Hash128 actualHash = XXHash128.ComputeHash(GetReadOnlySpan(stream));
+                Hash128 actualHash = Hash128.ComputeHash(GetReadOnlySpan(stream));
 
                 if (actualHash != expectedHash)
                 {
@@ -313,7 +313,7 @@ namespace ARMeilleure.Translation.PTC
                 Debug.Assert(stream.Position == stream.Length);
 
                 stream.Seek(Unsafe.SizeOf<Hash128>(), SeekOrigin.Begin);
-                Hash128 hash = XXHash128.ComputeHash(GetReadOnlySpan(stream));
+                Hash128 hash = Hash128.ComputeHash(GetReadOnlySpan(stream));
 
                 stream.Seek(0L, SeekOrigin.Begin);
                 SerializeStructure(stream, hash);
@@ -374,14 +374,14 @@ namespace ARMeilleure.Translation.PTC
             {
                 Span<OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
 
-                HeaderHash = XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]);
+                HeaderHash = Hash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]);
             }
 
             public bool IsHeaderValid()
             {
                 Span<OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
 
-                return XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]) == HeaderHash;
+                return Hash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader)[..(Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())]) == HeaderHash;
             }
         }
 
diff --git a/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLETable.cs b/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLETable.cs
index 43b701293..e3080228e 100644
--- a/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLETable.cs
+++ b/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroHLETable.cs
@@ -96,7 +96,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
             {
                 ref var entry = ref _table[i];
 
-                var hash = XXHash128.ComputeHash(mc[..entry.Length]);
+                var hash = Hash128.ComputeHash(mc[..entry.Length]);
                 if (hash == entry.Hash)
                 {
                     if (IsMacroHLESupported(caps, entry.Name))
diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs
index 0aca39075..13e5d2a86 100644
--- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs
+++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs
@@ -223,7 +223,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
 
             foreach (var entry in Table)
             {
-                Hash128 hash = XXHash128.ComputeHash(MemoryMarshal.Cast<uint, byte>(entry.Code));
+                Hash128 hash = Hash128.ComputeHash(MemoryMarshal.Cast<uint, byte>(entry.Code));
 
                 string[] constants = new string[entry.Constants != null ? entry.Constants.Length : 0];
 
diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendManager.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendManager.cs
index b336382d4..ce3d2c236 100644
--- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendManager.cs
+++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendManager.cs
@@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender
                 currentCode = currentCode[..codeLength];
             }
 
-            Hash128 hash = XXHash128.ComputeHash(MemoryMarshal.Cast<uint, byte>(currentCode));
+            Hash128 hash = Hash128.ComputeHash(MemoryMarshal.Cast<uint, byte>(currentCode));
 
             descriptor = default;
 
diff --git a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGuestStorage.cs b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGuestStorage.cs
index 08cd3bb02..22af88d31 100644
--- a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGuestStorage.cs
+++ b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheGuestStorage.cs
@@ -453,7 +453,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
         /// <returns>Hash of the data</returns>
         private static uint CalcHash(ReadOnlySpan<byte> data)
         {
-            return (uint)XXHash128.ComputeHash(data).Low;
+            return (uint)Hash128.ComputeHash(data).Low;
         }
     }
 }