-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial version of {Last}IndexOfAnyExcept #67941
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsThese are functional but not vectorized. At least some of these should be vectorized for at least some data types subsequently, but that's a more intensive change. Once that's in, we can update a few places to use these, e.g. Regex should end up using any of the overloads that are vectorized. Fixes #28795
|
These are functional but not vectorized. At least some of these should be vectorized for at least some data types subsequently, but that's a more intensive change. Once that's in, we can update a few places to use these, e.g. Regex should end up using any of the overloads that are vectorized.
c0ea74e
to
19841f4
Compare
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
Outdated
Show resolved
Hide resolved
/// </returns> | ||
public static int IndexOfAnyExcept<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values) where T : IEquatable<T> | ||
{ | ||
switch (values.Length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EgorBo do we still have limitations around inlining switch
statements or was that one of the things that was minimally fixed up?
return IndexOfAnyExcept(span, values[0], values[1]); | ||
|
||
case 3: | ||
return IndexOfAnyExcept(span, values[0], values[1], values[2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JIT doesn't look to elide the bounds checks here. It does if you use an if (values.Length == 3)
(etc).
It also reduces it down to a single check if you grab values[2], values[1], values[0]
, but that's still 1 more check than using if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JIT doesn't look to elide the bounds checks here
I could have sworn it did, but I just re-checked, and you're right, it doesn't.
I'll address that subsequently, unless Egor gets there first and fixes the JIT here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming in late, but LGTM!
Actually, I take that back. IndexOfAnyExcept(..., <empty>)
should return -1 for an empty input span, 0 for a non-empty input span. For the backward search, it should return Length - 1
for any input span.
* Add initial version of {Last}IndexOfAnyExcept These are functional but not vectorized. At least some of these should be vectorized for at least some data types subsequently, but that's a more intensive change. Once that's in, we can update a few places to use these, e.g. Regex should end up using any of the overloads that are vectorized. * Fix comments
These are functional but not vectorized. At least some of these should be vectorized for at least some data types subsequently, but that's a more intensive change. Once that's in, we can update a few places to use these, e.g. Regex should end up using any of the overloads that are vectorized.
Fixes #28795
#67942 tracks vectorizing these.