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