Closed a74nh closed 4 months ago
Having said that, it now occurs to me that for AddAcross you could do:
a = Sve.AddAcross(Sve.ConditionalSelect(mask, a, zero));
But that doesn't work for all Across methods. For example, MinAcross()
.
@kunalspathak @tannergooding - this came up as part of implementing https://github.com/dotnet/runtime/pull/101674
We discussed it in https://github.com/dotnet/runtime/pull/101674#discussion_r1583392032
Cases like MinAcross
could be handled by doing Sve.MinAcross(Sve.ConditionalSelect(mask, a, Vector.Create(max))
(where max
for float is +Infinity
). That being said, predication of "across" APIs is in general a more complex case and so may be one of the scenarios that warrants having an overload that explicitly takes the mask.
We simply want to prefer ConditionSelect
in the cases where pattern matching and the pattern a user would need to write is "obvious" as it saves us from needing to expose thousands of additional API overloads. It also has the added benefit that it matches the patterns users already have to write for ISAs without built-in masking support, such as AdvSimd
(NEON), and so allows existing code to be shared across these ISAs and to implicitly light up, making the entire ecosystem trivially better.
I think in these cases extra API methods would make sense.
This probably needs splitting into two issues then:
*Across(ConditionalSelect)
style, something in lowering to detect and optimise.Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in area-owners.md if you want to be subscribed.
Opened:
Closing this issue in favour of those
ConditionalSelect is used to mask an API, for example:
Is equivalent to:
This does not work when using the across methods.
Is saying to add together all the elements in
a
and place in field 0, zeroing all other elements. Then usemask
to select which elements to pick from the result. That is valid C#, but is a weird thing to do.the more likely use case is to take all the elements in
a
that are marked as active inmask
and add them together, putting them in field 0, zeroing all other elements. There is no obvious way to do this?