-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Consider refactoring the System.Runtime.Intrinsics #47837
Comments
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. |
CC. @jkotas, @echesakovMSFT |
Tagging subscribers to this area: @tannergooding Issue DetailsCurrently
When you are talking about pure IL size, this is a win as all "unsupported" intrinsics can have their method bodies shared. A local experiment shows we can reduce the size of the x64 System.Private.Corelib.dll by [DoesNotReturn]
internal static void ThrowPlatformNotSupportedException()
{
throw new PlatformNotSupportedException();
}
[DoesNotReturn]
internal static T ThrowPlatformNotSupportedException<T>()
{
throw new PlatformNotSupportedException();
} The downside to this approach is that the calls are no longer recursive and so the existing logic in the JIT to support invoking these via reflection will be broken. An indirect benefit of doing this is that dev's could actually see hwintrinsic codegen in the altjit which may assist with situations where ARM64 hardware is not readily available: #41518
|
I think a better way to get even better size reduction would be to stop AOTing methods that always throw for R2R. Throwing exceptions is rare and slow, so it is ok to fallback to JIT for these cases.
I see this as a hack to get equivalent of inlined IL. I do not think we should be growing it beyond that. Ideally, I would love to see this replaced by build-time step.
Isn't the actual problem with altjit that arm intrinsics are not marked as intrinsics in x64 corelib? Can the altjit problem be fixed by assuming that anything is intrinsic when the JIT is running in the altjit mode? The intrinsic attribute is a throughput optimization to avoid looking up and matching the method names for every method. It should be ok to not have this optimization in altjit mode. |
That's fair and also reasonable. I had just noticed the size difference when doing other investigations so wanted to raise its visibility.
If we don't go this route, it might still be worth seeing if the JIT can detect these methods as "supported intrinsics" in a cheapish way. We are currently taking up 6 bytes of IL per recursive hwintrinsic. We currently look to see if the method calls itself to detect this and then just force expand in this scenario. If we could instead detect, for example, that we are in a method marked intrinsic that is just "newobj; throw", we might be able to expand anyways; but I'm not sure how expensive that would be.
Right, we only check for the type level attribute in the "supported" namespace for the VM layer; so the JIT never sees the methods as intrinsic otherwise. |
Going to close this given the above conversation. |
Currently
System.Runtime.Intrinsics
types have two implementations:Isa.cs
which is recursiveIsa.PlatformNotSupported.cs
which is justthrow new PlatformNotSupportedException()
When you are talking about pure IL size, this is a win as all "unsupported" intrinsics can have their method bodies shared.
However, in practice (I believe due to our usage of crossgen) we actually end up increasing the size of the assembly (If this is due to crossgen, then the "unsupported" methods are each
28
bytes in size to contain the logic for throwing an exception; compared to only7
bytes for a non-expanded recursive call).A local experiment shows we can reduce the size of the x64 System.Private.Corelib.dll by
98kb
(from8990kb
to8892kb
) by refactoring all of the methods to no longer be recursive and instead to call into a shared throw helper:The downside to this approach is that the calls are no longer recursive and so the existing logic in the JIT to support invoking these via reflection will be broken.
However, we do support changing the IL for method bodies in the VM and do such with
System.Runtime.CompilerServices.Unsafe
and a few others, so we could theoretically do the same with the HWIntrinsics and given that this is only required during recursive calls we might even be able to make it "pay for play"An indirect benefit of doing this is that dev's could actually see hwintrinsic codegen in the altjit which may assist with situations where ARM64 hardware is not readily available: #41518
The text was updated successfully, but these errors were encountered: