3 pub fn clif_intcast<'a, 'tcx: 'a>(
4 fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
9 let from = fx.bcx.func.dfg.value_type(val);
12 (_, _) if from == to => val,
16 let wider = if from == types::I64 {
19 fx.bcx.ins().sextend(types::I64, val)
21 fx.bcx.ins().uextend(types::I64, val)
23 let zero = fx.bcx.ins().iconst(types::I64, 0);
24 fx.bcx.ins().iconcat(wider, zero)
26 (_, _) if to.wider_or_equal(from) => {
28 fx.bcx.ins().sextend(to, val)
30 fx.bcx.ins().uextend(to, val)
36 let (lsb, _msb) = fx.bcx.ins().isplit(val);
40 fx.bcx.ins().ireduce(to, lsb)
44 fx.bcx.ins().ireduce(to, val)
49 pub fn clif_int_or_float_cast(
50 fx: &mut FunctionCx<'_, '_, impl Backend>,
55 let from_ty = fx.bcx.func.dfg.value_type(from);
57 if from_ty.is_int() && to_ty.is_int() {
58 // int-like -> int-like
65 } else if from_ty.is_int() && to_ty.is_float() {
68 fx.bcx.ins().fcvt_from_sint(to_ty, from)
70 fx.bcx.ins().fcvt_from_uint(to_ty, from)
72 } else if from_ty.is_float() && to_ty.is_int() {
75 fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
77 fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
79 } else if from_ty.is_float() && to_ty.is_float() {
81 match (from_ty, to_ty) {
82 (types::F32, types::F64) => {
83 fx.bcx.ins().fpromote(types::F64, from)
85 (types::F64, types::F32) => {
86 fx.bcx.ins().fdemote(types::F32, from)
91 unreachable!("cast value from {:?} to {:?}", from_ty, to_ty);