This repository was archived by the owner on May 21, 2019. It is now read-only.
File tree 2 files changed +13
-13
lines changed
2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -22,27 +22,26 @@ COMPILER_RT_ABI fp_t
22
22
__floatsidf (int a ) {
23
23
24
24
const int aWidth = sizeof a * CHAR_BIT ;
25
-
25
+
26
26
// Handle zero as a special case to protect clz
27
27
if (a == 0 )
28
28
return fromRep (0 );
29
29
30
30
// All other cases begin by extracting the sign and absolute value of a
31
31
rep_t sign = 0 ;
32
+ unsigned aAbs = (unsigned )a ;
32
33
if (a < 0 ) {
33
34
sign = signBit ;
34
- a = - a ;
35
+ aAbs = ~( unsigned ) a + 1U ;
35
36
}
36
37
37
38
// Exponent of (fp_t)a is the width of abs(a).
38
- const int exponent = (aWidth - 1 ) - __builtin_clz (a );
39
+ const int exponent = (aWidth - 1 ) - __builtin_clz (aAbs );
39
40
rep_t result ;
40
41
41
- // Shift a into the significand field and clear the implicit bit. Extra
42
- // cast to unsigned int is necessary to get the correct behavior for
43
- // the input INT_MIN.
42
+ // Shift a into the significand field and clear the implicit bit.
44
43
const int shift = significandBits - exponent ;
45
- result = (rep_t )( unsigned int ) a << shift ^ implicitBit ;
44
+ result = (rep_t )aAbs << shift ^ implicitBit ;
46
45
47
46
// Insert the exponent
48
47
result += (rep_t )(exponent + exponentBias ) << significandBits ;
Original file line number Diff line number Diff line change @@ -22,30 +22,31 @@ COMPILER_RT_ABI fp_t
22
22
__floatsisf (int a ) {
23
23
24
24
const int aWidth = sizeof a * CHAR_BIT ;
25
-
25
+
26
26
// Handle zero as a special case to protect clz
27
27
if (a == 0 )
28
28
return fromRep (0 );
29
29
30
30
// All other cases begin by extracting the sign and absolute value of a
31
31
rep_t sign = 0 ;
32
+ unsigned aAbs = (unsigned )a ;
32
33
if (a < 0 ) {
33
34
sign = signBit ;
34
- a = - a ;
35
+ aAbs = ~( unsigned ) a + 1U ;
35
36
}
36
37
37
38
// Exponent of (fp_t)a is the width of abs(a).
38
- const int exponent = (aWidth - 1 ) - __builtin_clz (a );
39
+ const int exponent = (aWidth - 1 ) - __builtin_clz (aAbs );
39
40
rep_t result ;
40
41
41
42
// Shift a into the significand field, rounding if it is a right-shift
42
43
if (exponent <= significandBits ) {
43
44
const int shift = significandBits - exponent ;
44
- result = (rep_t )a << shift ^ implicitBit ;
45
+ result = (rep_t )aAbs << shift ^ implicitBit ;
45
46
} else {
46
47
const int shift = exponent - significandBits ;
47
- result = (rep_t )a >> shift ^ implicitBit ;
48
- rep_t round = (rep_t )a << (typeWidth - shift );
48
+ result = (rep_t )aAbs >> shift ^ implicitBit ;
49
+ rep_t round = (rep_t )aAbs << (typeWidth - shift );
49
50
if (round > signBit ) result ++ ;
50
51
if (round == signBit ) result += result & 1 ;
51
52
}
You can’t perform that action at this time.
0 commit comments