Skip to content

Investigate optimizations for vectorized Span<byte> {Last}IndexOf{Any} APIs #24443

@ahsonkhan

Description

@ahsonkhan

From dotnet/corefx#25848 (comment)

Consider avoiding the memory alignment checks and only loop byte at a time until we get Vector.Count aligned.

The APIs to consider optimizing (for typeof(T) == byte):

public static int IndexOf<T>(this Span<T> span, T value) where T : IEquatable<T> { throw null; }
public static int IndexOf<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }

public static int IndexOfAny(this Span<byte> span, byte value0, byte value1) { throw null; }
public static int IndexOfAny(this Span<byte> span, byte value0, byte value1, byte value2) { throw null; }
public static int IndexOfAny(this Span<byte> span, ReadOnlySpan<byte> values) { throw null; }

public static int LastIndexOf<T>(this Span<T> span, T value) where T : IEquatable<T> { throw null; }
public static int LastIndexOf<T>(this Span<T> span, ReadOnlySpan<T> value) where T : IEquatable<T> { throw null; }

public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1) where T : IEquatable<T> { throw null; }
public static int LastIndexOfAny<T>(this Span<T> span, T value0, T value1, T value2) where T : IEquatable<T> { throw null; }
public static int LastIndexOfAny<T>(this Span<T> span, ReadOnlySpan<T> values) where T : IEquatable<T> { throw null; }
  • the equivalent ReadOnlySpan extension methods

See current implementation here:
https://github.com/dotnet/corefx/blob/c20881a8ea94a40e1f1f98f79ffdef9f6fc87c44/src/System.Memory/src/System/SpanHelpers.byte.cs#L91

cc @KrzysztofCwalina, @GrabYourPitchforks, @benaadams

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions