Skip to content

Commit 3a4cf0a

Browse files
authored
winch: x64 atomic stores (bytecodealliance#9987)
* add MemOpKind to wasm_store * add fence to x64 asm * implement atomic store for x64 masm * emit error for 128bits atomic store * propagate MemOpKind from Visitor * implement atomic store visitor methods * add atomic store tests * fmt * whitelist spec tests * atomic heap address compute align check * fmt * edit comment * cleanup check align function * add doc for check_align * review edits * review edits - use scratch register for tmp in emit_align_check - pop-push value from stack rather than peeking in emit_align_check * final edits
1 parent 7f9049b commit 3a4cf0a

19 files changed

+442
-51
lines changed

crates/wast-util/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,9 @@ impl WastTest {
488488
"spec_testsuite/simd_store8_lane.wast",
489489
// thread related failures
490490
"proposals/threads/atomic.wast",
491-
"misc_testsuite/threads/MP_wait.wast",
492-
"misc_testsuite/threads/load-store-alignment.wast",
493-
"misc_testsuite/threads/MP_atomic.wast",
494-
"misc_testsuite/threads/SB_atomic.wast",
495491
"misc_testsuite/threads/wait_notify.wast",
496-
"misc_testsuite/threads/LB_atomic.wast",
497492
"misc_testsuite/threads/atomics_wait_address.wast",
498493
"misc_testsuite/threads/atomics_notify.wast",
499-
"misc_testsuite/threads/load-store-alignment.wast",
500494
];
501495

502496
if unsupported.iter().any(|part| self.path.ends_with(part)) {

tests/disas/winch/x64/atomic/load/i32_atomic_load.wat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@
1313
;; movq 0x10(%r11), %r11
1414
;; addq $0x20, %r11
1515
;; cmpq %rsp, %r11
16-
;; ja 0x47
16+
;; ja 0x57
1717
;; 1c: movq %rdi, %r14
1818
;; subq $0x20, %rsp
1919
;; movq %rdi, 0x18(%rsp)
2020
;; movq %rsi, 0x10(%rsp)
2121
;; movl %edx, 0xc(%rsp)
2222
;; movl 0xc(%rsp), %eax
23+
;; andl $3, %eax
24+
;; cmpl $0, %eax
25+
;; jne 0x59
26+
;; 41: movl 0xc(%rsp), %eax
2327
;; movq 0x58(%r14), %r11
2428
;; movq (%r11), %rcx
2529
;; addq %rax, %rcx
2630
;; movl (%rcx), %eax
2731
;; addq $0x20, %rsp
2832
;; popq %rbp
2933
;; retq
30-
;; 47: ud2
34+
;; 57: ud2
35+
;; 59: ud2

tests/disas/winch/x64/atomic/load/i32_atomic_load16_u.wat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@
1313
;; movq 0x10(%r11), %r11
1414
;; addq $0x20, %r11
1515
;; cmpq %rsp, %r11
16-
;; ja 0x49
16+
;; ja 0x5b
1717
;; 1c: movq %rdi, %r14
1818
;; subq $0x20, %rsp
1919
;; movq %rdi, 0x18(%rsp)
2020
;; movq %rsi, 0x10(%rsp)
2121
;; movl %edx, 0xc(%rsp)
2222
;; movl 0xc(%rsp), %eax
23+
;; andw $1, %ax
24+
;; cmpw $0, %ax
25+
;; jne 0x5d
26+
;; 43: movl 0xc(%rsp), %eax
2327
;; movq 0x58(%r14), %r11
2428
;; movq (%r11), %rcx
2529
;; addq %rax, %rcx
2630
;; movzwq (%rcx), %rax
2731
;; addq $0x20, %rsp
2832
;; popq %rbp
2933
;; retq
30-
;; 49: ud2
34+
;; 5b: ud2
35+
;; 5d: ud2

tests/disas/winch/x64/atomic/load/i64_atomic_load.wat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@
1414
;; movq 0x10(%r11), %r11
1515
;; addq $0x10, %r11
1616
;; cmpq %rsp, %r11
17-
;; ja 0x41
17+
;; ja 0x54
1818
;; 1c: movq %rdi, %r14
1919
;; subq $0x10, %rsp
2020
;; movq %rdi, 8(%rsp)
2121
;; movq %rsi, (%rsp)
2222
;; movl $0, %eax
23+
;; andq $7, %rax
24+
;; cmpq $0, %rax
25+
;; jne 0x56
26+
;; 3f: movl $0, %eax
2327
;; movq 0x60(%r14), %rcx
2428
;; addq %rax, %rcx
2529
;; movq (%rcx), %rax
2630
;; addq $0x10, %rsp
2731
;; popq %rbp
2832
;; retq
29-
;; 41: ud2
33+
;; 54: ud2
34+
;; 56: ud2

tests/disas/winch/x64/atomic/load/i64_atomic_load16_u.wat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@
1414
;; movq 0x10(%r11), %r11
1515
;; addq $0x10, %r11
1616
;; cmpq %rsp, %r11
17-
;; ja 0x42
17+
;; ja 0x55
1818
;; 1c: movq %rdi, %r14
1919
;; subq $0x10, %rsp
2020
;; movq %rdi, 8(%rsp)
2121
;; movq %rsi, (%rsp)
2222
;; movl $0, %eax
23+
;; andw $1, %ax
24+
;; cmpw $0, %ax
25+
;; jne 0x57
26+
;; 3f: movl $0, %eax
2327
;; movq 0x60(%r14), %rcx
2428
;; addq %rax, %rcx
2529
;; movzwq (%rcx), %rax
2630
;; addq $0x10, %rsp
2731
;; popq %rbp
2832
;; retq
29-
;; 42: ud2
33+
;; 55: ud2
34+
;; 57: ud2

tests/disas/winch/x64/atomic/load/i64_atomic_load32_u.wat

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@
1414
;; movq 0x10(%r11), %r11
1515
;; addq $0x10, %r11
1616
;; cmpq %rsp, %r11
17-
;; ja 0x40
17+
;; ja 0x51
1818
;; 1c: movq %rdi, %r14
1919
;; subq $0x10, %rsp
2020
;; movq %rdi, 8(%rsp)
2121
;; movq %rsi, (%rsp)
2222
;; movl $0, %eax
23+
;; andl $3, %eax
24+
;; cmpl $0, %eax
25+
;; jne 0x53
26+
;; 3d: movl $0, %eax
2327
;; movq 0x60(%r14), %rcx
2428
;; addq %rax, %rcx
2529
;; movl (%rcx), %eax
2630
;; addq $0x10, %rsp
2731
;; popq %rbp
2832
;; retq
29-
;; 40: ud2
33+
;; 51: ud2
34+
;; 53: ud2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
4+
(module
5+
(import "env" "memory" (memory 1 1 shared))
6+
(func (i32.atomic.store (i32.const 0) (i32.const 42))))
7+
;; wasm[0]::function[0]:
8+
;; pushq %rbp
9+
;; movq %rsp, %rbp
10+
;; movq 8(%rdi), %r11
11+
;; movq 0x10(%r11), %r11
12+
;; addq $0x10, %r11
13+
;; cmpq %rsp, %r11
14+
;; ja 0x5c
15+
;; 1c: movq %rdi, %r14
16+
;; subq $0x10, %rsp
17+
;; movq %rdi, 8(%rsp)
18+
;; movq %rsi, (%rsp)
19+
;; movl $0x2a, %eax
20+
;; movl $0, %ecx
21+
;; andl $3, %ecx
22+
;; cmpl $0, %ecx
23+
;; jne 0x5e
24+
;; 42: movl $0, %ecx
25+
;; movq 0x58(%r14), %r11
26+
;; movq (%r11), %rdx
27+
;; addq %rcx, %rdx
28+
;; movl %eax, (%rdx)
29+
;; mfence
30+
;; addq $0x10, %rsp
31+
;; popq %rbp
32+
;; retq
33+
;; 5c: ud2
34+
;; 5e: ud2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
4+
(module
5+
(import "env" "memory" (memory 1 1 shared))
6+
(func (i32.atomic.store16 (i32.const 0) (i32.const 42))))
7+
;; wasm[0]::function[0]:
8+
;; pushq %rbp
9+
;; movq %rsp, %rbp
10+
;; movq 8(%rdi), %r11
11+
;; movq 0x10(%r11), %r11
12+
;; addq $0x10, %r11
13+
;; cmpq %rsp, %r11
14+
;; ja 0x5f
15+
;; 1c: movq %rdi, %r14
16+
;; subq $0x10, %rsp
17+
;; movq %rdi, 8(%rsp)
18+
;; movq %rsi, (%rsp)
19+
;; movl $0x2a, %eax
20+
;; movl $0, %ecx
21+
;; andw $1, %cx
22+
;; cmpw $0, %cx
23+
;; jne 0x61
24+
;; 44: movl $0, %ecx
25+
;; movq 0x58(%r14), %r11
26+
;; movq (%r11), %rdx
27+
;; addq %rcx, %rdx
28+
;; movw %ax, (%rdx)
29+
;; mfence
30+
;; addq $0x10, %rsp
31+
;; popq %rbp
32+
;; retq
33+
;; 5f: ud2
34+
;; 61: ud2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
4+
(module
5+
(import "env" "memory" (memory 1 1 shared))
6+
(func (i32.atomic.store8 (i32.const 0) (i32.const 42))))
7+
;; wasm[0]::function[0]:
8+
;; pushq %rbp
9+
;; movq %rsp, %rbp
10+
;; movq 8(%rdi), %r11
11+
;; movq 0x10(%r11), %r11
12+
;; addq $0x10, %r11
13+
;; cmpq %rsp, %r11
14+
;; ja 0x4b
15+
;; 1c: movq %rdi, %r14
16+
;; subq $0x10, %rsp
17+
;; movq %rdi, 8(%rsp)
18+
;; movq %rsi, (%rsp)
19+
;; movl $0x2a, %eax
20+
;; movl $0, %ecx
21+
;; movq 0x58(%r14), %r11
22+
;; movq (%r11), %rdx
23+
;; addq %rcx, %rdx
24+
;; movb %al, (%rdx)
25+
;; mfence
26+
;; addq $0x10, %rsp
27+
;; popq %rbp
28+
;; retq
29+
;; 4b: ud2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
4+
(module
5+
(import "env" "memory" (memory 1 1 shared))
6+
(func (i64.atomic.store (i32.const 0) (i64.const 42))))
7+
;; wasm[0]::function[0]:
8+
;; pushq %rbp
9+
;; movq %rsp, %rbp
10+
;; movq 8(%rdi), %r11
11+
;; movq 0x10(%r11), %r11
12+
;; addq $0x10, %r11
13+
;; cmpq %rsp, %r11
14+
;; ja 0x61
15+
;; 1c: movq %rdi, %r14
16+
;; subq $0x10, %rsp
17+
;; movq %rdi, 8(%rsp)
18+
;; movq %rsi, (%rsp)
19+
;; movq $0x2a, %rax
20+
;; movl $0, %ecx
21+
;; andq $7, %rcx
22+
;; cmpq $0, %rcx
23+
;; jne 0x63
24+
;; 46: movl $0, %ecx
25+
;; movq 0x58(%r14), %r11
26+
;; movq (%r11), %rdx
27+
;; addq %rcx, %rdx
28+
;; movq %rax, (%rdx)
29+
;; mfence
30+
;; addq $0x10, %rsp
31+
;; popq %rbp
32+
;; retq
33+
;; 61: ud2
34+
;; 63: ud2

0 commit comments

Comments
 (0)