4
4
#![ cfg_attr( feature = "nightly" , feature( rustdoc_internals) ) ]
5
5
6
6
use std:: fmt;
7
- use std:: num:: { NonZeroUsize , ParseIntError } ;
7
+ use std:: num:: { NonZero , ParseIntError } ;
8
8
use std:: ops:: { Add , AddAssign , Mul , RangeInclusive , Sub } ;
9
9
use std:: str:: FromStr ;
10
10
@@ -926,6 +926,41 @@ impl Integer {
926
926
}
927
927
}
928
928
929
+ /// Floating-point types.
930
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
931
+ #[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
932
+ pub enum Float {
933
+ F16 ,
934
+ F32 ,
935
+ F64 ,
936
+ F128 ,
937
+ }
938
+
939
+ impl Float {
940
+ pub fn size ( self ) -> Size {
941
+ use Float :: * ;
942
+
943
+ match self {
944
+ F16 => Size :: from_bits ( 16 ) ,
945
+ F32 => Size :: from_bits ( 32 ) ,
946
+ F64 => Size :: from_bits ( 64 ) ,
947
+ F128 => Size :: from_bits ( 128 ) ,
948
+ }
949
+ }
950
+
951
+ pub fn align < C : HasDataLayout > ( self , cx : & C ) -> AbiAndPrefAlign {
952
+ use Float :: * ;
953
+ let dl = cx. data_layout ( ) ;
954
+
955
+ match self {
956
+ F16 => dl. f16_align ,
957
+ F32 => dl. f32_align ,
958
+ F64 => dl. f64_align ,
959
+ F128 => dl. f128_align ,
960
+ }
961
+ }
962
+ }
963
+
929
964
/// Fundamental unit of memory access and layout.
930
965
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
931
966
#[ cfg_attr( feature = "nightly" , derive( HashStable_Generic ) ) ]
@@ -938,10 +973,7 @@ pub enum Primitive {
938
973
/// a negative integer passed by zero-extension will appear positive in
939
974
/// the callee, and most operations on it will produce the wrong values.
940
975
Int ( Integer , bool ) ,
941
- F16 ,
942
- F32 ,
943
- F64 ,
944
- F128 ,
976
+ Float ( Float ) ,
945
977
Pointer ( AddressSpace ) ,
946
978
}
947
979
@@ -952,10 +984,7 @@ impl Primitive {
952
984
953
985
match self {
954
986
Int ( i, _) => i. size ( ) ,
955
- F16 => Size :: from_bits ( 16 ) ,
956
- F32 => Size :: from_bits ( 32 ) ,
957
- F64 => Size :: from_bits ( 64 ) ,
958
- F128 => Size :: from_bits ( 128 ) ,
987
+ Float ( f) => f. size ( ) ,
959
988
// FIXME(erikdesjardins): ignoring address space is technically wrong, pointers in
960
989
// different address spaces can have different sizes
961
990
// (but TargetDataLayout doesn't currently parse that part of the DL string)
@@ -969,10 +998,7 @@ impl Primitive {
969
998
970
999
match self {
971
1000
Int ( i, _) => i. align ( dl) ,
972
- F16 => dl. f16_align ,
973
- F32 => dl. f32_align ,
974
- F64 => dl. f64_align ,
975
- F128 => dl. f128_align ,
1001
+ Float ( f) => f. align ( dl) ,
976
1002
// FIXME(erikdesjardins): ignoring address space is technically wrong, pointers in
977
1003
// different address spaces can have different alignments
978
1004
// (but TargetDataLayout doesn't currently parse that part of the DL string)
@@ -1149,7 +1175,7 @@ pub enum FieldsShape<FieldIdx: Idx> {
1149
1175
Primitive ,
1150
1176
1151
1177
/// All fields start at no offset. The `usize` is the field count.
1152
- Union ( NonZeroUsize ) ,
1178
+ Union ( NonZero < usize > ) ,
1153
1179
1154
1180
/// Array/vector-like placement, with all fields of identical types.
1155
1181
Array { stride : Size , count : u64 } ,
0 commit comments