Skip to content

Commit

Permalink
winch(arm64): and, or, xor, shifts (bytecodealliance#8921)
Browse files Browse the repository at this point in the history
* winch(arm64): and, or, xor, shifts

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* fmt

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* docs

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* shift

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* shifts: test cases

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* cleanup

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* apply first batch of suggestions

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* refactor shift operations

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* fix doc strings

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>

* Minor cleanups

This commit includes very minor clean-ups, these are mechanical changes
only.

* Rename `shift_rr` to `shift`, as we're still passing the context in,
  the callee can decide what to do with the instruction arguments.

* Delete the un-used `Into<AluOp> for ShiftKind`

---------

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Saúl Cabrera <saulecabrera@gmail.com>
  • Loading branch information
evacchi and saulecabrera authored Jul 16, 2024
1 parent 88b45a4 commit c69ab34
Show file tree
Hide file tree
Showing 68 changed files with 2,235 additions and 82 deletions.
26 changes: 26 additions & 0 deletions tests/disas/winch/aarch64/i32_and/const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 2)
(i32.and)
)
)
;; 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, #1
;; mov w0, w16
;; and w0, w0, #2
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
44 changes: 44 additions & 0 deletions tests/disas/winch/aarch64/i32_and/locals.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(local $foo i32)
(local $bar i32)

(i32.const 1)
(local.set $foo)

(i32.const 2)
(local.set $bar)

(local.get $foo)
(local.get $bar)
(i32.and)
)
)
;; 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]
;; mov x16, #0
;; stur x16, [x28]
;; mov x16, #1
;; mov w0, w16
;; stur w0, [x28, #4]
;; mov x16, #2
;; mov w0, w16
;; stur w0, [x28]
;; ldur w0, [x28]
;; ldur w1, [x28, #4]
;; and w1, w1, w0
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
29 changes: 29 additions & 0 deletions tests/disas/winch/aarch64/i32_and/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.and)
)
)
;; 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]
;; and w1, w1, w0
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
26 changes: 26 additions & 0 deletions tests/disas/winch/aarch64/i32_or/const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 2)
(i32.or)
)
)
;; 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, #1
;; mov w0, w16
;; orr w0, w0, #2
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
44 changes: 44 additions & 0 deletions tests/disas/winch/aarch64/i32_or/locals.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(local $foo i32)
(local $bar i32)

(i32.const 1)
(local.set $foo)

(i32.const 2)
(local.set $bar)

(local.get $foo)
(local.get $bar)
(i32.or)
)
)
;; 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]
;; mov x16, #0
;; stur x16, [x28]
;; mov x16, #1
;; mov w0, w16
;; stur w0, [x28, #4]
;; mov x16, #2
;; mov w0, w16
;; stur w0, [x28]
;; ldur w0, [x28]
;; ldur w1, [x28, #4]
;; orr w1, w1, w0
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
29 changes: 29 additions & 0 deletions tests/disas/winch/aarch64/i32_or/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.or)
)
)
;; 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]
;; orr w1, w1, w0
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
28 changes: 28 additions & 0 deletions tests/disas/winch/aarch64/i32_rotl/16_const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 512)
(i32.rotl)
)
)
;; 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, #1
;; mov w0, w16
;; sub w0, w0, wzr
;; mov x16, #0x200
;; ror w0, w0, w16
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
27 changes: 27 additions & 0 deletions tests/disas/winch/aarch64/i32_rotl/8_const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 2)
(i32.rotl)
)
)
;; 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, #1
;; mov w0, w16
;; sub w0, w0, wzr
;; ror w0, w0, #2
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
45 changes: 45 additions & 0 deletions tests/disas/winch/aarch64/i32_rotl/locals.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(local $foo i32)
(local $bar i32)

(i32.const 1)
(local.set $foo)

(i32.const 2)
(local.set $bar)

(local.get $foo)
(local.get $bar)
(i32.rotl)
)
)
;; 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]
;; mov x16, #0
;; stur x16, [x28]
;; mov x16, #1
;; mov w0, w16
;; stur w0, [x28, #4]
;; mov x16, #2
;; mov w0, w16
;; stur w0, [x28]
;; ldur w0, [x28]
;; ldur w1, [x28, #4]
;; sub w0, w0, wzr
;; ror w1, w1, w0
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
30 changes: 30 additions & 0 deletions tests/disas/winch/aarch64/i32_rotl/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (param i32) (param i32) (result i32)
(local.get 0)
(local.get 1)
(i32.rotl)
)
)
;; 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]
;; sub w0, w0, wzr
;; ror w1, w1, w0
;; mov w0, w1
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
27 changes: 27 additions & 0 deletions tests/disas/winch/aarch64/i32_rotr/16_const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 512)
(i32.rotr)
)
)
;; 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, #1
;; mov w0, w16
;; mov x16, #0x200
;; ror w0, w0, w16
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
26 changes: 26 additions & 0 deletions tests/disas/winch/aarch64/i32_rotr/8_const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i32)
(i32.const 1)
(i32.const 2)
(i32.rotr)
)
)
;; 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, #1
;; mov w0, w16
;; ror w0, w0, #2
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
Loading

0 comments on commit c69ab34

Please sign in to comment.