Skip to content

Commit

Permalink
pulley: Fix trap opcode encoding (#9643)
Browse files Browse the repository at this point in the history
* pulley: Fix trap opcode encoding

This was a copy/paste typo and needs updating.

* Fix test expectations
  • Loading branch information
alexcrichton authored Nov 21, 2024
1 parent 642ee73 commit 663e85f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
15 changes: 14 additions & 1 deletion cranelift/codegen/src/isa/pulley_shared/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ where
type LabelUse = LabelUse;
type ABIMachineSpec = PulleyMachineDeps<P>;

const TRAP_OPCODE: &'static [u8] = &[0];
const TRAP_OPCODE: &'static [u8] = TRAP_OPCODE;

fn gen_dummy_use(_reg: Reg) -> Self {
todo!()
Expand Down Expand Up @@ -468,6 +468,19 @@ where
}
}

const TRAP_OPCODE: &'static [u8] = &[
pulley_interpreter::opcode::Opcode::ExtendedOp as u8,
((pulley_interpreter::opcode::ExtendedOpcode::Trap as u16) >> 0) as u8,
((pulley_interpreter::opcode::ExtendedOpcode::Trap as u16) >> 8) as u8,
];

#[test]
fn test_trap_encoding() {
let mut dst = std::vec::Vec::new();
pulley_interpreter::encode::trap(&mut dst);
assert_eq!(dst, TRAP_OPCODE);
}

//=============================================================================
// Pretty-printing of instructions.

Expand Down
12 changes: 6 additions & 6 deletions cranelift/filetests/filetests/isa/pulley32/trap.clif
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapz(i64) {
block0(v0: i64):
Expand All @@ -51,7 +51,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapnz_icmp_fold(i64) {
block0(v0: i64):
Expand All @@ -71,7 +71,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapz_icmp_fold(i64) {
block0(v0: i64):
Expand All @@ -91,7 +91,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapnz_iconst_fold(i64) {
block0(v0: i64):
Expand Down Expand Up @@ -126,7 +126,7 @@ block2:
; a: 14 06 00 xconst8 x6, 0
; d: 0c 05 06 08 00 00 00 br_if_xneq64 x5, x6, 0x8 // target = 0x15
; 14: 00 ret
; 15: 00 ret
; 15: 43 00 00 trap

function %trapz_iconst_fold(i64) {
block0(v0: i64):
Expand Down Expand Up @@ -161,5 +161,5 @@ block2:
; c: 0b 04 05 09 00 00 00 br_if_xeq64 x4, x5, 0x9 // target = 0x15
; 13: 00 ret
; 14: 00 ret
; 15: 00 ret
; 15: 43 00 00 trap

12 changes: 6 additions & 6 deletions cranelift/filetests/filetests/isa/pulley64/trap.clif
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapz(i64) {
block0(v0: i64):
Expand All @@ -51,7 +51,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapnz_icmp_fold(i64) {
block0(v0: i64):
Expand All @@ -71,7 +71,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapz_icmp_fold(i64) {
block0(v0: i64):
Expand All @@ -91,7 +91,7 @@ block0(v0: i64):
; 0: 14 02 2a xconst8 x2, 42
; 3: 0c 00 02 08 00 00 00 br_if_xneq64 x0, x2, 0x8 // target = 0xb
; a: 00 ret
; b: 00 ret
; b: 43 00 00 trap

function %trapnz_iconst_fold(i64) {
block0(v0: i64):
Expand Down Expand Up @@ -126,7 +126,7 @@ block2:
; a: 14 06 00 xconst8 x6, 0
; d: 0c 05 06 08 00 00 00 br_if_xneq64 x5, x6, 0x8 // target = 0x15
; 14: 00 ret
; 15: 00 ret
; 15: 43 00 00 trap

function %trapz_iconst_fold(i64) {
block0(v0: i64):
Expand Down Expand Up @@ -161,5 +161,5 @@ block2:
; c: 0b 04 05 09 00 00 00 br_if_xeq64 x4, x5, 0x9 // target = 0x15
; 13: 00 ret
; 14: 00 ret
; 15: 00 ret
; 15: 43 00 00 trap

0 comments on commit 663e85f

Please sign in to comment.