Skip to content

s390x: Improved TrapIf implementation#6079

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
uweigand:s390x-trapif
Mar 23, 2023
Merged

s390x: Improved TrapIf implementation#6079
alexcrichton merged 1 commit intobytecodealliance:mainfrom
uweigand:s390x-trapif

Conversation

@uweigand
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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