@@ -176,9 +176,12 @@ integer! { i8, u8 }
176176integer ! { i16 , u16 }
177177integer ! { i32 , u32 }
178178integer ! { i64 , u64 }
179+ #[ cfg( not( no_128_bit) ) ]
179180integer ! { i128 , u128 }
181+
180182macro_rules! debug {
181- ( $( $T: ident) * ) => { $(
183+ ( $( $( #[ $cfg: meta] ) ? $T: ident) * ) => { $(
184+ $( #[ $cfg] ) ?
182185 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
183186 impl fmt:: Debug for $T {
184187 #[ inline]
@@ -195,8 +198,30 @@ macro_rules! debug {
195198 ) * } ;
196199}
197200debug ! {
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
200225}
201226
202227// 2 digit decimal look up table
@@ -476,9 +501,11 @@ mod imp {
476501 impl_Exp ! ( i8 , u8 , i16 , u16 , i32 , u32 , isize , usize as u32 via to_u32 named exp_u32) ;
477502 impl_Exp ! ( i64 , u64 as u64 via to_u64 named exp_u64) ;
478503}
504+ #[ cfg( not( no_128_bit) ) ]
479505impl_Exp ! ( i128 , u128 as u128 via to_u128 named exp_u128) ;
480506
481507/// 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`
482509fn parse_u64_into < const N : usize > ( mut n : u64 , buf : & mut [ MaybeUninit < u8 > ; N ] , curr : & mut usize ) {
483510 let buf_ptr = MaybeUninit :: slice_as_mut_ptr ( buf) ;
484511 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
566593}
567594
568595#[ stable( feature = "rust1" , since = "1.0.0" ) ]
596+ #[ cfg( not( no_128_bit) ) ]
569597impl fmt:: Display for u128 {
570598 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
571599 fmt_u128 ( * self , true , f)
572600 }
573601}
574602
575603#[ stable( feature = "rust1" , since = "1.0.0" ) ]
604+ #[ cfg( not( no_128_bit) ) ]
576605impl fmt:: Display for i128 {
577606 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
578607 let is_nonnegative = * self >= 0 ;
@@ -590,6 +619,7 @@ impl fmt::Display for i128 {
590619/// into at most 2 u64s, and then chunks by 10e16, 10e8, 10e4, 10e2, and then 10e1.
591620/// It also has to handle 1 last item, as 10^40 > 2^128 > 10^39, whereas
592621/// 10^20 > 2^64 > 10^19.
622+ #[ cfg( not( no_128_bit) ) ]
593623fn fmt_u128 ( n : u128 , is_nonnegative : bool , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
594624 // 2^128 is about 3*10^38, so 39 gives an extra byte of space
595625 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
649679/// in Proc. of the SIGPLAN94 Conference on Programming Language Design and
650680/// Implementation, 1994, pp. 61–72
651681///
682+ #[ cfg( not( no_128_bit) ) ]
652683fn udiv_1e19 ( n : u128 ) -> ( u128 , u64 ) {
653684 const DIV : u64 = 1e19 as u64 ;
654685 const FACTOR : u128 = 156927543384667019095894735580191660403 ;
@@ -665,6 +696,7 @@ fn udiv_1e19(n: u128) -> (u128, u64) {
665696
666697/// Multiply unsigned 128 bit integers, return upper 128 bits of the result
667698#[ inline]
699+ #[ cfg( not( no_128_bit) ) ]
668700fn u128_mulhi ( x : u128 , y : u128 ) -> u128 {
669701 let x_lo = x as u64 ;
670702 let x_hi = ( x >> 64 ) as u64 ;
0 commit comments