@@ -5,7 +5,6 @@ use std::{cmp, iter};
55use rand:: RngCore ;
66use rustc_abi:: { Align , ExternAbi , FieldIdx , FieldsShape , Size , Variants } ;
77use rustc_apfloat:: Float ;
8- use rustc_apfloat:: ieee:: { Double , Half , Quad , Single } ;
98use rustc_hir:: Safety ;
109use rustc_hir:: def:: { DefKind , Namespace } ;
1110use rustc_hir:: def_id:: { CRATE_DEF_INDEX , CrateNum , DefId , LOCAL_CRATE } ;
@@ -14,7 +13,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1413use rustc_middle:: middle:: dependency_format:: Linkage ;
1514use rustc_middle:: middle:: exported_symbols:: ExportedSymbol ;
1615use rustc_middle:: ty:: layout:: { LayoutOf , MaybeResult , TyAndLayout } ;
17- use rustc_middle:: ty:: { self , FloatTy , IntTy , Ty , TyCtxt , UintTy } ;
16+ use rustc_middle:: ty:: { self , IntTy , Ty , TyCtxt , UintTy } ;
1817use rustc_session:: config:: CrateType ;
1918use rustc_span:: { Span , Symbol } ;
2019use rustc_symbol_mangling:: mangle_internal_symbol;
@@ -961,75 +960,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
961960 this. alloc_mark_immutable ( provenance. get_alloc_id ( ) . unwrap ( ) ) . unwrap ( ) ;
962961 }
963962
964- /// Converts `src` from floating point to integer type `dest_ty`
965- /// after rounding with mode `round`.
966- /// Returns `None` if `f` is NaN or out of range.
967- fn float_to_int_checked (
968- & self ,
969- src : & ImmTy < ' tcx > ,
970- cast_to : TyAndLayout < ' tcx > ,
971- round : rustc_apfloat:: Round ,
972- ) -> InterpResult < ' tcx , Option < ImmTy < ' tcx > > > {
973- let this = self . eval_context_ref ( ) ;
974-
975- fn float_to_int_inner < ' tcx , F : rustc_apfloat:: Float > (
976- ecx : & MiriInterpCx < ' tcx > ,
977- src : F ,
978- cast_to : TyAndLayout < ' tcx > ,
979- round : rustc_apfloat:: Round ,
980- ) -> ( Scalar , rustc_apfloat:: Status ) {
981- let int_size = cast_to. layout . size ;
982- match cast_to. ty . kind ( ) {
983- // Unsigned
984- ty:: Uint ( _) => {
985- let res = src. to_u128_r ( int_size. bits_usize ( ) , round, & mut false ) ;
986- ( Scalar :: from_uint ( res. value , int_size) , res. status )
987- }
988- // Signed
989- ty:: Int ( _) => {
990- let res = src. to_i128_r ( int_size. bits_usize ( ) , round, & mut false ) ;
991- ( Scalar :: from_int ( res. value , int_size) , res. status )
992- }
993- // Nothing else
994- _ =>
995- span_bug ! (
996- ecx. cur_span( ) ,
997- "attempted float-to-int conversion with non-int output type {}" ,
998- cast_to. ty,
999- ) ,
1000- }
1001- }
1002-
1003- let ty:: Float ( fty) = src. layout . ty . kind ( ) else {
1004- bug ! ( "float_to_int_checked: non-float input type {}" , src. layout. ty)
1005- } ;
1006-
1007- let ( val, status) = match fty {
1008- FloatTy :: F16 =>
1009- float_to_int_inner :: < Half > ( this, src. to_scalar ( ) . to_f16 ( ) ?, cast_to, round) ,
1010- FloatTy :: F32 =>
1011- float_to_int_inner :: < Single > ( this, src. to_scalar ( ) . to_f32 ( ) ?, cast_to, round) ,
1012- FloatTy :: F64 =>
1013- float_to_int_inner :: < Double > ( this, src. to_scalar ( ) . to_f64 ( ) ?, cast_to, round) ,
1014- FloatTy :: F128 =>
1015- float_to_int_inner :: < Quad > ( this, src. to_scalar ( ) . to_f128 ( ) ?, cast_to, round) ,
1016- } ;
1017-
1018- if status. intersects (
1019- rustc_apfloat:: Status :: INVALID_OP
1020- | rustc_apfloat:: Status :: OVERFLOW
1021- | rustc_apfloat:: Status :: UNDERFLOW ,
1022- ) {
1023- // Floating point value is NaN (flagged with INVALID_OP) or outside the range
1024- // of values of the integer type (flagged with OVERFLOW or UNDERFLOW).
1025- interp_ok ( None )
1026- } else {
1027- // Floating point value can be represented by the integer type after rounding.
1028- // The INEXACT flag is ignored on purpose to allow rounding.
1029- interp_ok ( Some ( ImmTy :: from_scalar ( val, cast_to) ) )
1030- }
1031- }
1032-
1033963 /// Returns an integer type that is twice wide as `ty`
1034964 fn get_twice_wide_int_ty ( & self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1035965 let this = self . eval_context_ref ( ) ;
@@ -1194,20 +1124,6 @@ pub(crate) fn bool_to_simd_element(b: bool, size: Size) -> Scalar {
11941124 Scalar :: from_int ( val, size)
11951125}
11961126
1197- pub ( crate ) fn simd_element_to_bool ( elem : ImmTy < ' _ > ) -> InterpResult < ' _ , bool > {
1198- assert ! (
1199- matches!( elem. layout. ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) ) ,
1200- "SIMD mask element type must be an integer, but this is `{}`" ,
1201- elem. layout. ty
1202- ) ;
1203- let val = elem. to_scalar ( ) . to_int ( elem. layout . size ) ?;
1204- interp_ok ( match val {
1205- 0 => false ,
1206- -1 => true ,
1207- _ => throw_ub_format ! ( "each element of a SIMD mask must be all-0-bits or all-1-bits" ) ,
1208- } )
1209- }
1210-
12111127/// Check whether an operation that writes to a target buffer was successful.
12121128/// Accordingly select return value.
12131129/// Local helper function to be used in Windows shims.
0 commit comments