Skip to content

Commit

Permalink
Winch: Implement rem for aarch64 (bytecodealliance#9781)
Browse files Browse the repository at this point in the history
* implement copy/clone for RemKind

* implement remainder operation for aarch64

* add tests

* fmt pass

* review edits
  • Loading branch information
MarinPostma authored Dec 11, 2024
1 parent 0fabffe commit da41a55
Show file tree
Hide file tree
Showing 23 changed files with 750 additions and 3 deletions.
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_rems/const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 7)
(i32.const 5)
(i32.rem_s)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #5
;; mov w0, w16
;; mov x16, #7
;; mov w1, w16
;; cbz x0, #0x58
;; 34: sxtw x0, w0
;; sxtw x1, w1
;; sdiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_rems/one_zero.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 0)
(i32.rem_s)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #0
;; mov w0, w16
;; mov x16, #1
;; mov w1, w16
;; cbz x0, #0x58
;; 34: sxtw x0, w0
;; sxtw x1, w1
;; sdiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_rems/overflow.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 0x80000000)
(i32.const -1)
(i32.rem_s)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; orr x16, xzr, #0xffffffff
;; mov w0, w16
;; mov x16, #0x80000000
;; mov w1, w16
;; cbz x0, #0x58
;; 34: sxtw x0, w0
;; sxtw x1, w1
;; sdiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_rems/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.rem_s)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x18
;; mov x28, sp
;; stur x0, [x28, #0x10]
;; stur x1, [x28, #8]
;; stur w2, [x28, #4]
;; stur w3, [x28]
;; ldur w0, [x28]
;; ldur w1, [x28, #4]
;; cbz x0, #0x58
;; 34: sxtw x0, w0
;; sxtw x1, w1
;; sdiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_rems/zero_zero.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 0)
(i32.const 0)
(i32.rem_s)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #0
;; mov w0, w16
;; mov x16, #0
;; mov w1, w16
;; cbz x0, #0x58
;; 34: sxtw x0, w0
;; sxtw x1, w1
;; sdiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_remu/const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 7)
(i32.const 5)
(i32.rem_u)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #5
;; mov w0, w16
;; mov x16, #7
;; mov w1, w16
;; cbz x0, #0x58
;; 34: mov w0, w0
;; mov w1, w1
;; udiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_remu/one_zero.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 0)
(i32.rem_u)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #0
;; mov w0, w16
;; mov x16, #1
;; mov w1, w16
;; cbz x0, #0x58
;; 34: mov w0, w0
;; mov w1, w1
;; udiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_remu/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.rem_u)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x18
;; mov x28, sp
;; stur x0, [x28, #0x10]
;; stur x1, [x28, #8]
;; stur w2, [x28, #4]
;; stur w3, [x28]
;; ldur w0, [x28]
;; ldur w1, [x28, #4]
;; cbz x0, #0x58
;; 34: mov w0, w0
;; mov w1, w1
;; udiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_remu/signed.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const -1)
(i32.const -1)
(i32.rem_u)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; orr x16, xzr, #0xffffffff
;; mov w0, w16
;; orr x16, xzr, #0xffffffff
;; mov w1, w16
;; cbz x0, #0x58
;; 34: mov w0, w0
;; mov w1, w1
;; udiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
35 changes: 35 additions & 0 deletions tests/disas/winch/aarch64/i32_remu/zero_zero.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 0)
(i32.const 0)
(i32.rem_u)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #0
;; mov w0, w16
;; mov x16, #0
;; mov w1, w16
;; cbz x0, #0x58
;; 34: mov w0, w0
;; mov w1, w1
;; udiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov w0, w1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 58: .byte 0x1f, 0xc1, 0x00, 0x00
33 changes: 33 additions & 0 deletions tests/disas/winch/aarch64/i64_rems/const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i64)
(i64.const 7)
(i64.const 5)
(i64.rem_s)
)
)

;; wasm[0]::function[0]:
;; stp x29, x30, [sp, #-0x10]!
;; mov x29, sp
;; mov x28, sp
;; mov x9, x0
;; sub sp, sp, #0x10
;; mov x28, sp
;; stur x0, [x28, #8]
;; stur x1, [x28]
;; mov x16, #5
;; mov x0, x16
;; mov x16, #7
;; mov x1, x16
;; cbz x0, #0x50
;; 34: sdiv x16, x1, x0
;; msub x1, x0, x16, x1
;; mov x0, x1
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
;; 50: .byte 0x1f, 0xc1, 0x00, 0x00
Loading

0 comments on commit da41a55

Please sign in to comment.