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

[Mono] Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.Vector{64, 128} on Arm64 #64072

Closed
55 tasks done
Tracked by #43051
fanyang-mono opened this issue Jan 20, 2022 · 8 comments
Assignees
Labels
area-Codegen-meta-mono runtime-mono specific to the Mono runtime
Milestone

Comments

@fanyang-mono
Copy link
Member

fanyang-mono commented Jan 20, 2022

System.Runtime.Intrinsics.Vector{64, 128} and System.Numerics.Vector:

System.Runtime.Intrinsics.Vector{64, 128}<T> and System.Numerics.Vector<T>:

@fanyang-mono fanyang-mono added the runtime-mono specific to the Mono runtime label Jan 20, 2022
@fanyang-mono fanyang-mono added this to the 7.0.0 milestone Jan 20, 2022
@fanyang-mono fanyang-mono self-assigned this Jan 20, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 20, 2022
@SamMonoRT SamMonoRT added area-Codegen-JIT-mono and removed untriaged New issue has not been triaged by the area owner labels Jan 20, 2022
@fanyang-mono
Copy link
Member Author

fanyang-mono commented Jan 20, 2022

Motivation of this work:

There is a recent change to System.Numerics.Vector in the library code, which, as a result, caused regressions in Mono runtime (#53450). The regression could be observed via TechEmpower benchmark
Screen Shot 2022-01-20 at 4 29 57 PM
and a few microbenchmarks, for example System.Tests.Perf_String.IndexOfAny
Screen Shot 2022-01-20 at 5 20 21 PM

When comparing the generated code for the above microbenchmark test, I noticed the big generated code change for System.Numerics.Vector:Equals. Before the change, the IL for it was very small and simple. Mono was able to replace the deferred function System.Numerics.Vector<T>:Equals with an instrinsic. After the change, the IL for this same method became much longer with a few more calls to various complex methods, which ended up becoming way longer assembly code. Here are the codegen logs of a simplified app running with Mono runtime before and after this change

The affected Mono flavors: JIT and AOT
The affected platforms: amd64 and arm64

The solution to this regression is to intrinsify the methods of System.Numerics.Vector.

@fanyang-mono
Copy link
Member Author

Implementation wise, look at SN_Equals case for System.Numerics.Vector<T> for inspiration.

@tannergooding
Copy link
Member

This should likely also extend to the APIs of the same names on Vector64, Vector128, and Vector256 (in the System.Runtime.Intrinsics namespace). It "should" hopefully be easy to add the support for both simultaneously.

@fanyang-mono
Copy link
Member Author

This should likely also extend to the APIs of the same names on Vector64, Vector128, and Vector256 (in the System.Runtime.Intrinsics namespace). It "should" hopefully be easy to add the support for both simultaneously.

That work has been tracked here #42350. Most of the intrinsics for Vector64, Vector128 have been implemented in .NET6. The ones for Vector256 will be implemented in .NET7.

@tannergooding
Copy link
Member

@fanyang-mono, these are new APIs introduced in .NET 7, so they wouldn't be covered by #42350

@fanyang-mono fanyang-mono changed the title Intrinsify methods of System.Numerics.Vector Intrinsify new API of System.Numerics.Vector, System.Runtime.Intrinsics.{64, 128,256} Jan 24, 2022
@fanyang-mono fanyang-mono changed the title Intrinsify new API of System.Numerics.Vector, System.Runtime.Intrinsics.{64, 128,256} Intrinsify new API of System.Numerics.Vector and System.Runtime.Intrinsics.{64, 128,256} Jan 24, 2022
@fanyang-mono fanyang-mono changed the title Intrinsify new API of System.Numerics.Vector and System.Runtime.Intrinsics.{64, 128,256} Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.{64, 128,256} Jan 24, 2022
@fanyang-mono
Copy link
Member Author

@fanyang-mono, these are new APIs introduced in .NET 7, so they wouldn't be covered by #42350

Good point. I've updated the description.

@fanyang-mono fanyang-mono changed the title Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.{64, 128,256} Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.{64, 128} on Arm64 Mar 9, 2022
@fanyang-mono fanyang-mono changed the title Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.{64, 128} on Arm64 [Mono] Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.{64, 128} on Arm64 Mar 9, 2022
akoeplinger pushed a commit that referenced this issue Mar 10, 2022
This PR contributes to  #64072

Added intrinsics for following operators
- Operator *
- Operator /
- Operator |
- Operator &
- Operator ^
- Unary operator -
- Unary operator ~

Co-authored-by: Fan Yang <[email protected]>
@fanyang-mono
Copy link
Member Author

I am closing this issue, as all the work planed for this issue has been finished.

@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2022
@fanyang-mono fanyang-mono changed the title [Mono] Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.{64, 128} on Arm64 [Mono] Intrinsify API's of System.Numerics.Vector and new API's of System.Runtime.Intrinsics.Vector{64, 128} on Arm64 Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-meta-mono runtime-mono specific to the Mono runtime
Projects
None yet
Development

No branches or pull requests

5 participants