Stream: git-wasmtime

Topic: wasmtime / PR #6325 riscv64: Add `VecALUImm` instruction ...


view this post on Zulip Wasmtime GitHub notifications bot (May 02 2023 at 13:54):

afonso360 opened PR #6325 from afonso360:riscv-vec-imm to bytecodealliance:main:

:wave: Hey,

This PR adds a new vector instruction format Vector+Imm. The encoding is exactly the same as v*.vv but the second register is instead a 5 bit field. This immediate is signed for most ops, but unsigned for some.

view this post on Zulip Wasmtime GitHub notifications bot (May 02 2023 at 13:54):

afonso360 requested elliottt for a review on PR #6325.

view this post on Zulip Wasmtime GitHub notifications bot (May 02 2023 at 13:54):

afonso360 requested wasmtime-compiler-reviewers for a review on PR #6325.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton created PR review comment:

Should this do i8::try_from(arg0 as i64).ok()??

Otherwise I think i64::MIN would accidentally get truncated to 0?

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton created PR review comment:

The mask here shouldn't be required, right? Or otherwise this would be ok to perhaps debug_assert! that the masked-out bits are all not set?

(similar for funct6 above too maybe?)

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton created PR review comment:

Oh I see now my thoughts are very much related to https://github.com/bytecodealliance/wasmtime/pull/6324#discussion_r1182744349

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton created PR review comment:

I don't know much about RISC-V, but should this AluOp be different than VecAluOpRRR or the same? The single data point of Vadd has the encodings the same, but I'm not sure if the pattern holds up elsewhere.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 18:17):

alexcrichton created PR review comment:

My curiosity has been piqued if you're willing to oblige -- according to this doc I see a bunch of V/X/I columns but I'm not sure how that translates to the encoding. Is there a different document that explains how these columns relate to the encoding?

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:03):

afonso360 created PR review comment:

That table does not seem to be explained anywhere, which is weird the closest thing is 10. Vector Arithmetic Instruction Formats which only really explains the format, but not the encoding in that table. The way I understand it is the following.

There are 3 columns, which correspond to the 3 columns for the minor opcodes at the top (i.e. OPIVV, OPIVX, OPMVX, etc..). The minor opcode corresponds to the funct3 field. (The exact encoding is specified here)

The minor opcodes correspond to the operands that instruction takes. OPIVV is for Vector/Vector instructions (i.e. vadd.vv), OPIVX is for Vector/X Register instructions (i.e. vadd.vx) and OPIVI is for Vector/Immediate instruction (i.e. vadd.vi) which is what is implemented in this PR.

I'm only planning on having 2 instruction formats, since OP*VV,OP*VX and OPFVF can share the same instruction format in cranelift. Just with an assert that we are using the correct regclass. OPIVI is the only special one here.

The big table displays the funct6 field. Take for example the vrsub instruction. It is in the leftmost column, and only has X and I formats. So we know that it only takes the minor opcode formats of OPIVX and OPIVI. vrsub itself has a funct6 of 0b000011 with both of those minor opcodes.

There are additional encoding spaces, at the bottom, but my understanding is that these are all OPIVI instructions and that encoding gets put in the immediate field (not 100% sure on this yet).

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:03):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:06):

afonso360 created PR review comment:

Yeah, I probably don't need the masking everywhere. I think I might take the approach that @jameysharp is suggesting and switch to debug_assert and try to figure out how to get better type safety in the future.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:06):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:09):

afonso360 created PR review comment:

Well, It is the same, but not all Opcodes work on both formats. vadd works for both, but vsub does not have a vsub.vi format. It would be nice if we could share the funct6 mapping somehow though since it is exactly the same on both.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:09):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 19:10):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 20:36):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 20:36):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 20:39):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 21:10):

afonso360 created PR review comment:

I've now put these into a VecOpCategory struct so that their encoding is somewhat centralized.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 21:10):

afonso360 updated PR #6325.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 21:11):

afonso360 updated PR #6325.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 21:18):

afonso360 edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (May 03 2023 at 21:26):

afonso360 updated PR #6325.

view this post on Zulip Wasmtime GitHub notifications bot (May 04 2023 at 20:09):

alexcrichton created PR review comment:

Ah ok makes sense, in that case sounds good to me to have a minor amount of duplication :+1:

view this post on Zulip Wasmtime GitHub notifications bot (May 04 2023 at 20:13):

alexcrichton submitted PR review:

Thanks for taking the time to explain! That all sounds good to me and everything looks good to me as well :+1:

view this post on Zulip Wasmtime GitHub notifications bot (May 04 2023 at 22:31):

afonso360 merged PR #6325.


Last updated: Nov 22 2024 at 17:03 UTC