| | | 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 AsciiByteSearchValues<TUniqueLowNibble> : SearchValues<byte> |
| | | 15 | | where TUniqueLowNibble : struct, SearchValues.IRuntimeConst |
| | | 16 | | { |
| | | 17 | | private IndexOfAnyAsciiSearcher.AsciiState _state; |
| | | 18 | | |
| | | 19 | | public AsciiByteSearchValues(ReadOnlySpan<byte> values) |
| | | 20 | | { |
| | | 21 | | // Despite the name being Ascii, this type may be used with non-ASCII values on ARM or WASM. |
| | | 22 | | // See comments in IndexOfAnyAsciiSearcher.CanUseUniqueLowNibbleSearch. |
| | 0 | 23 | | Debug.Assert(Ascii.IsValid(values) || (TUniqueLowNibble.Value && (AdvSimd.IsSupported || PackedSimd.IsSuppor |
| | | 24 | | |
| | 0 | 25 | | if (TUniqueLowNibble.Value) |
| | | 26 | | { |
| | 0 | 27 | | IndexOfAnyAsciiSearcher.ComputeUniqueLowNibbleState(values, out _state); |
| | | 28 | | } |
| | | 29 | | else |
| | | 30 | | { |
| | 0 | 31 | | IndexOfAnyAsciiSearcher.ComputeAsciiState(values, out _state); |
| | | 32 | | } |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | internal override byte[] GetValues() => |
| | 0 | 36 | | _state.Lookup.GetByteValues(); |
| | | 37 | | |
| | | 38 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 39 | | internal override bool ContainsCore(byte value) => |
| | 0 | 40 | | _state.Lookup.Contains(value); |
| | | 41 | | |
| | | 42 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 43 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 44 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 45 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 46 | | internal override int IndexOfAny(ReadOnlySpan<byte> span) => |
| | 0 | 47 | | IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TUniqueLowNibble>( |
| | 0 | 48 | | ref MemoryMarshal.GetReference(span), span.Length, ref _state); |
| | | 49 | | |
| | | 50 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 51 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 52 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 53 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 54 | | internal override int IndexOfAnyExcept(ReadOnlySpan<byte> span) => |
| | 0 | 55 | | IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TUniqueLowNibble>( |
| | 0 | 56 | | ref MemoryMarshal.GetReference(span), span.Length, ref _state); |
| | | 57 | | |
| | | 58 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 59 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 60 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 61 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 62 | | internal override int LastIndexOfAny(ReadOnlySpan<byte> span) => |
| | 0 | 63 | | IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TUniqueLowNibble>( |
| | 0 | 64 | | ref MemoryMarshal.GetReference(span), span.Length, ref _state); |
| | | 65 | | |
| | | 66 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 67 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 68 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 69 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 70 | | internal override int LastIndexOfAnyExcept(ReadOnlySpan<byte> span) => |
| | 0 | 71 | | IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TUniqueLowNibble>( |
| | 0 | 72 | | ref MemoryMarshal.GetReference(span), span.Length, ref _state); |
| | | 73 | | |
| | | 74 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 75 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 76 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 77 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 78 | | internal override bool ContainsAny(ReadOnlySpan<byte> span) => |
| | 0 | 79 | | IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TUniqueLowNibble>( |
| | 0 | 80 | | ref MemoryMarshal.GetReference(span), span.Length, ref _state); |
| | | 81 | | |
| | | 82 | | [CompExactlyDependsOn(typeof(Ssse3))] |
| | | 83 | | [CompExactlyDependsOn(typeof(AdvSimd))] |
| | | 84 | | [CompExactlyDependsOn(typeof(PackedSimd))] |
| | | 85 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 86 | | internal override bool ContainsAnyExcept(ReadOnlySpan<byte> span) => |
| | 0 | 87 | | IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TUniqueLowNibble>( |
| | 0 | 88 | | ref MemoryMarshal.GetReference(span), span.Length, ref _state); |
| | | 89 | | } |
| | | 90 | | } |
| | | 91 | | |