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

Add support for --instruction-set:native #87865

Merged
merged 17 commits into from
Jul 20, 2023

Conversation

MichalStrehovsky
Copy link
Member

This allows compiling for the ISA extensions that the currently running CPU supports.

This should work for both crossgen2 and ILC.

  • Moved instruction set detection code to minipal
  • Included the minipal code from the runtime and jitinterface.dll
  • Rewrote a bit of assembly with VC++ intrinsics

I didn't test anything but x64 Windows but since this will involve a ton of annoying manual testing, sending for review now.

Fixes #73246.

Cc @dotnet/ilc-contrib

This allows compiling for the ISA extensions that the currently running CPU supports.

Fixes dotnet#73246.
@ghost
Copy link

ghost commented Jun 21, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

This allows compiling for the ISA extensions that the currently running CPU supports.

This should work for both crossgen2 and ILC.

  • Moved instruction set detection code to minipal
  • Included the minipal code from the runtime and jitinterface.dll
  • Rewrote a bit of assembly with VC++ intrinsics

I didn't test anything but x64 Windows but since this will involve a ton of annoying manual testing, sending for review now.

Fixes #73246.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

}
HardwareIntrinsicHelpers.AddRuntimeRequiredIsaFlagsToBuilder(instructionSetSupportBuilder, cpuFeatures);
}
else if (instructionSet != null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open issue: should we allow computing optimistic instruction set or skip that when native was specified.

(Or should we actually skip the optimistic one if any instruction-set is specified?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it configurable? For example, we can introduce optimistic instruction set that would enable the optimistic checks; or we can introduce ? qualifier for instruction sets (in addition to the existing + and '-` qualifiers) that would enable optimistic checks for given instruction set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good plan.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean that you'd have to specify eg. native,foo?,bar?,baz? (with foo etc. being all opportunistic instruction sets you want guarded paths to be generated for) to get the resulting binary to use all the instruction sets available on the current machine, and guarded paths for all the other ones? I wonder if it would make sense to have a simplified way to express:

"Compile for native, but also add guarded paths for all existing other ISAs supported by the runtime".

Basically as a way to avoid having to manually look all of them up and add them with ? as a suffix for each after native. Just to get the idea across, something like native,all?. Or is something like this already possible in some other way?

Copy link
Contributor

@teo-tsirpanis teo-tsirpanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments on cpufeatures.c.

src/native/minipal/cpufeatures.c Show resolved Hide resolved
src/native/minipal/cpufeatures.c Show resolved Hide resolved
src/native/minipal/cpufeatures.c Show resolved Hide resolved
@jkotas
Copy link
Member

jkotas commented Jun 21, 2023

It would be nice to switch src/coreclr/vm+pal implementation of the detection over to the minipal one as well. It should be straightforward (delete what is there and switch to the minipal instead) and it would give us more confidence that the minipal implementation is right.

@MichalStrehovsky
Copy link
Member Author

It would be nice to switch src/coreclr/vm+pal implementation of the detection over to the minipal one as well.

Called out as stretch goal in #73246 (comment). Not looking for stretch goals right now. We can leave the issue open.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@MichalStrehovsky
Copy link
Member Author

@dotnet/ilc-contrib this is ready for review now

@jkotas
Copy link
Member

jkotas commented Jul 17, 2023

I didn't test anything but x64 Windows but since this will involve a ton of annoying manual testing,

Have you done some of this annoying manual testing?

LGTM modulo comments.

@MichalStrehovsky
Copy link
Member Author

Have you done some of this annoying manual testing?

I'll do this once this is ready to merge - I don't want to do that more than once. I wish I could test this in the CI but all of our ARM64 builds (where this is interesting) are crossbuilds.

I'm still considering making a managed test (that runs on top of CoreCLR) that would p/invoke into jitinterface.dll that we'd package with the test and compare returned flags with what we detect in C#. But not sure if it's worth the hassle.

@MichalStrehovsky
Copy link
Member Author

Have you done some of this annoying manual testing?

It appears to be working to the extent I could test. I suggest we get this in and more people can give it a try. I don't have e.g. ARM64 mac so it's really not possible for me to test this to the extent that would be necessary.

@jkotas
Copy link
Member

jkotas commented Jul 20, 2023

I'm still considering making a managed test (that runs on top of CoreCLR) that would p/invoke into jitinterface.dll that we'd package with the test and compare returned flags with what we detect in C#. But not sure if it's worth the hassle.

I think we would get most of the regression protection by sharing the code with CoreCLR. (It can be done as follow up.)

It appears to be working to the extent I could test. I suggest we get this in and more people can give it a try. I

Sounds good.

@MichalStrehovsky
Copy link
Member Author

Mono interp failure is known according to build analysis and this PR doesn't affect Mono legs. Merging for a follow up.

@MichalStrehovsky MichalStrehovsky merged commit 342bcdb into dotnet:main Jul 20, 2023
174 of 177 checks passed
@MichalStrehovsky MichalStrehovsky deleted the nativeinstructionset branch July 20, 2023 08:15
jkotas added a commit to jkotas/runtime that referenced this pull request Jul 22, 2023
jkotas added a commit that referenced this pull request Jul 23, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"native" instruction set alias for AOT compilers
4 participants