Skip to content
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

x64: Add support for the shld instruction #10233

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

alexcrichton
Copy link
Member

This commit is similar to #10229 except that it uses the x64 shld instruction. This instruction was not previously supported by Cranelift so I opted to add support via the new cranelift-assembler-x64 crate instead of trying to fit it into the existing emit.rs/MInst infrastructure. This was a good learning experience for myself and was also fun to do!

@alexcrichton
Copy link
Member Author

I'm opening this as a draft PR because #10232 should land first and this should rebase on top of that. In talking with Andrew I temporarily came up with the "solution" in this PR but our conclusion was that #10232 was the better way to go in terms of robustly supporting this encoding pattern in x64 instructions.

@alexcrichton
Copy link
Member Author

(also cc @abrown)

@abrown abrown self-requested a review February 14, 2025 18:12
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Feb 14, 2025
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "cranelift", "cranelift:area:x64", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

This commit is similar to bytecodealliance#10229 except that it uses the x64 `shld`
instruction. This instruction was not previously supported by Cranelift
so I opted to add support via the new `cranelift-assembler-x64` crate
instead of trying to fit it into the existing `emit.rs`/`MInst`
infrastructure. This was a good learning experience for myself and was
also fun to do!
@alexcrichton alexcrichton marked this pull request as ready for review February 14, 2025 20:03
@alexcrichton alexcrichton requested review from a team as code owners February 14, 2025 20:04
@alexcrichton alexcrichton requested review from pchickey and removed request for a team and pchickey February 14, 2025 20:04
Copy link
Contributor

@abrown abrown left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

.operands
.iter()
.rev()
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh... let's try this but I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh agreed! I figure we'll need to add more heuristics here eventually to figure out how to print and still match att/capstone ordering.

@@ -332,7 +335,7 @@ impl From<[u8; 3]> for Opcodes {
fn from(bytes: [u8; 3]) -> Opcodes {
let [a, b, c] = bytes;
match (LegacyPrefix::try_from(a), b, c) {
(Ok(prefix), 0x0f, primary) => Opcodes { prefix, escape: false, primary, secondary: None },
(Ok(prefix), 0x0f, primary) => Opcodes { prefix, escape: true, primary, secondary: None },
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@alexcrichton alexcrichton added this pull request to the merge queue Feb 14, 2025
Merged via the queue into bytecodealliance:main with commit 30b78b6 Feb 14, 2025
51 checks passed
@alexcrichton alexcrichton deleted the x64-shld branch February 14, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants