| | | 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.Runtime.CompilerServices; |
| | | 6 | | using System.Runtime.InteropServices; |
| | | 7 | | using System.Runtime.Intrinsics.Arm; |
| | | 8 | | using System.Runtime.Intrinsics.Wasm; |
| | | 9 | | using System.Runtime.Intrinsics.X86; |
| | | 10 | | using System.Text; |
| | | 11 | | |
| | | 12 | | namespace System.Buffers |
| | | 13 | | { |
| | | 14 | | internal sealed class AsciiCharSearchValues<TOptimizations, TUniqueLowNibble> : SearchValues<char> |
| | | 15 | | where TOptimizations : struct, IndexOfAnyAsciiSearcher.IOptimizations |
| | | 16 | | where TUniqueLowNibble : struct, SearchValues.IRuntimeConst |
| | | 17 | | { |
| | | 18 | | private IndexOfAnyAsciiSearcher.AsciiState _state; |
| | | 19 | | |
| | | 20 | | public AsciiCharSearchValues(ReadOnlySpan<char> values) |
| | | 21 | | { |
| | | 22 | | // Despite the name being Ascii, this type may be used with non-ASCII values on ARM or WASM. |
| | | 23 | | // See comments in IndexOfAnyAsciiSearcher.CanUseUniqueLowNibbleSearch. |
| | 705 | 24 | | Debug.Assert(Ascii.IsValid(values) || (TUniqueLowNibble.Value && (AdvSimd.IsSupported || PackedSimd.IsSuppor |
| | 705 | 25 | | Debug.Assert(!values.ContainsAnyInRange((char)byte.MaxValue, char.MaxValue)); |
| | | 26 | | |
| | 705 | 27 | | if (TUniqueLowNibble.Value) |
| | | 28 | | { |
| | 43 | 29 | | IndexOfAnyAsciiSearcher.ComputeUniqueLowNibbleState(values, out _state); |
| | | 30 | | } |
| | | 31 | | else |
| | | 32 | | { |
| | 662 | 33 | | IndexOfAnyAsciiSearcher.ComputeAsciiState(values, out _state); |
| | | 34 | | } |
| | 662 | 35 | | } |
| | | 36 | | |
| | | 37 | | internal override char[] GetValues() => |
| | 0 | 38 | | _state.Lookup.GetCharValues(); |
| | | 39 | | |
| | | 40 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 41 | | internal override bool ContainsCore(char value) => |
| | 226010 | 42 | | _state.Lookup.Contains256(value); |
| | | 43 | | |
| | | 44 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 45 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 46 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 47 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 48 | | internal override int IndexOfAny(ReadOnlySpan<char> span) => |
| | 2451 | 49 | | IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUniqueLowNibble>( |
| | 2451 | 50 | | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); |
| | | 51 | | |
| | | 52 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 53 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 54 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 55 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 56 | | internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) => |
| | 2112 | 57 | | IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUniqueLowNibble>( |
| | 2112 | 58 | | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); |
| | | 59 | | |
| | | 60 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 61 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 62 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 63 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 64 | | internal override int LastIndexOfAny(ReadOnlySpan<char> span) => |
| | 1408 | 65 | | IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUniqueLowNibble> |
| | 1408 | 66 | | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); |
| | | 67 | | |
| | | 68 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 69 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 70 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 71 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 72 | | internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) => |
| | 1408 | 73 | | IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUniqueLowNibble>( |
| | 1408 | 74 | | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); |
| | | 75 | | |
| | | 76 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 77 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 78 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 79 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 80 | | internal override bool ContainsAny(ReadOnlySpan<char> span) => |
| | 704 | 81 | | IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUniqueLowNibble>( |
| | 704 | 82 | | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); |
| | | 83 | | |
| | | 84 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 85 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 86 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 87 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 88 | | internal override bool ContainsAnyExcept(ReadOnlySpan<char> span) => |
| | 704 | 89 | | IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUniqueLowNibble>( |
| | 704 | 90 | | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); |
| | | 91 | | } |
| | | 92 | | } |
| | | 93 | | |