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

s390x: Improved TrapIf implementation #6079

Merged
merged 1 commit into from
Mar 23, 2023

Conversation

uweigand
Copy link
Member

Following up on the discussion in
#6011 this adds an improved implementation of TrapIf for s390x using a single conditional branch instruction.

If the trap conditions is true, we branch into the middle of the branch instruction - those middle two bytes are zero, which matches the encoding of the trap instruction.

// of the branch (BRCL) instruction itself - those middle two bytes
// are zero, which matches the trap instruction itself.
let opcode = 0xc04; // BCRL
let enc = &enc_ril_c(opcode, cond.bits(), 2);
Copy link
Member

Choose a reason for hiding this comment

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

Could this add some assertions that enc has length 6 and the middle 2 bytes are zeros?

let cond = cond.invert().pretty_print_default();
format!("j{} 6 ; trap", cond)
let cond = cond.pretty_print_default();
format!("jg{} .+2", cond)
Copy link
Member

Choose a reason for hiding this comment

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

Like the other backends (which Jamey suggested and I think is a good idea), could this include the trap code in the printing? The other backends do something like # trap={code} at the end IIRC

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, good idea. I've also added this for the unconditional traps now.

Following up on the discussion in
bytecodealliance#6011
this adds an improved implementation of TrapIf for s390x
using a single conditional branch instruction.

If the trap conditions is true, we branch into the middle of
the branch instruction - those middle two bytes are zero,
which matches the encoding of the trap instruction.

In addition, show the trap code for Trap and TrapIf
instructions in assembler output.
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Mar 21, 2023
@alexcrichton alexcrichton added this pull request to the merge queue Mar 23, 2023
Merged via the queue into bytecodealliance:main with commit 6f66abd Mar 23, 2023
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