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

* Fix more test expectations
  • Loading branch information
alexcrichton authored Nov 22, 2024
1 parent 74a703b commit 5af8930
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 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

4 changes: 2 additions & 2 deletions tests/disas/pulley/loads.wat
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
;; xconst8 spilltmp0, 16
;; xadd32 sp, sp, spilltmp0
;; ret
;; 33: ret
;; 33: trap
;;
;; wasm[0]::function[1]::i64:
;; xconst8 spilltmp0, -16
Expand All @@ -49,4 +49,4 @@
;; xconst8 spilltmp0, 16
;; xadd32 sp, sp, spilltmp0
;; ret
;; 33: ret
;; 33: trap

0 comments on commit 5af8930

Please sign in to comment.