Skip to content
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

Merged
merged 2 commits into from
Apr 19, 2022

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Apr 13, 2022

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.

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

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.

@ghost ghost assigned stephentoub Apr 13, 2022
@ghost
Copy link

ghost commented Apr 13, 2022

Tagging subscribers to this area: @dotnet/area-system-memory
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: stephentoub
Assignees: -
Labels:

area-System.Memory

Milestone: 7.0.0

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.
/// </returns>
public static int IndexOfAnyExcept<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> values) where T : IEquatable<T>
{
switch (values.Length)
Copy link
Member

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]);
Copy link
Member

@tannergooding tannergooding Apr 19, 2022

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

Copy link
Member Author

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 :)

@stephentoub stephentoub merged commit e62a1fe into dotnet:main Apr 19, 2022
@stephentoub stephentoub deleted the indexofanyexcept branch April 19, 2022 21:11
Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a 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.

directhex pushed a commit to directhex/runtime that referenced this pull request Apr 21, 2022
* 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
@ghost ghost locked as resolved and limited conversation to collaborators May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add API IndexNotOf
4 participants