-
Notifications
You must be signed in to change notification settings - Fork 1.5k
x64: handle ISA features more completely #11272
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
base: main
Are you sure you want to change the base?
Conversation
As discussed [here], we will soon need the ability to express more complex combinations of CPU features. These are best expressed as boolean terms: e.g., `(32-bit OR 64-bit) AND ...`, `(32-bit OR 64-bit) AND ((AVX512VL AND AVX512F) OR AVX10.1)`. This change modifies the generated code to have a `Inst::is_available` method which contains a Rust-ified version of the instruction's boolean term. To do this, we now pass in a `Features` trait, which the instruction can query to see if its desired feature set is available. [here]: https://bytecodealliance.zulipchat.com/#narrow/channel/217117-cranelift/topic/boolean.20terms.20for.20x64.20features
This change makes us of the assembler's new generated `Inst::is_available` methods to check an instruction's feature set in a more succinct (and likely quicker) way. Unfortunately, this does not allow us to print the missing ISA requirements on failure--something to address later.
This is a mechanical transformation converting all instruction definitions. Now, instructions should have a correct boolean term describe the features required: e.g., `(_64b | compat) & avx`.
"Cannot emit inst '{inst:?}' for target; failed to match ISA requirements: {isa_requirements:?}" | ||
) | ||
if !inst.is_available(&info) { | ||
panic!("Cannot emit inst '{inst:?}' for target; failed to match ISA requirements") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a bit unfortunate at the moment: we've lost the ability to see why this check has failed. I mulled this over for a bit, thinking how we can get this back. One option is to have the assembler just "return the right string" through some other method which we can paste in here. But I'm leaning toward adding an Inst::features() -> Features
, much like we had before, but that would return a boolean term like the one we have available at the meta level. Though this would duplicate the some of Features
, it would return an enum
that is more widely usable than a string while I still have all of this paged in.
Either option, "return a string" or "return a Features
", is really fine at this point and I'm interested in feedback. Also, this seems like something that could get fixed up in a follow-on PR.
I do expect this to fail in Winch: something about how we're using wasmtime/winch/codegen/src/isa/x64/masm.rs Lines 3205 to 3208 in 3c9305c
|
This adds full boolean term support for instructions emitted in the new assembler (terms like
(_64b | compat) & avx2
). Despite doing more checks, this may be quicker too: instead of building up aSmallVec<InstructionSet>
to compare against, this generates Rust code like the following that queries what features are available in the target via theAvailableFeatures
trait:With all of this in place, this PR has a large mechanical translation of all the old, incorrect feature definitions (
_64b | compat | avx2
) into their new, correct definitions ((_64b | compat) & avx2
). I expect this will see a lot more use of this when using more instructions from AVX512, AVX10, APX, etc.