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