winch: Add support for <i32|i64>.rem_* WebAssembly instructions (#5823)

This commit adds support for i32 and i64 remainder instructions for
x64.
This commit is contained in:
Saúl Cabrera
2023-02-20 12:52:06 -05:00
committed by GitHub
parent c26a65a854
commit 4d954f5c0e
25 changed files with 579 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 7)
(i32.const 5)
(i32.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b905000000 mov ecx, 5
;; 9: b807000000 mov eax, 7
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: 83f9ff cmp ecx, -1
;; 1c: 0f850a000000 jne 0x2c
;; 22: b800000000 mov eax, 0
;; 27: e903000000 jmp 0x2f
;; 2c: 99 cdq
;; 2d: f7f9 idiv ecx
;; 2f: 4889d0 mov rax, rdx
;; 32: 5d pop rbp
;; 33: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 1)
(i32.const 0)
(i32.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b900000000 mov ecx, 0
;; 9: b801000000 mov eax, 1
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: 83f9ff cmp ecx, -1
;; 1c: 0f850a000000 jne 0x2c
;; 22: b800000000 mov eax, 0
;; 27: e903000000 jmp 0x2f
;; 2c: 99 cdq
;; 2d: f7f9 idiv ecx
;; 2f: 4889d0 mov rax, rdx
;; 32: 5d pop rbp
;; 33: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 0x80000000)
(i32.const -1)
(i32.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b9ffffffff mov ecx, 0xffffffff
;; 9: b800000080 mov eax, 0x80000000
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: 83f9ff cmp ecx, -1
;; 1c: 0f850a000000 jne 0x2c
;; 22: b800000000 mov eax, 0
;; 27: e903000000 jmp 0x2f
;; 2c: 99 cdq
;; 2d: f7f9 idiv ecx
;; 2f: 4889d0 mov rax, rdx
;; 32: 5d pop rbp
;; 33: c3 ret

View File

@@ -0,0 +1,29 @@
;;! target = "x86_64"
(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.rem_s)
)
)
;; 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: 8b0c24 mov ecx, dword ptr [rsp]
;; 12: 8b442404 mov eax, dword ptr [rsp + 4]
;; 16: 83f900 cmp ecx, 0
;; 19: 0f8502000000 jne 0x21
;; 1f: 0f0b ud2
;; 21: 83f9ff cmp ecx, -1
;; 24: 0f850a000000 jne 0x34
;; 2a: b800000000 mov eax, 0
;; 2f: e903000000 jmp 0x37
;; 34: 99 cdq
;; 35: f7f9 idiv ecx
;; 37: 4889d0 mov rax, rdx
;; 3a: 4883c408 add rsp, 8
;; 3e: 5d pop rbp
;; 3f: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 0)
(i32.const 0)
(i32.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b900000000 mov ecx, 0
;; 9: b800000000 mov eax, 0
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: 83f9ff cmp ecx, -1
;; 1c: 0f850a000000 jne 0x2c
;; 22: b800000000 mov eax, 0
;; 27: e903000000 jmp 0x2f
;; 2c: 99 cdq
;; 2d: f7f9 idiv ecx
;; 2f: 4889d0 mov rax, rdx
;; 32: 5d pop rbp
;; 33: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 7)
(i32.const 5)
(i32.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b905000000 mov ecx, 5
;; 9: b807000000 mov eax, 7
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: ba00000000 mov edx, 0
;; 1e: f7f1 div ecx
;; 20: 4889d0 mov rax, rdx
;; 23: 5d pop rbp
;; 24: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 1)
(i32.const 0)
(i32.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b900000000 mov ecx, 0
;; 9: b801000000 mov eax, 1
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: ba00000000 mov edx, 0
;; 1e: f7f1 div ecx
;; 20: 4889d0 mov rax, rdx
;; 23: 5d pop rbp
;; 24: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.rem_u)
)
)
;; 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: 8b0c24 mov ecx, dword ptr [rsp]
;; 12: 8b442404 mov eax, dword ptr [rsp + 4]
;; 16: 83f900 cmp ecx, 0
;; 19: 0f8502000000 jne 0x21
;; 1f: 0f0b ud2
;; 21: ba00000000 mov edx, 0
;; 26: f7f1 div ecx
;; 28: 4889d0 mov rax, rdx
;; 2b: 4883c408 add rsp, 8
;; 2f: 5d pop rbp
;; 30: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const -1)
(i32.const -1)
(i32.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b9ffffffff mov ecx, 0xffffffff
;; 9: b8ffffffff mov eax, 0xffffffff
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: ba00000000 mov edx, 0
;; 1e: f7f1 div ecx
;; 20: 4889d0 mov rax, rdx
;; 23: 5d pop rbp
;; 24: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i32)
(i32.const 0)
(i32.const 0)
(i32.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: b900000000 mov ecx, 0
;; 9: b800000000 mov eax, 0
;; e: 83f900 cmp ecx, 0
;; 11: 0f8502000000 jne 0x19
;; 17: 0f0b ud2
;; 19: ba00000000 mov edx, 0
;; 1e: f7f1 div ecx
;; 20: 4889d0 mov rax, rdx
;; 23: 5d pop rbp
;; 24: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 7)
(i64.const 5)
(i64.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c105000000 mov rcx, 5
;; b: 48c7c007000000 mov rax, 7
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: 4883f9ff cmp rcx, -1
;; 22: 0f850a000000 jne 0x32
;; 28: b800000000 mov eax, 0
;; 2d: e905000000 jmp 0x37
;; 32: 4899 cqo
;; 34: 48f7f9 idiv rcx
;; 37: 4889d0 mov rax, rdx
;; 3a: 5d pop rbp
;; 3b: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 1)
(i64.const 0)
(i64.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c100000000 mov rcx, 0
;; b: 48c7c001000000 mov rax, 1
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: 4883f9ff cmp rcx, -1
;; 22: 0f850a000000 jne 0x32
;; 28: b800000000 mov eax, 0
;; 2d: e905000000 jmp 0x37
;; 32: 4899 cqo
;; 34: 48f7f9 idiv rcx
;; 37: 4889d0 mov rax, rdx
;; 3a: 5d pop rbp
;; 3b: c3 ret

View File

@@ -0,0 +1,26 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 0x8000000000000000)
(i64.const -1)
(i64.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c1ffffffff mov rcx, 0xffffffffffffffff
;; b: 48b80000000000000080
;; movabs rax, 0x8000000000000000
;; 15: 4883f900 cmp rcx, 0
;; 19: 0f8502000000 jne 0x21
;; 1f: 0f0b ud2
;; 21: 4883f9ff cmp rcx, -1
;; 25: 0f850a000000 jne 0x35
;; 2b: b800000000 mov eax, 0
;; 30: e905000000 jmp 0x3a
;; 35: 4899 cqo
;; 37: 48f7f9 idiv rcx
;; 3a: 4889d0 mov rax, rdx
;; 3d: 5d pop rbp
;; 3e: c3 ret

View File

@@ -0,0 +1,29 @@
;;! target = "x86_64"
(module
(func (param i64) (param i64) (result i64)
(local.get 0)
(local.get 1)
(i64.rem_s)
)
)
;; 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: 488b0c24 mov rcx, qword ptr [rsp]
;; 15: 488b442408 mov rax, qword ptr [rsp + 8]
;; 1a: 4883f900 cmp rcx, 0
;; 1e: 0f8502000000 jne 0x26
;; 24: 0f0b ud2
;; 26: 4883f9ff cmp rcx, -1
;; 2a: 0f850a000000 jne 0x3a
;; 30: b800000000 mov eax, 0
;; 35: e905000000 jmp 0x3f
;; 3a: 4899 cqo
;; 3c: 48f7f9 idiv rcx
;; 3f: 4889d0 mov rax, rdx
;; 42: 4883c410 add rsp, 0x10
;; 46: 5d pop rbp
;; 47: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 0)
(i64.const 0)
(i64.rem_s)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c100000000 mov rcx, 0
;; b: 48c7c000000000 mov rax, 0
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: 4883f9ff cmp rcx, -1
;; 22: 0f850a000000 jne 0x32
;; 28: b800000000 mov eax, 0
;; 2d: e905000000 jmp 0x37
;; 32: 4899 cqo
;; 34: 48f7f9 idiv rcx
;; 37: 4889d0 mov rax, rdx
;; 3a: 5d pop rbp
;; 3b: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 7)
(i64.const 5)
(i64.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c105000000 mov rcx, 5
;; b: 48c7c007000000 mov rax, 7
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: ba00000000 mov edx, 0
;; 23: 48f7f1 div rcx
;; 26: 4889d0 mov rax, rdx
;; 29: 5d pop rbp
;; 2a: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 1)
(i64.const 0)
(i64.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c100000000 mov rcx, 0
;; b: 48c7c001000000 mov rax, 1
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: ba00000000 mov edx, 0
;; 23: 48f7f1 div rcx
;; 26: 4889d0 mov rax, rdx
;; 29: 5d pop rbp
;; 2a: c3 ret

View File

@@ -0,0 +1,25 @@
;;! target = "x86_64"
(module
(func (param i64) (param i64) (result i64)
(local.get 0)
(local.get 1)
(i64.rem_u)
)
)
;; 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: 488b0c24 mov rcx, qword ptr [rsp]
;; 15: 488b442408 mov rax, qword ptr [rsp + 8]
;; 1a: 4883f900 cmp rcx, 0
;; 1e: 0f8502000000 jne 0x26
;; 24: 0f0b ud2
;; 26: ba00000000 mov edx, 0
;; 2b: 48f7f1 div rcx
;; 2e: 4889d0 mov rax, rdx
;; 31: 4883c410 add rsp, 0x10
;; 35: 5d pop rbp
;; 36: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const -1)
(i64.const -1)
(i64.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c1ffffffff mov rcx, 0xffffffffffffffff
;; b: 48c7c0ffffffff mov rax, 0xffffffffffffffff
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: ba00000000 mov edx, 0
;; 23: 48f7f1 div rcx
;; 26: 4889d0 mov rax, rdx
;; 29: 5d pop rbp
;; 2a: c3 ret

View File

@@ -0,0 +1,21 @@
;;! target = "x86_64"
(module
(func (result i64)
(i64.const 0)
(i64.const 0)
(i64.rem_u)
)
)
;; 0: 55 push rbp
;; 1: 4889e5 mov rbp, rsp
;; 4: 48c7c100000000 mov rcx, 0
;; b: 48c7c000000000 mov rax, 0
;; 12: 4883f900 cmp rcx, 0
;; 16: 0f8502000000 jne 0x1e
;; 1c: 0f0b ud2
;; 1e: ba00000000 mov edx, 0
;; 23: 48f7f1 div rcx
;; 26: 4889d0 mov rax, rdx
;; 29: 5d pop rbp
;; 2a: c3 ret