@@ -62,9 +62,8 @@ pub(crate) fn maybe_codegen<'tcx>(
6262 }
6363}
6464
65- pub ( crate ) fn maybe_codegen_checked < ' tcx > (
65+ pub ( crate ) fn maybe_codegen_mul_checked < ' tcx > (
6666 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
67- bin_op : BinOp ,
6867 lhs : CValue < ' tcx > ,
6968 rhs : CValue < ' tcx > ,
7069) -> Option < CValue < ' tcx > > {
@@ -78,25 +77,19 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
7877
7978 let is_signed = type_sign ( lhs. layout ( ) . ty ) ;
8079
81- match bin_op {
82- BinOp :: Add | BinOp :: Sub => None ,
83- BinOp :: Mul => {
84- let out_ty = Ty :: new_tup ( fx. tcx , & [ lhs. layout ( ) . ty , fx. tcx . types . bool ] ) ;
85- let out_place = CPlace :: new_stack_slot ( fx, fx. layout_of ( out_ty) ) ;
86- let param_types = vec ! [
87- AbiParam :: special( fx. pointer_type, ArgumentPurpose :: StructReturn ) ,
88- AbiParam :: new( types:: I128 ) ,
89- AbiParam :: new( types:: I128 ) ,
90- ] ;
91- let args = [ out_place. to_ptr ( ) . get_addr ( fx) , lhs. load_scalar ( fx) , rhs. load_scalar ( fx) ] ;
92- fx. lib_call (
93- if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" } ,
94- param_types,
95- vec ! [ ] ,
96- & args,
97- ) ;
98- Some ( out_place. to_cvalue ( fx) )
99- }
100- _ => bug ! ( "binop {:?} on checked int/uint lhs: {:?} rhs: {:?}" , bin_op, lhs, rhs) ,
101- }
80+ let out_ty = Ty :: new_tup ( fx. tcx , & [ lhs. layout ( ) . ty , fx. tcx . types . bool ] ) ;
81+ let out_place = CPlace :: new_stack_slot ( fx, fx. layout_of ( out_ty) ) ;
82+ let param_types = vec ! [
83+ AbiParam :: special( fx. pointer_type, ArgumentPurpose :: StructReturn ) ,
84+ AbiParam :: new( types:: I128 ) ,
85+ AbiParam :: new( types:: I128 ) ,
86+ ] ;
87+ let args = [ out_place. to_ptr ( ) . get_addr ( fx) , lhs. load_scalar ( fx) , rhs. load_scalar ( fx) ] ;
88+ fx. lib_call (
89+ if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" } ,
90+ param_types,
91+ vec ! [ ] ,
92+ & args,
93+ ) ;
94+ Some ( out_place. to_cvalue ( fx) )
10295}
0 commit comments