about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-02-16 16:24:38 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2019-02-16 16:24:38 +0100
commit4ecbee2f091cb22ebf191950cc15094a993605df (patch)
treea8b4c9238b56b0dba1a3b4fc5d78f15de6836e84
parentde94b62ba4e27dc0798dbf787a04ed61f0791552 (diff)
downloadrust-4ecbee2f091cb22ebf191950cc15094a993605df.tar.gz
rust-4ecbee2f091cb22ebf191950cc15094a993605df.zip
Implement float -> int/uint cast
-rw-r--r--src/base.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/base.rs b/src/base.rs
index f4766a1fc64..dfa5827e03f 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -518,6 +518,18 @@ fn trans_stmt<'a, 'tcx: 'a>(
                             };
                             lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
                         }
+                        (ty::Float(_), ty::Int(_)) => {
+                            let from = operand.load_scalar(fx);
+                            let i_type = fx.clif_type(to_ty).unwrap();
+                            let res = fx.bcx.ins().fcvt_to_sint_sat(i_type, from);
+                            lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
+                        }
+                        (ty::Float(_), ty::Uint(_)) => {
+                            let from = operand.load_scalar(fx);
+                            let i_type = fx.clif_type(to_ty).unwrap();
+                            let res = fx.bcx.ins().fcvt_to_uint_sat(i_type, from);
+                            lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
+                        }
                         (ty::Int(_), ty::Float(_)) => {
                             let from_ty = fx.clif_type(from_ty).unwrap();
                             let from = operand.load_scalar(fx);