From 03db32d2a0462ddefc9d87f3ff44a569c6cd6ce8 Mon Sep 17 00:00:00 2001 From: Michael Adelson Date: Sat, 19 Mar 2022 18:43:05 -0400 Subject: [PATCH 1/2] Vectorize Guid equality. --- src/libraries/System.Private.CoreLib/src/System/Guid.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Guid.cs b/src/libraries/System.Private.CoreLib/src/System/Guid.cs index 150e0f94da9f6..8e271d297a344 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Guid.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Guid.cs @@ -5,9 +5,9 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; using System.Runtime.Versioning; namespace System @@ -858,6 +858,11 @@ public override int GetHashCode() private static bool EqualsCore(in Guid left, in Guid right) { + if (Vector128.IsHardwareAccelerated) + { + return Unsafe.As>(ref Unsafe.AsRef(in left)) == Unsafe.As>(ref Unsafe.AsRef(in right)); + } + ref int rA = ref Unsafe.AsRef(in left._a); ref int rB = ref Unsafe.AsRef(in right._a); From 2a9c2282ea254f90a7685819b8ba3f0b24d86504 Mon Sep 17 00:00:00 2001 From: madelson <1269046+madelson@users.noreply.github.com> Date: Sun, 20 Mar 2022 13:38:30 -0400 Subject: [PATCH 2/2] Update src/libraries/System.Private.CoreLib/src/System/Guid.cs Feedback from https://github.com/dotnet/runtime/pull/66889#discussion_r830625854 Co-authored-by: Jan Kotas --- src/libraries/System.Private.CoreLib/src/System/Guid.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Guid.cs b/src/libraries/System.Private.CoreLib/src/System/Guid.cs index 8e271d297a344..25df001744576 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Guid.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Guid.cs @@ -860,7 +860,7 @@ private static bool EqualsCore(in Guid left, in Guid right) { if (Vector128.IsHardwareAccelerated) { - return Unsafe.As>(ref Unsafe.AsRef(in left)) == Unsafe.As>(ref Unsafe.AsRef(in right)); + return Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in left))) == Vector128.LoadUnsafe(ref Unsafe.As(ref Unsafe.AsRef(in right))); } ref int rA = ref Unsafe.AsRef(in left._a);