@@ -176,9 +176,12 @@ integer! { i8, u8 }
176
176
integer ! { i16 , u16 }
177
177
integer ! { i32 , u32 }
178
178
integer ! { i64 , u64 }
179
+ #[ cfg( not( no_128_bit) ) ]
179
180
integer ! { i128 , u128 }
181
+
180
182
macro_rules! debug {
181
- ( $( $T: ident) * ) => { $(
183
+ ( $( $( #[ $cfg: meta] ) ? $T: ident) * ) => { $(
184
+ $( #[ $cfg] ) ?
182
185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
183
186
impl fmt:: Debug for $T {
184
187
#[ inline]
@@ -195,8 +198,30 @@ macro_rules! debug {
195
198
) * } ;
196
199
}
197
200
debug ! {
198
- i8 i16 i32 i64 i128 isize
199
- u8 u16 u32 u64 u128 usize
201
+ i8 i16 i32 i64 #[ cfg( not( no_128_bit) ) ] i128 isize
202
+ u8 u16 u32 u64 #[ cfg( not( no_128_bit) ) ] u128 usize
203
+ }
204
+
205
+ macro_rules! fake_debug {
206
+ ( $( $( #[ $cfg: meta] ) ? $T: ident) * ) => { $(
207
+ $( #[ $cfg] ) ?
208
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
209
+ impl fmt:: Debug for $T {
210
+ #[ inline]
211
+ fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
212
+ // Debug formats are not stable so this is a legitimate implementation.
213
+ // It would be possible to hexdump the contents instead, or to
214
+ // fail or panic, but for an application which has specifically
215
+ // recompiled core to avoid i128, the former seems unnecessary
216
+ // and the latter needlessly harmful.
217
+ f. write_str( stringify!( $T) )
218
+ }
219
+ }
220
+ ) * }
221
+ }
222
+ fake_debug ! {
223
+ #[ cfg( no_128_bit) ] i128
224
+ #[ cfg( no_128_bit) ] u128
200
225
}
201
226
202
227
// 2 digit decimal look up table
@@ -476,9 +501,11 @@ mod imp {
476
501
impl_Exp ! ( i8 , u8 , i16 , u16 , i32 , u32 , isize , usize as u32 via to_u32 named exp_u32) ;
477
502
impl_Exp ! ( i64 , u64 as u64 via to_u64 named exp_u64) ;
478
503
}
504
+ #[ cfg( not( no_128_bit) ) ]
479
505
impl_Exp ! ( i128 , u128 as u128 via to_u128 named exp_u128) ;
480
506
481
507
/// Helper function for writing a u64 into `buf` going from last to first, with `curr`.
508
+ #[ cfg( not( no_128_bit) ) ] // unused for `no_128_bit`
482
509
fn parse_u64_into < const N : usize > ( mut n : u64 , buf : & mut [ MaybeUninit < u8 > ; N ] , curr : & mut usize ) {
483
510
let buf_ptr = MaybeUninit :: slice_as_mut_ptr ( buf) ;
484
511
let lut_ptr = DEC_DIGITS_LUT . as_ptr ( ) ;
@@ -566,13 +593,15 @@ fn parse_u64_into<const N: usize>(mut n: u64, buf: &mut [MaybeUninit<u8>; N], cu
566
593
}
567
594
568
595
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
596
+ #[ cfg( not( no_128_bit) ) ]
569
597
impl fmt:: Display for u128 {
570
598
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
571
599
fmt_u128 ( * self , true , f)
572
600
}
573
601
}
574
602
575
603
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
604
+ #[ cfg( not( no_128_bit) ) ]
576
605
impl fmt:: Display for i128 {
577
606
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
578
607
let is_nonnegative = * self >= 0 ;
@@ -590,6 +619,7 @@ impl fmt::Display for i128 {
590
619
/// into at most 2 u64s, and then chunks by 10e16, 10e8, 10e4, 10e2, and then 10e1.
591
620
/// It also has to handle 1 last item, as 10^40 > 2^128 > 10^39, whereas
592
621
/// 10^20 > 2^64 > 10^19.
622
+ #[ cfg( not( no_128_bit) ) ]
593
623
fn fmt_u128 ( n : u128 , is_nonnegative : bool , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
594
624
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
595
625
let mut buf = [ MaybeUninit :: < u8 > :: uninit ( ) ; 39 ] ;
@@ -649,6 +679,7 @@ fn fmt_u128(n: u128, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::R
649
679
/// in Proc. of the SIGPLAN94 Conference on Programming Language Design and
650
680
/// Implementation, 1994, pp. 61–72
651
681
///
682
+ #[ cfg( not( no_128_bit) ) ]
652
683
fn udiv_1e19 ( n : u128 ) -> ( u128 , u64 ) {
653
684
const DIV : u64 = 1e19 as u64 ;
654
685
const FACTOR : u128 = 156927543384667019095894735580191660403 ;
@@ -665,6 +696,7 @@ fn udiv_1e19(n: u128) -> (u128, u64) {
665
696
666
697
/// Multiply unsigned 128 bit integers, return upper 128 bits of the result
667
698
#[ inline]
699
+ #[ cfg( not( no_128_bit) ) ]
668
700
fn u128_mulhi ( x : u128 , y : u128 ) -> u128 {
669
701
let x_lo = x as u64 ;
670
702
let x_hi = ( x >> 64 ) as u64 ;
0 commit comments