]> git.lizzy.rs Git - rust.git/blobdiff - src/codegen_i128.rs
Start moving away from the intrinsic_match macro
[rust.git] / src / codegen_i128.rs
index 4e50f4d6817ab67c8c4cf2f98f0b7054c329bd17..638b2d573b5ddbe00ae715e12417cde097f12072 100644 (file)
@@ -27,29 +27,53 @@ pub(crate) fn maybe_codegen<'tcx>(
             None
         }
         BinOp::Add | BinOp::Sub if !checked => None,
-        BinOp::Mul if !checked => {
-            let val_ty = if is_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 };
-            if fx.tcx.sess.target.is_like_windows {
-                let ret_place = CPlace::new_stack_slot(fx, lhs.layout());
-                let (lhs_ptr, lhs_extra) = lhs.force_stack(fx);
-                let (rhs_ptr, rhs_extra) = rhs.force_stack(fx);
-                assert!(lhs_extra.is_none());
-                assert!(rhs_extra.is_none());
-                let args =
-                    [ret_place.to_ptr().get_addr(fx), lhs_ptr.get_addr(fx), rhs_ptr.get_addr(fx)];
-                fx.lib_call(
-                    "__multi3",
+        BinOp::Mul if !checked || is_signed => {
+            if !checked {
+                let val_ty = if is_signed { fx.tcx.types.i128 } else { fx.tcx.types.u128 };
+                if fx.tcx.sess.target.is_like_windows {
+                    let ret_place = CPlace::new_stack_slot(fx, lhs.layout());
+                    let (lhs_ptr, lhs_extra) = lhs.force_stack(fx);
+                    let (rhs_ptr, rhs_extra) = rhs.force_stack(fx);
+                    assert!(lhs_extra.is_none());
+                    assert!(rhs_extra.is_none());
+                    let args = [
+                        ret_place.to_ptr().get_addr(fx),
+                        lhs_ptr.get_addr(fx),
+                        rhs_ptr.get_addr(fx),
+                    ];
+                    fx.lib_call(
+                        "__multi3",
+                        vec![
+                            AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
+                            AbiParam::new(fx.pointer_type),
+                            AbiParam::new(fx.pointer_type),
+                        ],
+                        vec![],
+                        &args,
+                    );
+                    Some(ret_place.to_cvalue(fx))
+                } else {
+                    Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
+                }
+            } else {
+                let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
+                let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
+                let lhs = lhs.load_scalar(fx);
+                let rhs = rhs.load_scalar(fx);
+                let oflow_ptr = oflow.to_ptr().get_addr(fx);
+                let res = fx.lib_call(
+                    "__muloti4",
                     vec![
-                        AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
-                        AbiParam::new(fx.pointer_type),
+                        AbiParam::new(types::I128),
+                        AbiParam::new(types::I128),
                         AbiParam::new(fx.pointer_type),
                     ],
-                    vec![],
-                    &args,
-                );
-                Some(ret_place.to_cvalue(fx))
-            } else {
-                Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
+                    vec![AbiParam::new(types::I128)],
+                    &[lhs, rhs, oflow_ptr],
+                )[0];
+                let oflow = oflow.to_cvalue(fx).load_scalar(fx);
+                let oflow = fx.bcx.ins().ireduce(types::I8, oflow);
+                Some(CValue::by_val_pair(res, oflow, fx.layout_of(out_ty)))
             }
         }
         BinOp::Add | BinOp::Sub | BinOp::Mul => {
@@ -85,7 +109,6 @@ pub(crate) fn maybe_codegen<'tcx>(
                 (BinOp::Sub, false) => "__rust_u128_subo",
                 (BinOp::Sub, true) => "__rust_i128_subo",
                 (BinOp::Mul, false) => "__rust_u128_mulo",
-                (BinOp::Mul, true) => "__rust_i128_mulo",
                 _ => unreachable!(),
             };
             fx.lib_call(name, param_types, vec![], &args);