@@ -98,10 +98,7 @@ pub mod diy_float;
98
98
99
99
// `Int` + `SignedInt` implemented for signed integers
100
100
macro_rules! int_impl {
101
- ( $SelfT: ty, $ActualT: ident, $UnsignedT: ty, $BITS: expr,
102
- $add_with_overflow: path,
103
- $sub_with_overflow: path,
104
- $mul_with_overflow: path) => {
101
+ ( $SelfT: ty, $ActualT: ident, $UnsignedT: ty, $BITS: expr) => {
105
102
/// Returns the smallest value that can be represented by this integer type.
106
103
///
107
104
/// # Examples
@@ -862,11 +859,11 @@ macro_rules! int_impl {
862
859
#[ inline]
863
860
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
864
861
pub fn overflowing_add( self , rhs: Self ) -> ( Self , bool ) {
865
- unsafe {
866
- let ( a , b ) = $ add_with_overflow( self as $ActualT,
867
- rhs as $ActualT) ;
868
- ( a as Self , b )
869
- }
862
+ let ( a , b ) = unsafe {
863
+ intrinsics :: add_with_overflow( self as $ActualT,
864
+ rhs as $ActualT)
865
+ } ;
866
+ ( a as Self , b )
870
867
}
871
868
872
869
/// Calculates `self` - `rhs`
@@ -888,11 +885,11 @@ macro_rules! int_impl {
888
885
#[ inline]
889
886
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
890
887
pub fn overflowing_sub( self , rhs: Self ) -> ( Self , bool ) {
891
- unsafe {
892
- let ( a , b ) = $ sub_with_overflow( self as $ActualT,
893
- rhs as $ActualT) ;
894
- ( a as Self , b )
895
- }
888
+ let ( a , b ) = unsafe {
889
+ intrinsics :: sub_with_overflow( self as $ActualT,
890
+ rhs as $ActualT)
891
+ } ;
892
+ ( a as Self , b )
896
893
}
897
894
898
895
/// Calculates the multiplication of `self` and `rhs`.
@@ -912,11 +909,11 @@ macro_rules! int_impl {
912
909
#[ inline]
913
910
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
914
911
pub fn overflowing_mul( self , rhs: Self ) -> ( Self , bool ) {
915
- unsafe {
916
- let ( a , b ) = $ mul_with_overflow( self as $ActualT,
917
- rhs as $ActualT) ;
918
- ( a as Self , b )
919
- }
912
+ let ( a , b ) = unsafe {
913
+ intrinsics :: mul_with_overflow( self as $ActualT,
914
+ rhs as $ActualT)
915
+ } ;
916
+ ( a as Self , b )
920
917
}
921
918
922
919
/// Calculates the divisor when `self` is divided by `rhs`.
@@ -1204,82 +1201,50 @@ macro_rules! int_impl {
1204
1201
1205
1202
#[ lang = "i8" ]
1206
1203
impl i8 {
1207
- int_impl ! { i8 , i8 , u8 , 8 ,
1208
- intrinsics:: add_with_overflow,
1209
- intrinsics:: sub_with_overflow,
1210
- intrinsics:: mul_with_overflow }
1204
+ int_impl ! { i8 , i8 , u8 , 8 }
1211
1205
}
1212
1206
1213
1207
#[ lang = "i16" ]
1214
1208
impl i16 {
1215
- int_impl ! { i16 , i16 , u16 , 16 ,
1216
- intrinsics:: add_with_overflow,
1217
- intrinsics:: sub_with_overflow,
1218
- intrinsics:: mul_with_overflow }
1209
+ int_impl ! { i16 , i16 , u16 , 16 }
1219
1210
}
1220
1211
1221
1212
#[ lang = "i32" ]
1222
1213
impl i32 {
1223
- int_impl ! { i32 , i32 , u32 , 32 ,
1224
- intrinsics:: add_with_overflow,
1225
- intrinsics:: sub_with_overflow,
1226
- intrinsics:: mul_with_overflow }
1214
+ int_impl ! { i32 , i32 , u32 , 32 }
1227
1215
}
1228
1216
1229
1217
#[ lang = "i64" ]
1230
1218
impl i64 {
1231
- int_impl ! { i64 , i64 , u64 , 64 ,
1232
- intrinsics:: add_with_overflow,
1233
- intrinsics:: sub_with_overflow,
1234
- intrinsics:: mul_with_overflow }
1219
+ int_impl ! { i64 , i64 , u64 , 64 }
1235
1220
}
1236
1221
1237
1222
#[ lang = "i128" ]
1238
1223
impl i128 {
1239
- int_impl ! { i128 , i128 , u128 , 128 ,
1240
- intrinsics:: add_with_overflow,
1241
- intrinsics:: sub_with_overflow,
1242
- intrinsics:: mul_with_overflow }
1224
+ int_impl ! { i128 , i128 , u128 , 128 }
1243
1225
}
1244
1226
1245
1227
#[ cfg( target_pointer_width = "16" ) ]
1246
1228
#[ lang = "isize" ]
1247
1229
impl isize {
1248
- int_impl ! { isize , i16 , u16 , 16 ,
1249
- intrinsics:: add_with_overflow,
1250
- intrinsics:: sub_with_overflow,
1251
- intrinsics:: mul_with_overflow }
1230
+ int_impl ! { isize , i16 , u16 , 16 }
1252
1231
}
1253
1232
1254
1233
#[ cfg( target_pointer_width = "32" ) ]
1255
1234
#[ lang = "isize" ]
1256
1235
impl isize {
1257
- int_impl ! { isize , i32 , u32 , 32 ,
1258
- intrinsics:: add_with_overflow,
1259
- intrinsics:: sub_with_overflow,
1260
- intrinsics:: mul_with_overflow }
1236
+ int_impl ! { isize , i32 , u32 , 32 }
1261
1237
}
1262
1238
1263
1239
#[ cfg( target_pointer_width = "64" ) ]
1264
1240
#[ lang = "isize" ]
1265
1241
impl isize {
1266
- int_impl ! { isize , i64 , u64 , 64 ,
1267
- intrinsics:: add_with_overflow,
1268
- intrinsics:: sub_with_overflow,
1269
- intrinsics:: mul_with_overflow }
1242
+ int_impl ! { isize , i64 , u64 , 64 }
1270
1243
}
1271
1244
1272
1245
// `Int` + `UnsignedInt` implemented for unsigned integers
1273
1246
macro_rules! uint_impl {
1274
- ( $SelfT: ty, $ActualT: ty, $BITS: expr,
1275
- $ctpop: path,
1276
- $ctlz: path,
1277
- $ctlz_nonzero: path,
1278
- $cttz: path,
1279
- $bswap: path,
1280
- $add_with_overflow: path,
1281
- $sub_with_overflow: path,
1282
- $mul_with_overflow: path) => {
1247
+ ( $SelfT: ty, $ActualT: ty, $BITS: expr) => {
1283
1248
/// Returns the smallest value that can be represented by this integer type.
1284
1249
///
1285
1250
/// # Examples
@@ -1343,7 +1308,7 @@ macro_rules! uint_impl {
1343
1308
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1344
1309
#[ inline]
1345
1310
pub fn count_ones( self ) -> u32 {
1346
- unsafe { $ ctpop( self as $ActualT) as u32 }
1311
+ unsafe { intrinsics :: ctpop( self as $ActualT) as u32 }
1347
1312
}
1348
1313
1349
1314
/// Returns the number of zeros in the binary representation of `self`.
@@ -1378,7 +1343,7 @@ macro_rules! uint_impl {
1378
1343
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1379
1344
#[ inline]
1380
1345
pub fn leading_zeros( self ) -> u32 {
1381
- unsafe { $ ctlz( self as $ActualT) as u32 }
1346
+ unsafe { intrinsics :: ctlz( self as $ActualT) as u32 }
1382
1347
}
1383
1348
1384
1349
/// Returns the number of trailing zeros in the binary representation
@@ -1474,7 +1439,7 @@ macro_rules! uint_impl {
1474
1439
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1475
1440
#[ inline]
1476
1441
pub fn swap_bytes( self ) -> Self {
1477
- unsafe { $ bswap( self as $ActualT) as Self }
1442
+ unsafe { intrinsics :: bswap( self as $ActualT) as Self }
1478
1443
}
1479
1444
1480
1445
/// Converts an integer from big endian to the target's endianness.
@@ -1978,11 +1943,11 @@ macro_rules! uint_impl {
1978
1943
#[ inline]
1979
1944
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1980
1945
pub fn overflowing_add( self , rhs: Self ) -> ( Self , bool ) {
1981
- unsafe {
1982
- let ( a , b ) = $ add_with_overflow( self as $ActualT,
1983
- rhs as $ActualT) ;
1984
- ( a as Self , b )
1985
- }
1946
+ let ( a , b ) = unsafe {
1947
+ intrinsics :: add_with_overflow( self as $ActualT,
1948
+ rhs as $ActualT)
1949
+ } ;
1950
+ ( a as Self , b )
1986
1951
}
1987
1952
1988
1953
/// Calculates `self` - `rhs`
@@ -2004,11 +1969,11 @@ macro_rules! uint_impl {
2004
1969
#[ inline]
2005
1970
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2006
1971
pub fn overflowing_sub( self , rhs: Self ) -> ( Self , bool ) {
2007
- unsafe {
2008
- let ( a , b ) = $ sub_with_overflow( self as $ActualT,
2009
- rhs as $ActualT) ;
2010
- ( a as Self , b )
2011
- }
1972
+ let ( a , b ) = unsafe {
1973
+ intrinsics :: sub_with_overflow( self as $ActualT,
1974
+ rhs as $ActualT)
1975
+ } ;
1976
+ ( a as Self , b )
2012
1977
}
2013
1978
2014
1979
/// Calculates the multiplication of `self` and `rhs`.
@@ -2028,11 +1993,11 @@ macro_rules! uint_impl {
2028
1993
#[ inline]
2029
1994
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2030
1995
pub fn overflowing_mul( self , rhs: Self ) -> ( Self , bool ) {
2031
- unsafe {
2032
- let ( a , b ) = $ mul_with_overflow( self as $ActualT,
2033
- rhs as $ActualT) ;
2034
- ( a as Self , b )
2035
- }
1996
+ let ( a , b ) = unsafe {
1997
+ intrinsics :: mul_with_overflow( self as $ActualT,
1998
+ rhs as $ActualT)
1999
+ } ;
2000
+ ( a as Self , b )
2036
2001
}
2037
2002
2038
2003
/// Calculates the divisor when `self` is divided by `rhs`.
@@ -2217,7 +2182,7 @@ macro_rules! uint_impl {
2217
2182
// (such as intel pre-haswell) have more efficient ctlz
2218
2183
// intrinsics when the argument is non-zero.
2219
2184
let p = self - 1 ;
2220
- let z = unsafe { $ ctlz_nonzero( p) } ;
2185
+ let z = unsafe { intrinsics :: ctlz_nonzero( p) } ;
2221
2186
<$SelfT>:: max_value( ) >> z
2222
2187
}
2223
2188
@@ -2264,15 +2229,7 @@ macro_rules! uint_impl {
2264
2229
2265
2230
#[ lang = "u8" ]
2266
2231
impl u8 {
2267
- uint_impl ! { u8 , u8 , 8 ,
2268
- intrinsics:: ctpop,
2269
- intrinsics:: ctlz,
2270
- intrinsics:: ctlz_nonzero,
2271
- intrinsics:: cttz,
2272
- intrinsics:: bswap,
2273
- intrinsics:: add_with_overflow,
2274
- intrinsics:: sub_with_overflow,
2275
- intrinsics:: mul_with_overflow }
2232
+ uint_impl ! { u8 , u8 , 8 }
2276
2233
2277
2234
2278
2235
/// Checks if the value is within the ASCII range.
@@ -2818,95 +2775,39 @@ impl u8 {
2818
2775
2819
2776
#[ lang = "u16" ]
2820
2777
impl u16 {
2821
- uint_impl ! { u16 , u16 , 16 ,
2822
- intrinsics:: ctpop,
2823
- intrinsics:: ctlz,
2824
- intrinsics:: ctlz_nonzero,
2825
- intrinsics:: cttz,
2826
- intrinsics:: bswap,
2827
- intrinsics:: add_with_overflow,
2828
- intrinsics:: sub_with_overflow,
2829
- intrinsics:: mul_with_overflow }
2778
+ uint_impl ! { u16 , u16 , 16 }
2830
2779
}
2831
2780
2832
2781
#[ lang = "u32" ]
2833
2782
impl u32 {
2834
- uint_impl ! { u32 , u32 , 32 ,
2835
- intrinsics:: ctpop,
2836
- intrinsics:: ctlz,
2837
- intrinsics:: ctlz_nonzero,
2838
- intrinsics:: cttz,
2839
- intrinsics:: bswap,
2840
- intrinsics:: add_with_overflow,
2841
- intrinsics:: sub_with_overflow,
2842
- intrinsics:: mul_with_overflow }
2783
+ uint_impl ! { u32 , u32 , 32 }
2843
2784
}
2844
2785
2845
2786
#[ lang = "u64" ]
2846
2787
impl u64 {
2847
- uint_impl ! { u64 , u64 , 64 ,
2848
- intrinsics:: ctpop,
2849
- intrinsics:: ctlz,
2850
- intrinsics:: ctlz_nonzero,
2851
- intrinsics:: cttz,
2852
- intrinsics:: bswap,
2853
- intrinsics:: add_with_overflow,
2854
- intrinsics:: sub_with_overflow,
2855
- intrinsics:: mul_with_overflow }
2788
+ uint_impl ! { u64 , u64 , 64 }
2856
2789
}
2857
2790
2858
2791
#[ lang = "u128" ]
2859
2792
impl u128 {
2860
- uint_impl ! { u128 , u128 , 128 ,
2861
- intrinsics:: ctpop,
2862
- intrinsics:: ctlz,
2863
- intrinsics:: ctlz_nonzero,
2864
- intrinsics:: cttz,
2865
- intrinsics:: bswap,
2866
- intrinsics:: add_with_overflow,
2867
- intrinsics:: sub_with_overflow,
2868
- intrinsics:: mul_with_overflow }
2793
+ uint_impl ! { u128 , u128 , 128 }
2869
2794
}
2870
2795
2871
2796
#[ cfg( target_pointer_width = "16" ) ]
2872
2797
#[ lang = "usize" ]
2873
2798
impl usize {
2874
- uint_impl ! { usize , u16 , 16 ,
2875
- intrinsics:: ctpop,
2876
- intrinsics:: ctlz,
2877
- intrinsics:: ctlz_nonzero,
2878
- intrinsics:: cttz,
2879
- intrinsics:: bswap,
2880
- intrinsics:: add_with_overflow,
2881
- intrinsics:: sub_with_overflow,
2882
- intrinsics:: mul_with_overflow }
2799
+ uint_impl ! { usize , u16 , 16 }
2883
2800
}
2884
2801
#[ cfg( target_pointer_width = "32" ) ]
2885
2802
#[ lang = "usize" ]
2886
2803
impl usize {
2887
- uint_impl ! { usize , u32 , 32 ,
2888
- intrinsics:: ctpop,
2889
- intrinsics:: ctlz,
2890
- intrinsics:: ctlz_nonzero,
2891
- intrinsics:: cttz,
2892
- intrinsics:: bswap,
2893
- intrinsics:: add_with_overflow,
2894
- intrinsics:: sub_with_overflow,
2895
- intrinsics:: mul_with_overflow }
2804
+ uint_impl ! { usize , u32 , 32 }
2896
2805
}
2897
2806
2898
2807
#[ cfg( target_pointer_width = "64" ) ]
2899
2808
#[ lang = "usize" ]
2900
2809
impl usize {
2901
- uint_impl ! { usize , u64 , 64 ,
2902
- intrinsics:: ctpop,
2903
- intrinsics:: ctlz,
2904
- intrinsics:: ctlz_nonzero,
2905
- intrinsics:: cttz,
2906
- intrinsics:: bswap,
2907
- intrinsics:: add_with_overflow,
2908
- intrinsics:: sub_with_overflow,
2909
- intrinsics:: mul_with_overflow }
2810
+ uint_impl ! { usize , u64 , 64 }
2910
2811
}
2911
2812
2912
2813
/// A classification of floating point numbers.
0 commit comments