public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0
@ 2013-02-18 16:57 burnus at gcc dot gnu.org
  2013-02-18 17:31 ` [Bug libquadmath/56379] " burnus at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-18 16:57 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

             Bug #: 56379
           Summary: libquadmath: Wrong result for strtoflt128.c if
                    compiled with -O0
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libquadmath
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: jakub@gcc.gnu.org


As reported by Tilo Schwarz at
http://gcc.gnu.org/ml/fortran/2013-02/msg00091.html

When libquadmath's strtod/strtoflt128.c is compiled with -O1 or -O2, it gives
the correct result. However, for -O0 it doesn't. Hence, gfortran.dg/quad_2.f90
fails.

Mathematically,
sqrt(2.0) ==
1.414213562373095048801688724209698078569671875376948073176679737990…

The string str3 is (== fp2 and == fp4 with -O1/-O2):
    str3 is "1.41421356237309504880168872420969798"

If libquadmath/strtod/strtoflt128.c is compiled with -O0, reading the string to
fp4 and printing its value yields:
   fp4:     "1.41421356237309504885589883283397321"
   fp2-fp4: -0.00000000000000000005421010862427522


Might (or might not) be related to PR48111 (strtoflt128 on MinGW).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
@ 2013-02-18 17:31 ` burnus at gcc dot gnu.org
  2013-02-18 23:42 ` burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-18 17:31 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-18 17:31:26 UTC ---
C test case

#include <quadmath.h>
#include <stdio.h>
int main ()
{
  __float128 r, sqrt2;
  r = strtoflt128 ("1.41421356237309504880168872420969798", NULL);
  printf ( "sqrt(2)=1.41421356237309504880168872420969798\n");
  printf ( "r      =%37.35Qf\n", r);
  return 0;
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
  2013-02-18 17:31 ` [Bug libquadmath/56379] " burnus at gcc dot gnu.org
@ 2013-02-18 23:42 ` burnus at gcc dot gnu.org
  2013-02-19 10:16 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-18 23:42 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-18 23:42:18 UTC ---
Some debugging. If one adds the following debugging patch:

--- a/libquadmath/strtod/strtod_l.c
+++ b/libquadmath/strtod/strtod_l.c
@@ -441,3 +441,5 @@ mpn_lshift_1 (mp_limb_t *ptr, mp_size_t size, unsigned int
count,
     {
+printf("1:mpn_lshift_1 ptr=%lu, size=%u, count=%u\n", ptr[0], size, count);
       (void) mpn_lshift (ptr, ptr, size, count);
+printf("2:mpn_lshift_1 ptr=%lu, size=%u, count=%u\n", ptr[0], size, count);
       ptr[0] |= limb >> (BITS_PER_MP_LIMB - count);


One gets with -O1 (for strtod/strtoflt128.c):
1:mpn_lshift_1 ptr=7640891576956012808, size=2, count=48
2:mpn_lshift_1 ptr=14485828201437200384, size=2, count=48
sqrt(2)=1.41421356237309504880168872420969798
r      =1.41421356237309504880168872420969798


And with -O0 (for strtod/strtoflt128.c):
1:mpn_lshift_1 ptr=1, size=2, count=64
2:mpn_lshift_1 ptr=1, size=2, count=64
1:mpn_lshift_1 ptr=7640891576956012809, size=2, count=48
2:mpn_lshift_1 ptr=14486109676413911040, size=2, count=48
sqrt(2)=1.41421356237309504880168872420969798
r      =1.41421356237309504885589883283397321


Note: "mpn_lshift" itself is in printf/lshift.c, which is compiled with default
options, i.e. with -O2.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
  2013-02-18 17:31 ` [Bug libquadmath/56379] " burnus at gcc dot gnu.org
  2013-02-18 23:42 ` burnus at gcc dot gnu.org
@ 2013-02-19 10:16 ` jakub at gcc dot gnu.org
  2013-02-19 11:28 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-19 10:16 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-19 10:16:17 UTC ---
Yeah, the bug is obvious.  glibc refuses to compile with -O0, so it was never a
problem for it.
The problem is that while mpn_lshift_1 function is always_inline, at -O0 the
__builtin_constant_p folds to 0 early in:
if (__builtin_constant_p (count) && count == BITS_PER_MP_LIMB)
and the else code isn't prepared to handle BITS_PER_MP_LIMB value.
The function is always either called with constant BITS_PER_MP_LIMB count, or
variable count that is always < BITS_PER_MP_LIMB, so it works fine for -O1+.

To fix this, either mpn_lshift_1 could be rewritten as macro, or as a macro
calling two different inline functions, or __builtin_constant_p (count) &&
could be guarded with #ifdef __OPTIMIZE__.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-02-19 10:16 ` jakub at gcc dot gnu.org
@ 2013-02-19 11:28 ` burnus at gcc dot gnu.org
  2013-02-19 21:50 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-19 11:28 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-02-19
     Ever Confirmed|0                           |1

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-19 11:28:27 UTC ---
RFC patch to solve this upstream at GLIBC:
http://www.sourceware.org/ml/libc-alpha/2013-02/msg00372.html


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2013-02-19 11:28 ` burnus at gcc dot gnu.org
@ 2013-02-19 21:50 ` jakub at gcc dot gnu.org
  2013-03-06 10:39 ` skannan at redhat dot com
  2013-03-06 21:46 ` burnus at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-19 21:50 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-19 21:50:14 UTC ---
Author: jakub
Date: Tue Feb 19 21:50:10 2013
New Revision: 196155

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196155
Log:
    PR libquadmath/56379
    * strtod/strtod_l.c (mpn_lshift_1): Rewritten as function-like
    macro.

Modified:
    trunk/libquadmath/ChangeLog
    trunk/libquadmath/strtod/strtod_l.c


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2013-02-19 21:50 ` jakub at gcc dot gnu.org
@ 2013-03-06 10:39 ` skannan at redhat dot com
  2013-03-06 21:46 ` burnus at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: skannan at redhat dot com @ 2013-03-06 10:39 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

Shakthi Kannan <skannan at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |skannan at redhat dot com

--- Comment #6 from Shakthi Kannan <skannan at redhat dot com> 2013-03-06 10:39:00 UTC ---
I tested the code on trunk r196485, and the output is shown correctly. 

This bug can be closed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libquadmath/56379] libquadmath: Wrong result for strtoflt128.c if compiled with -O0
  2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2013-03-06 10:39 ` skannan at redhat dot com
@ 2013-03-06 21:46 ` burnus at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-03-06 21:46 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56379

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-03-06 21:45:53 UTC ---
Let's close this bug as FIXED.

(As libquadmath is - by default - never compiled with -O0 and as it is not a
regression, I don't think that there is a need to backport a fix.)


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-03-06 21:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-18 16:57 [Bug libquadmath/56379] New: libquadmath: Wrong result for strtoflt128.c if compiled with -O0 burnus at gcc dot gnu.org
2013-02-18 17:31 ` [Bug libquadmath/56379] " burnus at gcc dot gnu.org
2013-02-18 23:42 ` burnus at gcc dot gnu.org
2013-02-19 10:16 ` jakub at gcc dot gnu.org
2013-02-19 11:28 ` burnus at gcc dot gnu.org
2013-02-19 21:50 ` jakub at gcc dot gnu.org
2013-03-06 10:39 ` skannan at redhat dot com
2013-03-06 21:46 ` burnus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).