1
Fork 0

Implement simd_reduce_{min,max} for floats

This commit is contained in:
bjorn3 2021-11-18 19:27:49 +01:00
parent a8be7ea503
commit d288c6924d

View file

@ -405,27 +405,27 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
}; };
simd_reduce_min, (c v) { simd_reduce_min, (c v) {
// FIXME support floats
validate_simd_type!(fx, intrinsic, span, v.layout().ty); validate_simd_type!(fx, intrinsic, span, v.layout().ty);
simd_reduce(fx, v, None, ret, |fx, layout, a, b| { simd_reduce(fx, v, None, ret, |fx, layout, a, b| {
let lt = fx.bcx.ins().icmp(if layout.ty.is_signed() { let lt = match layout.ty.kind() {
IntCC::SignedLessThan ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedLessThan, a, b),
} else { ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedLessThan, a, b),
IntCC::UnsignedLessThan ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::LessThan, a, b),
}, a, b); _ => unreachable!(),
};
fx.bcx.ins().select(lt, a, b) fx.bcx.ins().select(lt, a, b)
}); });
}; };
simd_reduce_max, (c v) { simd_reduce_max, (c v) {
// FIXME support floats
validate_simd_type!(fx, intrinsic, span, v.layout().ty); validate_simd_type!(fx, intrinsic, span, v.layout().ty);
simd_reduce(fx, v, None, ret, |fx, layout, a, b| { simd_reduce(fx, v, None, ret, |fx, layout, a, b| {
let gt = fx.bcx.ins().icmp(if layout.ty.is_signed() { let gt = match layout.ty.kind() {
IntCC::SignedGreaterThan ty::Int(_) => fx.bcx.ins().icmp(IntCC::SignedGreaterThan, a, b),
} else { ty::Uint(_) => fx.bcx.ins().icmp(IntCC::UnsignedGreaterThan, a, b),
IntCC::UnsignedGreaterThan ty::Float(_) => fx.bcx.ins().fcmp(FloatCC::GreaterThan, a, b),
}, a, b); _ => unreachable!(),
};
fx.bcx.ins().select(gt, a, b) fx.bcx.ins().select(gt, a, b)
}); });
}; };