diff --git a/src/BizHawk.Common/Extensions/SpanSplit.cs b/src/BizHawk.Common/Extensions/SpanSplit.cs index 9fc43a4a76..167e01abde 100644 --- a/src/BizHawk.Common/Extensions/SpanSplit.cs +++ b/src/BizHawk.Common/Extensions/SpanSplit.cs @@ -5,16 +5,13 @@ * and https://github.com/dotnet/runtime/blob/v9.0.0/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs */ -#if !NET8_0_OR_GREATER +#if !NET9_0_OR_GREATER #pragma warning disable RS0030 // `Debug.Assert` w/o message, breaks BizHawk convention #pragma warning disable SA1514 // "Element documentation header should be preceded by blank line" using System.Buffers; using System.Diagnostics; using System.Runtime.CompilerServices; -#if NETCOREAPP3_0_OR_GREATER -using System.Runtime.Intrinsics; -#endif namespace BizHawk.Common { @@ -534,13 +531,6 @@ namespace BizHawk.Common sep0 = separators[0]; sep1 = separators.Length > 1 ? separators[1] : sep0; sep2 = separators.Length > 2 ? separators[2] : sep1; -#if NETCOREAPP3_0_OR_GREATER - if (Vector128.IsHardwareAccelerated && source.Length >= Vector128.Count * 2) - { - MakeSeparatorListVectorized(source, ref sepListBuilder, sep0, sep1, sep2); - return; - } -#endif for (int i = 0; i < source.Length; i++) { @@ -583,120 +573,6 @@ namespace BizHawk.Common } } -#if NETCOREAPP3_0_OR_GREATER - private static void MakeSeparatorListVectorized(ReadOnlySpan sourceSpan, ref ValueListBuilder sepListBuilder, char c, char c2, char c3) - { - // Redundant test so we won't prejit remainder of this method - // on platforms where it is not supported - if (!Vector128.IsHardwareAccelerated) - { - throw new PlatformNotSupportedException(); - } - Debug.Assert(sourceSpan.Length >= Vector128.Count); - nuint lengthToExamine = (uint)sourceSpan.Length; - nuint offset = 0; - ref char source = ref MemoryMarshal.GetReference(sourceSpan); - - if (Vector512.IsHardwareAccelerated && lengthToExamine >= (uint)Vector512.Count*2) - { - Vector512 v1 = Vector512.Create((ushort)c); - Vector512 v2 = Vector512.Create((ushort)c2); - Vector512 v3 = Vector512.Create((ushort)c3); - - do - { - Vector512 vector = Vector512.LoadUnsafe(ref source, offset); - Vector512 v1Eq = Vector512.Equals(vector, v1); - Vector512 v2Eq = Vector512.Equals(vector, v2); - Vector512 v3Eq = Vector512.Equals(vector, v3); - Vector512 cmp = (v1Eq | v2Eq | v3Eq).AsByte(); - - if (cmp != Vector512.Zero) - { - // Skip every other bit - ulong mask = cmp.ExtractMostSignificantBits() & 0x5555555555555555; - do - { - uint bitPos = (uint)BitOperations.TrailingZeroCount(mask) / sizeof(char); - sepListBuilder.Append((int)(offset + bitPos)); - mask = BitOperations.ResetLowestSetBit(mask); - } while (mask != 0); - } - - offset += (nuint)Vector512.Count; - } while (offset <= lengthToExamine - (nuint)Vector512.Count); - } - else if (Vector256.IsHardwareAccelerated && lengthToExamine >= (uint)Vector256.Count*2) - { - Vector256 v1 = Vector256.Create((ushort)c); - Vector256 v2 = Vector256.Create((ushort)c2); - Vector256 v3 = Vector256.Create((ushort)c3); - - do - { - Vector256 vector = Vector256.LoadUnsafe(ref source, offset); - Vector256 v1Eq = Vector256.Equals(vector, v1); - Vector256 v2Eq = Vector256.Equals(vector, v2); - Vector256 v3Eq = Vector256.Equals(vector, v3); - Vector256 cmp = (v1Eq | v2Eq | v3Eq).AsByte(); - - if (cmp != Vector256.Zero) - { - // Skip every other bit - uint mask = cmp.ExtractMostSignificantBits() & 0x55555555; - do - { - uint bitPos = (uint)BitOperations.TrailingZeroCount(mask) / sizeof(char); - sepListBuilder.Append((int)(offset + bitPos)); - mask = BitOperations.ResetLowestSetBit(mask); - } while (mask != 0); - } - - offset += (nuint)Vector256.Count; - } while (offset <= lengthToExamine - (nuint)Vector256.Count); - } - else if (Vector128.IsHardwareAccelerated) - { - Vector128 v1 = Vector128.Create((ushort)c); - Vector128 v2 = Vector128.Create((ushort)c2); - Vector128 v3 = Vector128.Create((ushort)c3); - - do - { - Vector128 vector = Vector128.LoadUnsafe(ref source, offset); - Vector128 v1Eq = Vector128.Equals(vector, v1); - Vector128 v2Eq = Vector128.Equals(vector, v2); - Vector128 v3Eq = Vector128.Equals(vector, v3); - Vector128 cmp = (v1Eq | v2Eq | v3Eq).AsByte(); - - if (cmp != Vector128.Zero) - { - // Skip every other bit - uint mask = cmp.ExtractMostSignificantBits() & 0x5555; - do - { - uint bitPos = (uint)BitOperations.TrailingZeroCount(mask) / sizeof(char); - sepListBuilder.Append((int)(offset + bitPos)); - mask = BitOperations.ResetLowestSetBit(mask); - } while (mask != 0); - } - - offset += (nuint)Vector128.Count; - } while (offset <= lengthToExamine - (nuint)Vector128.Count); - } - - while (offset < lengthToExamine) - { - char curr = Unsafe.Add(ref source, offset); - if (curr == c || curr == c2 || curr == c3) - { - sepListBuilder.Append((int)offset); - } - offset++; - } - } -#endif - /// /// Uses ValueListBuilder to create list that holds indexes of separators in string. ///