Skip to content

Commit

Permalink
Winch: x64 wait, notify and fence (#10092)
Browse files Browse the repository at this point in the history
* memory.atomic.wait32/64

* memory.atomic.notify

* atomic.fence

* enable spec tests

* fmt

* remove commented tests

* fix typos in comments

* fix test post-rebase

* gate wait/notify instructions

* review edits
  • Loading branch information
MarinPostma authored Jan 27, 2025
1 parent 5dfccc0 commit 1bd66bf
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 7 deletions.
6 changes: 0 additions & 6 deletions crates/wast-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ impl WastTest {
"component-model/modules.wast",
"extended-const/elem.wast",
"extended-const/global.wast",
"memory64/threads.wast",
"misc_testsuite/externref-id-function.wast",
"misc_testsuite/externref-segment.wast",
"misc_testsuite/externref-segments.wast",
Expand Down Expand Up @@ -483,11 +482,6 @@ impl WastTest {
"spec_testsuite/simd_store32_lane.wast",
"spec_testsuite/simd_store64_lane.wast",
"spec_testsuite/simd_store8_lane.wast",
// thread related failures
"proposals/threads/atomic.wast",
"misc_testsuite/threads/wait_notify.wast",
"misc_testsuite/threads/atomics_wait_address.wast",
"misc_testsuite/threads/atomics_notify.wast",
];

if unsupported.iter().any(|part| self.path.ends_with(part)) {
Expand Down
38 changes: 38 additions & 0 deletions tests/disas/winch/x64/atomic/fence/fence.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(i32.store (i32.const 0) (i32.const 42))
(atomic.fence)
(i32.load (i32.const 0))
))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x10, %r11
;; cmpq %rsp, %r11
;; ja 0x5c
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
;; movq 0x48(%r14), %r11
;; movq (%r11), %rdx
;; addq %rcx, %rdx
;; movl %eax, (%rdx)
;; mfence
;; movl $0, %eax
;; movq 0x48(%r14), %r11
;; movq (%r11), %rcx
;; addq %rax, %rcx
;; movl (%rcx), %eax
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 5c: ud2
37 changes: 37 additions & 0 deletions tests/disas/winch/x64/atomic/notify/notify.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(memory.atomic.notify (i32.const 0) (i32.const 10))))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x20, %r11
;; cmpq %rsp, %r11
;; ja 0x6b
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0xa, %eax
;; movl $0, %ecx
;; pushq %rcx
;; subq $4, %rsp
;; movl %eax, (%rsp)
;; subq $4, %rsp
;; movq %r14, %rdi
;; movl $0, %esi
;; movq 8(%rsp), %rdx
;; movl 4(%rsp), %ecx
;; callq 0x18e
;; addq $4, %rsp
;; addq $0xc, %rsp
;; movq 8(%rsp), %r14
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 6b: ud2
38 changes: 38 additions & 0 deletions tests/disas/winch/x64/atomic/notify/notify_offset.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(memory.atomic.notify offset=8 (i32.const 0) (i32.const 10))))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x20, %r11
;; cmpq %rsp, %r11
;; ja 0x6f
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0xa, %eax
;; movl $0, %ecx
;; addq $8, %rcx
;; pushq %rcx
;; subq $4, %rsp
;; movl %eax, (%rsp)
;; subq $4, %rsp
;; movq %r14, %rdi
;; movl $0, %esi
;; movq 8(%rsp), %rdx
;; movl 4(%rsp), %ecx
;; callq 0x192
;; addq $4, %rsp
;; addq $0xc, %rsp
;; movq 8(%rsp), %r14
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 6f: ud2
40 changes: 40 additions & 0 deletions tests/disas/winch/x64/atomic/wait/wait32.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(memory.atomic.wait32 (i32.const 4) (i32.const 0) (i64.const -1))))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x30, %r11
;; cmpq %rsp, %r11
;; ja 0x78
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movq $18446744073709551615, %rax
;; movl $0, %ecx
;; movl $4, %edx
;; pushq %rdx
;; subq $4, %rsp
;; movl %ecx, (%rsp)
;; pushq %rax
;; subq $0xc, %rsp
;; movq %r14, %rdi
;; movl $0, %esi
;; movq 0x18(%rsp), %rdx
;; movl 0x14(%rsp), %ecx
;; movq 0xc(%rsp), %r8
;; callq 0x19b
;; addq $0xc, %rsp
;; addq $0x14, %rsp
;; movq 8(%rsp), %r14
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 78: ud2
44 changes: 44 additions & 0 deletions tests/disas/winch/x64/atomic/wait/wait32_offset.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(memory.atomic.wait32 offset=8
(i32.const 4)
(i32.const 0)
(i64.const -1))))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x30, %r11
;; cmpq %rsp, %r11
;; ja 0x7c
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movq $18446744073709551615, %rax
;; movl $0, %ecx
;; movl $4, %edx
;; addq $8, %rdx
;; pushq %rdx
;; subq $4, %rsp
;; movl %ecx, (%rsp)
;; pushq %rax
;; subq $0xc, %rsp
;; movq %r14, %rdi
;; movl $0, %esi
;; movq 0x18(%rsp), %rdx
;; movl 0x14(%rsp), %ecx
;; movq 0xc(%rsp), %r8
;; callq 0x19f
;; addq $0xc, %rsp
;; addq $0x14, %rsp
;; movq 8(%rsp), %r14
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 7c: ud2
39 changes: 39 additions & 0 deletions tests/disas/winch/x64/atomic/wait/wait64.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(memory.atomic.wait64 (i32.const 4) (i64.const 0) (i64.const -1))))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x30, %r11
;; cmpq %rsp, %r11
;; ja 0x75
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movq $18446744073709551615, %rax
;; movq $0, %rcx
;; movl $4, %edx
;; pushq %rdx
;; pushq %rcx
;; pushq %rax
;; subq $8, %rsp
;; movq %r14, %rdi
;; movl $0, %esi
;; movq 0x18(%rsp), %rdx
;; movq 0x10(%rsp), %rcx
;; movq 8(%rsp), %r8
;; callq 0x198
;; addq $8, %rsp
;; addq $0x18, %rsp
;; movq 8(%rsp), %r14
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 75: ud2
43 changes: 43 additions & 0 deletions tests/disas/winch/x64/atomic/wait/wait64_offset.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
;;! target = "x86_64"
;;! test = "winch"

(module
(memory 1 1 shared)
(func (export "_start") (result i32)
(memory.atomic.wait64 offset=8
(i32.const 4)
(i64.const 0)
(i64.const -1))))
;; wasm[0]::function[0]:
;; pushq %rbp
;; movq %rsp, %rbp
;; movq 8(%rdi), %r11
;; movq 0x10(%r11), %r11
;; addq $0x30, %r11
;; cmpq %rsp, %r11
;; ja 0x79
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movq $18446744073709551615, %rax
;; movq $0, %rcx
;; movl $4, %edx
;; addq $8, %rdx
;; pushq %rdx
;; pushq %rcx
;; pushq %rax
;; subq $8, %rsp
;; movq %r14, %rdi
;; movl $0, %esi
;; movq 0x18(%rsp), %rdx
;; movq 0x10(%rsp), %rcx
;; movq 8(%rsp), %r8
;; callq 0x19c
;; addq $8, %rsp
;; addq $0x18, %rsp
;; movq 8(%rsp), %r14
;; addq $0x10, %rsp
;; popq %rbp
;; retq
;; 79: ud2
Loading

0 comments on commit 1bd66bf

Please sign in to comment.