| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Numerics; |
| | | 6 | | using System.Runtime.CompilerServices; |
| | | 7 | | using System.Runtime.Intrinsics; |
| | | 8 | | using System.Runtime.Intrinsics.X86; |
| | | 9 | | |
| | | 10 | | namespace System |
| | | 11 | | { |
| | | 12 | | // This is a separate class instead of 'partial SpanHelpers' to hide the private helpers |
| | | 13 | | // included in this file which are specific to the packed implementation. |
| | | 14 | | internal static partial class PackedSpanHelpers |
| | | 15 | | { |
| | | 16 | | // We only do this optimization if we have support for X86 intrinsics (Sse2) as the packing is noticeably cheape |
| | | 17 | | // While the impact on the worst-case (match at the start) is minimal on X86, it's prohibitively large on ARM. |
| | 148774 | 18 | | public static bool PackedIndexOfIsSupported => Sse2.IsSupported; |
| | | 19 | | |
| | | 20 | | // Not all values can benefit from packing the searchSpace. See comments in PackSources below. |
| | | 21 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 22 | | public static unsafe bool CanUsePackedIndexOf<T>(T value) |
| | | 23 | | { |
| | 80935 | 24 | | Debug.Assert(PackedIndexOfIsSupported); |
| | 80935 | 25 | | Debug.Assert(RuntimeHelpers.IsBitwiseEquatable<T>()); |
| | 80935 | 26 | | Debug.Assert(sizeof(T) == sizeof(ushort)); |
| | | 27 | | |
| | 80935 | 28 | | return Unsafe.BitCast<T, ushort>(value) - 1u < 254u; |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 32 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 33 | | public static int IndexOf(ref char searchSpace, char value, int length) => |
| | 11808 | 34 | | IndexOf<SpanHelpers.DontNegate<short>, NopTransform>(ref Unsafe.As<char, short>(ref searchSpace), (short)val |
| | | 35 | | |
| | | 36 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 37 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 38 | | public static int IndexOfAnyExcept(ref char searchSpace, char value, int length) => |
| | 1500 | 39 | | IndexOf<SpanHelpers.Negate<short>, NopTransform>(ref Unsafe.As<char, short>(ref searchSpace), (short)value, |
| | | 40 | | |
| | | 41 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 42 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 43 | | public static int IndexOfAny(ref char searchSpace, char value0, char value1, int length) => |
| | 1312 | 44 | | IndexOfAny<SpanHelpers.DontNegate<short>, NopTransform>(ref Unsafe.As<char, short>(ref searchSpace), (short) |
| | | 45 | | |
| | | 46 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 47 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 48 | | public static int IndexOfAnyExcept(ref char searchSpace, char value0, char value1, int length) => |
| | 1312 | 49 | | IndexOfAny<SpanHelpers.Negate<short>, NopTransform>(ref Unsafe.As<char, short>(ref searchSpace), (short)valu |
| | | 50 | | |
| | | 51 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 52 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 53 | | public static int IndexOfAny(ref char searchSpace, char value0, char value1, char value2, int length) => |
| | 1844 | 54 | | IndexOfAny<SpanHelpers.DontNegate<short>>(ref Unsafe.As<char, short>(ref searchSpace), (short)value0, (short |
| | | 55 | | |
| | | 56 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 57 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 58 | | public static int IndexOfAnyExcept(ref char searchSpace, char value0, char value1, char value2, int length) => |
| | 1844 | 59 | | IndexOfAny<SpanHelpers.Negate<short>>(ref Unsafe.As<char, short>(ref searchSpace), (short)value0, (short)val |
| | | 60 | | |
| | | 61 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 62 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 63 | | public static int IndexOfAnyIgnoreCase(ref char searchSpace, char value, int length) |
| | | 64 | | { |
| | 636 | 65 | | Debug.Assert((value | 0x20) == value); |
| | | 66 | | |
| | 636 | 67 | | return IndexOf<SpanHelpers.DontNegate<short>, Or20Transform>(ref Unsafe.As<char, short>(ref searchSpace), (s |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 71 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 72 | | public static int IndexOfAnyExceptIgnoreCase(ref char searchSpace, char value, int length) |
| | | 73 | | { |
| | 636 | 74 | | Debug.Assert((value | 0x20) == value); |
| | | 75 | | |
| | 636 | 76 | | return IndexOf<SpanHelpers.Negate<short>, Or20Transform>(ref Unsafe.As<char, short>(ref searchSpace), (short |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 80 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 81 | | public static int IndexOfAnyIgnoreCase(ref char searchSpace, char value0, char value1, int length) |
| | | 82 | | { |
| | 1440 | 83 | | Debug.Assert((value0 | 0x20) == value0); |
| | 1440 | 84 | | Debug.Assert((value1 | 0x20) == value1); |
| | | 85 | | |
| | 1440 | 86 | | return IndexOfAny<SpanHelpers.DontNegate<short>, Or20Transform>(ref Unsafe.As<char, short>(ref searchSpace), |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 90 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 91 | | public static int IndexOfAnyExceptIgnoreCase(ref char searchSpace, char value0, char value1, int length) |
| | | 92 | | { |
| | 1440 | 93 | | Debug.Assert((value0 | 0x20) == value0); |
| | 1440 | 94 | | Debug.Assert((value1 | 0x20) == value1); |
| | | 95 | | |
| | 1440 | 96 | | return IndexOfAny<SpanHelpers.Negate<short>, Or20Transform>(ref Unsafe.As<char, short>(ref searchSpace), (sh |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 100 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 101 | | public static int IndexOfAnyInRange(ref char searchSpace, char lowInclusive, char rangeInclusive, int length) => |
| | 1749 | 102 | | IndexOfAnyInRange<SpanHelpers.DontNegate<short>>(ref Unsafe.As<char, short>(ref searchSpace), (short)lowIncl |
| | | 103 | | |
| | | 104 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 105 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 106 | | public static int IndexOfAnyExceptInRange(ref char searchSpace, char lowInclusive, char rangeInclusive, int leng |
| | 1748 | 107 | | IndexOfAnyInRange<SpanHelpers.Negate<short>>(ref Unsafe.As<char, short>(ref searchSpace), (short)lowInclusiv |
| | | 108 | | |
| | | 109 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 110 | | public static bool Contains(ref short searchSpace, short value, int length) |
| | | 111 | | { |
| | 0 | 112 | | Debug.Assert(CanUsePackedIndexOf(value)); |
| | | 113 | | |
| | 0 | 114 | | if (length < Vector128<short>.Count) |
| | | 115 | | { |
| | 0 | 116 | | nuint offset = 0; |
| | | 117 | | |
| | 0 | 118 | | if (length >= 4) |
| | | 119 | | { |
| | 0 | 120 | | length -= 4; |
| | | 121 | | |
| | 0 | 122 | | if (searchSpace == value || |
| | 0 | 123 | | Unsafe.Add(ref searchSpace, 1) == value || |
| | 0 | 124 | | Unsafe.Add(ref searchSpace, 2) == value || |
| | 0 | 125 | | Unsafe.Add(ref searchSpace, 3) == value) |
| | | 126 | | { |
| | 0 | 127 | | return true; |
| | | 128 | | } |
| | | 129 | | |
| | 0 | 130 | | offset = 4; |
| | | 131 | | } |
| | | 132 | | |
| | 0 | 133 | | while (length > 0) |
| | | 134 | | { |
| | 0 | 135 | | length -= 1; |
| | | 136 | | |
| | 0 | 137 | | if (Unsafe.Add(ref searchSpace, offset) == value) |
| | | 138 | | { |
| | 0 | 139 | | return true; |
| | | 140 | | } |
| | | 141 | | |
| | 0 | 142 | | offset += 1; |
| | | 143 | | } |
| | | 144 | | } |
| | | 145 | | else |
| | | 146 | | { |
| | 0 | 147 | | ref short currentSearchSpace = ref searchSpace; |
| | | 148 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 0 | 149 | | if (Avx512BW.IsSupported && Vector512.IsHardwareAccelerated && length > Vector512<short>.Count) |
| | | 150 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 151 | | { |
| | 0 | 152 | | Vector512<byte> packedValue = Vector512.Create((byte)value); |
| | | 153 | | |
| | 0 | 154 | | if (length > 2 * Vector512<short>.Count) |
| | | 155 | | { |
| | | 156 | | // Process the input in chunks of 64 characters (2 * Vector512<short>). |
| | | 157 | | // If the input length is a multiple of 64, don't consume the last 16 characters in this loop. |
| | | 158 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 159 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 160 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector512<short> |
| | | 161 | | |
| | | 162 | | do |
| | | 163 | | { |
| | 0 | 164 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 165 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref currentSearchSpace, (nuint)Vector512<sho |
| | 0 | 166 | | Vector512<byte> packedSource = PackSources(source0, source1); |
| | | 167 | | |
| | 0 | 168 | | if (Vector512.EqualsAny(packedValue, packedSource)) |
| | | 169 | | { |
| | 0 | 170 | | return true; |
| | | 171 | | } |
| | | 172 | | |
| | 0 | 173 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector512<short>.Count); |
| | | 174 | | } |
| | 0 | 175 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 176 | | } |
| | | 177 | | |
| | | 178 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 179 | | // They may overlap, but we're only interested in whether any value matched. |
| | | 180 | | { |
| | 0 | 181 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector512<short>.Count |
| | | 182 | | |
| | 0 | 183 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 0 | 184 | | ? ref oneVectorAwayFromEnd |
| | 0 | 185 | | : ref currentSearchSpace; |
| | | 186 | | |
| | 0 | 187 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref firstVector); |
| | 0 | 188 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 0 | 189 | | Vector512<byte> packedSource = PackSources(source0, source1); |
| | | 190 | | |
| | 0 | 191 | | if (Vector512.EqualsAny(packedValue, packedSource)) |
| | | 192 | | { |
| | 0 | 193 | | return true; |
| | | 194 | | } |
| | | 195 | | } |
| | | 196 | | } |
| | | 197 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 0 | 198 | | else if (Avx2.IsSupported && length > Vector256<short>.Count) |
| | | 199 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 200 | | { |
| | 0 | 201 | | Vector256<byte> packedValue = Vector256.Create((byte)value); |
| | | 202 | | |
| | 0 | 203 | | if (length > 2 * Vector256<short>.Count) |
| | | 204 | | { |
| | | 205 | | // Process the input in chunks of 32 characters (2 * Vector256<short>). |
| | | 206 | | // If the input length is a multiple of 32, don't consume the last 16 characters in this loop. |
| | | 207 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 208 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 209 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector256<short> |
| | | 210 | | |
| | | 211 | | do |
| | | 212 | | { |
| | 0 | 213 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 214 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref currentSearchSpace, (nuint)Vector256<sho |
| | 0 | 215 | | Vector256<byte> packedSource = PackSources(source0, source1); |
| | 0 | 216 | | Vector256<byte> result = Vector256.Equals(packedValue, packedSource); |
| | | 217 | | |
| | 0 | 218 | | if (result != Vector256<byte>.Zero) |
| | | 219 | | { |
| | 0 | 220 | | return true; |
| | | 221 | | } |
| | | 222 | | |
| | 0 | 223 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector256<short>.Count); |
| | | 224 | | } |
| | 0 | 225 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 229 | | // They may overlap, but we're only interested in whether any value matched. |
| | | 230 | | { |
| | 0 | 231 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector256<short>.Count |
| | | 232 | | |
| | 0 | 233 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 0 | 234 | | ? ref oneVectorAwayFromEnd |
| | 0 | 235 | | : ref currentSearchSpace; |
| | | 236 | | |
| | 0 | 237 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref firstVector); |
| | 0 | 238 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 0 | 239 | | Vector256<byte> packedSource = PackSources(source0, source1); |
| | 0 | 240 | | Vector256<byte> result = Vector256.Equals(packedValue, packedSource); |
| | | 241 | | |
| | 0 | 242 | | if (result != Vector256<byte>.Zero) |
| | | 243 | | { |
| | 0 | 244 | | return true; |
| | | 245 | | } |
| | | 246 | | } |
| | | 247 | | } |
| | | 248 | | else |
| | | 249 | | { |
| | 0 | 250 | | Vector128<byte> packedValue = Vector128.Create((byte)value); |
| | | 251 | | |
| | | 252 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibConditionParsing // A negated IsSupported condition isn't parsea |
| | | 253 | | // with the check above of Avx2.IsSupported && |
| | | 254 | | // in this if statement dead code when Avx2.IsS |
| | | 255 | | // not generating dead code. |
| | | 256 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // This is paired with the check abov |
| | | 257 | | // may take a dependence on the JIT c |
| | | 258 | | // This logic MUST NOT be extracted t |
| | 0 | 259 | | if (!Avx2.IsSupported && length > 2 * Vector128<short>.Count) |
| | | 260 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 261 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibConditionParsing |
| | | 262 | | { |
| | | 263 | | // Process the input in chunks of 16 characters (2 * Vector128<short>). |
| | | 264 | | // If the input length is a multiple of 16, don't consume the last 16 characters in this loop. |
| | | 265 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 266 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 267 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector128<short> |
| | | 268 | | |
| | | 269 | | do |
| | | 270 | | { |
| | 0 | 271 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 272 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref currentSearchSpace, (nuint)Vector128<sho |
| | 0 | 273 | | Vector128<byte> packedSource = PackSources(source0, source1); |
| | 0 | 274 | | Vector128<byte> result = Vector128.Equals(packedValue, packedSource); |
| | | 275 | | |
| | 0 | 276 | | if (result != Vector128<byte>.Zero) |
| | | 277 | | { |
| | 0 | 278 | | return true; |
| | | 279 | | } |
| | | 280 | | |
| | 0 | 281 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector128<short>.Count); |
| | | 282 | | } |
| | 0 | 283 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 284 | | } |
| | | 285 | | |
| | | 286 | | // We have 1-16 characters remaining. Process the first and last vector in the search space. |
| | | 287 | | // They may overlap, but we're only interested in whether any value matched. |
| | | 288 | | { |
| | 0 | 289 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector128<short>.Count |
| | | 290 | | |
| | 0 | 291 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 0 | 292 | | ? ref oneVectorAwayFromEnd |
| | 0 | 293 | | : ref currentSearchSpace; |
| | | 294 | | |
| | 0 | 295 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref firstVector); |
| | 0 | 296 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 0 | 297 | | Vector128<byte> packedSource = PackSources(source0, source1); |
| | 0 | 298 | | Vector128<byte> result = Vector128.Equals(packedValue, packedSource); |
| | | 299 | | |
| | 0 | 300 | | if (result != Vector128<byte>.Zero) |
| | | 301 | | { |
| | 0 | 302 | | return true; |
| | | 303 | | } |
| | | 304 | | } |
| | | 305 | | } |
| | | 306 | | } |
| | | 307 | | |
| | 0 | 308 | | return false; |
| | | 309 | | } |
| | | 310 | | |
| | | 311 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 312 | | private static int IndexOf<TNegator, TTransform>(ref short searchSpace, short value, int length) |
| | | 313 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 314 | | where TTransform : struct, ITransform |
| | | 315 | | { |
| | 14580 | 316 | | Debug.Assert(CanUsePackedIndexOf(value)); |
| | | 317 | | |
| | 14580 | 318 | | if (length < Vector128<short>.Count) |
| | | 319 | | { |
| | 2256 | 320 | | nuint offset = 0; |
| | | 321 | | |
| | 2256 | 322 | | if (length >= 4) |
| | | 323 | | { |
| | 816 | 324 | | length -= 4; |
| | | 325 | | |
| | 1224 | 326 | | if (TNegator.NegateIfNeeded(TTransform.TransformInput(searchSpace) == value)) return 0; |
| | 507 | 327 | | if (TNegator.NegateIfNeeded(TTransform.TransformInput(Unsafe.Add(ref searchSpace, 1)) == value)) ret |
| | 396 | 328 | | if (TNegator.NegateIfNeeded(TTransform.TransformInput(Unsafe.Add(ref searchSpace, 2)) == value)) ret |
| | 279 | 329 | | if (TNegator.NegateIfNeeded(TTransform.TransformInput(Unsafe.Add(ref searchSpace, 3)) == value)) ret |
| | | 330 | | |
| | 165 | 331 | | offset = 4; |
| | | 332 | | } |
| | | 333 | | |
| | 2721 | 334 | | while (length > 0) |
| | | 335 | | { |
| | 1830 | 336 | | length -= 1; |
| | | 337 | | |
| | 2544 | 338 | | if (TNegator.NegateIfNeeded(TTransform.TransformInput(Unsafe.Add(ref searchSpace, offset)) == value) |
| | | 339 | | |
| | 1116 | 340 | | offset += 1; |
| | | 341 | | } |
| | | 342 | | } |
| | | 343 | | else |
| | | 344 | | { |
| | 12324 | 345 | | ref short currentSearchSpace = ref searchSpace; |
| | | 346 | | |
| | | 347 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 12324 | 348 | | if (Avx512BW.IsSupported && Vector512.IsHardwareAccelerated && length > Vector512<short>.Count) |
| | | 349 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 350 | | { |
| | 10711 | 351 | | Vector512<byte> packedValue = Vector512.Create((byte)value); |
| | | 352 | | |
| | 10711 | 353 | | if (length > 2 * Vector512<short>.Count) |
| | | 354 | | { |
| | | 355 | | // Process the input in chunks of 64 characters (2 * Vector512<short>). |
| | | 356 | | // If the input length is a multiple of 64, don't consume the last 16 characters in this loop. |
| | | 357 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 358 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 10142 | 359 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector512<short> |
| | | 360 | | |
| | | 361 | | do |
| | | 362 | | { |
| | 12098 | 363 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref currentSearchSpace); |
| | 12098 | 364 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref currentSearchSpace, (nuint)Vector512<sho |
| | 12098 | 365 | | Vector512<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | | 366 | | |
| | 12098 | 367 | | if (HasMatch<TNegator>(packedValue, packedSource)) |
| | | 368 | | { |
| | 705 | 369 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, GetMatchMask<TNegator> |
| | | 370 | | } |
| | | 371 | | |
| | 11393 | 372 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector512<short>.Count); |
| | | 373 | | } |
| | 11393 | 374 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 375 | | } |
| | | 376 | | |
| | | 377 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 378 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 379 | | { |
| | 10006 | 380 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector512<short>.Count |
| | | 381 | | |
| | 10006 | 382 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 10006 | 383 | | ? ref oneVectorAwayFromEnd |
| | 10006 | 384 | | : ref currentSearchSpace; |
| | | 385 | | |
| | 10006 | 386 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref firstVector); |
| | 10006 | 387 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 10006 | 388 | | Vector512<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | | 389 | | |
| | 10006 | 390 | | if (HasMatch<TNegator>(packedValue, packedSource)) |
| | | 391 | | { |
| | 267 | 392 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 393 | | } |
| | | 394 | | } |
| | | 395 | | } |
| | | 396 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 1613 | 397 | | else if (Avx2.IsSupported && length > Vector256<short>.Count) |
| | | 398 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 399 | | { |
| | 240 | 400 | | Vector256<byte> packedValue = Vector256.Create((byte)value); |
| | | 401 | | |
| | 240 | 402 | | if (length > 2 * Vector256<short>.Count) |
| | | 403 | | { |
| | | 404 | | // Process the input in chunks of 32 characters (2 * Vector256<short>). |
| | | 405 | | // If the input length is a multiple of 32, don't consume the last 16 characters in this loop. |
| | | 406 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 407 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 408 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector256<short> |
| | | 409 | | |
| | | 410 | | do |
| | | 411 | | { |
| | 0 | 412 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 413 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref currentSearchSpace, (nuint)Vector256<sho |
| | 0 | 414 | | Vector256<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 0 | 415 | | Vector256<byte> result = Vector256.Equals(packedValue, packedSource); |
| | 0 | 416 | | result = NegateIfNeeded<TNegator>(result); |
| | | 417 | | |
| | 0 | 418 | | if (result != Vector256<byte>.Zero) |
| | | 419 | | { |
| | 0 | 420 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 421 | | } |
| | | 422 | | |
| | 0 | 423 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector256<short>.Count); |
| | | 424 | | } |
| | 0 | 425 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 426 | | } |
| | | 427 | | |
| | | 428 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 429 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 430 | | { |
| | 240 | 431 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector256<short>.Count |
| | | 432 | | |
| | 240 | 433 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 240 | 434 | | ? ref oneVectorAwayFromEnd |
| | 240 | 435 | | : ref currentSearchSpace; |
| | | 436 | | |
| | 240 | 437 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref firstVector); |
| | 240 | 438 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 240 | 439 | | Vector256<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 240 | 440 | | Vector256<byte> result = Vector256.Equals(packedValue, packedSource); |
| | 240 | 441 | | result = NegateIfNeeded<TNegator>(result); |
| | | 442 | | |
| | 240 | 443 | | if (result != Vector256<byte>.Zero) |
| | | 444 | | { |
| | 171 | 445 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 446 | | } |
| | | 447 | | } |
| | | 448 | | } |
| | | 449 | | else |
| | | 450 | | { |
| | 1373 | 451 | | Vector128<byte> packedValue = Vector128.Create((byte)value); |
| | | 452 | | |
| | | 453 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibConditionParsing // A negated IsSupported condition isn't parsea |
| | | 454 | | // with the check above of Avx2.IsSupported && |
| | | 455 | | // in this if statement dead code when Avx2.IsS |
| | | 456 | | // not generating dead code. |
| | | 457 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // This is paired with the check abov |
| | | 458 | | // may take a dependence on the JIT c |
| | | 459 | | // This logic MUST NOT be extracted t |
| | 1373 | 460 | | if (!Avx2.IsSupported && length > 2 * Vector128<short>.Count) |
| | | 461 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 462 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibConditionParsing |
| | | 463 | | { |
| | | 464 | | // Process the input in chunks of 16 characters (2 * Vector128<short>). |
| | | 465 | | // If the input length is a multiple of 16, don't consume the last 16 characters in this loop. |
| | | 466 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 467 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 468 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector128<short> |
| | | 469 | | |
| | | 470 | | do |
| | | 471 | | { |
| | 0 | 472 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 473 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref currentSearchSpace, (nuint)Vector128<sho |
| | 0 | 474 | | Vector128<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 0 | 475 | | Vector128<byte> result = Vector128.Equals(packedValue, packedSource); |
| | 0 | 476 | | result = NegateIfNeeded<TNegator>(result); |
| | | 477 | | |
| | 0 | 478 | | if (result != Vector128<byte>.Zero) |
| | | 479 | | { |
| | 0 | 480 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 481 | | } |
| | | 482 | | |
| | 0 | 483 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector128<short>.Count); |
| | | 484 | | } |
| | 0 | 485 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 486 | | } |
| | | 487 | | |
| | | 488 | | // We have 1-16 characters remaining. Process the first and last vector in the search space. |
| | | 489 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 490 | | { |
| | 1373 | 491 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector128<short>.Count |
| | | 492 | | |
| | 1373 | 493 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 1373 | 494 | | ? ref oneVectorAwayFromEnd |
| | 1373 | 495 | | : ref currentSearchSpace; |
| | | 496 | | |
| | 1373 | 497 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref firstVector); |
| | 1373 | 498 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 1373 | 499 | | Vector128<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 1373 | 500 | | Vector128<byte> result = Vector128.Equals(packedValue, packedSource); |
| | 1373 | 501 | | result = NegateIfNeeded<TNegator>(result); |
| | | 502 | | |
| | 1373 | 503 | | if (result != Vector128<byte>.Zero) |
| | | 504 | | { |
| | 270 | 505 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 506 | | } |
| | | 507 | | } |
| | | 508 | | } |
| | | 509 | | } |
| | | 510 | | |
| | 11802 | 511 | | return -1; |
| | | 512 | | } |
| | | 513 | | |
| | | 514 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 515 | | private static int IndexOfAny<TNegator, TTransform>(ref short searchSpace, short value0, short value1, int lengt |
| | | 516 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 517 | | where TTransform : struct, ITransform |
| | | 518 | | { |
| | 5504 | 519 | | Debug.Assert(CanUsePackedIndexOf(value0)); |
| | 5504 | 520 | | Debug.Assert(CanUsePackedIndexOf(value1)); |
| | | 521 | | |
| | 5504 | 522 | | if (length < Vector128<short>.Count) |
| | | 523 | | { |
| | 2822 | 524 | | nuint offset = 0; |
| | | 525 | | short lookUp; |
| | | 526 | | |
| | 2822 | 527 | | if (length >= 4) |
| | | 528 | | { |
| | 1722 | 529 | | length -= 4; |
| | | 530 | | |
| | 1722 | 531 | | lookUp = TTransform.TransformInput(searchSpace); |
| | 2583 | 532 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1)) return 0; |
| | 861 | 533 | | lookUp = TTransform.TransformInput(Unsafe.Add(ref searchSpace, 1)); |
| | 1011 | 534 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1)) return 1; |
| | 711 | 535 | | lookUp = TTransform.TransformInput(Unsafe.Add(ref searchSpace, 2)); |
| | 789 | 536 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1)) return 2; |
| | 633 | 537 | | lookUp = TTransform.TransformInput(Unsafe.Add(ref searchSpace, 3)); |
| | 726 | 538 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1)) return 3; |
| | | 539 | | |
| | 540 | 540 | | offset = 4; |
| | | 541 | | } |
| | | 542 | | |
| | 2734 | 543 | | while (length > 0) |
| | | 544 | | { |
| | 1701 | 545 | | length -= 1; |
| | | 546 | | |
| | 1701 | 547 | | lookUp = TTransform.TransformInput(Unsafe.Add(ref searchSpace, offset)); |
| | 2308 | 548 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1)) return (int)offset; |
| | | 549 | | |
| | 1094 | 550 | | offset += 1; |
| | | 551 | | } |
| | | 552 | | } |
| | | 553 | | else |
| | | 554 | | { |
| | 2682 | 555 | | ref short currentSearchSpace = ref searchSpace; |
| | | 556 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 2682 | 557 | | if (Avx512BW.IsSupported && Vector512.IsHardwareAccelerated && length > Vector512<short>.Count) |
| | | 558 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 559 | | { |
| | 1542 | 560 | | Vector512<byte> packedValue0 = Vector512.Create((byte)value0); |
| | 1542 | 561 | | Vector512<byte> packedValue1 = Vector512.Create((byte)value1); |
| | | 562 | | |
| | 1542 | 563 | | if (length > 2 * Vector512<short>.Count) |
| | | 564 | | { |
| | | 565 | | // Process the input in chunks of 64 characters (2 * Vector512<short>). |
| | | 566 | | // If the input length is a multiple of 64, don't consume the last 16 characters in this loop. |
| | | 567 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 568 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 1164 | 569 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector512<short> |
| | | 570 | | |
| | | 571 | | do |
| | | 572 | | { |
| | 2964 | 573 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref currentSearchSpace); |
| | 2964 | 574 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref currentSearchSpace, (nuint)Vector512<sho |
| | 2964 | 575 | | Vector512<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 2964 | 576 | | Vector512<byte> result = NegateIfNeeded<TNegator>(Vector512.Equals(packedValue0, packedSourc |
| | | 577 | | |
| | 2964 | 578 | | if (result != Vector512<byte>.Zero) |
| | | 579 | | { |
| | 795 | 580 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 581 | | } |
| | | 582 | | |
| | 2169 | 583 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector512<short>.Count); |
| | | 584 | | } |
| | 2169 | 585 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 586 | | } |
| | | 587 | | |
| | | 588 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 589 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 590 | | { |
| | 747 | 591 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector512<short>.Count |
| | | 592 | | |
| | 747 | 593 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 747 | 594 | | ? ref oneVectorAwayFromEnd |
| | 747 | 595 | | : ref currentSearchSpace; |
| | | 596 | | |
| | 747 | 597 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref firstVector); |
| | 747 | 598 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 747 | 599 | | Vector512<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 747 | 600 | | Vector512<byte> result = NegateIfNeeded<TNegator>(Vector512.Equals(packedValue0, packedSource) | |
| | | 601 | | |
| | 747 | 602 | | if (result != Vector512<byte>.Zero) |
| | | 603 | | { |
| | 378 | 604 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 605 | | } |
| | | 606 | | } |
| | | 607 | | } |
| | | 608 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 1140 | 609 | | else if (Avx2.IsSupported && length > Vector256<short>.Count) |
| | | 610 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 611 | | { |
| | 570 | 612 | | Vector256<byte> packedValue0 = Vector256.Create((byte)value0); |
| | 570 | 613 | | Vector256<byte> packedValue1 = Vector256.Create((byte)value1); |
| | | 614 | | |
| | 570 | 615 | | if (length > 2 * Vector256<short>.Count) |
| | | 616 | | { |
| | | 617 | | // Process the input in chunks of 32 characters (2 * Vector256<short>). |
| | | 618 | | // If the input length is a multiple of 32, don't consume the last 16 characters in this loop. |
| | | 619 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 620 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 621 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector256<short> |
| | | 622 | | |
| | | 623 | | do |
| | | 624 | | { |
| | 0 | 625 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 626 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref currentSearchSpace, (nuint)Vector256<sho |
| | 0 | 627 | | Vector256<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 0 | 628 | | Vector256<byte> result = Vector256.Equals(packedValue0, packedSource) | Vector256.Equals(pac |
| | 0 | 629 | | result = NegateIfNeeded<TNegator>(result); |
| | | 630 | | |
| | 0 | 631 | | if (result != Vector256<byte>.Zero) |
| | | 632 | | { |
| | 0 | 633 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 634 | | } |
| | | 635 | | |
| | 0 | 636 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector256<short>.Count); |
| | | 637 | | } |
| | 0 | 638 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 639 | | } |
| | | 640 | | |
| | | 641 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 642 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 643 | | { |
| | 570 | 644 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector256<short>.Count |
| | | 645 | | |
| | 570 | 646 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 570 | 647 | | ? ref oneVectorAwayFromEnd |
| | 570 | 648 | | : ref currentSearchSpace; |
| | | 649 | | |
| | 570 | 650 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref firstVector); |
| | 570 | 651 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 570 | 652 | | Vector256<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 570 | 653 | | Vector256<byte> result = Vector256.Equals(packedValue0, packedSource) | Vector256.Equals(packedV |
| | 570 | 654 | | result = NegateIfNeeded<TNegator>(result); |
| | | 655 | | |
| | 570 | 656 | | if (result != Vector256<byte>.Zero) |
| | | 657 | | { |
| | 444 | 658 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 659 | | } |
| | | 660 | | } |
| | | 661 | | } |
| | | 662 | | else |
| | | 663 | | { |
| | 570 | 664 | | Vector128<byte> packedValue0 = Vector128.Create((byte)value0); |
| | 570 | 665 | | Vector128<byte> packedValue1 = Vector128.Create((byte)value1); |
| | | 666 | | |
| | | 667 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibConditionParsing // A negated IsSupported condition isn't parsea |
| | | 668 | | // with the check above of Avx2.IsSupported && |
| | | 669 | | // in this if statement dead code when Avx2.IsS |
| | | 670 | | // not generating dead code. |
| | | 671 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // This is paired with the check abov |
| | | 672 | | // may take a dependence on the JIT c |
| | | 673 | | // This logic MUST NOT be extracted t |
| | 570 | 674 | | if (!Avx2.IsSupported && length > 2 * Vector128<short>.Count) |
| | | 675 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 676 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibConditionParsing |
| | | 677 | | { |
| | | 678 | | // Process the input in chunks of 16 characters (2 * Vector128<short>). |
| | | 679 | | // If the input length is a multiple of 16, don't consume the last 16 characters in this loop. |
| | | 680 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 681 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 682 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector128<short> |
| | | 683 | | |
| | | 684 | | do |
| | | 685 | | { |
| | 0 | 686 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 687 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref currentSearchSpace, (nuint)Vector128<sho |
| | 0 | 688 | | Vector128<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 0 | 689 | | Vector128<byte> result = Vector128.Equals(packedValue0, packedSource) | Vector128.Equals(pac |
| | 0 | 690 | | result = NegateIfNeeded<TNegator>(result); |
| | | 691 | | |
| | 0 | 692 | | if (result != Vector128<byte>.Zero) |
| | | 693 | | { |
| | 0 | 694 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 695 | | } |
| | | 696 | | |
| | 0 | 697 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector128<short>.Count); |
| | | 698 | | } |
| | 0 | 699 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 700 | | } |
| | | 701 | | |
| | | 702 | | // We have 1-16 characters remaining. Process the first and last vector in the search space. |
| | | 703 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 704 | | { |
| | 570 | 705 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector128<short>.Count |
| | | 706 | | |
| | 570 | 707 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 570 | 708 | | ? ref oneVectorAwayFromEnd |
| | 570 | 709 | | : ref currentSearchSpace; |
| | | 710 | | |
| | 570 | 711 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref firstVector); |
| | 570 | 712 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 570 | 713 | | Vector128<byte> packedSource = TTransform.TransformInput(PackSources(source0, source1)); |
| | 570 | 714 | | Vector128<byte> result = Vector128.Equals(packedValue0, packedSource) | Vector128.Equals(packedV |
| | 570 | 715 | | result = NegateIfNeeded<TNegator>(result); |
| | | 716 | | |
| | 570 | 717 | | if (result != Vector128<byte>.Zero) |
| | | 718 | | { |
| | 438 | 719 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 720 | | } |
| | | 721 | | } |
| | | 722 | | } |
| | | 723 | | } |
| | | 724 | | |
| | 1660 | 725 | | return -1; |
| | | 726 | | } |
| | | 727 | | |
| | | 728 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 729 | | private static int IndexOfAny<TNegator>(ref short searchSpace, short value0, short value1, short value2, int len |
| | | 730 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 731 | | { |
| | 3688 | 732 | | Debug.Assert(CanUsePackedIndexOf(value0)); |
| | 3688 | 733 | | Debug.Assert(CanUsePackedIndexOf(value1)); |
| | 3688 | 734 | | Debug.Assert(CanUsePackedIndexOf(value2)); |
| | | 735 | | |
| | 3688 | 736 | | if (length < Vector128<short>.Count) |
| | | 737 | | { |
| | 1732 | 738 | | nuint offset = 0; |
| | | 739 | | short lookUp; |
| | | 740 | | |
| | 1732 | 741 | | if (length >= 4) |
| | | 742 | | { |
| | 594 | 743 | | length -= 4; |
| | | 744 | | |
| | 594 | 745 | | lookUp = searchSpace; |
| | 891 | 746 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1 || lookUp == value2)) return 0; |
| | 297 | 747 | | lookUp = Unsafe.Add(ref searchSpace, 1); |
| | 393 | 748 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1 || lookUp == value2)) return 1; |
| | 201 | 749 | | lookUp = Unsafe.Add(ref searchSpace, 2); |
| | 282 | 750 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1 || lookUp == value2)) return 2; |
| | 120 | 751 | | lookUp = Unsafe.Add(ref searchSpace, 3); |
| | 177 | 752 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1 || lookUp == value2)) return 3; |
| | | 753 | | |
| | 63 | 754 | | offset = 4; |
| | | 755 | | } |
| | | 756 | | |
| | 2755 | 757 | | while (length > 0) |
| | | 758 | | { |
| | 2162 | 759 | | length -= 1; |
| | | 760 | | |
| | 2162 | 761 | | lookUp = Unsafe.Add(ref searchSpace, offset); |
| | 2770 | 762 | | if (TNegator.NegateIfNeeded(lookUp == value0 || lookUp == value1 || lookUp == value2)) return (int)o |
| | | 763 | | |
| | 1554 | 764 | | offset += 1; |
| | | 765 | | } |
| | | 766 | | } |
| | | 767 | | else |
| | | 768 | | { |
| | 1956 | 769 | | ref short currentSearchSpace = ref searchSpace; |
| | | 770 | | |
| | | 771 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 1956 | 772 | | if (Avx512BW.IsSupported && Vector512.IsHardwareAccelerated && length > Vector512<short>.Count) |
| | | 773 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 774 | | { |
| | 1320 | 775 | | Vector512<byte> packedValue0 = Vector512.Create((byte)value0); |
| | 1320 | 776 | | Vector512<byte> packedValue1 = Vector512.Create((byte)value1); |
| | 1320 | 777 | | Vector512<byte> packedValue2 = Vector512.Create((byte)value2); |
| | | 778 | | |
| | 1320 | 779 | | if (length > 2 * Vector512<short>.Count) |
| | | 780 | | { |
| | | 781 | | // Process the input in chunks of 64 characters (2 * Vector512<short>). |
| | | 782 | | // If the input length is a multiple of 64, don't consume the last 16 characters in this loop. |
| | | 783 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 784 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 1092 | 785 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector512<short> |
| | | 786 | | |
| | | 787 | | do |
| | | 788 | | { |
| | 3648 | 789 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref currentSearchSpace); |
| | 3648 | 790 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref currentSearchSpace, (nuint)Vector512<sho |
| | 3648 | 791 | | Vector512<byte> packedSource = PackSources(source0, source1); |
| | 3648 | 792 | | Vector512<byte> result = NegateIfNeeded<TNegator>(Vector512.Equals(packedValue0, packedSourc |
| | | 793 | | |
| | 3648 | 794 | | if (result != Vector512<byte>.Zero) |
| | | 795 | | { |
| | 768 | 796 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 797 | | } |
| | | 798 | | |
| | 2880 | 799 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector512<short>.Count); |
| | | 800 | | } |
| | 2880 | 801 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 802 | | } |
| | | 803 | | |
| | | 804 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 805 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 806 | | { |
| | 552 | 807 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector512<short>.Count |
| | | 808 | | |
| | 552 | 809 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 552 | 810 | | ? ref oneVectorAwayFromEnd |
| | 552 | 811 | | : ref currentSearchSpace; |
| | | 812 | | |
| | 552 | 813 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref firstVector); |
| | 552 | 814 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 552 | 815 | | Vector512<byte> packedSource = PackSources(source0, source1); |
| | 552 | 816 | | Vector512<byte> result = NegateIfNeeded<TNegator>(Vector512.Equals(packedValue0, packedSource) | |
| | | 817 | | |
| | 552 | 818 | | if (result != Vector512<byte>.Zero) |
| | | 819 | | { |
| | 297 | 820 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 821 | | } |
| | | 822 | | } |
| | | 823 | | } |
| | | 824 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 636 | 825 | | else if (Avx2.IsSupported && length > Vector256<short>.Count) |
| | | 826 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 827 | | { |
| | 300 | 828 | | Vector256<byte> packedValue0 = Vector256.Create((byte)value0); |
| | 300 | 829 | | Vector256<byte> packedValue1 = Vector256.Create((byte)value1); |
| | 300 | 830 | | Vector256<byte> packedValue2 = Vector256.Create((byte)value2); |
| | | 831 | | |
| | 300 | 832 | | if (length > 2 * Vector256<short>.Count) |
| | | 833 | | { |
| | | 834 | | // Process the input in chunks of 32 characters (2 * Vector256<short>). |
| | | 835 | | // If the input length is a multiple of 32, don't consume the last 16 characters in this loop. |
| | | 836 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 837 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 838 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector256<short> |
| | | 839 | | |
| | | 840 | | do |
| | | 841 | | { |
| | 0 | 842 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 843 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref currentSearchSpace, (nuint)Vector256<sho |
| | 0 | 844 | | Vector256<byte> packedSource = PackSources(source0, source1); |
| | 0 | 845 | | Vector256<byte> result = Vector256.Equals(packedValue0, packedSource) | Vector256.Equals(pac |
| | 0 | 846 | | result = NegateIfNeeded<TNegator>(result); |
| | | 847 | | |
| | 0 | 848 | | if (result != Vector256<byte>.Zero) |
| | | 849 | | { |
| | 0 | 850 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 851 | | } |
| | | 852 | | |
| | 0 | 853 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector256<short>.Count); |
| | | 854 | | } |
| | 0 | 855 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 856 | | } |
| | | 857 | | |
| | | 858 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 859 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 860 | | { |
| | 300 | 861 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector256<short>.Count |
| | | 862 | | |
| | 300 | 863 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 300 | 864 | | ? ref oneVectorAwayFromEnd |
| | 300 | 865 | | : ref currentSearchSpace; |
| | | 866 | | |
| | 300 | 867 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref firstVector); |
| | 300 | 868 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 300 | 869 | | Vector256<byte> packedSource = PackSources(source0, source1); |
| | 300 | 870 | | Vector256<byte> result = Vector256.Equals(packedValue0, packedSource) | Vector256.Equals(packedV |
| | 300 | 871 | | result = NegateIfNeeded<TNegator>(result); |
| | | 872 | | |
| | 300 | 873 | | if (result != Vector256<byte>.Zero) |
| | | 874 | | { |
| | 255 | 875 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 876 | | } |
| | | 877 | | } |
| | | 878 | | } |
| | | 879 | | else |
| | | 880 | | { |
| | 336 | 881 | | Vector128<byte> packedValue0 = Vector128.Create((byte)value0); |
| | 336 | 882 | | Vector128<byte> packedValue1 = Vector128.Create((byte)value1); |
| | 336 | 883 | | Vector128<byte> packedValue2 = Vector128.Create((byte)value2); |
| | | 884 | | |
| | | 885 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibConditionParsing // A negated IsSupported condition isn't parsea |
| | | 886 | | // with the check above of Avx2.IsSupported && |
| | | 887 | | // in this if statement dead code when Avx2.IsS |
| | | 888 | | // not generating dead code. |
| | | 889 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // This is paired with the check abov |
| | | 890 | | // may take a dependence on the JIT c |
| | | 891 | | // This logic MUST NOT be extracted t |
| | 336 | 892 | | if (!Avx2.IsSupported && length > 2 * Vector128<short>.Count) |
| | | 893 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 894 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibConditionParsing |
| | | 895 | | { |
| | | 896 | | // Process the input in chunks of 16 characters (2 * Vector128<short>). |
| | | 897 | | // If the input length is a multiple of 16, don't consume the last 16 characters in this loop. |
| | | 898 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 899 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 900 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector128<short> |
| | | 901 | | |
| | | 902 | | do |
| | | 903 | | { |
| | 0 | 904 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 905 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref currentSearchSpace, (nuint)Vector128<sho |
| | 0 | 906 | | Vector128<byte> packedSource = PackSources(source0, source1); |
| | 0 | 907 | | Vector128<byte> result = Vector128.Equals(packedValue0, packedSource) | Vector128.Equals(pac |
| | 0 | 908 | | result = NegateIfNeeded<TNegator>(result); |
| | | 909 | | |
| | 0 | 910 | | if (result != Vector128<byte>.Zero) |
| | | 911 | | { |
| | 0 | 912 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 913 | | } |
| | | 914 | | |
| | 0 | 915 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector128<short>.Count); |
| | | 916 | | } |
| | 0 | 917 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 918 | | } |
| | | 919 | | |
| | | 920 | | // We have 1-16 characters remaining. Process the first and last vector in the search space. |
| | | 921 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 922 | | { |
| | 336 | 923 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector128<short>.Count |
| | | 924 | | |
| | 336 | 925 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 336 | 926 | | ? ref oneVectorAwayFromEnd |
| | 336 | 927 | | : ref currentSearchSpace; |
| | | 928 | | |
| | 336 | 929 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref firstVector); |
| | 336 | 930 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 336 | 931 | | Vector128<byte> packedSource = PackSources(source0, source1); |
| | 336 | 932 | | Vector128<byte> result = Vector128.Equals(packedValue0, packedSource) | Vector128.Equals(packedV |
| | 336 | 933 | | result = NegateIfNeeded<TNegator>(result); |
| | | 934 | | |
| | 336 | 935 | | if (result != Vector128<byte>.Zero) |
| | | 936 | | { |
| | 273 | 937 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 938 | | } |
| | | 939 | | } |
| | | 940 | | } |
| | | 941 | | } |
| | | 942 | | |
| | 956 | 943 | | return -1; |
| | | 944 | | } |
| | | 945 | | |
| | | 946 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 947 | | private static int IndexOfAnyInRange<TNegator>(ref short searchSpace, short lowInclusive, short rangeInclusive, |
| | | 948 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 949 | | { |
| | 3497 | 950 | | Debug.Assert(CanUsePackedIndexOf(lowInclusive)); |
| | 3497 | 951 | | Debug.Assert(CanUsePackedIndexOf((short)(lowInclusive + rangeInclusive))); |
| | 3497 | 952 | | Debug.Assert(rangeInclusive >= 0); |
| | | 953 | | |
| | 3497 | 954 | | if (length < Vector128<short>.Count) |
| | | 955 | | { |
| | 829 | 956 | | uint lowInclusiveUint = (uint)lowInclusive; |
| | 829 | 957 | | uint rangeInclusiveUint = (uint)rangeInclusive; |
| | 4008 | 958 | | for (int i = 0; i < length; i++) |
| | | 959 | | { |
| | 1653 | 960 | | uint current = (uint)Unsafe.Add(ref searchSpace, i); |
| | 1653 | 961 | | if (TNegator.NegateIfNeeded((current - lowInclusiveUint) <= rangeInclusiveUint)) |
| | | 962 | | { |
| | 478 | 963 | | return i; |
| | | 964 | | } |
| | | 965 | | } |
| | | 966 | | } |
| | | 967 | | else |
| | | 968 | | { |
| | 2668 | 969 | | ref short currentSearchSpace = ref searchSpace; |
| | | 970 | | |
| | | 971 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 2668 | 972 | | if (Avx512BW.IsSupported && Vector512.IsHardwareAccelerated && length > Vector512<short>.Count) |
| | | 973 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 974 | | { |
| | 1754 | 975 | | Vector512<byte> lowVector = Vector512.Create((byte)lowInclusive); |
| | 1754 | 976 | | Vector512<byte> rangeVector = Vector512.Create((byte)rangeInclusive); |
| | | 977 | | |
| | 1754 | 978 | | if (length > 2 * Vector512<short>.Count) |
| | | 979 | | { |
| | | 980 | | // Process the input in chunks of 64 characters (2 * Vector512<short>). |
| | | 981 | | // If the input length is a multiple of 64, don't consume the last 16 characters in this loop. |
| | | 982 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 983 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 1330 | 984 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector512<short> |
| | | 985 | | |
| | | 986 | | do |
| | | 987 | | { |
| | 3825 | 988 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref currentSearchSpace); |
| | 3825 | 989 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref currentSearchSpace, (nuint)Vector512<sho |
| | 3825 | 990 | | Vector512<byte> packedSource = PackSources(source0, source1) - lowVector; |
| | | 991 | | |
| | 3825 | 992 | | if (HasMatchInRange<TNegator>(packedSource, rangeVector)) |
| | | 993 | | { |
| | 827 | 994 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, GetMatchInRangeMask<TN |
| | | 995 | | } |
| | | 996 | | |
| | 2998 | 997 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector512<short>.Count); |
| | | 998 | | } |
| | 2998 | 999 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 1000 | | } |
| | | 1001 | | |
| | | 1002 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 1003 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 1004 | | { |
| | 927 | 1005 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector512<short>.Count |
| | | 1006 | | |
| | 927 | 1007 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 927 | 1008 | | ? ref oneVectorAwayFromEnd |
| | 927 | 1009 | | : ref currentSearchSpace; |
| | | 1010 | | |
| | 927 | 1011 | | Vector512<short> source0 = Vector512.LoadUnsafe(ref firstVector); |
| | 927 | 1012 | | Vector512<short> source1 = Vector512.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 927 | 1013 | | Vector512<byte> packedSource = PackSources(source0, source1) - lowVector; |
| | | 1014 | | |
| | 927 | 1015 | | if (HasMatchInRange<TNegator>(packedSource, rangeVector)) |
| | | 1016 | | { |
| | 419 | 1017 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 1018 | | } |
| | | 1019 | | } |
| | | 1020 | | } |
| | | 1021 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // The else condition for this if sta |
| | 914 | 1022 | | else if (Avx2.IsSupported && length > Vector256<short>.Count) |
| | | 1023 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 1024 | | { |
| | 570 | 1025 | | Vector256<byte> lowVector = Vector256.Create((byte)lowInclusive); |
| | 570 | 1026 | | Vector256<byte> rangeVector = Vector256.Create((byte)rangeInclusive); |
| | | 1027 | | |
| | 570 | 1028 | | if (length > 2 * Vector256<short>.Count) |
| | | 1029 | | { |
| | | 1030 | | // Process the input in chunks of 32 characters (2 * Vector256<short>). |
| | | 1031 | | // If the input length is a multiple of 32, don't consume the last 16 characters in this loop. |
| | | 1032 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 1033 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 1034 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector256<short> |
| | | 1035 | | |
| | | 1036 | | do |
| | | 1037 | | { |
| | 0 | 1038 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 1039 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref currentSearchSpace, (nuint)Vector256<sho |
| | 0 | 1040 | | Vector256<byte> packedSource = PackSources(source0, source1); |
| | 0 | 1041 | | Vector256<byte> result = Vector256.LessThanOrEqual(packedSource - lowVector, rangeVector); |
| | 0 | 1042 | | result = NegateIfNeeded<TNegator>(result); |
| | | 1043 | | |
| | 0 | 1044 | | if (result != Vector256<byte>.Zero) |
| | | 1045 | | { |
| | 0 | 1046 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 1047 | | } |
| | | 1048 | | |
| | 0 | 1049 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector256<short>.Count); |
| | | 1050 | | } |
| | 0 | 1051 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 1052 | | } |
| | | 1053 | | |
| | | 1054 | | // We have 1-32 characters remaining. Process the first and last vector in the search space. |
| | | 1055 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 1056 | | { |
| | 570 | 1057 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector256<short>.Count |
| | | 1058 | | |
| | 570 | 1059 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 570 | 1060 | | ? ref oneVectorAwayFromEnd |
| | 570 | 1061 | | : ref currentSearchSpace; |
| | | 1062 | | |
| | 570 | 1063 | | Vector256<short> source0 = Vector256.LoadUnsafe(ref firstVector); |
| | 570 | 1064 | | Vector256<short> source1 = Vector256.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 570 | 1065 | | Vector256<byte> packedSource = PackSources(source0, source1); |
| | 570 | 1066 | | Vector256<byte> result = Vector256.LessThanOrEqual(packedSource - lowVector, rangeVector); |
| | 570 | 1067 | | result = NegateIfNeeded<TNegator>(result); |
| | | 1068 | | |
| | 570 | 1069 | | if (result != Vector256<byte>.Zero) |
| | | 1070 | | { |
| | 396 | 1071 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 1072 | | } |
| | | 1073 | | } |
| | | 1074 | | } |
| | | 1075 | | else |
| | | 1076 | | { |
| | 344 | 1077 | | Vector128<byte> lowVector = Vector128.Create((byte)lowInclusive); |
| | 344 | 1078 | | Vector128<byte> rangeVector = Vector128.Create((byte)rangeInclusive); |
| | | 1079 | | |
| | | 1080 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibConditionParsing // A negated IsSupported condition isn't parsea |
| | | 1081 | | // with the check above of Avx2.IsSupported && |
| | | 1082 | | // in this if statement dead code when Avx2.IsS |
| | | 1083 | | // not generating dead code. |
| | | 1084 | | #pragma warning disable IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough // This is paired with the check abov |
| | | 1085 | | // may take a dependence on the JIT c |
| | | 1086 | | // This logic MUST NOT be extracted t |
| | 344 | 1087 | | if (!Avx2.IsSupported && length > 2 * Vector128<short>.Count) |
| | | 1088 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibAttributeNotSpecificEnough |
| | | 1089 | | #pragma warning restore IntrinsicsInSystemPrivateCoreLibConditionParsing |
| | | 1090 | | { |
| | | 1091 | | // Process the input in chunks of 16 characters (2 * Vector128<short>). |
| | | 1092 | | // If the input length is a multiple of 16, don't consume the last 16 characters in this loop. |
| | | 1093 | | // Let the fallback below handle it instead. This is why the condition is |
| | | 1094 | | // ">" instead of ">=" above, and why "IsAddressLessThan" is used instead of "IsAddressLessThanO |
| | 0 | 1095 | | ref short twoVectorsAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - (2 * Vector128<short> |
| | | 1096 | | |
| | | 1097 | | do |
| | | 1098 | | { |
| | 0 | 1099 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref currentSearchSpace); |
| | 0 | 1100 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref currentSearchSpace, (nuint)Vector128<sho |
| | 0 | 1101 | | Vector128<byte> packedSource = PackSources(source0, source1); |
| | 0 | 1102 | | Vector128<byte> result = Vector128.LessThanOrEqual(packedSource - lowVector, rangeVector); |
| | 0 | 1103 | | result = NegateIfNeeded<TNegator>(result); |
| | | 1104 | | |
| | 0 | 1105 | | if (result != Vector128<byte>.Zero) |
| | | 1106 | | { |
| | 0 | 1107 | | return ComputeFirstIndex(ref searchSpace, ref currentSearchSpace, result); |
| | | 1108 | | } |
| | | 1109 | | |
| | 0 | 1110 | | currentSearchSpace = ref Unsafe.Add(ref currentSearchSpace, 2 * Vector128<short>.Count); |
| | | 1111 | | } |
| | 0 | 1112 | | while (Unsafe.IsAddressLessThan(ref currentSearchSpace, ref twoVectorsAwayFromEnd)); |
| | | 1113 | | } |
| | | 1114 | | |
| | | 1115 | | // We have 1-16 characters remaining. Process the first and last vector in the search space. |
| | | 1116 | | // They may overlap, but we'll handle that in the index calculation if we do get a match. |
| | | 1117 | | { |
| | 344 | 1118 | | ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector128<short>.Count |
| | | 1119 | | |
| | 344 | 1120 | | ref short firstVector = ref Unsafe.IsAddressGreaterThan(ref currentSearchSpace, ref oneVectorAwa |
| | 344 | 1121 | | ? ref oneVectorAwayFromEnd |
| | 344 | 1122 | | : ref currentSearchSpace; |
| | | 1123 | | |
| | 344 | 1124 | | Vector128<short> source0 = Vector128.LoadUnsafe(ref firstVector); |
| | 344 | 1125 | | Vector128<short> source1 = Vector128.LoadUnsafe(ref oneVectorAwayFromEnd); |
| | 344 | 1126 | | Vector128<byte> packedSource = PackSources(source0, source1); |
| | 344 | 1127 | | Vector128<byte> result = Vector128.LessThanOrEqual(packedSource - lowVector, rangeVector); |
| | 344 | 1128 | | result = NegateIfNeeded<TNegator>(result); |
| | | 1129 | | |
| | 344 | 1130 | | if (result != Vector128<byte>.Zero) |
| | | 1131 | | { |
| | 199 | 1132 | | return ComputeFirstIndexOverlapped(ref searchSpace, ref firstVector, ref oneVectorAwayFromEn |
| | | 1133 | | } |
| | | 1134 | | } |
| | | 1135 | | } |
| | | 1136 | | } |
| | | 1137 | | |
| | 1178 | 1138 | | return -1; |
| | | 1139 | | } |
| | | 1140 | | |
| | | 1141 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1142 | | [CompExactlyDependsOn(typeof(Avx512BW))] |
| | | 1143 | | internal static Vector512<byte> PackSources(Vector512<short> source0, Vector512<short> source1) |
| | | 1144 | | { |
| | 34767 | 1145 | | Debug.Assert(Avx512BW.IsSupported); |
| | | 1146 | | // Pack two vectors of characters into bytes. While the type is Vector256<short>, these are really UInt16 ch |
| | | 1147 | | // X86: Downcast every character using saturation. |
| | | 1148 | | // - Values <= 32767 result in min(value, 255). |
| | | 1149 | | // - Values > 32767 result in 0. Because of this we can't accept needles that contain 0. |
| | 34767 | 1150 | | return Avx512BW.PackUnsignedSaturate(source0, source1).AsByte(); |
| | | 1151 | | } |
| | | 1152 | | |
| | | 1153 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1154 | | [CompExactlyDependsOn(typeof(Avx2))] |
| | | 1155 | | internal static Vector256<byte> PackSources(Vector256<short> source0, Vector256<short> source1) |
| | | 1156 | | { |
| | 1680 | 1157 | | Debug.Assert(Avx2.IsSupported); |
| | | 1158 | | // Pack two vectors of characters into bytes. While the type is Vector256<short>, these are really UInt16 ch |
| | | 1159 | | // X86: Downcast every character using saturation. |
| | | 1160 | | // - Values <= 32767 result in min(value, 255). |
| | | 1161 | | // - Values > 32767 result in 0. Because of this we can't accept needles that contain 0. |
| | 1680 | 1162 | | return Avx2.PackUnsignedSaturate(source0, source1).AsByte(); |
| | | 1163 | | } |
| | | 1164 | | |
| | | 1165 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1166 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 1167 | | internal static Vector128<byte> PackSources(Vector128<short> source0, Vector128<short> source1) |
| | | 1168 | | { |
| | 2623 | 1169 | | Debug.Assert(Sse2.IsSupported); |
| | | 1170 | | // Pack two vectors of characters into bytes. While the type is Vector128<short>, these are really UInt16 ch |
| | | 1171 | | // X86: Downcast every character using saturation. |
| | | 1172 | | // - Values <= 32767 result in min(value, 255). |
| | | 1173 | | // - Values > 32767 result in 0. Because of this we can't accept needles that contain 0. |
| | 2623 | 1174 | | return Sse2.PackUnsignedSaturate(source0, source1).AsByte(); |
| | | 1175 | | } |
| | | 1176 | | |
| | | 1177 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1178 | | private static bool NegateIfNeeded<TNegator>(bool result) |
| | | 1179 | | where TNegator : struct, SpanHelpers.INegator<short> => |
| | | 1180 | | typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>) ? result : !result; |
| | | 1181 | | |
| | | 1182 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1183 | | private static Vector128<byte> NegateIfNeeded<TNegator>(Vector128<byte> result) |
| | | 1184 | | where TNegator : struct, SpanHelpers.INegator<short> => |
| | 2623 | 1185 | | typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>) ? result : ~result; |
| | | 1186 | | |
| | | 1187 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1188 | | private static Vector256<byte> NegateIfNeeded<TNegator>(Vector256<byte> result) |
| | | 1189 | | where TNegator : struct, SpanHelpers.INegator<short> => |
| | 1680 | 1190 | | typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>) ? result : ~result; |
| | | 1191 | | |
| | | 1192 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1193 | | private static Vector512<byte> NegateIfNeeded<TNegator>(Vector512<byte> result) |
| | | 1194 | | where TNegator : struct, SpanHelpers.INegator<short> => |
| | 7911 | 1195 | | typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>) ? result : ~result; |
| | | 1196 | | |
| | | 1197 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1198 | | private static bool HasMatch<TNegator>(Vector512<byte> left, Vector512<byte> right) |
| | | 1199 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 1200 | | { |
| | 22104 | 1201 | | return (typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>)) |
| | 22104 | 1202 | | ? Vector512.EqualsAny(left, right) : !Vector512.EqualsAll(left, right); |
| | | 1203 | | } |
| | | 1204 | | |
| | | 1205 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1206 | | private static Vector512<byte> GetMatchMask<TNegator>(Vector512<byte> left, Vector512<byte> right) |
| | | 1207 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 1208 | | { |
| | 972 | 1209 | | return (typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>)) |
| | 972 | 1210 | | ? Vector512.Equals(left, right) : ~Vector512.Equals(left, right); |
| | | 1211 | | } |
| | | 1212 | | |
| | | 1213 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1214 | | private static bool HasMatchInRange<TNegator>(Vector512<byte> left, Vector512<byte> right) |
| | | 1215 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 1216 | | { |
| | 4752 | 1217 | | return (typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>)) |
| | 4752 | 1218 | | ? Vector512.LessThanOrEqualAny(left, right) : !Vector512.LessThanOrEqualAll(left, right); |
| | | 1219 | | } |
| | | 1220 | | |
| | | 1221 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1222 | | private static Vector512<byte> GetMatchInRangeMask<TNegator>(Vector512<byte> left, Vector512<byte> right) |
| | | 1223 | | where TNegator : struct, SpanHelpers.INegator<short> |
| | | 1224 | | { |
| | 1246 | 1225 | | return (typeof(TNegator) == typeof(SpanHelpers.DontNegate<short>)) |
| | 1246 | 1226 | | ? Vector512.LessThanOrEqual(left, right) : ~Vector512.LessThanOrEqual(left, right); |
| | | 1227 | | } |
| | | 1228 | | |
| | | 1229 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1230 | | private static int ComputeFirstIndex(ref short searchSpace, ref short current, Vector128<byte> equals) |
| | | 1231 | | { |
| | 0 | 1232 | | uint notEqualsElements = equals.ExtractMostSignificantBits(); |
| | 0 | 1233 | | int index = BitOperations.TrailingZeroCount(notEqualsElements); |
| | 0 | 1234 | | return index + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current) / sizeof(short)); |
| | | 1235 | | } |
| | | 1236 | | |
| | | 1237 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1238 | | [CompExactlyDependsOn(typeof(Avx2))] |
| | | 1239 | | private static int ComputeFirstIndex(ref short searchSpace, ref short current, Vector256<byte> equals) |
| | | 1240 | | { |
| | 0 | 1241 | | uint notEqualsElements = FixUpPackedVector256Result(equals).ExtractMostSignificantBits(); |
| | 0 | 1242 | | int index = BitOperations.TrailingZeroCount(notEqualsElements); |
| | 0 | 1243 | | return index + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current) / sizeof(short)); |
| | | 1244 | | } |
| | | 1245 | | |
| | | 1246 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1247 | | [CompExactlyDependsOn(typeof(Avx512F))] |
| | | 1248 | | private static int ComputeFirstIndex(ref short searchSpace, ref short current, Vector512<byte> equals) |
| | | 1249 | | { |
| | 3095 | 1250 | | ulong notEqualsElements = FixUpPackedVector512Result(equals).ExtractMostSignificantBits(); |
| | 3095 | 1251 | | int index = BitOperations.TrailingZeroCount(notEqualsElements); |
| | 3095 | 1252 | | return index + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current) / sizeof(short)); |
| | | 1253 | | } |
| | | 1254 | | |
| | | 1255 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1256 | | private static int ComputeFirstIndexOverlapped(ref short searchSpace, ref short current0, ref short current1, Ve |
| | | 1257 | | { |
| | 1180 | 1258 | | uint notEqualsElements = equals.ExtractMostSignificantBits(); |
| | 1180 | 1259 | | int offsetInVector = BitOperations.TrailingZeroCount(notEqualsElements); |
| | 1180 | 1260 | | if (offsetInVector >= Vector128<short>.Count) |
| | | 1261 | | { |
| | | 1262 | | // We matched within the second vector |
| | 42 | 1263 | | current0 = ref current1; |
| | 42 | 1264 | | offsetInVector -= Vector128<short>.Count; |
| | | 1265 | | } |
| | 1180 | 1266 | | return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current0) / sizeof(short)); |
| | | 1267 | | } |
| | | 1268 | | |
| | | 1269 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1270 | | [CompExactlyDependsOn(typeof(Avx2))] |
| | | 1271 | | private static int ComputeFirstIndexOverlapped(ref short searchSpace, ref short current0, ref short current1, Ve |
| | | 1272 | | { |
| | 1266 | 1273 | | uint notEqualsElements = FixUpPackedVector256Result(equals).ExtractMostSignificantBits(); |
| | 1266 | 1274 | | int offsetInVector = BitOperations.TrailingZeroCount(notEqualsElements); |
| | 1266 | 1275 | | if (offsetInVector >= Vector256<short>.Count) |
| | | 1276 | | { |
| | | 1277 | | // We matched within the second vector |
| | 57 | 1278 | | current0 = ref current1; |
| | 57 | 1279 | | offsetInVector -= Vector256<short>.Count; |
| | | 1280 | | } |
| | 1266 | 1281 | | return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current0) / sizeof(short)); |
| | | 1282 | | } |
| | | 1283 | | |
| | | 1284 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1285 | | [CompExactlyDependsOn(typeof(Avx512F))] |
| | | 1286 | | private static int ComputeFirstIndexOverlapped(ref short searchSpace, ref short current0, ref short current1, Ve |
| | | 1287 | | { |
| | 1361 | 1288 | | ulong notEqualsElements = FixUpPackedVector512Result(equals).ExtractMostSignificantBits(); |
| | 1361 | 1289 | | int offsetInVector = BitOperations.TrailingZeroCount(notEqualsElements); |
| | 1361 | 1290 | | if (offsetInVector >= Vector512<short>.Count) |
| | | 1291 | | { |
| | | 1292 | | // We matched within the second vector |
| | 90 | 1293 | | current0 = ref current1; |
| | 90 | 1294 | | offsetInVector -= Vector512<short>.Count; |
| | | 1295 | | } |
| | 1361 | 1296 | | return offsetInVector + (int)((nuint)Unsafe.ByteOffset(ref searchSpace, ref current0) / sizeof(short)); |
| | | 1297 | | } |
| | | 1298 | | |
| | | 1299 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1300 | | [CompExactlyDependsOn(typeof(Avx2))] |
| | | 1301 | | internal static Vector256<byte> FixUpPackedVector256Result(Vector256<byte> result) |
| | | 1302 | | { |
| | 5591 | 1303 | | Debug.Assert(Avx2.IsSupported); |
| | | 1304 | | // Avx2.PackUnsignedSaturate(Vector256<short>.One, Vector256.Create<short>(2)) will result in |
| | | 1305 | | // 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 |
| | | 1306 | | // We want to swap the X and Y bits |
| | | 1307 | | // 1, 1, 1, 1, 1, 1, 1, 1, X, X, X, X, X, X, X, X, Y, Y, Y, Y, Y, Y, Y, Y, 2, 2, 2, 2, 2, 2, 2, 2 |
| | 5591 | 1308 | | return Avx2.Permute4x64(result.AsInt64(), 0b_11_01_10_00).AsByte(); |
| | | 1309 | | } |
| | | 1310 | | |
| | | 1311 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 1312 | | [CompExactlyDependsOn(typeof(Avx512F))] |
| | | 1313 | | internal static Vector512<byte> FixUpPackedVector512Result(Vector512<byte> result) |
| | | 1314 | | { |
| | 4456 | 1315 | | Debug.Assert(Avx512F.IsSupported); |
| | | 1316 | | // Avx512BW.PackUnsignedSaturate will interleave the inputs in 8-byte blocks. |
| | | 1317 | | // We want to preserve the order of the two input vectors, so we deinterleave the packed value. |
| | 4456 | 1318 | | return Avx512F.PermuteVar8x64(result.AsInt64(), Vector512.Create(0, 2, 4, 6, 1, 3, 5, 7)).AsByte(); |
| | | 1319 | | } |
| | | 1320 | | |
| | | 1321 | | private interface ITransform |
| | | 1322 | | { |
| | | 1323 | | static abstract short TransformInput(short input); |
| | | 1324 | | static abstract Vector128<byte> TransformInput(Vector128<byte> input); |
| | | 1325 | | static abstract Vector256<byte> TransformInput(Vector256<byte> input); |
| | | 1326 | | static abstract Vector512<byte> TransformInput(Vector512<byte> input); |
| | | 1327 | | } |
| | | 1328 | | |
| | | 1329 | | private readonly struct NopTransform : ITransform |
| | | 1330 | | { |
| | 5052 | 1331 | | public static short TransformInput(short input) => input; |
| | 1439 | 1332 | | public static Vector128<byte> TransformInput(Vector128<byte> input) => input; |
| | 348 | 1333 | | public static Vector256<byte> TransformInput(Vector256<byte> input) => input; |
| | 23394 | 1334 | | public static Vector512<byte> TransformInput(Vector512<byte> input) => input; |
| | | 1335 | | } |
| | | 1336 | | |
| | | 1337 | | private readonly struct Or20Transform : ITransform |
| | | 1338 | | { |
| | 4161 | 1339 | | public static short TransformInput(short input) => (short)(input | 0x20); |
| | 504 | 1340 | | public static Vector128<byte> TransformInput(Vector128<byte> input) => input | Vector128.Create((byte)0x20); |
| | 462 | 1341 | | public static Vector256<byte> TransformInput(Vector256<byte> input) => input | Vector256.Create((byte)0x20); |
| | 2421 | 1342 | | public static Vector512<byte> TransformInput(Vector512<byte> input) => input | Vector512.Create((byte)0x20); |
| | | 1343 | | } |
| | | 1344 | | } |
| | | 1345 | | } |
| | | 1346 | | |