summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Dmitrouk <sdmitrouk@accesssoftek.com>2015-07-31 13:32:09 +0000
committerSergey Dmitrouk <sdmitrouk@accesssoftek.com>2015-07-31 13:32:09 +0000
commita2ce083d2daac54f3c026a2e0e04fc53338c47c6 (patch)
tree341d51fa7b01d6421f35f9bc97f11ee857f27e68
parente82f2947fd45e972614c80c99187df3588a200cc (diff)
downloadbcm5719-llvm-a2ce083d2daac54f3c026a2e0e04fc53338c47c6.tar.gz
bcm5719-llvm-a2ce083d2daac54f3c026a2e0e04fc53338c47c6.zip
Fix __floatsitf() for negative input
Negative numbers were handled properly initially, but got broken during addressing review, so none of them did actually work. Issues: * Wrong negation. * Wrong exponent calculation. llvm-svn: 243746
-rw-r--r--compiler-rt/lib/builtins/floatsitf.c8
-rw-r--r--compiler-rt/test/builtins/Unit/floatsitf_test.c2
2 files changed, 5 insertions, 5 deletions
diff --git a/compiler-rt/lib/builtins/floatsitf.c b/compiler-rt/lib/builtins/floatsitf.c
index 85346933f81..f0abca363b5 100644
--- a/compiler-rt/lib/builtins/floatsitf.c
+++ b/compiler-rt/lib/builtins/floatsitf.c
@@ -30,16 +30,14 @@ COMPILER_RT_ABI fp_t __floatsitf(int a) {
unsigned aAbs = (unsigned)a;
if (a < 0) {
sign = signBit;
- aAbs += 0x80000000;
+ aAbs = ~(unsigned)a + 1U;
}
// Exponent of (fp_t)a is the width of abs(a).
- const int exponent = (aWidth - 1) - __builtin_clz(a);
+ const int exponent = (aWidth - 1) - __builtin_clz(aAbs);
rep_t result;
- // Shift a into the significand field and clear the implicit bit. Extra
- // cast to unsigned int is necessary to get the correct behavior for
- // the input INT_MIN.
+ // Shift a into the significand field and clear the implicit bit.
const int shift = significandBits - exponent;
result = (rep_t)aAbs << shift ^ implicitBit;
diff --git a/compiler-rt/test/builtins/Unit/floatsitf_test.c b/compiler-rt/test/builtins/Unit/floatsitf_test.c
index 8373c7d96e2..6f98721b0a5 100644
--- a/compiler-rt/test/builtins/Unit/floatsitf_test.c
+++ b/compiler-rt/test/builtins/Unit/floatsitf_test.c
@@ -40,6 +40,8 @@ char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
int main()
{
#if __LDBL_MANT_DIG__ == 113
+ if (test__floatsitf(0x80000000, UINT64_C(0xc01e000000000000), UINT64_C(0x0)))
+ return 1;
if (test__floatsitf(0x7fffffff, UINT64_C(0x401dfffffffc0000), UINT64_C(0x0)))
return 1;
if (test__floatsitf(0, UINT64_C(0x0), UINT64_C(0x0)))
OpenPOWER on IntegriCloud