Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

winch(aarch64): v128 conversion ops (#13955)

Daniel Macoveibccd12218bb4
diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs
index ae1e531bbf..849b0f5742 100644
--- a/crates/test-util/src/wast.rs
+++ b/crates/test-util/src/wast.rs
@@ -530,6 +530,8 @@ impl WastTest {
"misc_testsuite/winch/replace_lane.wast",
"misc_testsuite/simd/v128-equal.wast",
"misc_testsuite/winch/issue-10331.wast",
+ "misc_testsuite/int-to-float-splat.wast",
+ "misc_testsuite/simd/cvt-from-uint.wast",
];
if now_supported.iter().any(|part| self.path.ends_with(part)) {
return false;
@@ -594,8 +596,12 @@ impl WastTest {
"misc_testsuite/winch/replace_lane.wast",
"misc_testsuite/simd/v128-equal.wast",
"misc_testsuite/winch/issue-10331.wast",
+ "misc_testsuite/int-to-float-splat.wast",
+ "misc_testsuite/simd/cvt-from-uint.wast",
"misc_testsuite/simd/v128-select.wast",
"misc_testsuite/winch/issue-10331.wast",
+ "misc_testsuite/int-to-float-splat.wast",
+ "misc_testsuite/simd/cvt-from-uint.wast",
"misc_testsuite/winch/issue-10357.wast",
"misc_testsuite/winch/issue-10460.wast",
"misc_testsuite/winch/replace_lane.wast",
@@ -687,10 +693,14 @@ impl WastTest {
"misc_testsuite/simd/spillslot-size-fuzzbug.wast",
"misc_testsuite/simd/sse-cannot-fold-unaligned-loads.wast",
"misc_testsuite/winch/issue-10331.wast",
+ "misc_testsuite/int-to-float-splat.wast",
+ "misc_testsuite/simd/cvt-from-uint.wast",
"misc_testsuite/winch/replace_lane.wast",
"misc_testsuite/simd/riscv64-replicated-imm5-works.wast",
"misc_testsuite/simd/v128-equal.wast",
"misc_testsuite/winch/issue-10331.wast",
+ "misc_testsuite/int-to-float-splat.wast",
+ "misc_testsuite/simd/cvt-from-uint.wast",
"spec_testsuite/simd_align.wast",
"spec_testsuite/simd_boolean.wast",
"spec_testsuite/simd_conversions.wast",
@@ -732,6 +742,8 @@ impl WastTest {
"misc_testsuite/winch/replace_lane.wast",
"misc_testsuite/simd/v128-equal.wast",
"misc_testsuite/winch/issue-10331.wast",
+ "misc_testsuite/int-to-float-splat.wast",
+ "misc_testsuite/simd/cvt-from-uint.wast",
"multi-memory/simd_memory-multi.wast",
"misc_testsuite/simd/issue4807.wast",
"spec_testsuite/simd_const.wast",
diff --git a/tests/disas/winch/aarch64/v128_ops/f32x4_convert_i32x4_s.wat b/tests/disas/winch/aarch64/v128_ops/f32x4_convert_i32x4_s.wat
new file mode 100644
index 0000000000..78d04e5543
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/f32x4_convert_i32x4_s.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (f32x4.convert_i32x4_s (v128.const i32x4 -1 2 0x80000000 7)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x70
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; scvtf v0.4s, v0.4s
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 70: udf #0xc11f
+;; 74: udf #0
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0xff, 0xff, 0xff, 0xff
+;; 84: udf #2
+;; 88: .byte 0x00, 0x00, 0x00, 0x80
+;; 8c: udf #7
diff --git a/tests/disas/winch/aarch64/v128_ops/f32x4_convert_i32x4_u.wat b/tests/disas/winch/aarch64/v128_ops/f32x4_convert_i32x4_u.wat
new file mode 100644
index 0000000000..04b652222c
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/f32x4_convert_i32x4_u.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (f32x4.convert_i32x4_u (v128.const i32x4 -1 2 0x80000000 7)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x70
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; ucvtf v0.4s, v0.4s
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 70: udf #0xc11f
+;; 74: udf #0
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0xff, 0xff, 0xff, 0xff
+;; 84: udf #2
+;; 88: .byte 0x00, 0x00, 0x00, 0x80
+;; 8c: udf #7
diff --git a/tests/disas/winch/aarch64/v128_ops/f32x4_demote_f64x2_zero.wat b/tests/disas/winch/aarch64/v128_ops/f32x4_demote_f64x2_zero.wat
new file mode 100644
index 0000000000..f66e397af4
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/f32x4_demote_f64x2_zero.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (f32x4.demote_f64x2_zero (v128.const f64x2 1.5 -2.5)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x70
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; fcvtn v0.2s, v0.2d
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 70: udf #0xc11f
+;; 74: udf #0
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: udf #0
+;; 84: .byte 0x00, 0x00, 0xf8, 0x3f
+;; 88: udf #0
+;; 8c: .byte 0x00, 0x00, 0x04, 0xc0
diff --git a/tests/disas/winch/aarch64/v128_ops/f64x2_convert_low_i32x4_s.wat b/tests/disas/winch/aarch64/v128_ops/f64x2_convert_low_i32x4_s.wat
new file mode 100644
index 0000000000..051364cbe6
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/f64x2_convert_low_i32x4_s.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (f64x2.convert_low_i32x4_s (v128.const i32x4 -1 0x80000000 99 99)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x74
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; sshll v0.2d, v0.2s, #0
+;; scvtf v0.2d, v0.2d
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 74: udf #0xc11f
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0xff, 0xff, 0xff, 0xff
+;; 84: .byte 0x00, 0x00, 0x00, 0x80
+;; 88: udf #0x63
+;; 8c: udf #0x63
diff --git a/tests/disas/winch/aarch64/v128_ops/f64x2_convert_low_i32x4_u.wat b/tests/disas/winch/aarch64/v128_ops/f64x2_convert_low_i32x4_u.wat
new file mode 100644
index 0000000000..c90b8b4596
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/f64x2_convert_low_i32x4_u.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (f64x2.convert_low_i32x4_u (v128.const i32x4 -1 0x80000000 99 99)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x74
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; ushll v0.2d, v0.2s, #0
+;; ucvtf v0.2d, v0.2d
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 74: udf #0xc11f
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0xff, 0xff, 0xff, 0xff
+;; 84: .byte 0x00, 0x00, 0x00, 0x80
+;; 88: udf #0x63
+;; 8c: udf #0x63
diff --git a/tests/disas/winch/aarch64/v128_ops/f64x2_promote_low_f32x4.wat b/tests/disas/winch/aarch64/v128_ops/f64x2_promote_low_f32x4.wat
new file mode 100644
index 0000000000..35da4a03fa
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/f64x2_promote_low_f32x4.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (f64x2.promote_low_f32x4 (v128.const f32x4 1.5 -2.5 99 99)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x70
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; fcvtl v0.2d, v0.2s
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 70: udf #0xc11f
+;; 74: udf #0
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0x00, 0x00, 0xc0, 0x3f
+;; 84: .byte 0x00, 0x00, 0x20, 0xc0
+;; 88: .byte 0x00, 0x00, 0xc6, 0x42
+;; 8c: .byte 0x00, 0x00, 0xc6, 0x42
diff --git a/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f32x4_s.wat b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f32x4_s.wat
new file mode 100644
index 0000000000..27ee1e7c4c
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f32x4_s.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (i32x4.trunc_sat_f32x4_s (v128.const f32x4 1.5 -2.7 nan 3e9)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x70
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; fcvtzs v0.4s, v0.4s
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 70: udf #0xc11f
+;; 74: udf #0
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0x00, 0x00, 0xc0, 0x3f
+;; 84: .byte 0xcd, 0xcc, 0x2c, 0xc0
+;; 88: .byte 0x00, 0x00, 0xc0, 0x7f
+;; 8c: .byte 0x5e, 0xd0, 0x32, 0x4f
diff --git a/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f32x4_u.wat b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f32x4_u.wat
new file mode 100644
index 0000000000..f7fb53f602
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f32x4_u.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (i32x4.trunc_sat_f32x4_u (v128.const f32x4 1.5 -2.7 nan 5e9)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x70
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; fcvtzu v0.4s, v0.4s
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 70: udf #0xc11f
+;; 74: udf #0
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0x00, 0x00, 0xc0, 0x3f
+;; 84: .byte 0xcd, 0xcc, 0x2c, 0xc0
+;; 88: .byte 0x00, 0x00, 0xc0, 0x7f
+;; 8c: fmlal v25.4s, v23.4h, v5.h[1]
diff --git a/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f64x2_s_zero.wat b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f64x2_s_zero.wat
new file mode 100644
index 0000000000..c5776dc5c2
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f64x2_s_zero.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (i32x4.trunc_sat_f64x2_s_zero (v128.const f64x2 -3e10 2.9)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x74
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; fcvtzs v0.2d, v0.2d
+;; sqxtn v0.2s, v0.2d
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 74: udf #0xc11f
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: adrp x0, #0x1000
+;; 84: .byte 0x8e, 0xf0, 0x1b, 0xc2
+;; 88: .byte 0x33, 0x33, 0x33, 0x33
+;; 8c: .byte 0x33, 0x33, 0x07, 0x40
diff --git a/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f64x2_u_zero.wat b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f64x2_u_zero.wat
new file mode 100644
index 0000000000..1bf77f6da5
--- /dev/null
+++ b/tests/disas/winch/aarch64/v128_ops/i32x4_trunc_sat_f64x2_u_zero.wat
@@ -0,0 +1,45 @@
+;;! target = "aarch64"
+;;! test = "winch"
+
+(module
+ (memory 1)
+ (func (export "run")
+ (v128.store (i32.const 0)
+ (i32x4.trunc_sat_f64x2_u_zero (v128.const f64x2 5e9 -1)))))
+;; wasm[0]::function[0]:
+;; stp x29, x30, [sp, #-0x10]!
+;; mov x29, sp
+;; str x28, [sp, #-0x10]!
+;; mov x28, sp
+;; ldur x16, [x0, #8]
+;; ldur x16, [x16, #0x18]
+;; mov x17, #0
+;; movk x17, #0x10
+;; add x16, x16, x17
+;; cmp sp, x16
+;; b.lo #0x74
+;; 2c: mov x9, x0
+;; sub x28, x28, #0x10
+;; mov sp, x28
+;; stur x0, [x28, #8]
+;; stur x1, [x28]
+;; ldr q0, #0x80
+;; fcvtzu v0.2d, v0.2d
+;; uqxtn v0.2s, v0.2d
+;; mov x0, #0
+;; ldur x1, [x9, #0x38]
+;; add x1, x1, w0, uxtw
+;; stur q0, [x1]
+;; add x28, x28, #0x10
+;; mov sp, x28
+;; mov sp, x28
+;; ldr x28, [sp], #0x10
+;; ldp x29, x30, [sp], #0x10
+;; ret
+;; 74: udf #0xc11f
+;; 78: udf #0
+;; 7c: udf #0
+;; 80: .byte 0x00, 0x00, 0x00, 0x20
+;; 84: .byte 0x5f, 0xa0, 0xf2, 0x41
+;; 88: udf #0
+;; 8c: .byte 0x00, 0x00, 0xf0, 0xbf
diff --git a/winch/codegen/src/isa/aarch64/asm.rs b/winch/codegen/src/isa/aarch64/asm.rs
index aa2a2912bc..fb1cba0997 100644
--- a/winch/codegen/src/isa/aarch64/asm.rs
+++ b/winch/codegen/src/isa/aarch64/asm.rs
@@ -15,8 +15,8 @@ use crate::{
use cranelift_codegen::isa::aarch64;
use cranelift_codegen::isa::aarch64::inst::emit::{enc_arith_rrr, enc_move_wide, enc_movk};
use cranelift_codegen::isa::aarch64::inst::{
- ASIMDFPModImm, FpuToIntOp, MoveWideConst, NZCV, UImm5, VecALUModOp, VecExtendOp, VecRRNarrowOp,
- VecRRPairLongOp, VecRRRLongOp,
+ ASIMDFPModImm, FpuToIntOp, MoveWideConst, NZCV, UImm5, VecALUModOp, VecExtendOp, VecRRLongOp,
+ VecRRNarrowOp, VecRRPairLongOp, VecRRRLongOp,
};
use cranelift_codegen::{
Final, MachBuffer, MachBufferFinalized, MachInst, MachInstEmit, MachInstEmitState, MachLabel,
@@ -578,6 +578,16 @@ impl Assembler {
});
}
+ /// Vector lengthening operation: widen the low or high half's lanes.
+ pub fn vec_rr_long(&mut self, op: VecRRLongOp, rn: Reg, rd: WritableReg, high_half: bool) {
+ self.emit(Inst::VecRRLong {
+ op,
+ rd: rd.map(Into::into),
+ rn: rn.into(),
+ high_half,
+ });
+ }
+
/// Vector three-register ALU operation whose destination is also an input
pub fn vec_rrr_mod(
&mut self,
diff --git a/winch/codegen/src/isa/aarch64/masm.rs b/winch/codegen/src/isa/aarch64/masm.rs
index 7bba6eaa1a..a7673705de 100644
--- a/winch/codegen/src/isa/aarch64/masm.rs
+++ b/winch/codegen/src/isa/aarch64/masm.rs
@@ -34,8 +34,8 @@ use cranelift_codegen::{
isa::aarch64,
isa::aarch64::inst::{
self, Cond, ExtendOp, Imm12, ImmLogic, ImmShift, SImm7Scaled, SImm9, ScalarSize,
- VecALUModOp, VecALUOp, VecExtendOp, VecLanesOp, VecMisc2, VecRRNarrowOp, VecRRPairLongOp,
- VecRRRLongOp, VectorSize,
+ VecALUModOp, VecALUOp, VecExtendOp, VecLanesOp, VecMisc2, VecRRLongOp, VecRRNarrowOp,
+ VecRRPairLongOp, VecRRRLongOp, VectorSize,
},
settings,
};
@@ -1682,8 +1682,30 @@ impl Masm for MacroAssembler {
Ok(())
}
- fn v128_convert(&mut self, _src: Reg, _dst: WritableReg, _kind: V128ConvertKind) -> Result<()> {
- bail!(CodeGenError::unimplemented_masm_instruction())
+ fn v128_convert(&mut self, src: Reg, dst: WritableReg, kind: V128ConvertKind) -> Result<()> {
+ match kind {
+ V128ConvertKind::I32x4S => {
+ self.asm
+ .vec_misc(VecMisc2::Scvtf, src, dst, VectorSize::Size32x4);
+ }
+ V128ConvertKind::I32x4U => {
+ self.asm
+ .vec_misc(VecMisc2::Ucvtf, src, dst, VectorSize::Size32x4);
+ }
+ V128ConvertKind::I32x4LowS => {
+ self.asm
+ .vec_extend(VecExtendOp::Sxtl, src, dst, false, ScalarSize::Size64);
+ self.asm
+ .vec_misc(VecMisc2::Scvtf, dst.to_reg(), dst, VectorSize::Size64x2);
+ }
+ V128ConvertKind::I32x4LowU => {
+ self.asm
+ .vec_extend(VecExtendOp::Uxtl, src, dst, false, ScalarSize::Size64);
+ self.asm
+ .vec_misc(VecMisc2::Ucvtf, dst.to_reg(), dst, VectorSize::Size64x2);
+ }
+ }
+ Ok(())
}
fn v128_narrow(
@@ -1705,12 +1727,15 @@ impl Masm for MacroAssembler {
Ok(())
}
- fn v128_demote(&mut self, _src: Reg, _dst: WritableReg) -> Result<()> {
- bail!(CodeGenError::unimplemented_masm_instruction())
+ fn v128_demote(&mut self, src: Reg, dst: WritableReg) -> Result<()> {
+ self.asm
+ .vec_narrow(VecRRNarrowOp::Fcvtn, src, dst, false, ScalarSize::Size32);
+ Ok(())
}
- fn v128_promote(&mut self, _src: Reg, _dst: WritableReg) -> Result<()> {
- bail!(CodeGenError::unimplemented_masm_instruction())
+ fn v128_promote(&mut self, src: Reg, dst: WritableReg) -> Result<()> {
+ self.asm.vec_rr_long(VecRRLongOp::Fcvtl32, src, dst, false);
+ Ok(())
}
fn v128_extend(&mut self, src: Reg, dst: WritableReg, kind: V128ExtendKind) -> Result<()> {
@@ -1966,20 +1991,49 @@ impl Masm for MacroAssembler {
context: &mut CodeGenContext<Emission>,
kind: V128TruncKind,
) -> Result<()> {
+ let reg = writable!(context.pop_to_reg(self, None)?.reg);
match kind {
V128TruncKind::F32x4 | V128TruncKind::F64x2 => {
- let reg = writable!(context.pop_to_reg(self, None)?.reg);
self.asm.vec_misc(
VecMisc2::Frintz,
reg.to_reg(),
reg,
VectorSize::from_lane_size(kind.dst_lane_size().into(), true),
);
- context.stack.push(TypedReg::v128(reg.to_reg()).into());
- Ok(())
}
- _ => bail!(CodeGenError::unimplemented_masm_instruction()),
+ V128TruncKind::I32x4FromF32x4S => {
+ self.asm
+ .vec_misc(VecMisc2::Fcvtzs, reg.to_reg(), reg, VectorSize::Size32x4);
+ }
+ V128TruncKind::I32x4FromF32x4U => {
+ self.asm
+ .vec_misc(VecMisc2::Fcvtzu, reg.to_reg(), reg, VectorSize::Size32x4);
+ }
+ V128TruncKind::I32x4FromF64x2SZero => {
+ self.asm
+ .vec_misc(VecMisc2::Fcvtzs, reg.to_reg(), reg, VectorSize::Size64x2);
+ self.asm.vec_narrow(
+ VecRRNarrowOp::Sqxtn,
+ reg.to_reg(),
+ reg,
+ false,
+ ScalarSize::Size32,
+ );
+ }
+ V128TruncKind::I32x4FromF64x2UZero => {
+ self.asm
+ .vec_misc(VecMisc2::Fcvtzu, reg.to_reg(), reg, VectorSize::Size64x2);
+ self.asm.vec_narrow(
+ VecRRNarrowOp::Uqxtn,
+ reg.to_reg(),
+ reg,
+ false,
+ ScalarSize::Size32,
+ );
+ }
}
+ context.stack.push(TypedReg::v128(reg.to_reg()).into());
+ Ok(())
}
fn v128_min(