Skip to content

Commit d78544e

Browse files
eagrXuanwo
andauthored
pulley: Implement iadd_pairwise (bytecodealliance#9912)
* pulley: Implement iadd_pairwise * access by index Co-authored-by: Xuanwo <[email protected]> --------- Co-authored-by: Xuanwo <[email protected]>
1 parent 8d1c6c3 commit d78544e

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@
215215
(if-let neg_u32 (u32_try_from_u64 neg_u64))
216216
neg_u32)
217217

218-
219218
(rule 1 (lower (has_type $I8X16 (iadd a b))) (pulley_vaddi8x16 a b))
220219
(rule 1 (lower (has_type $I16X8 (iadd a b))) (pulley_vaddi16x8 a b))
221220
(rule 1 (lower (has_type $I32X4 (iadd a b))) (pulley_vaddi32x4 a b))
@@ -226,6 +225,11 @@
226225
(rule 1 (lower (has_type $I16X8 (sadd_sat a b))) (pulley_vaddi16x8_sat a b))
227226
(rule 1 (lower (has_type $I16X8 (uadd_sat a b))) (pulley_vaddu16x8_sat a b))
228227

228+
;;;; Rules for `iadd_pairwise` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
229+
230+
(rule (lower (has_type $I16X8 (iadd_pairwise a b))) (pulley_vaddpairwisei16x8_s a b))
231+
(rule (lower (has_type $I32X4 (iadd_pairwise a b))) (pulley_vaddpairwisei32x4_s a b))
232+
229233
;;;; Rules for `isub` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
230234

231235
(rule 0 (lower (has_type (ty_int (fits_in_32 _)) (isub a b))) (pulley_xsub32 a b))

crates/wast-util/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,20 +405,15 @@ impl WastTest {
405405
"misc_testsuite/simd/issue_3327_bnot_lowering.wast",
406406
"misc_testsuite/simd/v128-select.wast",
407407
"spec_testsuite/proposals/relaxed-simd/i32x4_relaxed_trunc.wast",
408-
"spec_testsuite/proposals/relaxed-simd/relaxed_dot_product.wast",
409408
"spec_testsuite/proposals/relaxed-simd/relaxed_madd_nmadd.wast",
410409
"spec_testsuite/proposals/memory64/relaxed_madd_nmadd.wast",
411-
"spec_testsuite/proposals/memory64/relaxed_dot_product.wast",
412410
"spec_testsuite/proposals/memory64/i32x4_relaxed_trunc.wast",
413411
"spec_testsuite/simd_f32x4_arith.wast",
414412
"spec_testsuite/simd_f32x4_cmp.wast",
415413
"spec_testsuite/simd_f32x4_pmin_pmax.wast",
416414
"spec_testsuite/simd_f64x2_arith.wast",
417415
"spec_testsuite/simd_f64x2_cmp.wast",
418416
"spec_testsuite/simd_f64x2_pmin_pmax.wast",
419-
"spec_testsuite/simd_i16x8_extadd_pairwise_i8x16.wast",
420-
"spec_testsuite/simd_i32x4_dot_i16x8.wast",
421-
"spec_testsuite/simd_i32x4_extadd_pairwise_i16x8.wast",
422417
"spec_testsuite/simd_i32x4_trunc_sat_f32x4.wast",
423418
"spec_testsuite/simd_i32x4_trunc_sat_f64x2.wast",
424419
"spec_testsuite/simd_load.wast",

pulley/src/interp.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,6 +3339,31 @@ impl ExtendedOpVisitor for Interpreter<'_> {
33393339
ControlFlow::Continue(())
33403340
}
33413341

3342+
fn vaddpairwisei16x8_s(&mut self, operands: BinaryOperands<VReg>) -> ControlFlow<Done> {
3343+
let a = self.state[operands.src1].get_i16x8();
3344+
let b = self.state[operands.src2].get_i16x8();
3345+
let mut result = [0i16; 8];
3346+
let half = result.len() / 2;
3347+
for i in 0..half {
3348+
result[i] = a[2 * i].wrapping_add(a[2 * i + 1]);
3349+
result[i + half] = b[2 * i].wrapping_add(b[2 * i + 1]);
3350+
}
3351+
self.state[operands.dst].set_i16x8(result);
3352+
ControlFlow::Continue(())
3353+
}
3354+
3355+
fn vaddpairwisei32x4_s(&mut self, operands: BinaryOperands<VReg>) -> ControlFlow<Done> {
3356+
let a = self.state[operands.src1].get_i32x4();
3357+
let b = self.state[operands.src2].get_i32x4();
3358+
let mut result = [0i32; 4];
3359+
result[0] = a[0].wrapping_add(a[1]);
3360+
result[1] = a[2].wrapping_add(a[3]);
3361+
result[2] = b[0].wrapping_add(b[1]);
3362+
result[3] = b[2].wrapping_add(b[3]);
3363+
self.state[operands.dst].set_i32x4(result);
3364+
ControlFlow::Continue(())
3365+
}
3366+
33423367
fn vshli8x16(&mut self, operands: BinaryOperands<VReg, VReg, XReg>) -> ControlFlow<Done> {
33433368
let a = self.state[operands.src1].get_i8x16();
33443369
let b = self.state[operands.src2].get_u32();

pulley/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ macro_rules! for_each_extended_op {
908908
/// `dst = satruating_add(src1, src2)`
909909
vaddu16x8_sat = VAddU16x8Sat { operands: BinaryOperands<VReg> };
910910

911+
/// `dst = [src1[0] + src1[1], ..., src2[6] + src2[7]]`
912+
vaddpairwisei16x8_s = VAddpairwiseI16x8S { operands: BinaryOperands<VReg> };
913+
/// `dst = [src1[0] + src1[1], ..., src2[2] + src2[3]]`
914+
vaddpairwisei32x4_s = VAddpairwiseI32x4S { operands: BinaryOperands<VReg> };
915+
911916
/// `dst = src1 << src2`
912917
vshli8x16 = VShlI8x16 { operands: BinaryOperands<VReg, VReg, XReg> };
913918
/// `dst = src1 << src2`

0 commit comments

Comments
 (0)