Skip to content

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

Add support for bitwise operations on 64-bit vectors (#11708)

Wardenfarc26e90190cc7
diff --git a/cranelift/codegen/src/isa/aarch64/inst.isle b/cranelift/codegen/src/isa/aarch64/inst.isle
index 14efbfef42..a9b3bdc236 100644
--- a/cranelift/codegen/src/isa/aarch64/inst.isle
+++ b/cranelift/codegen/src/isa/aarch64/inst.isle
@@ -1526,6 +1526,8 @@
(Bic)
;; Bitwise inclusive or
(Orr)
+ ;; Bitwise inclusive or not
+ (Orn)
;; Bitwise exclusive or
(Eor)
;; Unsigned maximum pairwise
@@ -3222,6 +3224,9 @@
(decl orr_vec (Reg Reg VectorSize) Reg)
(rule (orr_vec x y size) (vec_rrr (VecALUOp.Orr) x y size))
+(decl orn_vec (Reg Reg VectorSize) Reg)
+(rule (orn_vec x y size) (vec_rrr (VecALUOp.Orn) x y size))
+
;; Helpers for generating `and` instructions.
(spec (and_reg ty a b)
(provide
diff --git a/cranelift/codegen/src/isa/aarch64/inst/args.rs b/cranelift/codegen/src/isa/aarch64/inst/args.rs
index ee6e885d72..a382a5ef72 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/args.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/args.rs
@@ -613,6 +613,21 @@ pub enum VectorSize {
}
impl VectorSize {
+ /// Get the vector operand of the same size but with 8-bit lane size.
+ pub fn as_scalar8_vector(&self) -> VectorSize {
+ match self {
+ // 64-bit vector
+ VectorSize::Size8x8 | VectorSize::Size16x4 | VectorSize::Size32x2 => {
+ VectorSize::Size8x8
+ }
+ // 128-bit vector
+ VectorSize::Size8x16
+ | VectorSize::Size16x8
+ | VectorSize::Size32x4
+ | VectorSize::Size64x2 => VectorSize::Size8x16,
+ }
+ }
+
/// Get the vector operand size with the given scalar size as lane size.
pub fn from_lane_size(size: ScalarSize, is_128bit: bool) -> VectorSize {
match (size, is_128bit) {
diff --git a/cranelift/codegen/src/isa/aarch64/inst/emit.rs b/cranelift/codegen/src/isa/aarch64/inst/emit.rs
index 8310c41609..db910a650a 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/emit.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/emit.rs
@@ -2672,6 +2672,7 @@ impl MachInstEmit for Inst {
VecALUOp::And => (0b000_01110_00_1, 0b000111),
VecALUOp::Bic => (0b000_01110_01_1, 0b000111),
VecALUOp::Orr => (0b000_01110_10_1, 0b000111),
+ VecALUOp::Orn => (0b000_01110_11_1, 0b000111),
VecALUOp::Eor => (0b001_01110_00_1, 0b000111),
VecALUOp::Umaxp => {
debug_assert_ne!(size, VectorSize::Size64x2);
diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rs
index fdce52eb46..dbff1df1b6 100644
--- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs
+++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs
@@ -2216,10 +2216,6 @@ impl Inst {
VecALUOp::Fcmeq => ("fcmeq", size),
VecALUOp::Fcmgt => ("fcmgt", size),
VecALUOp::Fcmge => ("fcmge", size),
- VecALUOp::And => ("and", VectorSize::Size8x16),
- VecALUOp::Bic => ("bic", VectorSize::Size8x16),
- VecALUOp::Orr => ("orr", VectorSize::Size8x16),
- VecALUOp::Eor => ("eor", VectorSize::Size8x16),
VecALUOp::Umaxp => ("umaxp", size),
VecALUOp::Add => ("add", size),
VecALUOp::Sub => ("sub", size),
@@ -2245,6 +2241,14 @@ impl Inst {
VecALUOp::Uzp2 => ("uzp2", size),
VecALUOp::Trn1 => ("trn1", size),
VecALUOp::Trn2 => ("trn2", size),
+
+ // Lane division does not affect bitwise operations.
+ // However, when printing, use 8-bit lane division to conform to ARM formatting.
+ VecALUOp::And => ("and", size.as_scalar8_vector()),
+ VecALUOp::Bic => ("bic", size.as_scalar8_vector()),
+ VecALUOp::Orr => ("orr", size.as_scalar8_vector()),
+ VecALUOp::Orn => ("orn", size.as_scalar8_vector()),
+ VecALUOp::Eor => ("eor", size.as_scalar8_vector()),
};
let rd = pretty_print_vreg_vector(rd.to_reg(), size);
let rn = pretty_print_vreg_vector(rn, size);
@@ -2376,15 +2380,6 @@ impl Inst {
}
&Inst::VecMisc { op, rd, rn, size } => {
let (op, size, suffix) = match op {
- VecMisc2::Not => (
- "mvn",
- if size.is_128bits() {
- VectorSize::Size8x16
- } else {
- VectorSize::Size8x8
- },
- "",
- ),
VecMisc2::Neg => ("neg", size, ""),
VecMisc2::Abs => ("abs", size, ""),
VecMisc2::Fabs => ("fabs", size, ""),
@@ -2412,6 +2407,10 @@ impl Inst {
VecMisc2::Fcmgt0 => ("fcmgt", size, ", #0.0"),
VecMisc2::Fcmle0 => ("fcmle", size, ", #0.0"),
VecMisc2::Fcmlt0 => ("fcmlt", size, ", #0.0"),
+
+ // Lane division does not affect bitwise operations.
+ // However, when printing, use 8-bit lane division to conform to ARM formatting.
+ VecMisc2::Not => ("mvn", size.as_scalar8_vector(), ""),
};
let rd = pretty_print_vreg_vector(rd.to_reg(), size);
let rn = pretty_print_vreg_vector(rn, size);
diff --git a/cranelift/codegen/src/isa/aarch64/lower.isle b/cranelift/codegen/src/isa/aarch64/lower.isle
index 4efaac2dbc..6feccb82ec 100644
--- a/cranelift/codegen/src/isa/aarch64/lower.isle
+++ b/cranelift/codegen/src/isa/aarch64/lower.isle
@@ -1351,15 +1351,14 @@
;; Note that bitwise negation is implemented here as
;;
;; NOT rd, rm ==> ORR_NOT rd, zero, rm
-(rule bnot_base_case -1 (lower (has_type (fits_in_64 ty) (bnot x)))
+(rule bnot_base_case -3 (lower (has_type (fits_in_64 ty) (bnot x)))
(orr_not ty (zero_reg) x))
-;; Special case to use `orr_not_shift` if it's a `bnot` of a const-left-shifted
-;; value.
-(rule bnot_ishl 1 (lower (has_type (fits_in_64 ty)
- (bnot (ishl x (iconst k)))))
- (if-let amt (lshl_from_imm64 ty k))
- (orr_not_shift ty (zero_reg) x amt))
+;; Implementation of `bnot` for vector types.
+(rule -2 (lower (has_type (ty_vec64 ty) (bnot x)))
+ (not x (vector_size ty)))
+(rule -1 (lower (has_type (ty_vec128 ty) (bnot x)))
+ (not x (vector_size ty)))
;; Implementation of `bnot` for `i128`.
(rule (lower (has_type $I128 (bnot x)))
@@ -1370,9 +1369,12 @@
(new_hi Reg (orr_not $I64 (zero_reg) x_hi)))
(value_regs new_lo new_hi)))
-;; Implementation of `bnot` for vector types.
-(rule -2 (lower (has_type (ty_vec128 ty) (bnot x)))
- (not x (vector_size ty)))
+;; Special case to use `orr_not_shift` if it's a `bnot` of a const-left-shifted
+;; value.
+(rule bnot_ishl 1 (lower (has_type (fits_in_64 ty)
+ (bnot (ishl x (iconst k)))))
+ (if-let amt (lshl_from_imm64 ty k))
+ (orr_not_shift ty (zero_reg) x amt))
;; Special-cases for fusing a bnot with bxor
(rule 2 (lower (has_type (fits_in_64 ty) (bnot (bxor x y))))
@@ -1381,14 +1383,17 @@
;;;; Rules for `band` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(rule band_fits_in_64 -1 (lower (has_type (fits_in_64 ty) (band x y)))
+(rule band_fits_in_64 -3 (lower (has_type (fits_in_64 ty) (band x y)))
(alu_rs_imm_logic_commutative (ALUOp.And) ty x y))
-(rule (lower (has_type $I128 (band x y))) (i128_alu_bitop (ALUOp.And) $I64 x y))
-
-(rule -2 (lower (has_type (ty_vec128 ty) (band x y)))
+;; Implementation of `band` for vector types.
+(rule -2 (lower (has_type (ty_vec64 ty) (band x y)))
+ (and_vec x y (vector_size ty)))
+(rule -1 (lower (has_type (ty_vec128 ty) (band x y)))
(and_vec x y (vector_size ty)))
+(rule (lower (has_type $I128 (band x y))) (i128_alu_bitop (ALUOp.And) $I64 x y))
+
;; Specialized lowerings for `(band x (bnot y))` which is additionally produced
;; by Cranelift's `band_not` instruction that is legalized into the simpler
;; forms early on.
@@ -1407,14 +1412,17 @@
;;;; Rules for `bor` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(rule bor_fits_in_64 -1 (lower (has_type (fits_in_64 ty) (bor x y)))
+(rule bor_fits_in_64 -3 (lower (has_type (fits_in_64 ty) (bor x y)))
(alu_rs_imm_logic_commutative (ALUOp.Orr) ty x y))
-(rule (lower (has_type $I128 (bor x y))) (i128_alu_bitop (ALUOp.Orr) $I64 x y))
-
-(rule -2 (lower (has_type (ty_vec128 ty) (bor x y)))
+;; Implementation of `bor` for vector types.
+(rule -2 (lower (has_type (ty_vec64 ty) (bor x y)))
+ (orr_vec x y (vector_size ty)))
+(rule -1 (lower (has_type (ty_vec128 ty) (bor x y)))
(orr_vec x y (vector_size ty)))
+(rule (lower (has_type $I128 (bor x y))) (i128_alu_bitop (ALUOp.Orr) $I64 x y))
+
;; Specialized lowerings for `(bor x (bnot y))` which is additionally produced
;; by Cranelift's `bor_not` instruction that is legalized into the simpler
;; forms early on.
@@ -1426,6 +1434,17 @@
(rule 3 (lower (has_type $I128 (bor x (bnot y)))) (i128_alu_bitop (ALUOp.OrrNot) $I64 x y))
(rule 4 (lower (has_type $I128 (bor (bnot y) x))) (i128_alu_bitop (ALUOp.OrrNot) $I64 x y))
+(rule bor_not_right_vec64 5 (lower (has_type (ty_vec64 ty) (bor x (bnot y))))
+ (orn_vec x y (vector_size ty)))
+(rule bor_not_left_vec64 6 (lower (has_type (ty_vec64 ty) (bor (bnot y) x)))
+ (orn_vec x y (vector_size ty)))
+
+(rule bor_not_right_vec128 7 (lower (has_type (ty_vec128 ty) (bor x (bnot y))))
+ (orn_vec x y (vector_size ty)))
+(rule bor_not_left_vec128 8 (lower (has_type (ty_vec128 ty) (bor (bnot y) x)))
+ (orn_vec x y (vector_size ty)))
+
+
;; Specialized lowerings to generate the `extr` instruction.
;;
;; The `extr` instruction creates `a:b` and then extracts either 32 or 64-bits
@@ -1448,14 +1467,17 @@
;;;; Rules for `bxor` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(rule bxor_fits_in_64 -1 (lower (has_type (fits_in_64 ty) (bxor x y)))
+(rule bxor_fits_in_64 -3 (lower (has_type (fits_in_64 ty) (bxor x y)))
(alu_rs_imm_logic_commutative (ALUOp.Eor) ty x y))
-(rule (lower (has_type $I128 (bxor x y))) (i128_alu_bitop (ALUOp.Eor) $I64 x y))
-
-(rule -2 (lower (has_type (ty_vec128 ty) (bxor x y)))
+;; Implementation of `bxor` for vector types.
+(rule -2 (lower (has_type (ty_vec64 ty) (bxor x y)))
+ (eor_vec x y (vector_size ty)))
+(rule -1 (lower (has_type (ty_vec128 ty) (bxor x y)))
(eor_vec x y (vector_size ty)))
+(rule (lower (has_type $I128 (bxor x y))) (i128_alu_bitop (ALUOp.Eor) $I64 x y))
+
;; Specialized lowerings for `(bxor x (bnot y))` which is additionally produced
;; by Cranelift's `bxor_not` instruction that is legalized into the simpler
;; forms early on.
diff --git a/cranelift/filetests/filetests/isa/aarch64/bitops.clif b/cranelift/filetests/filetests/isa/aarch64/bitops.clif
index 0a59a5cf73..edc2b0cc39 100644
--- a/cranelift/filetests/filetests/isa/aarch64/bitops.clif
+++ b/cranelift/filetests/filetests/isa/aarch64/bitops.clif
@@ -628,6 +628,38 @@ block0(v0: i8x16):
; mvn v0.16b, v0.16b
; ret
+function %bnot_i8x8(i8x8) -> i8x8 {
+block0(v0: i8x8):
+ v1 = bnot v0
+ return v1
+}
+
+; VCode:
+; block0:
+; mvn v0.8b, v0.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; mvn v0.8b, v0.8b
+; ret
+
+function %bnot_i16x4(i16x4) -> i16x4 {
+block0(v0: i16x4):
+ v1 = bnot v0
+ return v1
+}
+
+; VCode:
+; block0:
+; mvn v0.8b, v0.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; mvn v0.8b, v0.8b
+; ret
+
function %band_i32(i32, i32) -> i32 {
block0(v0: i32, v1: i32):
v2 = band v0, v1
@@ -694,6 +726,38 @@ block0(v0: i8x16, v1: i8x16):
; and v0.16b, v0.16b, v1.16b
; ret
+function %band_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0: i8x8, v1: i8x8):
+ v2 = band v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; and v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; and v0.8b, v0.8b, v1.8b
+; ret
+
+function %band_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0: i16x4, v1: i16x4):
+ v2 = band v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; and v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; and v0.8b, v0.8b, v1.8b
+; ret
+
function %band_i64_constant(i64) -> i64 {
block0(v0: i64):
v1 = iconst.i64 3
@@ -830,6 +894,38 @@ block0(v0: i8x16, v1: i8x16):
; orr v0.16b, v0.16b, v1.16b
; ret
+function %bor_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0: i8x8, v1: i8x8):
+ v2 = bor v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; orr v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; orr v0.8b, v0.8b, v1.8b
+; ret
+
+function %bor_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0: i16x4, v1: i16x4):
+ v2 = bor v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; orr v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; orr v0.8b, v0.8b, v1.8b
+; ret
+
function %bor_i64_constant(i64) -> i64 {
block0(v0: i64):
v1 = iconst.i64 3
@@ -966,6 +1062,38 @@ block0(v0: i8x16, v1: i8x16):
; eor v0.16b, v0.16b, v1.16b
; ret
+function %bxor_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0: i8x8, v1: i8x8):
+ v2 = bxor v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; eor v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; eor v0.8b, v0.8b, v1.8b
+; ret
+
+function %bxor_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0: i16x4, v1: i16x4):
+ v2 = bxor v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; eor v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; eor v0.8b, v0.8b, v1.8b
+; ret
+
function %bxor_i64_constant(i64) -> i64 {
block0(v0: i64):
v1 = iconst.i64 3
@@ -1187,6 +1315,54 @@ block0(v0: i128, v1: i128):
; orn x1, x1, x3
; ret
+function %bor_not_i8x16(i8x16, i8x16) -> i8x16 {
+block0(v0: i8x16, v1: i8x16):
+ v2 = bor_not v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; orn v0.16b, v0.16b, v1.16b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; orn v0.16b, v0.16b, v1.16b
+; ret
+
+function %bor_not_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0: i8x8, v1: i8x8):
+ v2 = bor_not v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; orn v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; orn v0.8b, v0.8b, v1.8b
+; ret
+
+function %bor_not_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0: i16x4, v1: i16x4):
+ v2 = bor_not v0, v1
+ return v2
+}
+
+; VCode:
+; block0:
+; orn v0.8b, v0.8b, v1.8b
+; ret
+;
+; Disassembled:
+; block0: ; offset 0x0
+; orn v0.8b, v0.8b, v1.8b
+; ret
+
function %bor_not_i64_constant(i64) -> i64 {
block0(v0: i64):
v1 = iconst.i64 4
diff --git a/cranelift/filetests/filetests/runtests/simd-band-64bit.clif b/cranelift/filetests/filetests/runtests/simd-band-64bit.clif
new file mode 100644
index 0000000000..1dfb708802
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/simd-band-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_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0:i8x8, v1:i8x8):
+ v2 = band v0, v1
+ return v2
+}
+; run: %band_i8x8([0xFE 0xDC 0xBA 0x98 0x76 0x54 0x32 0x10], [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF]) == [0 0 0 0 0 0 0 0]
+; run: %band_i8x8([0xFE 0xEE 0xFF 0xFF 0xFE 0xEE 0xFF 0xFF], [0xDF 0xDB 0xFF 0xFF 0xDF 0xDB 0xFF 0xFF]) == [0xDE 0xCA 0xFF 0xFF 0xDE 0xCA 0xFF 0xFF]
+
+
+function %band_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0:i16x4, v1:i16x4):
+ v2 = band v0, v1
+ return v2
+}
+; run: %band_i16x4([0xFEDC 0xBA98 0x7654 0x3210], [0x0123 0x4567 0x89AB 0xCDEF]) == [0 0 0 0]
+; run: %band_i16x4([0xFEEE 0xFFFF 0xFEEE 0xFFFF], [0xDFDB 0xFFFF 0xDFDB 0xFFFF]) == [0xDECA 0xFFFF 0xDECA 0xFFFF]
+
+
+function %band_i32x2(i32x2, i32x2) -> i32x2 {
+block0(v0:i32x2, v1:i32x2):
+ v2 = band v0, v1
+ return v2
+}
+; run: %band_i32x2([0xFEDCBA98 0x76543210], [0x01234567 0x89ABCDEF]) == [0 0]
+; run: %band_i32x2([0xFEEEFFFF 0xFEEEFFFF], [0xDFDBFFFF 0xDFDBFFFF]) == [0xDECAFFFF 0xDECAFFFF]
diff --git a/cranelift/filetests/filetests/runtests/simd-bnot-64bit.clif b/cranelift/filetests/filetests/runtests/simd-bnot-64bit.clif
new file mode 100644
index 0000000000..9923fec82d
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/simd-bnot-64bit.clif
@@ -0,0 +1,38 @@
+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 %bnot_i8x8(i8x8) -> i8x8 {
+block0(v0: i8x8):
+ v1 = bnot v0
+ return v1
+}
+; run: %bnot_i8x8(0x0000000000000000) == 0xffffffffffffffff
+; run: %bnot_i8x8(0x1111111111111111) == 0xeeeeeeeeeeeeeeee
+; run: %bnot_i8x8(0x0101001100001111) == 0xfefeffeeffffeeee
+; run: %bnot_i8x8(0x0000000000000000) == 0xffffffffffffffff
+
+function %bnot_i16x4(i16x4) -> i16x4 {
+block0(v0: i16x4):
+ v1 = bnot v0
+ return v1
+}
+; run: %bnot_i16x4(0x0000000000000000) == 0xffffffffffffffff
+; run: %bnot_i16x4(0x1111111111111111) == 0xeeeeeeeeeeeeeeee
+; run: %bnot_i16x4(0x0101001100001111) == 0xfefeffeeffffeeee
+; run: %bnot_i16x4(0x0000000000000000) == 0xffffffffffffffff
+
+function %bnot_i32x2(i32x2) -> i32x2 {
+block0(v0: i32x2):
+ v1 = bnot v0
+ return v1
+}
+; run: %bnot_i32x2(0x0000000000000000) == 0xffffffffffffffff
+; run: %bnot_i32x2(0x1111111111111111) == 0xeeeeeeeeeeeeeeee
+; run: %bnot_i32x2(0x0101001100001111) == 0xfefeffeeffffeeee
+; run: %bnot_i32x2(0x0000000000000000) == 0xffffffffffffffff
diff --git a/cranelift/filetests/filetests/runtests/simd-bor-64bit.clif b/cranelift/filetests/filetests/runtests/simd-bor-64bit.clif
new file mode 100644
index 0000000000..463bd2c790
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/simd-bor-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 %bor_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0:i8x8, v1:i8x8):
+ v2 = bor v0, v1
+ return v2
+}
+; run: %bor_i8x8([0xFE 0xDC 0xBA 0x98 0x76 0x54 0x32 0x10], [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF]) == [0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF]
+; run: %bor_i8x8([0x8A 0x8A 0xAA 0xAA 0x8A 0x8A 0xAA 0xAA], [0x54 0x40 0x55 0x55 0x54 0x40 0x55 0x55]) == [0xDE 0xCA 0xFF 0xFF 0xDE 0xCA 0xFF 0xFF]
+
+
+function %bor_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0:i16x4, v1:i16x4):
+ v2 = bor v0, v1
+ return v2
+}
+; run: %bor_i16x4([0xFEDC 0xBA98 0x7654 0x3210], [0x0123 0x4567 0x89AB 0xCDEF]) == [0xFFFF 0xFFFF 0xFFFF 0xFFFF]
+; run: %bor_i16x4([0x8A8A 0xAAAA 0x8A8A 0xAAAA], [0x5440 0x5555 0x5440 0x5555]) == [0xDECA 0xFFFF 0xDECA 0xFFFF]
+
+
+function %bor_i32x2(i32x2, i32x2) -> i32x2 {
+block0(v0:i32x2, v1:i32x2):
+ v2 = bor v0, v1
+ return v2
+}
+; run: %bor_i32x2([0xFEDCBA98 0x76543210], [0x01234567 0x89ABCDEF]) == [0xFFFFFFFF 0xFFFFFFFF]
+; run: %bor_i32x2([0x8A8AAAAA 0x8A8AAAAA], [0x54405555 0x54405555]) == [0xDECAFFFF 0xDECAFFFF]
diff --git a/cranelift/filetests/filetests/runtests/simd-bornot-64bit.clif b/cranelift/filetests/filetests/runtests/simd-bornot-64bit.clif
new file mode 100644
index 0000000000..651ae2b869
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/simd-bornot-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 %bor_not_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0:i8x8, v1:i8x8):
+ v2 = bor_not v0, v1
+ return v2
+}
+; run: %bor_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: %bor_not_i8x8([0x8A 0x8A 0xAA 0xAA 0x8A 0x8A 0xAA 0xAA], [0x54 0x40 0x55 0x55 0x54 0x40 0x55 0x55]) == [0xAB 0xBF 0xAA 0xAA 0xAB 0xBF 0xAA 0xAA]
+
+
+function %bor_not_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0:i16x4, v1:i16x4):
+ v2 = bor_not v0, v1
+ return v2
+}
+; run: %bor_not_i16x4([0xFEDC 0xBA98 0x7654 0x3210], [0x0123 0x4567 0x89AB 0xCDEF]) == [0xFEDC 0xBA98 0x7654 0x3210]
+; run: %bor_not_i16x4([0x8A8A 0xAAAA 0x8A8A 0xAAAA], [0x5440 0x5555 0x5440 0x5555]) == [0xABBF 0xAAAA 0xABBF 0xAAAA]
+
+
+function %bor_not_i32x2(i32x2, i32x2) -> i32x2 {
+block0(v0:i32x2, v1:i32x2):
+ v2 = bor_not v0, v1
+ return v2
+}
+; run: %bor_not_i32x2([0xFEDCBA98 0x76543210], [0x01234567 0x89ABCDEF]) == [0xFEDCBA98 0x76543210]
+; run: %bor_not_i32x2([0x8A8AAAAA 0x8A8AAAAA], [0x54405555 0x54405555]) == [0xABBFAAAA 0xABBFAAAA]
diff --git a/cranelift/filetests/filetests/runtests/simd-bxor-64bit.clif b/cranelift/filetests/filetests/runtests/simd-bxor-64bit.clif
new file mode 100644
index 0000000000..f131de8de4
--- /dev/null
+++ b/cranelift/filetests/filetests/runtests/simd-bxor-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 %bxor_i8x8(i8x8, i8x8) -> i8x8 {
+block0(v0:i8x8, v1:i8x8):
+ v2 = bxor v0, v1
+ return v2
+}
+; run: %bxor_i8x8([0xFE 0xDC 0xBA 0x98 0x76 0x54 0x32 0x10], [0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF]) == [0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF]
+; run: %bxor_i8x8([0x94 0x40 0xA0 0x7D 0x94 0x40 0xA0 0x7D], [0x4A 0x8A 0x5F 0x82 0x4A 0x8A 0x5F 0x82]) == [0xDE 0xCA 0xFF 0xFF 0xDE 0xCA 0xFF 0xFF]
+
+
+function %bxor_i16x4(i16x4, i16x4) -> i16x4 {
+block0(v0:i16x4, v1:i16x4):
+ v2 = bxor v0, v1
+ return v2
+}
+; run: %bxor_i16x4([0xFEDC 0xBA98 0x7654 0x3210], [0x0123 0x4567 0x89AB 0xCDEF]) == [0xFFFF 0xFFFF 0xFFFF 0xFFFF]
+; run: %bxor_i16x4([0x9440 0xA07D 0x9440 0xA07D], [0x4A8A 0x5F82 0x4A8A 0x5F82]) == [0xDECA 0xFFFF 0xDECA 0xFFFF]
+
+
+function %bxor_i32x2(i32x2, i32x2) -> i32x2 {
+block0(v0:i32x2, v1:i32x2):
+ v2 = bxor v0, v1
+ return v2
+}
+; run: %bxor_i32x2([0xFEDCBA98 0x76543210], [0x01234567 0x89ABCDEF]) == [0xFFFFFFFF 0xFFFFFFFF]
+; run: %bxor_i32x2([0x9440A07D 0x9440A07D], [0x4A8A5F82 0x4A8A5F82]) == [0xDECAFFFF 0xDECAFFFF]
diff --git a/cranelift/interpreter/src/value.rs b/cranelift/interpreter/src/value.rs
index cd9bfbb096..a6987e24d9 100644
--- a/cranelift/interpreter/src/value.rs
+++ b/cranelift/interpreter/src/value.rs
@@ -235,6 +235,13 @@ macro_rules! bitop {
(DataValue::I128(a), DataValue::I128(b)) => DataValue::I128(a $op b),
(DataValue::F32(a), DataValue::F32(b)) => DataValue::F32(a $op b),
(DataValue::F64(a), DataValue::F64(b)) => DataValue::F64(a $op b),
+ (DataValue::V64(a), DataValue::V64(b)) => {
+ let mut a2 = a.clone();
+ for (a, b) in a2.iter_mut().zip(b.iter()) {
+ *a = *a $op *b;
+ }
+ DataValue::V64(a2)
+ }
(DataValue::V128(a), DataValue::V128(b)) => {
let mut a2 = a.clone();
for (a, b) in a2.iter_mut().zip(b.iter()) {
@@ -774,6 +781,12 @@ impl DataValueExt for DataValue {
DataValue::I128(a) => DataValue::I128(!a),
DataValue::F32(a) => DataValue::F32(!a),
DataValue::F64(a) => DataValue::F64(!a),
+ DataValue::V64(mut a) => {
+ for byte in a.iter_mut() {
+ *byte = !*byte;
+ }
+ DataValue::V64(a)
+ }
DataValue::V128(mut a) => {
for byte in a.iter_mut() {
*byte = !*byte;