@@ -84,7 +84,7 @@ pub(crate) fn clif_int_or_float_cast(
84
84
fx. bcx . ins ( ) . fcvt_from_uint ( to_ty, from)
85
85
}
86
86
} else if from_ty. is_float ( ) && to_ty. is_int ( ) {
87
- if to_ty == types:: I128 {
87
+ let val = if to_ty == types:: I128 {
88
88
// _____sssf___
89
89
// __fix sfti: f32 -> i128
90
90
// __fix dfti: f64 -> i128
@@ -109,13 +109,9 @@ pub(crate) fn clif_int_or_float_cast(
109
109
110
110
let to_rust_ty = if to_signed { fx. tcx . types . i128 } else { fx. tcx . types . u128 } ;
111
111
112
- return fx
113
- . easy_call ( & name, & [ CValue :: by_val ( from, fx. layout_of ( from_rust_ty) ) ] , to_rust_ty)
114
- . load_scalar ( fx) ;
115
- }
116
-
117
- // float -> int-like
118
- if to_ty == types:: I8 || to_ty == types:: I16 {
112
+ fx. easy_call ( & name, & [ CValue :: by_val ( from, fx. layout_of ( from_rust_ty) ) ] , to_rust_ty)
113
+ . load_scalar ( fx)
114
+ } else if to_ty == types:: I8 || to_ty == types:: I16 {
119
115
// FIXME implement fcvt_to_*int_sat.i8/i16
120
116
let val = if to_signed {
121
117
fx. bcx . ins ( ) . fcvt_to_sint_sat ( types:: I32 , from)
@@ -146,6 +142,23 @@ pub(crate) fn clif_int_or_float_cast(
146
142
fx. bcx . ins ( ) . fcvt_to_sint_sat ( to_ty, from)
147
143
} else {
148
144
fx. bcx . ins ( ) . fcvt_to_uint_sat ( to_ty, from)
145
+ } ;
146
+
147
+ if let Some ( false ) = fx. tcx . sess . opts . debugging_opts . saturating_float_casts {
148
+ return val;
149
+ }
150
+
151
+ let is_not_nan = fx. bcx . ins ( ) . fcmp ( FloatCC :: Equal , from, from) ;
152
+ if to_ty == types:: I128 {
153
+ // FIXME(bytecodealliance/wasmtime#3963): select.i128 on fcmp eq miscompiles
154
+ let ( lsb, msb) = fx. bcx . ins ( ) . isplit ( val) ;
155
+ let zero = fx. bcx . ins ( ) . iconst ( types:: I64 , 0 ) ;
156
+ let lsb = fx. bcx . ins ( ) . select ( is_not_nan, lsb, zero) ;
157
+ let msb = fx. bcx . ins ( ) . select ( is_not_nan, msb, zero) ;
158
+ fx. bcx . ins ( ) . iconcat ( lsb, msb)
159
+ } else {
160
+ let zero = fx. bcx . ins ( ) . iconst ( to_ty, 0 ) ;
161
+ fx. bcx . ins ( ) . select ( is_not_nan, val, zero)
149
162
}
150
163
} else if from_ty. is_float ( ) && to_ty. is_float ( ) {
151
164
// float -> float
0 commit comments