Skip to content

Commit 3f876fe

Browse files
authored
winch: Implement check_stack for aarch64 (#10763)
* winch: Implement check_stack for aarch64 * winch: update aarch64 snapshot tests for check_stack change * winch: address review comments on aarch64 check_stack * winch: update aarch64 snapshot tests: check_stack uses unsigned compare * winch: update aarch64 snapshot tests: stack grows down * winch: aarch64 check_stack correct direction and alignment * winch: aarch64 enable stack_stack wast checks
1 parent 23e27ba commit 3f876fe

File tree

473 files changed

+4954
-1019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

473 files changed

+4954
-1019
lines changed

cranelift/codegen/src/isa/aarch64/inst/emit.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,8 @@ fn machreg_to_gpr_or_vec(m: Reg) -> u32 {
107107
u32::from(m.to_real_reg().unwrap().hw_enc() & 31)
108108
}
109109

110-
pub(crate) fn enc_arith_rrr(
111-
bits_31_21: u32,
112-
bits_15_10: u32,
113-
rd: Writable<Reg>,
114-
rn: Reg,
115-
rm: Reg,
116-
) -> u32 {
110+
/// Encode a 3-register aeithmeric instruction.
111+
pub fn enc_arith_rrr(bits_31_21: u32, bits_15_10: u32, rd: Writable<Reg>, rn: Reg, rm: Reg) -> u32 {
117112
(bits_31_21 << 21)
118113
| (bits_15_10 << 10)
119114
| machreg_to_gpr(rd.to_reg())
@@ -204,7 +199,13 @@ fn enc_test_bit_and_branch(
204199
| machreg_to_gpr(reg)
205200
}
206201

207-
fn enc_move_wide(op: MoveWideOp, rd: Writable<Reg>, imm: MoveWideConst, size: OperandSize) -> u32 {
202+
/// Encode a move-wide instruction.
203+
pub fn enc_move_wide(
204+
op: MoveWideOp,
205+
rd: Writable<Reg>,
206+
imm: MoveWideConst,
207+
size: OperandSize,
208+
) -> u32 {
208209
assert!(imm.shift <= 0b11);
209210
let op = match op {
210211
MoveWideOp::MovN => 0b00,
@@ -218,7 +219,8 @@ fn enc_move_wide(op: MoveWideOp, rd: Writable<Reg>, imm: MoveWideConst, size: Op
218219
| machreg_to_gpr(rd.to_reg())
219220
}
220221

221-
fn enc_movk(rd: Writable<Reg>, imm: MoveWideConst, size: OperandSize) -> u32 {
222+
/// Encode a move-keep immediate instruction.
223+
pub fn enc_movk(rd: Writable<Reg>, imm: MoveWideConst, size: OperandSize) -> u32 {
222224
assert!(imm.shift <= 0b11);
223225
0x72800000
224226
| size.sf_bit() << 31

crates/cranelift/src/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl wasmtime_environ::Compiler for Compiler {
225225
// check to all functions for how much native stack is remaining. The
226226
// `VMContext` pointer is the first argument to all functions, and the
227227
// first field of this structure is `*const VMStoreContext` and the
228-
// first field of that is the stack limit. Note that the stack limit in
228+
// third field of that is the stack limit. Note that the stack limit in
229229
// this case means "if the stack pointer goes below this, trap". Each
230230
// function which consumes stack space or isn't a leaf function starts
231231
// off by loading the stack limit, checking it against the stack

crates/test-util/src/wast.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,6 @@ impl WastTest {
418418
if config.compiler == Compiler::Winch {
419419
if cfg!(target_arch = "aarch64") {
420420
let unsupported = [
421-
// Missing stack checks (#8321)
422-
"spec_testsuite/call.wast",
423-
"spec_testsuite/fac.wast",
424-
"spec_testsuite/skip-stack-guard-page.wast",
425-
"misc_testsuite/stack_overflow.wast",
426421
// Fails intermittently
427422
"misc_testsuite/table_copy_on_imported_tables.wast",
428423
// Segfault

tests/disas/winch/aarch64/br/as_br_if_cond.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
;; mov x29, sp
1111
;; str x28, [sp, #-0x10]!
1212
;; mov x28, sp
13-
;; mov x9, x0
13+
;; ldur x16, [x0, #8]
14+
;; ldur x16, [x16, #0x10]
15+
;; mov x17, #0
16+
;; movk x17, #0x10
17+
;; add x16, x16, x17
18+
;; cmp sp, x16
19+
;; b.lo #0x58
20+
;; 2c: mov x9, x0
1421
;; sub x28, x28, #0x10
1522
;; mov sp, x28
1623
;; stur x0, [x28, #8]
@@ -21,3 +28,4 @@
2128
;; ldr x28, [sp], #0x10
2229
;; ldp x29, x30, [sp], #0x10
2330
;; ret
31+
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00

tests/disas/winch/aarch64/br/as_br_value.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
;; mov x29, sp
1111
;; str x28, [sp, #-0x10]!
1212
;; mov x28, sp
13-
;; mov x9, x0
13+
;; ldur x16, [x0, #8]
14+
;; ldur x16, [x16, #0x10]
15+
;; mov x17, #0
16+
;; movk x17, #0x10
17+
;; add x16, x16, x17
18+
;; cmp sp, x16
19+
;; b.lo #0x60
20+
;; 2c: mov x9, x0
1421
;; sub x28, x28, #0x10
1522
;; mov sp, x28
1623
;; stur x0, [x28, #8]
@@ -23,3 +30,4 @@
2330
;; ldr x28, [sp], #0x10
2431
;; ldp x29, x30, [sp], #0x10
2532
;; ret
33+
;; 60: .byte 0x1f, 0xc1, 0x00, 0x00

tests/disas/winch/aarch64/br/as_if_cond.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
;; mov x29, sp
1616
;; str x28, [sp, #-0x10]!
1717
;; mov x28, sp
18-
;; mov x9, x0
18+
;; ldur x16, [x0, #8]
19+
;; ldur x16, [x16, #0x10]
20+
;; mov x17, #0
21+
;; movk x17, #0x10
22+
;; add x16, x16, x17
23+
;; cmp sp, x16
24+
;; b.lo #0x60
25+
;; 2c: mov x9, x0
1926
;; sub x28, x28, #0x10
2027
;; mov sp, x28
2128
;; stur x0, [x28, #8]
@@ -28,3 +35,4 @@
2835
;; ldr x28, [sp], #0x10
2936
;; ldp x29, x30, [sp], #0x10
3037
;; ret
38+
;; 60: .byte 0x1f, 0xc1, 0x00, 0x00

tests/disas/winch/aarch64/br/as_if_else.wat

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
;; mov x29, sp
1616
;; str x28, [sp, #-0x10]!
1717
;; mov x28, sp
18-
;; mov x9, x0
18+
;; ldur x16, [x0, #8]
19+
;; ldur x16, [x16, #0x10]
20+
;; mov x17, #0
21+
;; movk x17, #0x18
22+
;; add x16, x16, x17
23+
;; cmp sp, x16
24+
;; b.lo #0x80
25+
;; 2c: mov x9, x0
1926
;; sub x28, x28, #0x18
2027
;; mov sp, x28
2128
;; stur x0, [x28, #0x10]
@@ -24,15 +31,16 @@
2431
;; stur w3, [x28]
2532
;; ldur w0, [x28, #4]
2633
;; tst w0, w0
27-
;; b.eq #0x44
28-
;; b #0x3c
29-
;; 3c: ldur w0, [x28]
30-
;; b #0x4c
31-
;; 44: mov x16, #4
34+
;; b.eq #0x60
35+
;; b #0x58
36+
;; 58: ldur w0, [x28]
37+
;; b #0x68
38+
;; 60: mov x16, #4
3239
;; mov w0, w16
3340
;; add x28, x28, #0x18
3441
;; mov sp, x28
3542
;; mov sp, x28
3643
;; ldr x28, [sp], #0x10
3744
;; ldp x29, x30, [sp], #0x10
3845
;; ret
46+
;; 80: .byte 0x1f, 0xc1, 0x00, 0x00

tests/disas/winch/aarch64/br/as_if_then.wat

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
;; mov x29, sp
1616
;; str x28, [sp, #-0x10]!
1717
;; mov x28, sp
18-
;; mov x9, x0
18+
;; ldur x16, [x0, #8]
19+
;; ldur x16, [x16, #0x10]
20+
;; mov x17, #0
21+
;; movk x17, #0x18
22+
;; add x16, x16, x17
23+
;; cmp sp, x16
24+
;; b.lo #0x80
25+
;; 2c: mov x9, x0
1926
;; sub x28, x28, #0x18
2027
;; mov sp, x28
2128
;; stur x0, [x28, #0x10]
@@ -24,15 +31,16 @@
2431
;; stur w3, [x28]
2532
;; ldur w0, [x28, #4]
2633
;; tst w0, w0
27-
;; b.eq #0x48
28-
;; b #0x3c
29-
;; 3c: mov x16, #3
34+
;; b.eq #0x64
35+
;; b #0x58
36+
;; 58: mov x16, #3
3037
;; mov w0, w16
31-
;; b #0x4c
32-
;; 48: ldur w0, [x28]
38+
;; b #0x68
39+
;; 64: ldur w0, [x28]
3340
;; add x28, x28, #0x18
3441
;; mov sp, x28
3542
;; mov sp, x28
3643
;; ldr x28, [sp], #0x10
3744
;; ldp x29, x30, [sp], #0x10
3845
;; ret
46+
;; 80: .byte 0x1f, 0xc1, 0x00, 0x00

tests/disas/winch/aarch64/br/as_loop_first.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
;; mov x29, sp
1212
;; str x28, [sp, #-0x10]!
1313
;; mov x28, sp
14-
;; mov x9, x0
14+
;; ldur x16, [x0, #8]
15+
;; ldur x16, [x16, #0x10]
16+
;; mov x17, #0
17+
;; movk x17, #0x10
18+
;; add x16, x16, x17
19+
;; cmp sp, x16
20+
;; b.lo #0x60
21+
;; 2c: mov x9, x0
1522
;; sub x28, x28, #0x10
1623
;; mov sp, x28
1724
;; stur x0, [x28, #8]
@@ -24,3 +31,4 @@
2431
;; ldr x28, [sp], #0x10
2532
;; ldp x29, x30, [sp], #0x10
2633
;; ret
34+
;; 60: .byte 0x1f, 0xc1, 0x00, 0x00

tests/disas/winch/aarch64/br/br_jump.wat

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
;; mov x29, sp
1919
;; str x28, [sp, #-0x10]!
2020
;; mov x28, sp
21-
;; mov x9, x0
21+
;; ldur x16, [x0, #8]
22+
;; ldur x16, [x16, #0x10]
23+
;; mov x17, #0
24+
;; movk x17, #0x20
25+
;; add x16, x16, x17
26+
;; cmp sp, x16
27+
;; b.lo #0x8c
28+
;; 2c: mov x9, x0
2229
;; sub x28, x28, #0x18
2330
;; mov sp, x28
2431
;; stur x0, [x28, #0x10]
@@ -35,10 +42,11 @@
3542
;; stur w16, [x28]
3643
;; add x28, x28, #4
3744
;; mov sp, x28
38-
;; b #0x3c
39-
;; 58: add x28, x28, #0x18
45+
;; b #0x58
46+
;; 74: add x28, x28, #0x18
4047
;; mov sp, x28
4148
;; mov sp, x28
4249
;; ldr x28, [sp], #0x10
4350
;; ldp x29, x30, [sp], #0x10
4451
;; ret
52+
;; 8c: .byte 0x1f, 0xc1, 0x00, 0x00

0 commit comments

Comments
 (0)