jlb6740 requested abrown for a review on PR #10754.
jlb6740 requested wasmtime-compiler-reviewers for a review on PR #10754.
jlb6740 opened PR #10754 from jlb6740:add-initial-vex-encoding to bytecodealliance:main:
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
jlb6740 commented on PR #10754:
The review for this patch started here https://github.com/bytecodealliance/wasmtime/pull/10695. This attempts to add support for vex encoding and in the process adds the lowering of couple of initial vex instructions vaddpd and vaddps.
@rahulchaphalkar
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
abrown created PR review comment:
I'm still not convinced we need these yet. Maybe we should wait to add YMM and ZMM when we actually need those instructions.
abrown created PR review comment:
For printing
VexPPandVexMMMMM, if we print using.instead of_then we can match the manual a bit more closely. E.g.,VEX.128.0F.WIG 58 /r.
abrown created PR review comment:
Nit: move the
xmm_*locations together?rm8 | rm16 | rm32 | rm64 | m8 | m16 | m32 | m64 | xmm_m32 | xmm_m64 | xmm_m128
abrown created PR review comment:
If this is for VEX encoding maybe it should go with the VEX-related code. Plus, don't we need to check the actual values in each group?
abrown submitted PR review:
There's some smaller review comments mixed but I wanted to highlight the
VexInstructionencoding as the only major thing left to resolve; otherwise this looks good to me. I left some comments here about that encoding part but we can talk offline in more detail.
abrown created PR review comment:
Let's not make this public if we don't have to.
abrown created PR review comment:
abrown created PR review comment:
We should not create default registers.
abrown created PR review comment:
You can use the following to manually format the instruction definition on a single line.
#[rustfmt::skip] // Keeps instructions on a single line. pub fn list() -> Vec<Inst> {
abrown created PR review comment:
Let's not make these public if we don't have to.
abrown created PR review comment:
Might as well inline
generate_vexhere since there are no other uses.
abrown created PR review comment:
This still seems unaddressed from the previous PR: let's look for a way to avoid creating defaults that we later overwrite (or forget to overwrite!).
abrown created PR review comment:
But let's just keep these in
add.rsfor now; if we want to reorganize every instruction into separate files later, we can as a separate refactor.
abrown created PR review comment:
abrown created PR review comment:
The manual says
00000is reserved for them-mmmmfield and would result in a#UD. Maybe we should removeNonesince we can't use it (?).
abrown created PR review comment:
I don't think this (or
reg) is quite right: we won't always have a memory operand here. It would seem we need to do the REX flags encoding, extract theR,X, andBfields, and pass those around here.There are instructions like the following that we won't be able to handle with this approach:
VMOVHLPS xmm1, xmm2, xmm3VBLENDVPS xmm1, xmm2, xmm3/m128, xmm4If we alter the
VexInstructionthing to just emit the VEX _prefixes_, not the whole instruction, then I think things will work better here (no more default instructions) and will be more flexible for the future. Plus, we can reuse all of the suffix stuff that should be the same (seeencode_rex_suffixes).
abrown created PR review comment:
abrown created PR review comment:
The only possibilities for the
ppfield are:None,66,F3, andF2. We can pare this down and rename itPporPrefix?
abrown created PR review comment:
Let's set up a
matchstatement over the operands like the one that exists for REX. This code only handles one specific pattern,[xmm1, xmm2, xmm_m128], but there are others. We can leave a_ => unimplemented!()so it is clear that we just haven't worked on the other patterns yet.
abrown created PR review comment:
In fact, do we even use this?
abrown submitted PR review.
abrown submitted PR review.
abrown created PR review comment:
We might not use this either in the DSL phase; isn't this only necessary when we encode in the
cranelift-assembler-x64crate?
jlb6740 submitted PR review.
jlb6740 created PR review comment:
I think the underscore is needed because this naming is not just used for printing, but it also used as part of syntax for an associated item:
vex.vvvv = Some(self.xmm2.enc()); // cranelift/assembler-x64/meta/src/generate/format.rs:135 vex.prefix = LegacyPrefix::.66; // cranelift/assembler-x64/meta/src/generate/format.rs:136 vex.map = OpcodeMap::_0F; // cranelift/assembler-x64/meta/src/generate/format.rs:137where here the
LegacyPrefix::.66is not valid syntax.
jlb6740 edited PR review comment.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
Maybe I can get around this. Will see.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
I am not really sure what to do here other than duplicating it? The primary encode function in vex.rs calls this directly. I don't want to try to refactor or move that code as it is well tested as the same as in the current codegen and it doesn't belong in mem.rs. The emit_modrm_sib_disp is common code to rex and vex and I assume evex encoding and it was public. Being common to multiple encodings, what's the motivation for making it private?
jlb6740 edited PR review comment.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
None is used as default value when creating a VexInstruction. I could change that to be an option, but the way it is now is the exact same as the current implementation in the codegen encoding:
Do you think we should change this to be an option?
jlb6740 submitted PR review.
jlb6740 created PR review comment:
No .. will remove. I believe it remained as an artifact of a rebase when in fact it could/should have been purged at that time.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
Yes, I believe this is copied over or merged from the codegen. I called this vexPP in the DSL. Will do the same here.
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
Yes .. could not remove but any suggestions to overcome the "expected identifier" error welcomed.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
Got rid of the default method and removed this.
jlb6740 submitted PR review.
jlb6740 created PR review comment:
Let's discuss this further. I am not sure what is being recommended here but it I think you are suggesting a different approach than using the current vex emit function? I need to understand exactly what is meant here, but can we iterate on this recommendation?
jlb6740 commented on PR #10754:
@abrown Hi this is ready for second review. Everything with a +1 I believe is addressed and everything with a confuse emoji means it is not addressed due to whatever is written in the comment that follows.
jlb6740 deleted a comment on PR #10754:
@abrown Hi this is ready for second review. Everything with a +1 I believe is addressed and everything with a confuse emoji means it is not addressed due to whatever is written in the comment that follows.
jlb6740 commented on PR #10754:
@abrown Hi, thanks for all the very good comments. This is ready for second review. Everything with a +1 I believe is addressed and everything with a confuse emoji means it is not addressed due to whatever is written in the comment that follows.
jlb6740 deleted a comment on PR #10754:
@abrown Hi, thanks for all the very good comments. This is ready for second review. Everything with a +1 I believe is addressed and everything with a confuse emoji means it is not addressed due to whatever is written in the comment that follows.
jlb6740 updated PR #10754.
abrown submitted PR review.
abrown created PR review comment:
If you
write!(f, "66")here, then we can add whatever prefix we want later,fmtln!(f, "_{}", vex.pp)orfmtln!(f, ".{}", vex.pp).
abrown submitted PR review.
abrown created PR review comment:
I don't think we need this, right?
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 updated PR #10754.
jlb6740 commented on PR #10754:
@abrown Hi, thanks for all the great comments. This is ready for second review. Everything with a +1 I believe is addressed and everything with a confuse emoji means it is not addressed due to whatever commentary follows.
abrown submitted PR review:
Let's merge this; I'll continue working on this to refine the encoding logic so it will work with more instructions. Thanks!
abrown updated PR #10754.
abrown has enabled auto merge for PR #10754.
abrown merged PR #10754.
Last updated: Dec 06 2025 at 07:03 UTC