[compiler-rt] r243746 - Fix __floatsitf() for negative input
Sergey Dmitrouk
sdmitrouk at accesssoftek.com
Fri Jul 31 06:32:09 PDT 2015
Author: sdmitrouk
Date: Fri Jul 31 08:32:09 2015
New Revision: 243746
URL: http://llvm.org/viewvc/llvm-project?rev=243746&view=rev
Log:
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.
Modified:
compiler-rt/trunk/lib/builtins/floatsitf.c
compiler-rt/trunk/test/builtins/Unit/floatsitf_test.c
Modified: compiler-rt/trunk/lib/builtins/floatsitf.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/floatsitf.c?rev=243746&r1=243745&r2=243746&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/floatsitf.c (original)
+++ compiler-rt/trunk/lib/builtins/floatsitf.c Fri Jul 31 08:32:09 2015
@@ -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;
Modified: compiler-rt/trunk/test/builtins/Unit/floatsitf_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/floatsitf_test.c?rev=243746&r1=243745&r2=243746&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/floatsitf_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/floatsitf_test.c Fri Jul 31 08:32:09 2015
@@ -40,6 +40,8 @@ char assumption_1[sizeof(long double) *
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)))
More information about the llvm-commits
mailing list