Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

winch(x64): Ensure correct operand size on memory alignment check (#13337)

Saúl Cabrera5123100095ff
diff --git a/tests/disas/winch/x64/atomic/load/i32_atomic_load16_u.wat b/tests/disas/winch/x64/atomic/load/i32_atomic_load16_u.wat
index 8f190c3b6b..23c7a08f2a 100644
--- a/tests/disas/winch/x64/atomic/load/i32_atomic_load16_u.wat
+++ b/tests/disas/winch/x64/atomic/load/i32_atomic_load16_u.wat
@@ -20,8 +20,8 @@
;; movq %rsi, 0x10(%rsp)
;; movl %edx, 0xc(%rsp)
;; movl 0xc(%rsp), %eax
-;; andw $1, %ax
-;; cmpw $0, %ax
+;; andl $1, %eax
+;; cmpl $0, %eax
;; jne 0x65
;; 46: movl 0xc(%rsp), %eax
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/load/i64_atomic_load.wat b/tests/disas/winch/x64/atomic/load/i64_atomic_load.wat
index 1482297c2c..697736c046 100644
--- a/tests/disas/winch/x64/atomic/load/i64_atomic_load.wat
+++ b/tests/disas/winch/x64/atomic/load/i64_atomic_load.wat
@@ -14,16 +14,16 @@
;; movq 0x18(%r11), %r11
;; addq $0x10, %r11
;; cmpq %rsp, %r11
-;; ja 0x5e
+;; ja 0x5c
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0, %eax
-;; andq $7, %rax
-;; cmpq $0, %rax
-;; jne 0x60
-;; 44: movl $0, %eax
+;; andl $7, %eax
+;; cmpl $0, %eax
+;; jne 0x5e
+;; 42: movl $0, %eax
;; movq 0x38(%r14), %rcx
;; movl %eax, %eax
;; addq %rax, %rcx
@@ -31,5 +31,5 @@
;; addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 5c: ud2
;; 5e: ud2
-;; 60: ud2
diff --git a/tests/disas/winch/x64/atomic/load/i64_atomic_load16_u.wat b/tests/disas/winch/x64/atomic/load/i64_atomic_load16_u.wat
index a27b432cb7..133549a68b 100644
--- a/tests/disas/winch/x64/atomic/load/i64_atomic_load16_u.wat
+++ b/tests/disas/winch/x64/atomic/load/i64_atomic_load16_u.wat
@@ -20,8 +20,8 @@
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0, %eax
-;; andw $1, %ax
-;; cmpw $0, %ax
+;; andl $1, %eax
+;; cmpl $0, %eax
;; jne 0x5f
;; 42: movl $0, %eax
;; movq 0x38(%r14), %rcx
diff --git a/tests/disas/winch/x64/atomic/load/large_offset.wat b/tests/disas/winch/x64/atomic/load/large_offset.wat
new file mode 100644
index 0000000000..1654aba209
--- /dev/null
+++ b/tests/disas/winch/x64/atomic/load/large_offset.wat
@@ -0,0 +1,53 @@
+;;! target = "x86_64"
+;;! test = "winch"
+
+(module
+ (memory 2)
+ (func (export "f") (param i32) (result i32)
+ local.get 0
+ i32.atomic.load16_u offset=0x80000000
+ )
+)
+;; wasm[0]::function[0]:
+;; pushq %rbp
+;; movq %rsp, %rbp
+;; movq 8(%rdi), %r11
+;; movq 0x18(%r11), %r11
+;; addq $0x20, %r11
+;; cmpq %rsp, %r11
+;; ja 0x9c
+;; 1c: movq %rdi, %r14
+;; subq $0x20, %rsp
+;; movq %rdi, 0x18(%rsp)
+;; movq %rsi, 0x10(%rsp)
+;; movl %edx, 0xc(%rsp)
+;; movl 0xc(%rsp), %eax
+;; movl $0x80000000, %r11d
+;; addl %r11d, %eax
+;; andl $1, %eax
+;; cmpl $0, %eax
+;; jne 0x9e
+;; 4f: movl 0xc(%rsp), %eax
+;; movq 0x40(%r14), %rcx
+;; movl %eax, %edx
+;; movl $0x80000002, %r11d
+;; addq %r11, %rdx
+;; jb 0xa0
+;; 68: cmpq %rcx, %rdx
+;; ja 0xa2
+;; 71: movq 0x38(%r14), %rbx
+;; movl %eax, %eax
+;; addq %rax, %rbx
+;; movl $0x80000000, %r11d
+;; addq %r11, %rbx
+;; movl $0, %esi
+;; cmpq %rcx, %rdx
+;; cmovaq %rsi, %rbx
+;; movzwq (%rbx), %rax
+;; addq $0x20, %rsp
+;; popq %rbp
+;; retq
+;; 9c: ud2
+;; 9e: ud2
+;; a0: ud2
+;; a2: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/add/i32_atomic_rmw16_addu.wat b/tests/disas/winch/x64/atomic/rmw/add/i32_atomic_rmw16_addu.wat
index a99c2426dc..cc0edf24a2 100644
--- a/tests/disas/winch/x64/atomic/rmw/add/i32_atomic_rmw16_addu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/add/i32_atomic_rmw16_addu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6c
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw16_addu.wat b/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw16_addu.wat
index 2286d393fc..52c9c73f40 100644
--- a/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw16_addu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw16_addu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6d
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw_add.wat b/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw_add.wat
index 6757431d1a..0d78dcbbf2 100644
--- a/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw_add.wat
+++ b/tests/disas/winch/x64/atomic/rmw/add/i64_atomic_rmw_add.wat
@@ -12,17 +12,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x10, %r11
;; cmpq %rsp, %r11
-;; ja 0x69
+;; ja 0x67
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x6b
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x69
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -31,5 +31,5 @@
;; addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 67: ud2
;; 69: ud2
-;; 6b: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/and/i32_atomic_rmw16_andu.wat b/tests/disas/winch/x64/atomic/rmw/and/i32_atomic_rmw16_andu.wat
index 057896fc79..2216fe92bd 100644
--- a/tests/disas/winch/x64/atomic/rmw/and/i32_atomic_rmw16_andu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/and/i32_atomic_rmw16_andu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x91
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw16_andu.wat b/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw16_andu.wat
index c008dad438..2dd9023fba 100644
--- a/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw16_andu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw16_andu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x80
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw_and.wat b/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw_and.wat
index e314c7be1a..cbb085743c 100644
--- a/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw_and.wat
+++ b/tests/disas/winch/x64/atomic/rmw/and/i64_atomic_rmw_and.wat
@@ -12,17 +12,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x18, %r11
;; cmpq %rsp, %r11
-;; ja 0x7a
+;; ja 0x78
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x7c
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x7a
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -33,9 +33,9 @@
;; movq %rax, %r11
;; andq %rcx, %r11
;; lock cmpxchgq %r11, (%rdx)
-;; jne 0x60
-;; 71: addq $0x10, %rsp
+;; jne 0x5e
+;; 6f: addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 78: ud2
;; 7a: ud2
-;; 7c: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/cmpxchg/i32_atomic_rmw16_cmpxchgu.wat b/tests/disas/winch/x64/atomic/rmw/cmpxchg/i32_atomic_rmw16_cmpxchgu.wat
index 1b6a30c9f4..bc8c92da94 100644
--- a/tests/disas/winch/x64/atomic/rmw/cmpxchg/i32_atomic_rmw16_cmpxchgu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/cmpxchg/i32_atomic_rmw16_cmpxchgu.wat
@@ -20,8 +20,8 @@
;; movl $0x539, %eax
;; movl $0x2a, %ecx
;; movl $0, %edx
-;; andw $1, %dx
-;; cmpw $0, %dx
+;; andl $1, %edx
+;; cmpl $0, %edx
;; jne 0x99
;; 4d: movl $0, %edx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw16_cmpxchgu.wat b/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw16_cmpxchgu.wat
index 14c5d7b0a3..c0cb871d21 100644
--- a/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw16_cmpxchgu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw16_cmpxchgu.wat
@@ -20,8 +20,8 @@
;; movl $0x539, %eax
;; movl $0x2a, %ecx
;; movl $0, %edx
-;; andw $1, %dx
-;; cmpw $0, %dx
+;; andl $1, %edx
+;; cmpl $0, %edx
;; jne 0x76
;; 4d: movl $0, %edx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw_cmpxchg.wat b/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw_cmpxchg.wat
index 08c068ef24..a1a39590ba 100644
--- a/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw_cmpxchg.wat
+++ b/tests/disas/winch/x64/atomic/rmw/cmpxchg/i64_atomic_rmw_cmpxchg.wat
@@ -12,7 +12,7 @@
;; movq 0x18(%r11), %r11
;; addq $0x20, %r11
;; cmpq %rsp, %r11
-;; ja 0x72
+;; ja 0x70
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
@@ -20,10 +20,10 @@
;; movl $0x539, %eax
;; movl $0x2a, %ecx
;; movl $0, %edx
-;; andq $7, %rdx
-;; cmpq $0, %rdx
-;; jne 0x74
-;; 4f: movl $0, %edx
+;; andl $7, %edx
+;; cmpl $0, %edx
+;; jne 0x72
+;; 4d: movl $0, %edx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rbx
;; movl %edx, %edx
@@ -36,5 +36,5 @@
;; addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 70: ud2
;; 72: ud2
-;; 74: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/or/i32_atomic_rmw16_oru.wat b/tests/disas/winch/x64/atomic/rmw/or/i32_atomic_rmw16_oru.wat
index ee570769a8..329eb5169e 100644
--- a/tests/disas/winch/x64/atomic/rmw/or/i32_atomic_rmw16_oru.wat
+++ b/tests/disas/winch/x64/atomic/rmw/or/i32_atomic_rmw16_oru.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x91
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw16_oru.wat b/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw16_oru.wat
index 76a44e3422..cb5c1ee3d6 100644
--- a/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw16_oru.wat
+++ b/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw16_oru.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x80
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw_or.wat b/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw_or.wat
index 7e2aee8a68..c68efac930 100644
--- a/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw_or.wat
+++ b/tests/disas/winch/x64/atomic/rmw/or/i64_atomic_rmw_or.wat
@@ -12,17 +12,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x18, %r11
;; cmpq %rsp, %r11
-;; ja 0x7a
+;; ja 0x78
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x7c
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x7a
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -33,9 +33,9 @@
;; movq %rax, %r11
;; orq %rcx, %r11
;; lock cmpxchgq %r11, (%rdx)
-;; jne 0x60
-;; 71: addq $0x10, %rsp
+;; jne 0x5e
+;; 6f: addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 78: ud2
;; 7a: ud2
-;; 7c: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/sub/i32_atomic_rmw16_subu.wat b/tests/disas/winch/x64/atomic/rmw/sub/i32_atomic_rmw16_subu.wat
index 4d36496e59..bdb0064801 100644
--- a/tests/disas/winch/x64/atomic/rmw/sub/i32_atomic_rmw16_subu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/sub/i32_atomic_rmw16_subu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6f
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw16_subu.wat b/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw16_subu.wat
index 11abf18984..cf0eace16f 100644
--- a/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw16_subu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw16_subu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x70
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw_sub.wat b/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw_sub.wat
index 9b3ad2543e..1d7e8d2e20 100644
--- a/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw_sub.wat
+++ b/tests/disas/winch/x64/atomic/rmw/sub/i64_atomic_rmw_sub.wat
@@ -12,17 +12,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x10, %r11
;; cmpq %rsp, %r11
-;; ja 0x6c
+;; ja 0x6a
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x6e
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x6c
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -32,5 +32,5 @@
;; addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 6a: ud2
;; 6c: ud2
-;; 6e: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/xchg/i32_atomic_rmw16_xchgu.wat b/tests/disas/winch/x64/atomic/rmw/xchg/i32_atomic_rmw16_xchgu.wat
index 5652d7a767..5e3fed76ef 100644
--- a/tests/disas/winch/x64/atomic/rmw/xchg/i32_atomic_rmw16_xchgu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/xchg/i32_atomic_rmw16_xchgu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6a
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw16_xchgu.wat b/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw16_xchgu.wat
index 2d698249f8..be1c50a0c4 100644
--- a/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw16_xchgu.wat
+++ b/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw16_xchgu.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6b
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw_xchg.wat b/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw_xchg.wat
index 72f9400fc6..9af4d5c28f 100644
--- a/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw_xchg.wat
+++ b/tests/disas/winch/x64/atomic/rmw/xchg/i64_atomic_rmw_xchg.wat
@@ -12,17 +12,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x10, %r11
;; cmpq %rsp, %r11
-;; ja 0x67
+;; ja 0x65
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x69
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x67
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -31,5 +31,5 @@
;; addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 65: ud2
;; 67: ud2
-;; 69: ud2
diff --git a/tests/disas/winch/x64/atomic/rmw/xor/i32_atomic_rmw16_xoru.wat b/tests/disas/winch/x64/atomic/rmw/xor/i32_atomic_rmw16_xoru.wat
index 0f2ff36f13..2dd77dbff6 100644
--- a/tests/disas/winch/x64/atomic/rmw/xor/i32_atomic_rmw16_xoru.wat
+++ b/tests/disas/winch/x64/atomic/rmw/xor/i32_atomic_rmw16_xoru.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x91
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw16_xoru.wat b/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw16_xoru.wat
index a97056891f..d557a144e3 100644
--- a/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw16_xoru.wat
+++ b/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw16_xoru.wat
@@ -19,8 +19,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x80
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw_xor.wat b/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw_xor.wat
index ec89efebde..5125257018 100644
--- a/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw_xor.wat
+++ b/tests/disas/winch/x64/atomic/rmw/xor/i64_atomic_rmw_xor.wat
@@ -12,17 +12,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x18, %r11
;; cmpq %rsp, %r11
-;; ja 0x7a
+;; ja 0x78
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x7c
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x7a
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -33,9 +33,9 @@
;; movq %rax, %r11
;; xorq %rcx, %r11
;; lock cmpxchgq %r11, (%rdx)
-;; jne 0x60
-;; 71: addq $0x10, %rsp
+;; jne 0x5e
+;; 6f: addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 78: ud2
;; 7a: ud2
-;; 7c: ud2
diff --git a/tests/disas/winch/x64/atomic/store/i32_atomic_store16.wat b/tests/disas/winch/x64/atomic/store/i32_atomic_store16.wat
index c2f2b03390..b0462762f7 100644
--- a/tests/disas/winch/x64/atomic/store/i32_atomic_store16.wat
+++ b/tests/disas/winch/x64/atomic/store/i32_atomic_store16.wat
@@ -18,8 +18,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6a
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/tests/disas/winch/x64/atomic/store/i64_atomic_store.wat b/tests/disas/winch/x64/atomic/store/i64_atomic_store.wat
index 9f931f720e..776e6e434b 100644
--- a/tests/disas/winch/x64/atomic/store/i64_atomic_store.wat
+++ b/tests/disas/winch/x64/atomic/store/i64_atomic_store.wat
@@ -11,17 +11,17 @@
;; movq 0x18(%r11), %r11
;; addq $0x10, %r11
;; cmpq %rsp, %r11
-;; ja 0x6a
+;; ja 0x68
;; 1c: movq %rdi, %r14
;; subq $0x10, %rsp
;; movq %rdi, 8(%rsp)
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andq $7, %rcx
-;; cmpq $0, %rcx
-;; jne 0x6c
-;; 4a: movl $0, %ecx
+;; andl $7, %ecx
+;; cmpl $0, %ecx
+;; jne 0x6a
+;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
;; movq (%r11), %rdx
;; movl %ecx, %ecx
@@ -31,5 +31,5 @@
;; addq $0x10, %rsp
;; popq %rbp
;; retq
+;; 68: ud2
;; 6a: ud2
-;; 6c: ud2
diff --git a/tests/disas/winch/x64/atomic/store/i64_atomic_store16.wat b/tests/disas/winch/x64/atomic/store/i64_atomic_store16.wat
index 6d64ff49f8..4adc0c894a 100644
--- a/tests/disas/winch/x64/atomic/store/i64_atomic_store16.wat
+++ b/tests/disas/winch/x64/atomic/store/i64_atomic_store16.wat
@@ -18,8 +18,8 @@
;; movq %rsi, (%rsp)
;; movl $0x2a, %eax
;; movl $0, %ecx
-;; andw $1, %cx
-;; cmpw $0, %cx
+;; andl $1, %ecx
+;; cmpl $0, %ecx
;; jne 0x6a
;; 48: movl $0, %ecx
;; movq 0x30(%r14), %r11
diff --git a/winch/codegen/src/codegen/mod.rs b/winch/codegen/src/codegen/mod.rs
index 69a2baf76b..a42776c3b4 100644
--- a/winch/codegen/src/codegen/mod.rs
+++ b/winch/codegen/src/codegen/mod.rs
@@ -669,6 +669,7 @@ where
/// detecting an out of bounds access at compile time.
pub fn emit_compute_heap_address(
&mut self,
+ heap: &HeapData,
memarg: &MemArg,
access_size: OperandSize,
) -> Result<Option<Reg>> {
@@ -678,8 +679,6 @@ where
(access_size.bytes() as u64) + (offset.as_u32() as u64)
};
- let memory_index = MemoryIndex::from_u32(memarg.memory);
- let heap = self.env.resolve_heap(memory_index);
let index = Index::from_typed_reg(self.context.pop_to_reg(self.masm, None)?);
let offset = bounds::ensure_index_and_offset(
@@ -866,10 +865,16 @@ where
Ok(addr)
}
- /// Emit checks to ensure that the address at `memarg` is correctly aligned for `size`.
- fn emit_check_align(&mut self, memarg: &MemArg, size: OperandSize) -> Result<()> {
- if size.bytes() > 1 {
- // Peek addr from top of the stack by popping and pushing.
+ /// Emit checks to ensure that the address at `memarg` is
+ /// correctly aligned for the access size.
+ fn emit_check_align(
+ &mut self,
+ heap: &HeapData,
+ memarg: &MemArg,
+ access_size: OperandSize,
+ ) -> Result<()> {
+ if access_size.bytes() > 1 {
+ let heap_ty_size: OperandSize = heap.index_type().try_into()?;
let addr = *self
.context
.stack
@@ -883,18 +888,18 @@ where
writable!(tmp),
tmp,
RegImm::Imm(Imm::I64(memarg.offset)),
- size,
+ heap_ty_size,
)?;
}
self.masm.and(
writable!(tmp),
tmp,
- RegImm::Imm(Imm::I32(size.bytes() - 1)),
- size,
+ RegImm::Imm(Imm::I32(access_size.bytes() - 1)),
+ heap_ty_size,
)?;
- self.masm.cmp(tmp, RegImm::Imm(Imm::i64(0)), size)?;
+ self.masm.cmp(tmp, RegImm::Imm(Imm::i64(0)), heap_ty_size)?;
self.masm.trapif(IntCmpKind::Ne, TRAP_HEAP_MISALIGNED)?;
self.context.free_reg(tmp);
}
@@ -904,11 +909,12 @@ where
pub fn emit_compute_heap_address_align_checked(
&mut self,
+ heap: &HeapData,
memarg: &MemArg,
access_size: OperandSize,
) -> Result<Option<Reg>> {
- self.emit_check_align(memarg, access_size)?;
- self.emit_compute_heap_address(memarg, access_size)
+ self.emit_check_align(heap, memarg, access_size)?;
+ self.emit_compute_heap_address(heap, memarg, access_size)
}
/// Emit a WebAssembly load.
@@ -928,6 +934,9 @@ where
Ok(())
};
+ let memory_index = MemoryIndex::from_u32(arg.memory);
+ let heap = self.env.resolve_heap(memory_index);
+
// Ensure that the destination register is not allocated if
// `emit_compute_heap_address` does not return an address.
match kind {
@@ -936,7 +945,8 @@ where
// `emit_compute_heap_address` expects an integer register
// containing the address to load to be at the top of the stack.
let dst = self.context.pop_to_reg(self.masm, None)?;
- let addr = self.emit_compute_heap_address(&arg, kind.derive_operand_size())?;
+ let addr =
+ self.emit_compute_heap_address(&heap, &arg, kind.derive_operand_size())?;
if let Some(addr) = addr {
emit_load(self, dst.reg, addr, kind)?;
} else {
@@ -946,10 +956,11 @@ where
_ => {
let maybe_addr = match kind {
LoadKind::Atomic(_, _) => self.emit_compute_heap_address_align_checked(
+ &heap,
&arg,
kind.derive_operand_size(),
)?,
- _ => self.emit_compute_heap_address(&arg, kind.derive_operand_size())?,
+ _ => self.emit_compute_heap_address(&heap, &arg, kind.derive_operand_size())?,
};
if let Some(addr) = maybe_addr {
@@ -970,12 +981,16 @@ where
/// Emit a WebAssembly store.
pub fn emit_wasm_store(&mut self, arg: &MemArg, kind: StoreKind) -> Result<()> {
+ let memory_index = MemoryIndex::from_u32(arg.memory);
+ let heap = self.env.resolve_heap(memory_index);
let src = self.context.pop_to_reg(self.masm, None)?;
let maybe_addr = match kind {
- StoreKind::Atomic(size) => self.emit_compute_heap_address_align_checked(&arg, size)?,
+ StoreKind::Atomic(size) => {
+ self.emit_compute_heap_address_align_checked(&heap, &arg, size)?
+ }
StoreKind::Operand(size) | StoreKind::VectorLane(LaneSelector { size, .. }) => {
- self.emit_compute_heap_address(&arg, size)?
+ self.emit_compute_heap_address(&heap, &arg, size)?
}
};
@@ -1396,11 +1411,13 @@ where
size: OperandSize,
extend: Option<Extend<Zero>>,
) -> Result<()> {
+ let memory_index = MemoryIndex::from_u32(arg.memory);
+ let heap = self.env.resolve_heap(memory_index);
// We need to pop-push the operand to compute the address before passing control over to
// masm, because some architectures may have specific requirements for the registers used
// in some atomic operations.
let operand = self.context.pop_to_reg(self.masm, None)?;
- if let Some(addr) = self.emit_compute_heap_address_align_checked(arg, size)? {
+ if let Some(addr) = self.emit_compute_heap_address_align_checked(&heap, arg, size)? {
let src = self.masm.address_at_reg(addr, 0)?;
self.context.stack.push(operand.into());
self.masm
@@ -1437,7 +1454,9 @@ where
let replacement = self.context.pop_to_reg(self.masm, None)?;
let expected = self.context.pop_to_reg(self.masm, None)?;
- if let Some(addr) = self.emit_compute_heap_address_align_checked(arg, size)? {
+ let memory_index = MemoryIndex::from_u32(arg.memory);
+ let heap = self.env.resolve_heap(memory_index);
+ if let Some(addr) = self.emit_compute_heap_address_align_checked(&heap, arg, size)? {
self.context.stack.push(expected.into());
self.context.stack.push(replacement.into());