1
1
use crate :: float:: Float ;
2
- use crate :: int:: { CastInto , Int } ;
2
+ use crate :: int:: { CastInto , Int , MinInt } ;
3
3
4
4
/// Returns `a + b`
5
5
fn add < F : Float > ( a : F , b : F ) -> F
@@ -57,17 +57,17 @@ where
57
57
}
58
58
59
59
// zero + anything = anything
60
- if a_abs == Int :: ZERO {
60
+ if a_abs == MinInt :: ZERO {
61
61
// but we need to get the sign right for zero + zero
62
- if b_abs == Int :: ZERO {
62
+ if b_abs == MinInt :: ZERO {
63
63
return F :: from_repr ( a. repr ( ) & b. repr ( ) ) ;
64
64
} else {
65
65
return b;
66
66
}
67
67
}
68
68
69
69
// anything + zero = anything
70
- if b_abs == Int :: ZERO {
70
+ if b_abs == MinInt :: ZERO {
71
71
return a;
72
72
}
73
73
}
@@ -113,10 +113,10 @@ where
113
113
// Shift the significand of b by the difference in exponents, with a sticky
114
114
// bottom bit to get rounding correct.
115
115
let align = a_exponent. wrapping_sub ( b_exponent) . cast ( ) ;
116
- if align != Int :: ZERO {
116
+ if align != MinInt :: ZERO {
117
117
if align < bits {
118
118
let sticky =
119
- F :: Int :: from_bool ( b_significand << bits. wrapping_sub ( align) . cast ( ) != Int :: ZERO ) ;
119
+ F :: Int :: from_bool ( b_significand << bits. wrapping_sub ( align) . cast ( ) != MinInt :: ZERO ) ;
120
120
b_significand = ( b_significand >> align. cast ( ) ) | sticky;
121
121
} else {
122
122
b_significand = one; // sticky; b is known to be non-zero.
@@ -125,8 +125,8 @@ where
125
125
if subtraction {
126
126
a_significand = a_significand. wrapping_sub ( b_significand) ;
127
127
// If a == -b, return +zero.
128
- if a_significand == Int :: ZERO {
129
- return F :: from_repr ( Int :: ZERO ) ;
128
+ if a_significand == MinInt :: ZERO {
129
+ return F :: from_repr ( MinInt :: ZERO ) ;
130
130
}
131
131
132
132
// If partial cancellation occured, we need to left-shift the result
@@ -143,8 +143,8 @@ where
143
143
144
144
// If the addition carried up, we need to right-shift the result and
145
145
// adjust the exponent:
146
- if a_significand & implicit_bit << 4 != Int :: ZERO {
147
- let sticky = F :: Int :: from_bool ( a_significand & one != Int :: ZERO ) ;
146
+ if a_significand & implicit_bit << 4 != MinInt :: ZERO {
147
+ let sticky = F :: Int :: from_bool ( a_significand & one != MinInt :: ZERO ) ;
148
148
a_significand = a_significand >> 1 | sticky;
149
149
a_exponent += 1 ;
150
150
}
@@ -160,7 +160,7 @@ where
160
160
// need to shift the significand.
161
161
let shift = ( 1 - a_exponent) . cast ( ) ;
162
162
let sticky =
163
- F :: Int :: from_bool ( ( a_significand << bits. wrapping_sub ( shift) . cast ( ) ) != Int :: ZERO ) ;
163
+ F :: Int :: from_bool ( ( a_significand << bits. wrapping_sub ( shift) . cast ( ) ) != MinInt :: ZERO ) ;
164
164
a_significand = a_significand >> shift. cast ( ) | sticky;
165
165
a_exponent = 0 ;
166
166
}
@@ -203,6 +203,16 @@ intrinsics! {
203
203
add( a, b)
204
204
}
205
205
206
+ #[ cfg( not( any( feature = "no-f16-f128" , target_arch = "powerpc" , target_arch = "powerpc64" ) ) ) ]
207
+ pub extern "C" fn __addtf3( a: f128, b: f128) -> f128 {
208
+ add( a, b)
209
+ }
210
+
211
+ #[ cfg( all( not( feature = "no-f16-f128" ) , any( target_arch = "powerpc" , target_arch = "powerpc64" ) ) ) ]
212
+ pub extern "C" fn __addkf3( a: f128, b: f128) -> f128 {
213
+ add( a, b)
214
+ }
215
+
206
216
#[ cfg( target_arch = "arm" ) ]
207
217
pub extern "C" fn __addsf3vfp( a: f32 , b: f32 ) -> f32 {
208
218
a + b
0 commit comments