@@ -66,7 +66,7 @@ pub mod reimpls {
66
66
}
67
67
68
68
#[ export_name="__ashlti3" ]
69
- pub extern fn shl ( a : u128_ , b : u128_ ) -> u128_ {
69
+ pub extern "C" fn shl ( a : u128_ , b : u128_ ) -> u128_ {
70
70
ashl ! ( a, b, u128_)
71
71
}
72
72
@@ -89,7 +89,7 @@ pub mod reimpls {
89
89
}
90
90
91
91
#[ export_name="__ashrti3" ]
92
- pub extern fn shr ( a : i128_ , b : i128_ ) -> i128_ {
92
+ pub extern "C" fn shr ( a : i128_ , b : i128_ ) -> i128_ {
93
93
ashr ! ( a, b, i128_)
94
94
}
95
95
@@ -110,13 +110,13 @@ pub mod reimpls {
110
110
111
111
112
112
#[ export_name="__lshrti3" ]
113
- pub extern fn lshr ( a : u128_ , b : u128_ ) -> u128_ {
113
+ pub extern "C" fn lshr ( a : u128_ , b : u128_ ) -> u128_ {
114
114
lshr ! ( a, b, u128_)
115
115
}
116
116
117
117
#[ cfg( stage0) ]
118
118
#[ export_name="__udivmodti4" ]
119
- pub extern fn u128_div_mod ( n : u128_ , d : u128_ , rem : * mut u128_ ) -> u128_ {
119
+ pub extern "C" fn u128_div_mod ( n : u128_ , d : u128_ , rem : * mut u128_ ) -> u128_ {
120
120
unsafe {
121
121
if !rem. is_null ( ) {
122
122
* rem = unchecked_rem ( n, d) ;
@@ -127,7 +127,7 @@ pub mod reimpls {
127
127
128
128
#[ cfg( not( stage0) ) ]
129
129
#[ export_name="__udivmodti4" ]
130
- pub extern fn u128_div_mod ( n : u128_ , d : u128_ , rem : * mut u128_ ) -> u128_ {
130
+ pub extern "C" fn u128_div_mod ( n : u128_ , d : u128_ , rem : * mut u128_ ) -> u128_ {
131
131
// Translated from Figure 3-40 of The PowerPC Compiler Writer's Guide
132
132
unsafe {
133
133
// special cases, X is unknown, K != 0
@@ -261,7 +261,12 @@ pub mod reimpls {
261
261
// 1 <= sr <= u64::bits() - 1
262
262
let mut carry = 0 ;
263
263
264
- for _ in 0 ..sr {
264
+ // FIXME: replace this with a for loop
265
+ // (atm not doable as this generates call to
266
+ // eh_personality when optimisations are turned off,
267
+ // which in turn gives a linker error in later
268
+ // compilation steps)
269
+ while sr > 0 {
265
270
// r:q = ((r:q) << 1) | carry
266
271
r = ( r << 1 ) | ( q >> ( 128 - 1 ) ) ;
267
272
q = ( q << 1 ) | carry as u128 ;
@@ -274,6 +279,7 @@ pub mod reimpls {
274
279
let s = ( d. wrapping_sub ( r) . wrapping_sub ( 1 ) ) as i128 >> ( 128 - 1 ) ;
275
280
carry = ( s & 1 ) as u64 ;
276
281
r -= d & s as u128 ;
282
+ sr -= 1 ;
277
283
}
278
284
279
285
if !rem. is_null ( ) {
@@ -284,7 +290,7 @@ pub mod reimpls {
284
290
}
285
291
286
292
#[ export_name="__umodti3" ]
287
- pub extern fn u128_mod ( a : u128_ , b : u128_ ) -> u128_ {
293
+ pub extern "C" fn u128_mod ( a : u128_ , b : u128_ ) -> u128_ {
288
294
unsafe {
289
295
let mut r = :: core:: mem:: zeroed ( ) ;
290
296
u128_div_mod ( a, b, & mut r) ;
@@ -293,7 +299,7 @@ pub mod reimpls {
293
299
}
294
300
295
301
#[ export_name="__modti3" ]
296
- pub extern fn i128_mod ( a : i128_ , b : i128_ ) -> i128_ {
302
+ pub extern "C" fn i128_mod ( a : i128_ , b : i128_ ) -> i128_ {
297
303
let b = b. uabs ( ) ;
298
304
let sa = a. signum ( ) ;
299
305
let a = a. uabs ( ) ;
@@ -305,7 +311,7 @@ pub mod reimpls {
305
311
}
306
312
307
313
#[ export_name="__divti3" ]
308
- pub extern fn i128_div ( a : i128_ , b : i128_ ) -> i128_ {
314
+ pub extern "C" fn i128_div ( a : i128_ , b : i128_ ) -> i128_ {
309
315
let sa = a. signum ( ) ;
310
316
let sb = b. signum ( ) ;
311
317
let a = a. uabs ( ) ;
@@ -319,7 +325,7 @@ pub mod reimpls {
319
325
}
320
326
321
327
#[ export_name="__udivti3" ]
322
- pub extern fn u128_div ( a : u128_ , b : u128_ ) -> u128_ {
328
+ pub extern "C" fn u128_div ( a : u128_ , b : u128_ ) -> u128_ {
323
329
u128_div_mod ( a, b, ptr:: null_mut ( ) )
324
330
}
325
331
@@ -365,7 +371,7 @@ pub mod reimpls {
365
371
366
372
// FIXME: i32 here should be c_int.
367
373
#[ export_name="__muloti4" ]
368
- pub extern fn i128_mul_oflow ( a : i128_ , b : i128_ , o : & mut i32 ) -> i128_ {
374
+ pub extern "C" fn i128_mul_oflow ( a : i128_ , b : i128_ , o : & mut i32 ) -> i128_ {
369
375
mulo ! ( a, b, o, i128_)
370
376
}
371
377
@@ -465,24 +471,25 @@ pub mod reimpls {
465
471
466
472
#[ cfg( stage0) ]
467
473
#[ export_name="__multi3" ]
468
- pub extern fn u128_mul ( a : i128_ , b : i128_ ) -> i128_ {
474
+ pub extern "C" fn u128_mul ( a : i128_ , b : i128_ ) -> i128_ {
469
475
( a as i64 * b as i64 ) as i128_
470
476
}
471
477
472
478
#[ cfg( not( stage0) ) ]
473
479
#[ export_name="__multi3" ]
474
- pub extern fn u128_mul ( a : i128_ , b : i128_ ) -> i128_ {
480
+ pub extern "C" fn u128_mul ( a : i128_ , b : i128_ ) -> i128_ {
475
481
mul ! ( a, b, i128_, i64 )
476
482
}
477
483
478
484
trait AbsExt : Sized {
479
- fn uabs ( self ) -> u128_ {
480
- self . iabs ( ) as u128_
481
- }
485
+ fn uabs ( self ) -> u128_ ;
482
486
fn iabs ( self ) -> i128_ ;
483
487
}
484
488
485
489
impl AbsExt for i128_ {
490
+ fn uabs ( self ) -> u128_ {
491
+ self . iabs ( ) as u128_
492
+ }
486
493
fn iabs ( self ) -> i128_ {
487
494
( ( self ^ self ) . wrapping_sub ( self ) )
488
495
}
@@ -550,12 +557,12 @@ pub mod reimpls {
550
557
}
551
558
552
559
#[ export_name="__fixunsdfti" ]
553
- pub extern fn f64_as_u128 ( a : f64 ) -> u128_ {
560
+ pub extern "C" fn f64_as_u128 ( a : f64 ) -> u128_ {
554
561
float_as_unsigned ! ( a, f64 , u128_)
555
562
}
556
563
557
564
#[ export_name="__fixunssfti" ]
558
- pub extern fn f32_as_u128 ( a : f32 ) -> u128_ {
565
+ pub extern "C" fn f32_as_u128 ( a : f32 ) -> u128_ {
559
566
float_as_unsigned ! ( a, f32 , u128_)
560
567
}
561
568
@@ -582,17 +589,17 @@ pub mod reimpls {
582
589
}
583
590
584
591
#[ export_name="__fixdfti" ]
585
- pub extern fn f64_as_i128 ( a : f64 ) -> i128_ {
592
+ pub extern "C" fn f64_as_i128 ( a : f64 ) -> i128_ {
586
593
float_as_signed ! ( a, f64 , i128_)
587
594
}
588
595
589
596
#[ export_name="__fixsfti" ]
590
- pub extern fn f32_as_i128 ( a : f32 ) -> i128_ {
597
+ pub extern "C" fn f32_as_i128 ( a : f32 ) -> i128_ {
591
598
float_as_signed ! ( a, f32 , i128_)
592
599
}
593
600
594
601
#[ export_name="__floattidf" ]
595
- pub extern fn i128_as_f64 ( a : i128_ ) -> f64 {
602
+ pub extern "C" fn i128_as_f64 ( a : i128_ ) -> f64 {
596
603
match a. signum ( ) {
597
604
1 => u128_as_f64 ( a. uabs ( ) ) ,
598
605
0 => 0.0 ,
@@ -602,7 +609,7 @@ pub mod reimpls {
602
609
}
603
610
604
611
#[ export_name="__floattisf" ]
605
- pub extern fn i128_as_f32 ( a : i128_ ) -> f32 {
612
+ pub extern "C" fn i128_as_f32 ( a : i128_ ) -> f32 {
606
613
match a. signum ( ) {
607
614
1 => u128_as_f32 ( a. uabs ( ) ) ,
608
615
0 => 0.0 ,
@@ -612,7 +619,7 @@ pub mod reimpls {
612
619
}
613
620
614
621
#[ export_name="__floatuntidf" ]
615
- pub extern fn u128_as_f64 ( mut a : u128_ ) -> f64 {
622
+ pub extern "C" fn u128_as_f64 ( mut a : u128_ ) -> f64 {
616
623
use :: core:: f64:: MANTISSA_DIGITS ;
617
624
if a == 0 { return 0.0 ; }
618
625
let sd = 128 - a. leading_zeros ( ) ;
@@ -643,7 +650,7 @@ pub mod reimpls {
643
650
}
644
651
645
652
#[ export_name="__floatuntisf" ]
646
- pub extern fn u128_as_f32 ( mut a : u128_ ) -> f32 {
653
+ pub extern "C" fn u128_as_f32 ( mut a : u128_ ) -> f32 {
647
654
use :: core:: f32:: MANTISSA_DIGITS ;
648
655
if a == 0 { return 0.0 ; }
649
656
let sd = 128 - a. leading_zeros ( ) ;
0 commit comments