@@ -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
@@ -865,11 +862,11 @@ macro_rules! int_impl {
865
862
#[ inline]
866
863
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
867
864
pub fn overflowing_add( self , rhs: Self ) -> ( Self , bool ) {
868
- unsafe {
869
- let ( a , b ) = $ add_with_overflow( self as $ActualT,
870
- rhs as $ActualT) ;
871
- ( a as Self , b )
872
- }
865
+ let ( a , b ) = unsafe {
866
+ intrinsics :: add_with_overflow( self as $ActualT,
867
+ rhs as $ActualT)
868
+ } ;
869
+ ( a as Self , b )
873
870
}
874
871
875
872
/// Calculates `self` - `rhs`
@@ -891,11 +888,11 @@ macro_rules! int_impl {
891
888
#[ inline]
892
889
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
893
890
pub fn overflowing_sub( self , rhs: Self ) -> ( Self , bool ) {
894
- unsafe {
895
- let ( a , b ) = $ sub_with_overflow( self as $ActualT,
896
- rhs as $ActualT) ;
897
- ( a as Self , b )
898
- }
891
+ let ( a , b ) = unsafe {
892
+ intrinsics :: sub_with_overflow( self as $ActualT,
893
+ rhs as $ActualT)
894
+ } ;
895
+ ( a as Self , b )
899
896
}
900
897
901
898
/// Calculates the multiplication of `self` and `rhs`.
@@ -915,11 +912,11 @@ macro_rules! int_impl {
915
912
#[ inline]
916
913
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
917
914
pub fn overflowing_mul( self , rhs: Self ) -> ( Self , bool ) {
918
- unsafe {
919
- let ( a , b ) = $ mul_with_overflow( self as $ActualT,
920
- rhs as $ActualT) ;
921
- ( a as Self , b )
922
- }
915
+ let ( a , b ) = unsafe {
916
+ intrinsics :: mul_with_overflow( self as $ActualT,
917
+ rhs as $ActualT)
918
+ } ;
919
+ ( a as Self , b )
923
920
}
924
921
925
922
/// Calculates the divisor when `self` is divided by `rhs`.
@@ -1207,82 +1204,50 @@ macro_rules! int_impl {
1207
1204
1208
1205
#[ lang = "i8" ]
1209
1206
impl i8 {
1210
- int_impl ! { i8 , i8 , u8 , 8 ,
1211
- intrinsics:: add_with_overflow,
1212
- intrinsics:: sub_with_overflow,
1213
- intrinsics:: mul_with_overflow }
1207
+ int_impl ! { i8 , i8 , u8 , 8 }
1214
1208
}
1215
1209
1216
1210
#[ lang = "i16" ]
1217
1211
impl i16 {
1218
- int_impl ! { i16 , i16 , u16 , 16 ,
1219
- intrinsics:: add_with_overflow,
1220
- intrinsics:: sub_with_overflow,
1221
- intrinsics:: mul_with_overflow }
1212
+ int_impl ! { i16 , i16 , u16 , 16 }
1222
1213
}
1223
1214
1224
1215
#[ lang = "i32" ]
1225
1216
impl i32 {
1226
- int_impl ! { i32 , i32 , u32 , 32 ,
1227
- intrinsics:: add_with_overflow,
1228
- intrinsics:: sub_with_overflow,
1229
- intrinsics:: mul_with_overflow }
1217
+ int_impl ! { i32 , i32 , u32 , 32 }
1230
1218
}
1231
1219
1232
1220
#[ lang = "i64" ]
1233
1221
impl i64 {
1234
- int_impl ! { i64 , i64 , u64 , 64 ,
1235
- intrinsics:: add_with_overflow,
1236
- intrinsics:: sub_with_overflow,
1237
- intrinsics:: mul_with_overflow }
1222
+ int_impl ! { i64 , i64 , u64 , 64 }
1238
1223
}
1239
1224
1240
1225
#[ lang = "i128" ]
1241
1226
impl i128 {
1242
- int_impl ! { i128 , i128 , u128 , 128 ,
1243
- intrinsics:: add_with_overflow,
1244
- intrinsics:: sub_with_overflow,
1245
- intrinsics:: mul_with_overflow }
1227
+ int_impl ! { i128 , i128 , u128 , 128 }
1246
1228
}
1247
1229
1248
1230
#[ cfg( target_pointer_width = "16" ) ]
1249
1231
#[ lang = "isize" ]
1250
1232
impl isize {
1251
- int_impl ! { isize , i16 , u16 , 16 ,
1252
- intrinsics:: add_with_overflow,
1253
- intrinsics:: sub_with_overflow,
1254
- intrinsics:: mul_with_overflow }
1233
+ int_impl ! { isize , i16 , u16 , 16 }
1255
1234
}
1256
1235
1257
1236
#[ cfg( target_pointer_width = "32" ) ]
1258
1237
#[ lang = "isize" ]
1259
1238
impl isize {
1260
- int_impl ! { isize , i32 , u32 , 32 ,
1261
- intrinsics:: add_with_overflow,
1262
- intrinsics:: sub_with_overflow,
1263
- intrinsics:: mul_with_overflow }
1239
+ int_impl ! { isize , i32 , u32 , 32 }
1264
1240
}
1265
1241
1266
1242
#[ cfg( target_pointer_width = "64" ) ]
1267
1243
#[ lang = "isize" ]
1268
1244
impl isize {
1269
- int_impl ! { isize , i64 , u64 , 64 ,
1270
- intrinsics:: add_with_overflow,
1271
- intrinsics:: sub_with_overflow,
1272
- intrinsics:: mul_with_overflow }
1245
+ int_impl ! { isize , i64 , u64 , 64 }
1273
1246
}
1274
1247
1275
1248
// `Int` + `UnsignedInt` implemented for unsigned integers
1276
1249
macro_rules! uint_impl {
1277
- ( $SelfT: ty, $ActualT: ty, $BITS: expr,
1278
- $ctpop: path,
1279
- $ctlz: path,
1280
- $ctlz_nonzero: path,
1281
- $cttz: path,
1282
- $bswap: path,
1283
- $add_with_overflow: path,
1284
- $sub_with_overflow: path,
1285
- $mul_with_overflow: path) => {
1250
+ ( $SelfT: ty, $ActualT: ty, $BITS: expr) => {
1286
1251
/// Returns the smallest value that can be represented by this integer type.
1287
1252
///
1288
1253
/// # Examples
@@ -1346,7 +1311,7 @@ macro_rules! uint_impl {
1346
1311
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1347
1312
#[ inline]
1348
1313
pub fn count_ones( self ) -> u32 {
1349
- unsafe { $ ctpop( self as $ActualT) as u32 }
1314
+ unsafe { intrinsics :: ctpop( self as $ActualT) as u32 }
1350
1315
}
1351
1316
1352
1317
/// Returns the number of zeros in the binary representation of `self`.
@@ -1381,7 +1346,7 @@ macro_rules! uint_impl {
1381
1346
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1382
1347
#[ inline]
1383
1348
pub fn leading_zeros( self ) -> u32 {
1384
- unsafe { $ ctlz( self as $ActualT) as u32 }
1349
+ unsafe { intrinsics :: ctlz( self as $ActualT) as u32 }
1385
1350
}
1386
1351
1387
1352
/// Returns the number of trailing zeros in the binary representation
@@ -1480,7 +1445,7 @@ macro_rules! uint_impl {
1480
1445
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1481
1446
#[ inline]
1482
1447
pub fn swap_bytes( self ) -> Self {
1483
- unsafe { $ bswap( self as $ActualT) as Self }
1448
+ unsafe { intrinsics :: bswap( self as $ActualT) as Self }
1484
1449
}
1485
1450
1486
1451
/// Converts an integer from big endian to the target's endianness.
@@ -1984,11 +1949,11 @@ macro_rules! uint_impl {
1984
1949
#[ inline]
1985
1950
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
1986
1951
pub fn overflowing_add( self , rhs: Self ) -> ( Self , bool ) {
1987
- unsafe {
1988
- let ( a , b ) = $ add_with_overflow( self as $ActualT,
1989
- rhs as $ActualT) ;
1990
- ( a as Self , b )
1991
- }
1952
+ let ( a , b ) = unsafe {
1953
+ intrinsics :: add_with_overflow( self as $ActualT,
1954
+ rhs as $ActualT)
1955
+ } ;
1956
+ ( a as Self , b )
1992
1957
}
1993
1958
1994
1959
/// Calculates `self` - `rhs`
@@ -2010,11 +1975,11 @@ macro_rules! uint_impl {
2010
1975
#[ inline]
2011
1976
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2012
1977
pub fn overflowing_sub( self , rhs: Self ) -> ( Self , bool ) {
2013
- unsafe {
2014
- let ( a , b ) = $ sub_with_overflow( self as $ActualT,
2015
- rhs as $ActualT) ;
2016
- ( a as Self , b )
2017
- }
1978
+ let ( a , b ) = unsafe {
1979
+ intrinsics :: sub_with_overflow( self as $ActualT,
1980
+ rhs as $ActualT)
1981
+ } ;
1982
+ ( a as Self , b )
2018
1983
}
2019
1984
2020
1985
/// Calculates the multiplication of `self` and `rhs`.
@@ -2034,11 +1999,11 @@ macro_rules! uint_impl {
2034
1999
#[ inline]
2035
2000
#[ stable( feature = "wrapping" , since = "1.7.0" ) ]
2036
2001
pub fn overflowing_mul( self , rhs: Self ) -> ( Self , bool ) {
2037
- unsafe {
2038
- let ( a , b ) = $ mul_with_overflow( self as $ActualT,
2039
- rhs as $ActualT) ;
2040
- ( a as Self , b )
2041
- }
2002
+ let ( a , b ) = unsafe {
2003
+ intrinsics :: mul_with_overflow( self as $ActualT,
2004
+ rhs as $ActualT)
2005
+ } ;
2006
+ ( a as Self , b )
2042
2007
}
2043
2008
2044
2009
/// Calculates the divisor when `self` is divided by `rhs`.
@@ -2223,7 +2188,7 @@ macro_rules! uint_impl {
2223
2188
// (such as intel pre-haswell) have more efficient ctlz
2224
2189
// intrinsics when the argument is non-zero.
2225
2190
let p = self - 1 ;
2226
- let z = unsafe { $ ctlz_nonzero( p) } ;
2191
+ let z = unsafe { intrinsics :: ctlz_nonzero( p) } ;
2227
2192
<$SelfT>:: max_value( ) >> z
2228
2193
}
2229
2194
@@ -2270,15 +2235,7 @@ macro_rules! uint_impl {
2270
2235
2271
2236
#[ lang = "u8" ]
2272
2237
impl u8 {
2273
- uint_impl ! { u8 , u8 , 8 ,
2274
- intrinsics:: ctpop,
2275
- intrinsics:: ctlz,
2276
- intrinsics:: ctlz_nonzero,
2277
- intrinsics:: cttz,
2278
- intrinsics:: bswap,
2279
- intrinsics:: add_with_overflow,
2280
- intrinsics:: sub_with_overflow,
2281
- intrinsics:: mul_with_overflow }
2238
+ uint_impl ! { u8 , u8 , 8 }
2282
2239
2283
2240
2284
2241
/// Checks if the value is within the ASCII range.
@@ -2824,95 +2781,39 @@ impl u8 {
2824
2781
2825
2782
#[ lang = "u16" ]
2826
2783
impl u16 {
2827
- uint_impl ! { u16 , u16 , 16 ,
2828
- intrinsics:: ctpop,
2829
- intrinsics:: ctlz,
2830
- intrinsics:: ctlz_nonzero,
2831
- intrinsics:: cttz,
2832
- intrinsics:: bswap,
2833
- intrinsics:: add_with_overflow,
2834
- intrinsics:: sub_with_overflow,
2835
- intrinsics:: mul_with_overflow }
2784
+ uint_impl ! { u16 , u16 , 16 }
2836
2785
}
2837
2786
2838
2787
#[ lang = "u32" ]
2839
2788
impl u32 {
2840
- uint_impl ! { u32 , u32 , 32 ,
2841
- intrinsics:: ctpop,
2842
- intrinsics:: ctlz,
2843
- intrinsics:: ctlz_nonzero,
2844
- intrinsics:: cttz,
2845
- intrinsics:: bswap,
2846
- intrinsics:: add_with_overflow,
2847
- intrinsics:: sub_with_overflow,
2848
- intrinsics:: mul_with_overflow }
2789
+ uint_impl ! { u32 , u32 , 32 }
2849
2790
}
2850
2791
2851
2792
#[ lang = "u64" ]
2852
2793
impl u64 {
2853
- uint_impl ! { u64 , u64 , 64 ,
2854
- intrinsics:: ctpop,
2855
- intrinsics:: ctlz,
2856
- intrinsics:: ctlz_nonzero,
2857
- intrinsics:: cttz,
2858
- intrinsics:: bswap,
2859
- intrinsics:: add_with_overflow,
2860
- intrinsics:: sub_with_overflow,
2861
- intrinsics:: mul_with_overflow }
2794
+ uint_impl ! { u64 , u64 , 64 }
2862
2795
}
2863
2796
2864
2797
#[ lang = "u128" ]
2865
2798
impl u128 {
2866
- uint_impl ! { u128 , u128 , 128 ,
2867
- intrinsics:: ctpop,
2868
- intrinsics:: ctlz,
2869
- intrinsics:: ctlz_nonzero,
2870
- intrinsics:: cttz,
2871
- intrinsics:: bswap,
2872
- intrinsics:: add_with_overflow,
2873
- intrinsics:: sub_with_overflow,
2874
- intrinsics:: mul_with_overflow }
2799
+ uint_impl ! { u128 , u128 , 128 }
2875
2800
}
2876
2801
2877
2802
#[ cfg( target_pointer_width = "16" ) ]
2878
2803
#[ lang = "usize" ]
2879
2804
impl usize {
2880
- uint_impl ! { usize , u16 , 16 ,
2881
- intrinsics:: ctpop,
2882
- intrinsics:: ctlz,
2883
- intrinsics:: ctlz_nonzero,
2884
- intrinsics:: cttz,
2885
- intrinsics:: bswap,
2886
- intrinsics:: add_with_overflow,
2887
- intrinsics:: sub_with_overflow,
2888
- intrinsics:: mul_with_overflow }
2805
+ uint_impl ! { usize , u16 , 16 }
2889
2806
}
2890
2807
#[ cfg( target_pointer_width = "32" ) ]
2891
2808
#[ lang = "usize" ]
2892
2809
impl usize {
2893
- uint_impl ! { usize , u32 , 32 ,
2894
- intrinsics:: ctpop,
2895
- intrinsics:: ctlz,
2896
- intrinsics:: ctlz_nonzero,
2897
- intrinsics:: cttz,
2898
- intrinsics:: bswap,
2899
- intrinsics:: add_with_overflow,
2900
- intrinsics:: sub_with_overflow,
2901
- intrinsics:: mul_with_overflow }
2810
+ uint_impl ! { usize , u32 , 32 }
2902
2811
}
2903
2812
2904
2813
#[ cfg( target_pointer_width = "64" ) ]
2905
2814
#[ lang = "usize" ]
2906
2815
impl usize {
2907
- uint_impl ! { usize , u64 , 64 ,
2908
- intrinsics:: ctpop,
2909
- intrinsics:: ctlz,
2910
- intrinsics:: ctlz_nonzero,
2911
- intrinsics:: cttz,
2912
- intrinsics:: bswap,
2913
- intrinsics:: add_with_overflow,
2914
- intrinsics:: sub_with_overflow,
2915
- intrinsics:: mul_with_overflow }
2816
+ uint_impl ! { usize , u64 , 64 }
2916
2817
}
2917
2818
2918
2819
/// A classification of floating point numbers.
0 commit comments