]> git.lizzy.rs Git - rust.git/blobdiff - src/cast.rs
Implement more simd_reduce_* intrinsics
[rust.git] / src / cast.rs
index acec7add7f01cef16c0946901faebaac8b32861a..57204de1135be435c524b2fbbb3ce69d608da6ff 100644 (file)
@@ -1,7 +1,9 @@
+//! Various number casting functions
+
 use crate::prelude::*;
 
 pub(crate) fn clif_intcast(
-    fx: &mut FunctionCx<'_, '_, impl Backend>,
+    fx: &mut FunctionCx<'_, '_, impl Module>,
     val: Value,
     to: Type,
     signed: bool,
@@ -49,7 +51,7 @@ pub(crate) fn clif_intcast(
 }
 
 pub(crate) fn clif_int_or_float_cast(
-    fx: &mut FunctionCx<'_, '_, impl Backend>,
+    fx: &mut FunctionCx<'_, '_, impl Module>,
     from: Value,
     from_signed: bool,
     to_ty: Type,
@@ -86,14 +88,14 @@ pub(crate) fn clif_int_or_float_cast(
             );
 
             let from_rust_ty = if from_signed {
-                fxcodegen_cx.tcx.types.i128
+                fx.tcx.types.i128
             } else {
-                fxcodegen_cx.tcx.types.u128
+                fx.tcx.types.u128
             };
 
             let to_rust_ty = match to_ty {
-                types::F32 => fxcodegen_cx.tcx.types.f32,
-                types::F64 => fxcodegen_cx.tcx.types.f64,
+                types::F32 => fx.tcx.types.f32,
+                types::F64 => fx.tcx.types.f64,
                 _ => unreachable!(),
             };
 
@@ -131,15 +133,15 @@ pub(crate) fn clif_int_or_float_cast(
             );
 
             let from_rust_ty = match from_ty {
-                types::F32 => fxcodegen_cx.tcx.types.f32,
-                types::F64 => fxcodegen_cx.tcx.types.f64,
+                types::F32 => fx.tcx.types.f32,
+                types::F64 => fx.tcx.types.f64,
                 _ => unreachable!(),
             };
 
             let to_rust_ty = if to_signed {
-                fxcodegen_cx.tcx.types.i128
+                fx.tcx.types.i128
             } else {
-                fxcodegen_cx.tcx.types.u128
+                fx.tcx.types.u128
             };
 
             return fx
@@ -179,12 +181,10 @@ pub(crate) fn clif_int_or_float_cast(
                 fx.bcx.ins().select(has_overflow, max_val, val)
             };
             fx.bcx.ins().ireduce(to_ty, val)
+        } else if to_signed {
+            fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
         } else {
-            if to_signed {
-                fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
-            } else {
-                fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
-            }
+            fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
         }
     } else if from_ty.is_float() && to_ty.is_float() {
         // float -> float