Skip to content

Commit fe5ea39

Browse files
authored
winch: Fix memory.size on maximally-sized 32-bit memories (#12908)
* winch: Fix `memory.size` on maximally-sized 32-bit memories This commit fixes a minor issue in the Winch backend where when a 32-bit linear memory had the full 4GiB size the `memory.size` instruction would return 0 instead of returning `0x1_0000`. This is due to the shift to create the number of pages being done with the index type of the linear memory instead of the pointer size of the machine. * Update test expectations
1 parent f81160c commit fe5ea39

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

tests/disas/winch/x64/load/grow_load.wat

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
;; movq 0x18(%r11), %r11
3535
;; addq $0x70, %r11
3636
;; cmpq %rsp, %r11
37-
;; ja 0x134
37+
;; ja 0x135
3838
;; 1c: movq %rsi, %r14
3939
;; subq $0x60, %rsp
4040
;; movq %rsi, 0x58(%rsp)
@@ -58,7 +58,7 @@
5858
;; subl $1, %eax
5959
;; movl %eax, 0x60(%r14)
6060
;; movq 0x40(%r14), %rax
61-
;; shrl $0x10, %eax
61+
;; shrq $0x10, %rax
6262
;; subq $4, %rsp
6363
;; movl %eax, (%rsp)
6464
;; subq $0xc, %rsp
@@ -74,11 +74,11 @@
7474
;; addq %rax, %rcx
7575
;; addq $0x23024, %rcx
7676
;; movsbq (%rcx), %rax
77-
;; movss 0x5d(%rip), %xmm0
77+
;; movss 0x5c(%rip), %xmm0
7878
;; subq $0xc, %rsp
79-
;; movsd 0x55(%rip), %xmm15
79+
;; movsd 0x54(%rip), %xmm15
8080
;; movsd %xmm15, (%rsp)
81-
;; movss 0x3e(%rip), %xmm15
81+
;; movss 0x3d(%rip), %xmm15
8282
;; movss %xmm15, 8(%rsp)
8383
;; movq 0x14(%rsp), %rax
8484
;; movsd (%rsp), %xmm15
@@ -90,13 +90,12 @@
9090
;; addq $0x60, %rsp
9191
;; popq %rbp
9292
;; retq
93-
;; 134: ud2
94-
;; 136: addb %al, (%rax)
95-
;; 138: addb %al, (%rax)
96-
;; 13a: addb %al, (%rax)
97-
;; 13c: addb %al, (%rax)
98-
;; 13e: addb %al, (%rax)
99-
;; 140: addb %al, (%rax)
100-
;; 142: addb %al, (%rax)
101-
;; 144: addb %al, (%rax)
102-
;; 146: addb %al, (%rax)
93+
;; 135: ud2
94+
;; 137: addb %al, (%rax)
95+
;; 139: addb %al, (%rax)
96+
;; 13b: addb %al, (%rax)
97+
;; 13d: addb %al, (%rax)
98+
;; 13f: addb %al, (%rax)
99+
;; 141: addb %al, (%rax)
100+
;; 143: addb %al, (%rax)
101+
;; 145: addb %al, (%rax)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
;;! hogs_memory = true
22

33
(module
4-
(memory 0xffff)
4+
(memory 0xffff)
55

66
(func (export "grow") (param i32) (result i32)
77
local.get 0
88
memory.grow)
9+
10+
(func (export "size") (result i32)
11+
memory.size)
912
)
1013

1114
(assert_return (invoke "grow" (i32.const 0)) (i32.const 0xffff))
15+
(assert_return (invoke "size") (i32.const 0xffff))
1216
(assert_return (invoke "grow" (i32.const 1)) (i32.const 0xffff))
17+
(assert_return (invoke "size") (i32.const 0x10000))
1318
(assert_return (invoke "grow" (i32.const 0)) (i32.const 0x10000))
1419
(assert_return (invoke "grow" (i32.const 1)) (i32.const -1))

winch/codegen/src/codegen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ where
11001100
Imm::i32(pow as i32),
11011101
dst.into(),
11021102
ShiftKind::ShrU,
1103-
heap_data.index_type().try_into()?,
1103+
self.env.ptr_type().try_into()?,
11041104
)?;
11051105
self.context.stack.push(dst.into());
11061106
Ok(())

0 commit comments

Comments
 (0)