Skip to content

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

Add support for 'band not' on 64-bit vectors (#11728)

Wardenfar15b93f7c8866
diff --git a/cranelift/codegen/src/isa/aarch64/lower.isle b/cranelift/codegen/src/isa/aarch64/lower.isle
index 6feccb82ec..f304e5c620 100644
--- a/cranelift/codegen/src/isa/aarch64/lower.isle
+++ b/cranelift/codegen/src/isa/aarch64/lower.isle
@@ -1405,9 +1405,14 @@
(rule 3 (lower (has_type $I128 (band x (bnot y)))) (i128_alu_bitop (ALUOp.AndNot) $I64 x y))
(rule 4 (lower (has_type $I128 (band (bnot y) x))) (i128_alu_bitop (ALUOp.AndNot) $I64 x y))
-(rule 5 (lower (has_type (ty_vec128 ty) (band x (bnot y))))
+(rule 5 (lower (has_type (ty_vec64 ty) (band x (bnot y))))
(bic_vec x y (vector_size ty)))
-(rule 6 (lower (has_type (ty_vec128 ty) (band (bnot y) x)))
+(rule 6 (lower (has_type (ty_vec64 ty) (band (bnot y) x)))
+ (bic_vec x y (vector_size ty)))
+
+(rule 7 (lower (has_type (ty_vec128 ty) (band x (bnot y))))
+ (bic_vec x y (vector_size ty)))
+(rule 8 (lower (has_type (ty_vec128 ty) (band (bnot y) x)))
(bic_vec x y (vector_size ty)))
;;;; Rules for `bor` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/cranelift/filetests/filetests/isa/aarch64/bitops.clif b/cranelift/filetests/filetests/isa/aarch64/bitops.clif
index edc2b0cc39..d81abbb028 100644
--- a/cranelift/filetests/filetests/isa/aarch64/bitops.clif
+++ b/cranelift/filetests/filetests/isa/aarch64/bitops.clif
@@ -1230,6 +1230,38 @@ block0(v0: i8x16, v1: i8x16):
; bic v0.16b, v0.16b, v1.16b
; ret
+function %band_not_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0: i8x8, v1: i8x8):
+ v2 = band_not v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; bic v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; bic v0.8b, v0.8b, v1.8b
+; ret
+
+function %band_not_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0: i16x4, v1: i16x4):
+ v2 = band_not v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; bic v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; bic v0.8b, v0.8b, v1.8b
+; ret
+
function %band_not_i64_constant(i64) -> i64 {
block0(v0: i64):
v1 = iconst.i64 4
diff --git a/cranelift/filetests/filetests/runtests/simd-bandnot-64bit.clif b/cranelift/filetests/filetests/runtests/simd-bandnot-64bit.clif
new file mode 100644
index 0000000000..28ba165759
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/simd-bandnot-64bit.clif
@@ -0,0 +1,34 @@
+test interpret
+test run
+target aarch64
+set enable_multi_ret_implicit_sret
+target riscv64 has_v
+target riscv64 has_v has_c has_zcb
+; s390x and x86_64 do not support 64-bit vectors.
+
+
+function %band_not_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0:i8x8, v1:i8x8):
+ v2 = band_not v0, v1
+ return v2
+}
+; run: %band_not_i8x8([0xFE 0xDC 0xBA 0x98 0x76 0x54 0x32 0x10], [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF]) == [0xFE 0xDC 0xBA 0x98 0x76 0x54 0x32 0x10]
+; run: %band_not_i8x8([0xFE 0xEE 0xFF 0xFF 0xFE 0xEE 0xFF 0xFF], [0xDF 0xDB 0xFF 0xFF 0xDF 0xDB 0xFF 0xFF]) == [0x20 0x24 0x00 0x00 0x20 0x24 0x00 0x00]
+
+
+function %band_not_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0:i16x4, v1:i16x4):
+ v2 = band_not v0, v1
+ return v2
+}
+; run: %band_not_i16x4([0xFEDC 0xBA98 0x7654 0x3210], [0x0123 0x4567 0x89AB 0xCDEF]) == [0xFEDC 0xBA98 0x7654 0x3210]
+; run: %band_not_i16x4([0xFEEE 0xFFFF 0xFEEE 0xFFFF], [0xDFDB 0xFFFF 0xDFDB 0xFFFF]) == [0x2024 0x0000 0x2024 0x0000]
+
+
+function %band_not_i32x2(i32x2, i32x2) -> i32x2 {
+block0(v0:i32x2, v1:i32x2):
+ v2 = band_not v0, v1
+ return v2
+}
+; run: %band_not_i32x2([0xFEDCBA98 0x76543210], [0x01234567 0x89ABCDEF]) == [0xFEDCBA98 0x76543210]
+; run: %band_not_i32x2([0xFEEEFFFF 0xFEEEFFFF], [0xDFDBFFFF 0xDFDBFFFF]) == [0x20240000 0x20240000]