Skip to content

Conversation

@afonso360
Copy link
Contributor

Hey,

This PR adds support for parsing i128 data values, it also cleans up the i128 test suite to pass those values directly to the functions. (We previously passed the bottom and top half in i64's and iconcat them together)

This causes a bunch of noise in the diff (sorry!). I've separated this into two commits, the first one with the parser changes, and the second one with test suite changes. It might be easier to review it that way.

Since we now pass i128's directly we need to enable the enable_llvm_abi_extensions flag. This is because the windows_fastcall ABI does not specify how to pass i128 values to functions. This is only necessary for the tests to pass on x86_64 windows.

It doesn't add support for iconst.i128 since its instruction format (UnaryImm) doesen't allow us to include a 128 bit value. We would need to change it to UnaryConst for that.

@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Sep 15, 2021
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Thanks for this, especially all the really tedious test updates! Just a few comments below.

}

// Match and consume an i128 immediate.
fn match_imm128(&mut self, err_msg: &str) -> ParseResult<i128> {
Copy link
Member

Choose a reason for hiding this comment

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

I see the duplication is pre-existing, but it's also unfortunate to continue it here. While it may expand the scope of this PR a bit, I wonder if there's a way to write a single polymorphic implementation? Maybe it can take the signed/unsigned types and require FromStr / FromHex / whatever encapsulates wrapping_neg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing this as a generic function, but it was proving to be somewhat difficult, most of the functions that we need / could use are not in separate traits, but as functions associated with the primitive types. FromStr works, but FromHex doesen't exist. Casting between signed and unsigned types in a generic function, as far as I can tell is a no go.

We could solve pretty much all of these problems by adding a dependency on the num crate, but I don't think this justifies it.

I've implemented this as a macro, hope that is ok.

Copy link
Member

Choose a reason for hiding this comment

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

Perfect, thank you!

Transforming this into a generic function is proving to be a challenge
since most of the necessary methods are not in a trait. We also need to
cast between the signed and unsigned types, which is difficult to do
in a generic function.

This can be solved for example by adding the num crate as a dependency.
But adding a dependency just to solve this issue seems a bit much.
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

LGTM -- thanks!

}

// Match and consume an i128 immediate.
fn match_imm128(&mut self, err_msg: &str) -> ParseResult<i128> {
Copy link
Member

Choose a reason for hiding this comment

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

Perfect, thank you!

@cfallin cfallin merged commit ebe2af6 into bytecodealliance:main Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants