Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/disas/winch/aarch64/i32_clz/const.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;;! target = "aarch64"
;;! test = "winch"

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

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

(i32.const 10)
(local.tee $foo)

i32.clz
)
)
;; 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, #0xa
;; mov w0, w16
;; stur w0, [x28, #4]
;; clz w0, w0
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
25 changes: 25 additions & 0 deletions tests/disas/winch/aarch64/i32_clz/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;;! target = "aarch64"
;;! test = "winch"

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

(module
(func (result i32)
(local $foo i32)
(i32.const 10)
(local.tee $foo)
i32.ctz
)
)
;; 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, #0xa
;; mov w0, w16
;; stur w0, [x28, #4]
;; rbit w16, w0
;; clz w0, w16
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
26 changes: 26 additions & 0 deletions tests/disas/winch/aarch64/i32_ctz/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;! target = "aarch64"
;;! test = "winch"

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

(module
(func (result i64)
(i64.const 10)
(i64.clz)
)
)
;; 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, #0xa
;; mov x0, x16
;; clz x0, x0
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
32 changes: 32 additions & 0 deletions tests/disas/winch/aarch64/i64_clz/locals.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i64)
(local $foo i64)

(i64.const 10)
(local.tee $foo)

i64.clz
)
)
;; 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, #0xa
;; mov x0, x16
;; stur x0, [x28]
;; clz x0, x0
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
25 changes: 25 additions & 0 deletions tests/disas/winch/aarch64/i64_clz/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;;! target = "aarch64"
;;! test = "winch"

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

(module
(func (result i64)
(i64.const 10)
(i64.ctz)
)
)
;; 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, #0xa
;; mov x0, x16
;; rbit x16, x0
;; clz x0, x16
;; add sp, sp, #0x10
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
33 changes: 33 additions & 0 deletions tests/disas/winch/aarch64/i64_ctz/locals.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (result i64)
(local $foo i64)

(i64.const 10)
(local.tee $foo)

i64.ctz
)
)
;; 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, #0xa
;; mov x0, x16
;; stur x0, [x28]
;; rbit x16, x0
;; clz x0, x16
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
26 changes: 26 additions & 0 deletions tests/disas/winch/aarch64/i64_ctz/params.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;! target = "aarch64"
;;! test = "winch"

(module
(func (param i64) (result i64)
(local.get 0)
(i64.ctz)
)
)
;; 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 x2, [x28]
;; ldur x0, [x28]
;; rbit x16, x0
;; clz x0, x16
;; add sp, sp, #0x18
;; mov x28, sp
;; ldp x29, x30, [sp], #0x10
;; ret
23 changes: 21 additions & 2 deletions winch/codegen/src/isa/aarch64/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::masm::{FloatCmpKind, IntCmpKind, RoundingMode, ShiftKind};
use crate::{masm::OperandSize, reg::Reg};
use cranelift_codegen::isa::aarch64::inst::FPUOpRI::{UShr32, UShr64};
use cranelift_codegen::isa::aarch64::inst::{
Cond, FPULeftShiftImm, FPUOp1, FPUOp2, FPUOpRI, FPUOpRIMod, FPURightShiftImm, FpuRoundMode,
ImmLogic, ImmShift, ScalarSize,
BitOp, Cond, FPULeftShiftImm, FPUOp1, FPUOp2, FPUOpRI, FPUOpRIMod, FPURightShiftImm,
FpuRoundMode, ImmLogic, ImmShift, ScalarSize,
};
use cranelift_codegen::{
ir::{MemFlags, SourceLoc},
Expand Down Expand Up @@ -360,6 +360,16 @@ impl Assembler {
}
}

/// Count Leading Zeros.
pub fn clz(&mut self, rn: Reg, rd: Reg, size: OperandSize) {
self.emit_bit_rr(BitOp::Clz, rn, rd, size);
}

/// Reverse Bits reverses the bit order in a register.
pub fn rbit(&mut self, rn: Reg, rd: Reg, size: OperandSize) {
self.emit_bit_rr(BitOp::RBit, rn, rd, size);
}

/// Float add with three registers.
pub fn fadd_rrr(&mut self, rm: Reg, rn: Reg, rd: Reg, size: OperandSize) {
self.emit_fpu_rrr(FPUOp2::Add, rm, rn, rd, size);
Expand Down Expand Up @@ -595,6 +605,15 @@ impl Assembler {
});
}

fn emit_bit_rr(&mut self, op: BitOp, rn: Reg, rd: Reg, size: OperandSize) {
self.emit(Inst::BitRR {
op,
size: size.into(),
rd: Writable::from_reg(rd.into()),
rn: rn.into(),
});
}

// Convert ShiftKind to ALUOp. If kind == Rotl, then emulate it by emitting
// the negation of the given reg r, and returns ALUOp::RotR.
fn shift_kind_to_alu_op(&mut self, kind: ShiftKind, r: Reg, size: OperandSize) -> ALUOp {
Expand Down
Loading