Skip to content

Commit c81b6a9

Browse files
authored
pulley: Implement simd vector negation (bytecodealliance#9865)
Filling out some more miscellaneous `*.wast` tests
1 parent e4c27ae commit c81b6a9

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

cranelift/codegen/src/isa/pulley_shared/lower.isle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,13 @@
11621162
(rule 0 (lower (has_type (fits_in_32 _) (ineg a))) (pulley_xneg32 (sext32 a)))
11631163
(rule 1 (lower (has_type $I64 (ineg a))) (pulley_xneg64 a))
11641164

1165+
;; vector negation
1166+
1167+
(rule 1 (lower (has_type $I8X16 (ineg a))) (pulley_vneg8x16 a))
1168+
(rule 1 (lower (has_type $I16X8 (ineg a))) (pulley_vneg16x8 a))
1169+
(rule 1 (lower (has_type $I32X4 (ineg a))) (pulley_vneg32x4 a))
1170+
(rule 1 (lower (has_type $I64X2 (ineg a))) (pulley_vneg64x2 a))
1171+
11651172
;;;; Rules for `fabs` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11661173

11671174
(rule (lower (has_type $F32 (fabs a))) (pulley_fabs32 a))

cranelift/filetests/filetests/runtests/simd-ineg.clif

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ target x86_64 skylake
77
set enable_multi_ret_implicit_sret
88
target riscv64 has_v
99
target riscv64 has_v has_c has_zcb
10+
target pulley32
11+
target pulley32be
12+
target pulley64
13+
target pulley64be
1014

1115
function %ineg_i8x16(i8x16) -> i8x16 {
1216
block0(v0: i8x16):

crates/wast-util/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,20 +428,16 @@ impl WastTest {
428428
"spec_testsuite/simd_f64x2_cmp.wast",
429429
"spec_testsuite/simd_f64x2_pmin_pmax.wast",
430430
"spec_testsuite/simd_f64x2_rounding.wast",
431-
"spec_testsuite/simd_i16x8_arith.wast",
432431
"spec_testsuite/simd_i16x8_arith2.wast",
433432
"spec_testsuite/simd_i16x8_extadd_pairwise_i8x16.wast",
434433
"spec_testsuite/simd_i16x8_q15mulr_sat_s.wast",
435434
"spec_testsuite/simd_i16x8_sat_arith.wast",
436-
"spec_testsuite/simd_i32x4_arith.wast",
437435
"spec_testsuite/simd_i32x4_arith2.wast",
438436
"spec_testsuite/simd_i32x4_dot_i16x8.wast",
439437
"spec_testsuite/simd_i32x4_extadd_pairwise_i16x8.wast",
440438
"spec_testsuite/simd_i32x4_trunc_sat_f32x4.wast",
441439
"spec_testsuite/simd_i32x4_trunc_sat_f64x2.wast",
442-
"spec_testsuite/simd_i64x2_arith.wast",
443440
"spec_testsuite/simd_i64x2_arith2.wast",
444-
"spec_testsuite/simd_i8x16_arith.wast",
445441
"spec_testsuite/simd_i8x16_arith2.wast",
446442
"spec_testsuite/simd_i8x16_sat_arith.wast",
447443
"spec_testsuite/simd_lane.wast",

pulley/src/interp.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,4 +4055,28 @@ impl ExtendedOpVisitor for Interpreter<'_> {
40554055
self.state[operands.dst].set_u64x2(c);
40564056
ControlFlow::Continue(())
40574057
}
4058+
4059+
fn vneg8x16(&mut self, dst: VReg, src: VReg) -> ControlFlow<Done> {
4060+
let a = self.state[src].get_i8x16();
4061+
self.state[dst].set_i8x16(a.map(|i| i.wrapping_neg()));
4062+
ControlFlow::Continue(())
4063+
}
4064+
4065+
fn vneg16x8(&mut self, dst: VReg, src: VReg) -> ControlFlow<Done> {
4066+
let a = self.state[src].get_i16x8();
4067+
self.state[dst].set_i16x8(a.map(|i| i.wrapping_neg()));
4068+
ControlFlow::Continue(())
4069+
}
4070+
4071+
fn vneg32x4(&mut self, dst: VReg, src: VReg) -> ControlFlow<Done> {
4072+
let a = self.state[src].get_i32x4();
4073+
self.state[dst].set_i32x4(a.map(|i| i.wrapping_neg()));
4074+
ControlFlow::Continue(())
4075+
}
4076+
4077+
fn vneg64x2(&mut self, dst: VReg, src: VReg) -> ControlFlow<Done> {
4078+
let a = self.state[src].get_i64x2();
4079+
self.state[dst].set_i64x2(a.map(|i| i.wrapping_neg()));
4080+
ControlFlow::Continue(())
4081+
}
40584082
}

pulley/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,15 @@ macro_rules! for_each_extended_op {
11071107
vult64x2 = Vult64x2 { operands: BinaryOperands<VReg> };
11081108
/// `dst = src <= dst` (unsigned)
11091109
vulteq64x2 = Vulteq64x2 { operands: BinaryOperands<VReg> };
1110+
1111+
/// `dst = -src`
1112+
vneg8x16 = Vneg8x16 { dst: VReg, src: VReg };
1113+
/// `dst = -src`
1114+
vneg16x8 = Vneg16x8 { dst: VReg, src: VReg };
1115+
/// `dst = -src`
1116+
vneg32x4 = Vneg32x4 { dst: VReg, src: VReg };
1117+
/// `dst = -src`
1118+
vneg64x2 = Vneg64x2 { dst: VReg, src: VReg };
11101119
}
11111120
};
11121121
}

0 commit comments

Comments
 (0)