@@ -17,18 +17,11 @@ fn sqrt<'tcx, F: Float + FloatConvert<F> + Into<Scalar>>(
1717}
1818
1919/// Determine which float operation on which type this is.
20- fn is_host_unary_float_op ( intrinsic_name : & str ) -> Option < ( FloatTy , HostUnaryFloatOp ) > {
21- let ( op, ty) = intrinsic_name. rsplit_once ( 'f' ) ?;
22-
23- let float_ty = match ty {
24- "16" => FloatTy :: F16 ,
25- "32" => FloatTy :: F32 ,
26- "64" => FloatTy :: F64 ,
27- "128" => FloatTy :: F128 ,
28- _ => return None ,
29- } ;
30-
31- let host_float_op = match op {
20+ fn is_host_unary_float_op (
21+ intrinsic_name : & str ,
22+ generic_args : ty:: GenericArgsRef < ' _ > ,
23+ ) -> Option < ( FloatTy , HostUnaryFloatOp ) > {
24+ let host_float_op = match intrinsic_name {
3225 "sin" => HostUnaryFloatOp :: Sin ,
3326 "cos" => HostUnaryFloatOp :: Cos ,
3427 "exp" => HostUnaryFloatOp :: Exp ,
@@ -39,6 +32,9 @@ fn is_host_unary_float_op(intrinsic_name: &str) -> Option<(FloatTy, HostUnaryFlo
3932 _ => return None ,
4033 } ;
4134
35+ let ty:: Float ( float_ty) = * generic_args. type_at ( 0 ) . kind ( ) else {
36+ bug ! ( "`{intrinsic_name}` intrinsic called on non-float type" ) ;
37+ } ;
4238 Some ( ( float_ty, host_float_op) )
4339}
4440
@@ -96,7 +92,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
9692 fn emulate_math_intrinsic (
9793 & mut self ,
9894 intrinsic_name : & str ,
99- _generic_args : ty:: GenericArgsRef < ' tcx > ,
95+ generic_args : ty:: GenericArgsRef < ' tcx > ,
10096 args : & [ OpTy < ' tcx > ] ,
10197 dest : & PlaceTy < ' tcx > ,
10298 ) -> InterpResult < ' tcx , EmulateItemResult > {
@@ -179,7 +175,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
179175 }
180176
181177 // Operations that need host floats.
182- _ if let Some ( ( float_ty, op) ) = is_host_unary_float_op ( intrinsic_name) => {
178+ _ if let Some ( ( float_ty, op) ) =
179+ is_host_unary_float_op ( intrinsic_name, generic_args) =>
180+ {
183181 let [ f] = check_intrinsic_arg_count ( args) ?;
184182 match float_ty {
185183 FloatTy :: F16 => host_unary_float_op :: < HalfS > ( this, f, op, dest) ?,
0 commit comments