MarinPostma requested wasmtime-compiler-reviewers for a review on PR #10066.
MarinPostma requested fitzgen for a review on PR #10066.
MarinPostma opened PR #10066 from MarinPostma:movzv-unsigned-extend
to bytecodealliance:main
:
Followup to https://github.com/bytecodealliance/wasmtime/pull/10053
This PR has two commit:
1) The first commit makes
mov*
instruct receive the adequateExtend
operation. And it makes extend conversion operation harder to misuse.
2) The second commit it optional. This is an alternative toSigned/UnsignedExtend
, that merges the two into aExtend<T>
, and factorizes common behaviour, avoiding repetition. TheT
is eitherSigned
orZero
, with precautions in the design so that it's hard to misuse.
MarinPostma edited PR #10066:
Followup to https://github.com/bytecodealliance/wasmtime/pull/10053
This PR has two commit:
1) The first commit makes
mov*
instruct receive the adequateExtend
operation. And it makes extend conversion operation harder to misuse.
2) The second commit is optional. This is an alternative toSigned/UnsignedExtend
, that merges the two into aExtend<T>
, and factorizes common behaviour, avoiding repetition. TheT
is eitherSigned
orZero
, with precautions in the design so that it's hard to misuse.
saulecabrera submitted PR review:
Thanks for this. Left two minor comments inline.
saulecabrera created PR review comment:
To avoid an unused member, could you use
PhantomData
to hold the type instead? https://doc.rust-lang.org/std/marker/struct.PhantomData.html
saulecabrera created PR review comment:
Small naming convention/suggestion: we usually use
src
,dst
for explicit moves, could we keepfrom_bits
andto_bits
? Although given that this now returnsOperandSize
it could maybe befrom_size
andto_size
?
MarinPostma submitted PR review.
MarinPostma created PR review comment:
do you mean for every variant? like
I64ExtendI8(PhantomData<T>)
? I think that would make construction pretty cumbersome, no?
If you mean__Kind(PhamtomData<T>)
, then that defeats the purpose of this variant being unconstructible, since you can't constructSigned
andZero
MarinPostma created PR review comment:
No problem. It's just that it kinda overlaps with usual rust naming convention for
from_
andto_
, which I found a bit confusing. I'll make the change now.
MarinPostma submitted PR review.
MarinPostma updated PR #10066.
saulecabrera submitted PR review.
saulecabrera created PR review comment:
I meant more around the lines of:
pub enum ExtendBits { /// 8 to 32 bit extend. I32Extend8, /// 16 to 32 bit extend. I32Extend16, /// 8 to 64 bit extend. I64Extend8, /// 16 to 64 bit extend. I64Extend16, /// 32 to 64 bit extend. I64Extend32, } pub struct Extend<T> { bits: ExtendBits, marker: PhantomData<T>, }
Which is the kind of job that
PhantomData
is for.That way you can avoid the unused enum member. In your approach
Signed
andZero
are mostly used as type flags to ensure that the extension is associated correctly, but even though your comment states that the__Kind(T)
variant cannot be constructed, from a practical perspective, you could doExtend::__Kind(Signed)
I believe.
saulecabrera submitted PR review.
saulecabrera created PR review comment:
The general disadvantage that I see is that this approach adds a bit more complexity to the implementation.
saulecabrera submitted PR review.
saulecabrera created PR review comment:
But we can always iterate on this after landing this change, I think regardless of the unused member, extends are in a better place now.
saulecabrera submitted PR review.
MarinPostma submitted PR review.
MarinPostma created PR review comment:
| from a practical perspective, you could do Extend::__Kind(Signed) I believe.
that's in fact not possible :) You would need to exhibit a variant, but there are none, c.f: https://doc.rust-lang.org/reference/items/enumerations.html#zero-variant-enums
MarinPostma submitted PR review.
MarinPostma created PR review comment:
I think your proposal could work nicely too, if we implemented
Deref<Target = ExtendBits>
forExtend<T: ExtendType>
MarinPostma submitted PR review.
MarinPostma created PR review comment:
we'd need to add contructors to make instanciation simpler, though, which may hurt readability
saulecabrera submitted PR review.
saulecabrera created PR review comment:
Oh I see, I overlooked, I read this as
struct
notenum
(forSigned
andZero
), but this makes sense. Thanks for clarifying.we'd need to add contructors to make instanciation simpler, though, which may hurt readability
Yeah, I think the current approach is simple enough, if there's a strong reason to change it in the future then we can. For now I'd suggest we keep it as is.
saulecabrera merged PR #10066.
Last updated: Jan 24 2025 at 00:11 UTC