winch: Add support for integer multiplication in x64. (#5769)
This commit adds support for the `<i32|i64>.mul` WebAssembly instructions in x64.
This commit is contained in:
15
winch/filetests/filetests/x64/i32_mul/const.wat
Normal file
15
winch/filetests/filetests/x64/i32_mul/const.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i32)
|
||||
(i32.const 10)
|
||||
(i32.const 20)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: b80a000000 mov eax, 0xa
|
||||
;; 9: 6bc014 imul eax, eax, 0x14
|
||||
;; c: 5d pop rbp
|
||||
;; d: c3 ret
|
||||
33
winch/filetests/filetests/x64/i32_mul/locals.wat
Normal file
33
winch/filetests/filetests/x64/i32_mul/locals.wat
Normal file
@@ -0,0 +1,33 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i32)
|
||||
(local $foo i32)
|
||||
(local $bar i32)
|
||||
|
||||
(i32.const 10)
|
||||
(local.set $foo)
|
||||
|
||||
(i32.const 20)
|
||||
(local.set $bar)
|
||||
|
||||
(local.get $foo)
|
||||
(local.get $bar)
|
||||
i32.mul
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 4883ec08 sub rsp, 8
|
||||
;; 8: 48c7042400000000 mov qword ptr [rsp], 0
|
||||
;; 10: b80a000000 mov eax, 0xa
|
||||
;; 15: 89442404 mov dword ptr [rsp + 4], eax
|
||||
;; 19: b814000000 mov eax, 0x14
|
||||
;; 1e: 890424 mov dword ptr [rsp], eax
|
||||
;; 21: 8b0424 mov eax, dword ptr [rsp]
|
||||
;; 24: 8b4c2404 mov ecx, dword ptr [rsp + 4]
|
||||
;; 28: 0fafc8 imul ecx, eax
|
||||
;; 2b: 4889c8 mov rax, rcx
|
||||
;; 2e: 4883c408 add rsp, 8
|
||||
;; 32: 5d pop rbp
|
||||
;; 33: c3 ret
|
||||
14
winch/filetests/filetests/x64/i32_mul/max.wat
Normal file
14
winch/filetests/filetests/x64/i32_mul/max.wat
Normal file
@@ -0,0 +1,14 @@
|
||||
;;! target = "x86_64"
|
||||
(module
|
||||
(func (result i32)
|
||||
(i32.const 0x7fffffff)
|
||||
(i32.const -1)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: b8ffffff7f mov eax, 0x7fffffff
|
||||
;; 9: 6bc0ff imul eax, eax, -1
|
||||
;; c: 5d pop rbp
|
||||
;; d: c3 ret
|
||||
15
winch/filetests/filetests/x64/i32_mul/max_one.wat
Normal file
15
winch/filetests/filetests/x64/i32_mul/max_one.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i32)
|
||||
(i32.const 0x80000000)
|
||||
(i32.const -1)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: b800000080 mov eax, 0x80000000
|
||||
;; 9: 6bc0ff imul eax, eax, -1
|
||||
;; c: 5d pop rbp
|
||||
;; d: c3 ret
|
||||
15
winch/filetests/filetests/x64/i32_mul/mixed.wat
Normal file
15
winch/filetests/filetests/x64/i32_mul/mixed.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i32)
|
||||
(i32.const -1)
|
||||
(i32.const 1)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: b8ffffffff mov eax, 0xffffffff
|
||||
;; 9: 6bc001 imul eax, eax, 1
|
||||
;; c: 5d pop rbp
|
||||
;; d: c3 ret
|
||||
21
winch/filetests/filetests/x64/i32_mul/params.wat
Normal file
21
winch/filetests/filetests/x64/i32_mul/params.wat
Normal file
@@ -0,0 +1,21 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (param i32) (param i32) (result i32)
|
||||
(local.get 0)
|
||||
(local.get 1)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 4883ec08 sub rsp, 8
|
||||
;; 8: 897c2404 mov dword ptr [rsp + 4], edi
|
||||
;; c: 893424 mov dword ptr [rsp], esi
|
||||
;; f: 8b0424 mov eax, dword ptr [rsp]
|
||||
;; 12: 8b4c2404 mov ecx, dword ptr [rsp + 4]
|
||||
;; 16: 0fafc8 imul ecx, eax
|
||||
;; 19: 4889c8 mov rax, rcx
|
||||
;; 1c: 4883c408 add rsp, 8
|
||||
;; 20: 5d pop rbp
|
||||
;; 21: c3 ret
|
||||
15
winch/filetests/filetests/x64/i32_mul/signed.wat
Normal file
15
winch/filetests/filetests/x64/i32_mul/signed.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i32)
|
||||
(i32.const -1)
|
||||
(i32.const -1)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: b8ffffffff mov eax, 0xffffffff
|
||||
;; 9: 6bc0ff imul eax, eax, -1
|
||||
;; c: 5d pop rbp
|
||||
;; d: c3 ret
|
||||
15
winch/filetests/filetests/x64/i32_mul/unsigned_with_zero.wat
Normal file
15
winch/filetests/filetests/x64/i32_mul/unsigned_with_zero.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i32)
|
||||
(i32.const 1)
|
||||
(i32.const 0)
|
||||
(i32.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: b801000000 mov eax, 1
|
||||
;; 9: 6bc000 imul eax, eax, 0
|
||||
;; c: 5d pop rbp
|
||||
;; d: c3 ret
|
||||
15
winch/filetests/filetests/x64/i64_mul/const.wat
Normal file
15
winch/filetests/filetests/x64/i64_mul/const.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i64)
|
||||
(i64.const 10)
|
||||
(i64.const 20)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 48c7c00a000000 mov rax, 0xa
|
||||
;; b: 486bc014 imul rax, rax, 0x14
|
||||
;; f: 5d pop rbp
|
||||
;; 10: c3 ret
|
||||
35
winch/filetests/filetests/x64/i64_mul/locals.wat
Normal file
35
winch/filetests/filetests/x64/i64_mul/locals.wat
Normal file
@@ -0,0 +1,35 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i64)
|
||||
(local $foo i64)
|
||||
(local $bar i64)
|
||||
|
||||
(i64.const 10)
|
||||
(local.set $foo)
|
||||
|
||||
(i64.const 20)
|
||||
(local.set $bar)
|
||||
|
||||
(local.get $foo)
|
||||
(local.get $bar)
|
||||
i64.mul
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 4883ec10 sub rsp, 0x10
|
||||
;; 8: 4531db xor r11d, r11d
|
||||
;; b: 4c895c2408 mov qword ptr [rsp + 8], r11
|
||||
;; 10: 4c891c24 mov qword ptr [rsp], r11
|
||||
;; 14: 48c7c00a000000 mov rax, 0xa
|
||||
;; 1b: 4889442408 mov qword ptr [rsp + 8], rax
|
||||
;; 20: 48c7c014000000 mov rax, 0x14
|
||||
;; 27: 48890424 mov qword ptr [rsp], rax
|
||||
;; 2b: 488b0424 mov rax, qword ptr [rsp]
|
||||
;; 2f: 488b4c2408 mov rcx, qword ptr [rsp + 8]
|
||||
;; 34: 480fafc8 imul rcx, rax
|
||||
;; 38: 4889c8 mov rax, rcx
|
||||
;; 3b: 4883c410 add rsp, 0x10
|
||||
;; 3f: 5d pop rbp
|
||||
;; 40: c3 ret
|
||||
15
winch/filetests/filetests/x64/i64_mul/max.wat
Normal file
15
winch/filetests/filetests/x64/i64_mul/max.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
(module
|
||||
(func (result i64)
|
||||
(i64.const 0x7fffffffffffffff)
|
||||
(i64.const -1)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 48b8ffffffffffffff7f
|
||||
;; movabs rax, 0x7fffffffffffffff
|
||||
;; e: 486bc0ff imul rax, rax, -1
|
||||
;; 12: 5d pop rbp
|
||||
;; 13: c3 ret
|
||||
16
winch/filetests/filetests/x64/i64_mul/max_one.wat
Normal file
16
winch/filetests/filetests/x64/i64_mul/max_one.wat
Normal file
@@ -0,0 +1,16 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i64)
|
||||
(i64.const 0x8000000000000000)
|
||||
(i64.const -1)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 48b80000000000000080
|
||||
;; movabs rax, 0x8000000000000000
|
||||
;; e: 486bc0ff imul rax, rax, -1
|
||||
;; 12: 5d pop rbp
|
||||
;; 13: c3 ret
|
||||
15
winch/filetests/filetests/x64/i64_mul/mixed.wat
Normal file
15
winch/filetests/filetests/x64/i64_mul/mixed.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i64)
|
||||
(i64.const -1)
|
||||
(i64.const 1)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 48c7c0ffffffff mov rax, 0xffffffffffffffff
|
||||
;; b: 486bc001 imul rax, rax, 1
|
||||
;; f: 5d pop rbp
|
||||
;; 10: c3 ret
|
||||
21
winch/filetests/filetests/x64/i64_mul/params.wat
Normal file
21
winch/filetests/filetests/x64/i64_mul/params.wat
Normal file
@@ -0,0 +1,21 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (param i64) (param i64) (result i64)
|
||||
(local.get 0)
|
||||
(local.get 1)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 4883ec10 sub rsp, 0x10
|
||||
;; 8: 48897c2408 mov qword ptr [rsp + 8], rdi
|
||||
;; d: 48893424 mov qword ptr [rsp], rsi
|
||||
;; 11: 488b0424 mov rax, qword ptr [rsp]
|
||||
;; 15: 488b4c2408 mov rcx, qword ptr [rsp + 8]
|
||||
;; 1a: 480fafc8 imul rcx, rax
|
||||
;; 1e: 4889c8 mov rax, rcx
|
||||
;; 21: 4883c410 add rsp, 0x10
|
||||
;; 25: 5d pop rbp
|
||||
;; 26: c3 ret
|
||||
15
winch/filetests/filetests/x64/i64_mul/signed.wat
Normal file
15
winch/filetests/filetests/x64/i64_mul/signed.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i64)
|
||||
(i64.const -1)
|
||||
(i64.const -1)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 48c7c0ffffffff mov rax, 0xffffffffffffffff
|
||||
;; b: 486bc0ff imul rax, rax, -1
|
||||
;; f: 5d pop rbp
|
||||
;; 10: c3 ret
|
||||
15
winch/filetests/filetests/x64/i64_mul/unsigned_with_zero.wat
Normal file
15
winch/filetests/filetests/x64/i64_mul/unsigned_with_zero.wat
Normal file
@@ -0,0 +1,15 @@
|
||||
;;! target = "x86_64"
|
||||
|
||||
(module
|
||||
(func (result i64)
|
||||
(i64.const 1)
|
||||
(i64.const 0)
|
||||
(i64.mul)
|
||||
)
|
||||
)
|
||||
;; 0: 55 push rbp
|
||||
;; 1: 4889e5 mov rbp, rsp
|
||||
;; 4: 48c7c001000000 mov rax, 1
|
||||
;; b: 486bc000 imul rax, rax, 0
|
||||
;; f: 5d pop rbp
|
||||
;; 10: c3 ret
|
||||
Reference in New Issue
Block a user