Skip to content

Commit 5af8930

Browse files
authored
pulley: Fix trap opcode encoding (#9643)
* pulley: Fix trap opcode encoding This was a copy/paste typo and needs updating. * Fix test expectations * Fix more test expectations
1 parent 74a703b commit 5af8930

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

cranelift/codegen/src/isa/pulley_shared/inst/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ where
309309
type LabelUse = LabelUse;
310310
type ABIMachineSpec = PulleyMachineDeps<P>;
311311

312-
const TRAP_OPCODE: &'static [u8] = &[0];
312+
const TRAP_OPCODE: &'static [u8] = TRAP_OPCODE;
313313

314314
fn gen_dummy_use(_reg: Reg) -> Self {
315315
todo!()
@@ -468,6 +468,19 @@ where
468468
}
469469
}
470470

471+
const TRAP_OPCODE: &'static [u8] = &[
472+
pulley_interpreter::opcode::Opcode::ExtendedOp as u8,
473+
((pulley_interpreter::opcode::ExtendedOpcode::Trap as u16) >> 0) as u8,
474+
((pulley_interpreter::opcode::ExtendedOpcode::Trap as u16) >> 8) as u8,
475+
];
476+
477+
#[test]
478+
fn test_trap_encoding() {
479+
let mut dst = std::vec::Vec::new();
480+
pulley_interpreter::encode::trap(&mut dst);
481+
assert_eq!(dst, TRAP_OPCODE);
482+
}
483+
471484
//=============================================================================
472485
// Pretty-printing of instructions.
473486

cranelift/filetests/filetests/isa/pulley32/trap.clif

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ block0(v0: i64):
3131
; 0: 14 02 2a xconst8 x2, 42
3232
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
3333
; a: 00 ret
34-
; b: 00 ret
34+
; b: 43 00 00 trap
3535

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

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

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

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

131131
function %trapz_iconst_fold(i64) {
132132
block0(v0: i64):
@@ -161,5 +161,5 @@ block2:
161161
; c: 0b 04 05 09 00 00 00 br_if_xeq64 x4, x5, 0x9 // target = 0x15
162162
; 13: 00 ret
163163
; 14: 00 ret
164-
; 15: 00 ret
164+
; 15: 43 00 00 trap
165165

cranelift/filetests/filetests/isa/pulley64/trap.clif

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ block0(v0: i64):
3131
; 0: 14 02 2a xconst8 x2, 42
3232
; 3: 0b 00 02 08 00 00 00 br_if_xeq64 x0, x2, 0x8 // target = 0xb
3333
; a: 00 ret
34-
; b: 00 ret
34+
; b: 43 00 00 trap
3535

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

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

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

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

131131
function %trapz_iconst_fold(i64) {
132132
block0(v0: i64):
@@ -161,5 +161,5 @@ block2:
161161
; c: 0b 04 05 09 00 00 00 br_if_xeq64 x4, x5, 0x9 // target = 0x15
162162
; 13: 00 ret
163163
; 14: 00 ret
164-
; 15: 00 ret
164+
; 15: 43 00 00 trap
165165

tests/disas/pulley/loads.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
;; xconst8 spilltmp0, 16
3232
;; xadd32 sp, sp, spilltmp0
3333
;; ret
34-
;; 33: ret
34+
;; 33: trap
3535
;;
3636
;; wasm[0]::function[1]::i64:
3737
;; xconst8 spilltmp0, -16
@@ -49,4 +49,4 @@
4949
;; xconst8 spilltmp0, 16
5050
;; xadd32 sp, sp, spilltmp0
5151
;; ret
52-
;; 33: ret
52+
;; 33: trap

0 commit comments

Comments
 (0)