-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposa]: Provide vector functions covering common "mask" checks #98055
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics Issue DetailsSummaryWhen working with vectors, it is frequent that you will do some sequence of operations and ultimately do a comparison which produces a However, getting this bit mask is not efficient on all platforms ( API Proposalnamespace System.Numerics
{
public partial class Vector
{
public static bool AnyMatches<T>(Vector<T> value);
public static int GetMatchCount<T>(Vector<T> value);
public static int IndexOfFirstMatch<T>(Vector<T> value);
public static int IndexOfLastMatch<T>(Vector<T> value);
}
}
namespace System.Runtime.Intrinsics
{
public partial class Vector64
{
public static bool AnyMatches<T>(Vector64<T> value);
public static int GetMatchCount<T>(Vector64<T> value);
public static int IndexOfFirstMatch<T>(Vector64<T> value);
public static int IndexOfLastMatch<T>(Vector64<T> value);
}
public partial class Vector128
{
public static bool AnyMatches<T>(Vector128<T> value);
public static int GetMatchCount<T>(Vector128<T> value);
public static int IndexOfFirstMatch<T>(Vector128<T> value);
public static int IndexOfLastMatch<T>(Vector128<T> value);
}
public partial class Vector256
{
public static bool AnyMatches<T>(Vector256<T> value);
public static int GetMatchCount<T>(Vector256<T> value);
public static int IndexOfFirstMatch<T>(Vector256<T> value);
public static int IndexOfLastMatch<T>(Vector256<T> value);
}
public partial class Vector512
{
public static bool AnyMatches<T>(Vector512<T> value);
public static int GetMatchCount<T>(Vector512<T> value);
public static int IndexOfFirstMatch<T>(Vector512<T> value);
public static int IndexOfLastMatch<T>(Vector512<T> value);
}
}
|
namespace System.Numerics
{
public partial class Vector
{
public static bool Any<T>(Vector<T> vector, T value);
public static bool AnyWhereAllBitsSet<T>(Vector<T> vector);
public static int Count<T>(Vector<T> vector, T value);
public static int CountWhereAllBitsSet<T>(Vector<T> vector);
public static int IndexOf<T>(Vector<T> vector, T value);
public static int IndexOfWhereAllBitsSet<T>(Vector<T> vector);
public static int LastIndexOf<T>(Vector<T> vector, T value);
public static int LastIndexOfWhereAllBitsSet<T>(Vector<T> vector);
}
}
namespace System.Runtime.Intrinsics
{
public partial class Vector64
{
// ditto.
}
public partial class Vector128
{
// ditto.
}
public partial class Vector256
{
// ditto.
}
public partial class Vector512
{
// ditto.
}
} |
* Add AnyMatches() to iSimdVector interface * Switch to iSimdVector and Align WidenAsciiToUtf16. * Fixing perf * Addressing Review Comments. * Mirroring API change : #98055 (comment)
* Add AnyMatches() to iSimdVector interface * Switch to iSimdVector and Align WidenAsciiToUtf16. * Fixing perf * Addressing Review Comments. * Mirroring API change : dotnet#98055 (comment)
* Add AnyMatches() to iSimdVector interface * Switch to iSimdVector and Align WidenAsciiToUtf16. * Fixing perf * Addressing Review Comments. * Mirroring API change : dotnet#98055 (comment)
Summary
When working with vectors, it is frequent that you will do some sequence of operations and ultimately do a comparison which produces a
mask
. For the fixed-width vectors, you can then usevar mask = vector.ExtractMostSignificantBits()
to get a scalar bitmask that allows you to do many common operations such as determining if any matches existed (mask != 0
), getting the total number of matches (BitOperations.PopCount(mask)
), or getting the index of the first/last match (BitOperations.LeadingZeroCount(mask)
orBitOperations.TrailingZeroCount(mask)
).However, getting this bit mask is not efficient on all platforms (
Arm64
doesn't have an instruction similar topmovmskb
)_ nor can it be used with variable width vector types (Vector<T>
, which will impactSVE
on Arm64). As such, it is proposed that we expose some helpers for these "core" operations that abstract the logic, thus allowing more efficient handling in those scenarios.API Proposal
The text was updated successfully, but these errors were encountered: