@@ -103,6 +103,24 @@ mod int_to_float {
103103 repr :: < f64 > ( e, m)
104104 }
105105
106+ #[ cfg( f128_enabled) ]
107+ pub fn u32_to_f128_bits ( i : u32 ) -> u128 {
108+ if i == 0 {
109+ return 0 ;
110+ }
111+ let n = i. leading_zeros ( ) ;
112+
113+ // Shift into mantissa position that is correct for the type, but shifted into the lower
114+ // 64 bits over so can can avoid 128-bit math.
115+ let m = ( i as u64 ) << ( shift_f_gt_i :: < u32 , f128 > ( n) - 64 ) ;
116+ let e = exp :: < u32 , f128 > ( n) as u64 - 1 ;
117+ // High 64 bits of f128 representation.
118+ let h = ( e << ( f128:: SIGNIFICAND_BITS - 64 ) ) + m;
119+
120+ // Shift back to the high bits, the rest of the mantissa will always be 0.
121+ ( h as u128 ) << 64
122+ }
123+
106124 pub fn u64_to_f32_bits ( i : u64 ) -> u32 {
107125 let n = i. leading_zeros ( ) ;
108126 let i_m = i. wrapping_shl ( n) ;
@@ -129,6 +147,18 @@ mod int_to_float {
129147 repr :: < f64 > ( e, m)
130148 }
131149
150+ #[ cfg( f128_enabled) ]
151+ pub fn u64_to_f128_bits ( i : u64 ) -> u128 {
152+ if i == 0 {
153+ return 0 ;
154+ }
155+ let n = i. leading_zeros ( ) ;
156+ // Mantissa with implicit bit set
157+ let m = ( i as u128 ) << shift_f_gt_i :: < u64 , f128 > ( n) ;
158+ let e = exp :: < u64 , f128 > ( n) - 1 ;
159+ repr :: < f128 > ( e, m)
160+ }
161+
132162 pub fn u128_to_f32_bits ( i : u128 ) -> u32 {
133163 let n = i. leading_zeros ( ) ;
134164 let i_m = i. wrapping_shl ( n) ; // Mantissa, shifted so the first bit is nonzero
@@ -161,6 +191,20 @@ mod int_to_float {
161191 let e = if i == 0 { 0 } else { exp :: < u128 , f64 > ( n) - 1 } ;
162192 repr :: < f64 > ( e, m)
163193 }
194+
195+ #[ cfg( f128_enabled) ]
196+ pub fn u128_to_f128_bits ( i : u128 ) -> u128 {
197+ if i == 0 {
198+ return 0 ;
199+ }
200+ let n = i. leading_zeros ( ) ;
201+ // Mantissa with implicit bit set
202+ let m_base = ( i << n) >> f128:: EXPONENT_BITS ;
203+ let adj = ( i << n) << ( f128:: SIGNIFICAND_BITS + 1 ) ;
204+ let m = m_adj :: < f128 > ( m_base, adj) ;
205+ let e = exp :: < u128 , f128 > ( n) - 1 ;
206+ repr :: < f128 > ( e, m)
207+ }
164208}
165209
166210// Conversions from unsigned integers to floats.
@@ -194,6 +238,24 @@ intrinsics! {
194238 pub extern "C" fn __floatuntidf( i: u128 ) -> f64 {
195239 f64 :: from_bits( int_to_float:: u128_to_f64_bits( i) )
196240 }
241+
242+ #[ ppc_alias = __floatunsikf]
243+ #[ cfg( f128_enabled) ]
244+ pub extern "C" fn __floatunsitf( i: u32 ) -> f128 {
245+ f128:: from_bits( int_to_float:: u32_to_f128_bits( i) )
246+ }
247+
248+ #[ ppc_alias = __floatundikf]
249+ #[ cfg( f128_enabled) ]
250+ pub extern "C" fn __floatunditf( i: u64 ) -> f128 {
251+ f128:: from_bits( int_to_float:: u64_to_f128_bits( i) )
252+ }
253+
254+ #[ ppc_alias = __floatuntikf]
255+ #[ cfg( f128_enabled) ]
256+ pub extern "C" fn __floatuntitf( i: u128 ) -> f128 {
257+ f128:: from_bits( int_to_float:: u128_to_f128_bits( i) )
258+ }
197259}
198260
199261// Conversions from signed integers to floats.
@@ -227,6 +289,24 @@ intrinsics! {
227289 pub extern "C" fn __floattidf( i: i128 ) -> f64 {
228290 int_to_float:: signed( i, int_to_float:: u128_to_f64_bits)
229291 }
292+
293+ #[ ppc_alias = __floatsikf]
294+ #[ cfg( f128_enabled) ]
295+ pub extern "C" fn __floatsitf( i: i32 ) -> f128 {
296+ int_to_float:: signed( i, int_to_float:: u32_to_f128_bits)
297+ }
298+
299+ #[ ppc_alias = __floatdikf]
300+ #[ cfg( f128_enabled) ]
301+ pub extern "C" fn __floatditf( i: i64 ) -> f128 {
302+ int_to_float:: signed( i, int_to_float:: u64_to_f128_bits)
303+ }
304+
305+ #[ ppc_alias = __floattikf]
306+ #[ cfg( f128_enabled) ]
307+ pub extern "C" fn __floattitf( i: i128 ) -> f128 {
308+ int_to_float:: signed( i, int_to_float:: u128_to_f128_bits)
309+ }
230310}
231311
232312/// Generic float to unsigned int conversions.
0 commit comments