Skip to content

Commit 1aa3e03

Browse files
committed
implement SIMD unordered reduction intrinsics
1 parent 6ecd38c commit 1aa3e03

File tree

1 file changed

+28
-4
lines changed
  • compiler/rustc_const_eval/src/interpret/intrinsics

1 file changed

+28
-4
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics/simd.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,39 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
333333
}
334334
self.write_immediate(*res, &dest)?;
335335
}
336-
sym::simd_reduce_add_ordered | sym::simd_reduce_mul_ordered => {
336+
sym::simd_reduce_add_ordered
337+
| sym::simd_reduce_add_unordered
338+
| sym::simd_reduce_mul_ordered
339+
| sym::simd_reduce_mul_unordered => {
337340
use mir::BinOp;
338341

339342
let (op, op_len) = self.project_to_simd(&args[0])?;
340-
let init = self.read_immediate(&args[1])?;
343+
let elem_ty = op.layout.ty.sequence_element_type(*self.tcx);
344+
let elem_layout = self.layout_of(elem_ty).unwrap();
345+
let init = match intrinsic_name {
346+
sym::simd_reduce_add_unordered => ImmTy::from_int(0, elem_layout),
347+
sym::simd_reduce_mul_unordered => match elem_ty.kind() {
348+
ty::Int(_) => ImmTy::from_int(1i128, elem_layout),
349+
ty::Uint(_) => ImmTy::from_uint(1u128, elem_layout),
350+
ty::Float(float_ty) => ImmTy::from_scalar(
351+
match float_ty {
352+
FloatTy::F16 => Scalar::from_f16(Float::from_i128(1).value),
353+
FloatTy::F32 => Scalar::from_f32(Float::from_i128(1).value),
354+
FloatTy::F64 => Scalar::from_f64(Float::from_i128(1).value),
355+
FloatTy::F128 => Scalar::from_f128(Float::from_i128(1).value),
356+
},
357+
elem_layout,
358+
),
359+
_ => unreachable!(
360+
"`{intrinsic_name} called with unsupported SIMD element type `{elem_ty}`"
361+
),
362+
},
363+
_ => self.read_immediate(&args[1])?,
364+
};
341365

342366
let mir_op = match intrinsic_name {
343-
sym::simd_reduce_add_ordered => BinOp::Add,
344-
sym::simd_reduce_mul_ordered => BinOp::Mul,
367+
sym::simd_reduce_add_ordered | sym::simd_reduce_add_unordered => BinOp::Add,
368+
sym::simd_reduce_mul_ordered | sym::simd_reduce_mul_unordered => BinOp::Mul,
345369
_ => unreachable!(),
346370
};
347371

0 commit comments

Comments
 (0)