forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a SearchValues implementation for values with unique low nibbles (d…
…otnet#106900) * Add SearchValues implementation for values with unique low nibbles * More generics * Tweak comment * Remove extra empty line * Update comment
- Loading branch information
1 parent
4924fc2
commit 057be76
Showing
9 changed files
with
310 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 26 additions & 10 deletions
36
src/libraries/System.Private.CoreLib/src/System/SearchValues/AsciiCharSearchValues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,91 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Intrinsics.Arm; | ||
using System.Runtime.Intrinsics.Wasm; | ||
using System.Runtime.Intrinsics.X86; | ||
using System.Text; | ||
|
||
namespace System.Buffers | ||
{ | ||
internal sealed class AsciiCharSearchValues<TOptimizations> : SearchValues<char> | ||
internal sealed class AsciiCharSearchValues<TOptimizations, TUniqueLowNibble> : SearchValues<char> | ||
where TOptimizations : struct, IndexOfAnyAsciiSearcher.IOptimizations | ||
where TUniqueLowNibble : struct, SearchValues.IRuntimeConst | ||
{ | ||
private IndexOfAnyAsciiSearcher.AsciiState _state; | ||
|
||
public AsciiCharSearchValues(ReadOnlySpan<char> values) => | ||
IndexOfAnyAsciiSearcher.ComputeAsciiState(values, out _state); | ||
public AsciiCharSearchValues(ReadOnlySpan<char> values) | ||
{ | ||
// Despite the name being Ascii, this type may be used with non-ASCII values on ARM. | ||
// See IndexOfAnyAsciiSearcher.CanUseUniqueLowNibbleSearch. | ||
Debug.Assert(Ascii.IsValid(values) || (AdvSimd.IsSupported && TUniqueLowNibble.Value)); | ||
|
||
if (TUniqueLowNibble.Value) | ||
{ | ||
IndexOfAnyAsciiSearcher.ComputeUniqueLowNibbleState(values, out _state); | ||
} | ||
else | ||
{ | ||
IndexOfAnyAsciiSearcher.ComputeAsciiState(values, out _state); | ||
} | ||
} | ||
|
||
internal override char[] GetValues() => | ||
_state.Lookup.GetCharValues(); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override bool ContainsCore(char value) => | ||
_state.Lookup.Contains128(value); | ||
_state.Lookup.Contains256(value); | ||
|
||
[CompExactlyDependsOn(typeof(Ssse3))] | ||
[CompExactlyDependsOn(typeof(AdvSimd))] | ||
[CompExactlyDependsOn(typeof(PackedSimd))] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int IndexOfAny(ReadOnlySpan<char> span) => | ||
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>( | ||
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUniqueLowNibble>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); | ||
|
||
[CompExactlyDependsOn(typeof(Ssse3))] | ||
[CompExactlyDependsOn(typeof(AdvSimd))] | ||
[CompExactlyDependsOn(typeof(PackedSimd))] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) => | ||
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>( | ||
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUniqueLowNibble>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); | ||
|
||
[CompExactlyDependsOn(typeof(Ssse3))] | ||
[CompExactlyDependsOn(typeof(AdvSimd))] | ||
[CompExactlyDependsOn(typeof(PackedSimd))] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int LastIndexOfAny(ReadOnlySpan<char> span) => | ||
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>( | ||
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUniqueLowNibble>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); | ||
|
||
[CompExactlyDependsOn(typeof(Ssse3))] | ||
[CompExactlyDependsOn(typeof(AdvSimd))] | ||
[CompExactlyDependsOn(typeof(PackedSimd))] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) => | ||
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>( | ||
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUniqueLowNibble>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); | ||
|
||
[CompExactlyDependsOn(typeof(Ssse3))] | ||
[CompExactlyDependsOn(typeof(AdvSimd))] | ||
[CompExactlyDependsOn(typeof(PackedSimd))] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override bool ContainsAny(ReadOnlySpan<char> span) => | ||
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>( | ||
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUniqueLowNibble>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); | ||
|
||
[CompExactlyDependsOn(typeof(Ssse3))] | ||
[CompExactlyDependsOn(typeof(AdvSimd))] | ||
[CompExactlyDependsOn(typeof(PackedSimd))] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override bool ContainsAnyExcept(ReadOnlySpan<char> span) => | ||
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>( | ||
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUniqueLowNibble>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.