4 fx: &mut FunctionCx<'_, '_, 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>,
56 let from_ty = fx.bcx.func.dfg.value_type(from);
58 if from_ty.is_int() && to_ty.is_int() {
59 // int-like -> int-like
64 from_signed, // FIXME is this correct?
66 } else if from_ty.is_int() && to_ty.is_float() {
69 fx.bcx.ins().fcvt_from_sint(to_ty, from)
71 fx.bcx.ins().fcvt_from_uint(to_ty, from)
73 } else if from_ty.is_float() && to_ty.is_int() {
75 if to_ty == types::I8 || to_ty == types::I16 {
76 // FIXME implement fcvt_to_*int_sat.i8/i16
77 let val = if to_signed {
78 fx.bcx.ins().fcvt_to_sint_sat(types::I32, from)
80 fx.bcx.ins().fcvt_to_uint_sat(types::I32, from)
82 let (min, max) = type_min_max_value(to_ty, to_signed);
83 let min_val = fx.bcx.ins().iconst(types::I32, min);
84 let max_val = fx.bcx.ins().iconst(types::I32, max);
86 let val = if to_signed {
87 let has_underflow = fx.bcx.ins().icmp_imm(
88 IntCC::SignedLessThan,
92 let has_overflow = fx.bcx.ins().icmp_imm(
93 IntCC::SignedGreaterThan,
97 let bottom_capped = fx.bcx.ins().select(has_underflow, min_val, val);
98 fx.bcx.ins().select(has_overflow, max_val, bottom_capped)
100 let has_overflow = fx.bcx.ins().icmp_imm(
101 IntCC::UnsignedGreaterThan,
105 fx.bcx.ins().select(has_overflow, max_val, val)
107 fx.bcx.ins().ireduce(to_ty, val)
110 fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
112 fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
115 } else if from_ty.is_float() && to_ty.is_float() {
117 match (from_ty, to_ty) {
118 (types::F32, types::F64) => {
119 fx.bcx.ins().fpromote(types::F64, from)
121 (types::F64, types::F32) => {
122 fx.bcx.ins().fdemote(types::F32, from)
127 unreachable!("cast value from {:?} to {:?}", from_ty, to_ty);