@@ -43,14 +43,16 @@ pub enum Constant<'tcx> {
43
43
Char ( char ) ,
44
44
/// An integer's bit representation.
45
45
Int ( u128 ) ,
46
- /// An `f16`.
47
- F16 ( f16 ) ,
46
+ /// An `f16` bitcast to a `u16`.
47
+ // FIXME(f16_f128): use `f16` once builtins are available on all host tools platforms.
48
+ F16 ( u16 ) ,
48
49
/// An `f32`.
49
50
F32 ( f32 ) ,
50
51
/// An `f64`.
51
52
F64 ( f64 ) ,
52
- /// An `f128`.
53
- F128 ( f128 ) ,
53
+ /// An `f128` bitcast to a `u128`.
54
+ // FIXME(f16_f128): use `f128` once builtins are available on all host tools platforms.
55
+ F128 ( u128 ) ,
54
56
/// `true` or `false`.
55
57
Bool ( bool ) ,
56
58
/// An array of constants.
@@ -177,7 +179,7 @@ impl Hash for Constant<'_> {
177
179
} ,
178
180
Self :: F16 ( f) => {
179
181
// FIXME(f16_f128): once conversions to/from `f128` are available on all platforms,
180
- f. to_bits ( ) . hash ( state) ;
182
+ f. hash ( state) ;
181
183
} ,
182
184
Self :: F32 ( f) => {
183
185
f64:: from ( f) . to_bits ( ) . hash ( state) ;
@@ -186,7 +188,7 @@ impl Hash for Constant<'_> {
186
188
f. to_bits ( ) . hash ( state) ;
187
189
} ,
188
190
Self :: F128 ( f) => {
189
- f. to_bits ( ) . hash ( state) ;
191
+ f. hash ( state) ;
190
192
} ,
191
193
Self :: Bool ( b) => {
192
194
b. hash ( state) ;
@@ -292,12 +294,12 @@ impl Constant<'_> {
292
294
293
295
fn parse_f16 ( s : & str ) -> Self {
294
296
let f: Half = s. parse ( ) . unwrap ( ) ;
295
- Self :: F16 ( f16 :: from_bits ( f. to_bits ( ) . try_into ( ) . unwrap ( ) ) )
297
+ Self :: F16 ( f. to_bits ( ) . try_into ( ) . unwrap ( ) )
296
298
}
297
299
298
300
fn parse_f128 ( s : & str ) -> Self {
299
301
let f: Quad = s. parse ( ) . unwrap ( ) ;
300
- Self :: F128 ( f128 :: from_bits ( f. to_bits ( ) ) )
302
+ Self :: F128 ( f. to_bits ( ) )
301
303
}
302
304
}
303
305
@@ -868,10 +870,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::Const<'tcx>) -> Option
868
870
ty:: Adt ( adt_def, _) if adt_def. is_struct ( ) => Some ( Constant :: Adt ( result) ) ,
869
871
ty:: Bool => Some ( Constant :: Bool ( int == ScalarInt :: TRUE ) ) ,
870
872
ty:: Uint ( _) | ty:: Int ( _) => Some ( Constant :: Int ( int. to_bits ( int. size ( ) ) ) ) ,
871
- ty:: Float ( FloatTy :: F16 ) => Some ( Constant :: F16 ( f16 :: from_bits ( int. into ( ) ) ) ) ,
873
+ ty:: Float ( FloatTy :: F16 ) => Some ( Constant :: F16 ( int. into ( ) ) ) ,
872
874
ty:: Float ( FloatTy :: F32 ) => Some ( Constant :: F32 ( f32:: from_bits ( int. into ( ) ) ) ) ,
873
875
ty:: Float ( FloatTy :: F64 ) => Some ( Constant :: F64 ( f64:: from_bits ( int. into ( ) ) ) ) ,
874
- ty:: Float ( FloatTy :: F128 ) => Some ( Constant :: F128 ( f128 :: from_bits ( int. into ( ) ) ) ) ,
876
+ ty:: Float ( FloatTy :: F128 ) => Some ( Constant :: F128 ( int. into ( ) ) ) ,
875
877
ty:: RawPtr ( _, _) => Some ( Constant :: RawPtr ( int. to_bits ( int. size ( ) ) ) ) ,
876
878
_ => None ,
877
879
} ,
@@ -892,10 +894,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::Const<'tcx>) -> Option
892
894
let range = alloc_range ( offset + size * idx, size) ;
893
895
let val = alloc. read_scalar ( & tcx, range, /* read_provenance */ false ) . ok ( ) ?;
894
896
res. push ( match flt {
895
- FloatTy :: F16 => Constant :: F16 ( f16 :: from_bits ( val. to_u16 ( ) . discard_err ( ) ?) ) ,
897
+ FloatTy :: F16 => Constant :: F16 ( val. to_u16 ( ) . discard_err ( ) ?) ,
896
898
FloatTy :: F32 => Constant :: F32 ( f32:: from_bits ( val. to_u32 ( ) . discard_err ( ) ?) ) ,
897
899
FloatTy :: F64 => Constant :: F64 ( f64:: from_bits ( val. to_u64 ( ) . discard_err ( ) ?) ) ,
898
- FloatTy :: F128 => Constant :: F128 ( f128 :: from_bits ( val. to_u128 ( ) . discard_err ( ) ?) ) ,
900
+ FloatTy :: F128 => Constant :: F128 ( val. to_u128 ( ) . discard_err ( ) ?) ,
899
901
} ) ;
900
902
}
901
903
Some ( Constant :: Vec ( res) )
0 commit comments