public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/51007] New: Quadmath I/O doesn't work on MinGW
@ 2011-11-07 10:57 fxcoudert at gcc dot gnu.org
  2011-11-07 10:58 ` [Bug target/51007] " fxcoudert at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2011-11-07 10:57 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51007
           Summary: Quadmath I/O doesn't work on MinGW
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fxcoudert@gcc.gnu.org
            Target: i586-pc-mingw32


The following test program works fine with current trunk on i686 and
x86_64-linux:


#include <quadmath.h>
#include <stdio.h>

int main (void)
{
  char buf[100];
  quadmath_snprintf (buf, sizeof buf, "%.60Qg", (__float128) 3.14);
  puts (buf);
}


It outputs "3.140000000000000124344978758017532527446746826171875". When
compiled and run on MinGW, it gives an incorrect output (on my test system,
"1.9163987915738935076000483121420225908698150840344985584492e-4932"). I
confirmed with both a native MinGW build (i586-pc-mingw32) and a cross-compiler
for i586-pc-mingw32, running on x86_64-apple-darwin11, and running the result
under either Wine or a real Windows.

The cross-compiler is configured as such:


../../gcc/trunk/configure --target=i586-pc-mingw32 --disable-werror
--enable-languages=c,fortran


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
@ 2011-11-07 10:58 ` fxcoudert at gcc dot gnu.org
  2011-11-07 11:03 ` fxcoudert at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2011-11-07 10:58 UTC (permalink / raw)
  To: gcc-bugs

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

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-11-07
     Ever Confirmed|0                           |1


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
  2011-11-07 10:58 ` [Bug target/51007] " fxcoudert at gcc dot gnu.org
@ 2011-11-07 11:03 ` fxcoudert at gcc dot gnu.org
  2011-11-07 11:30 ` fxcoudert at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2011-11-07 11:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> 2011-11-07 11:03:32 UTC ---
I don't know if it's related, or two different bugs, but hexadecimal printing
has the correct mantissa with a wrong exponent. See below the same testcase
compile on my mac (native compiler) and cross-compiled to mingw:

$ cat v.c 
#include <quadmath.h>
#include <stdio.h>

int main (void)
{
  char buf[100];
  quadmath_snprintf (buf, sizeof buf, "%.60Qa", (__float128) 3.14);
  puts (buf);
}
$ gcc-4.6 v.c -lquadmath && ./a.out 
0x1.91eb851eb851f00000000000000000000000000000000000000000000000p+1
$ ./cross/bin/i586-pc-mingw32-gcc v.c -static -lquadmath
$ /opt/wine/bin/wine ./a.exe 
0x1.91eb851eb851f00000000000000000000000000000000000000000000000p-5318


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
  2011-11-07 10:58 ` [Bug target/51007] " fxcoudert at gcc dot gnu.org
  2011-11-07 11:03 ` fxcoudert at gcc dot gnu.org
@ 2011-11-07 11:30 ` fxcoudert at gcc dot gnu.org
  2011-11-07 11:39 ` fxcoudert at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2011-11-07 11:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> 2011-11-07 11:29:39 UTC ---
The bug is not in the I/O routine, it can be reproduce by this simple
self-contained testcase (which doesn't need libquadmath).

#include <stdint.h>

typedef union
{
  __float128 value;

  struct
  {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
    unsigned negative:1;
    unsigned exponent:15;
    uint64_t mant_high:48;
    uint64_t mant_low:64;
#else
    uint64_t mant_low:64;
    uint64_t mant_high:48;
    unsigned exponent:15;
    unsigned negative:1;
#endif
  } ieee;
} ieee854_float128;

int main (void)
{
  ieee854_float128 d;
  d.value = (__float128) 3.14;
  __builtin_printf ("%u\n", (unsigned) d.ieee.exponent);
}

On darwin, this program consistently outputs 16384. When cross-compiled to
mingw, and run on Windows XP, it consistently outputs 6448. When the same
executable is run under Wine on darwin, it outputs inconsistent, wrong values
(the last few invocations here show: 4755, 12947, 21139).


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-11-07 11:30 ` fxcoudert at gcc dot gnu.org
@ 2011-11-07 11:39 ` fxcoudert at gcc dot gnu.org
  2011-11-07 12:01 ` ktietz at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2011-11-07 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> 2011-11-07 11:39:12 UTC ---
Going further: I tried to compare the trees generated by the simple function
below:


#include <stdint.h>

typedef union
{
  __float128 value;

  struct
  {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
    unsigned negative:1;
    unsigned exponent:15;
    uint64_t mant_high:48;
    uint64_t mant_low:64;
#else
    uint64_t mant_low:64;
    uint64_t mant_high:48;
    unsigned exponent:15;
    unsigned negative:1;
#endif
  } ieee;
} ieee854_float128;

unsigned foo (__float128 x)
{
  ieee854_float128 d;
  d.value = x;
  return d.ieee.exponent;
}


AFAICT, both the original and the optimized tree for darwin and mingw are
identical. The assembly code generated for a common arch (-march=core2 -O0)
differs:

***** on mingw *****
_foo:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $40, %esp
        movdqa  8(%ebp), %xmm0
        movdqa  %xmm0, -40(%ebp)
        movzwl  -24(%ebp), %eax
        andw    $32767, %ax
        movzwl  %ax, %eax
        leave
        ret

***** on darwin *****
_foo:
    pushq    %rbp
    movq    %rsp, %rbp
    movdqa    %xmm0, -32(%rbp)
    movdqa    -32(%rbp), %xmm0
    movdqa    %xmm0, -16(%rbp)
    movzwl    -2(%rbp), %eax
    andw    $32767, %ax
    movzwl    %ax, %eax
    popq    %rbp
    ret


Now, my assembly skills are pretty close to nil, so I can't figure out if the
differences are meaningful, and what they mean. I only hope that I got it close
enough that someone can, from here, understand where this code generation come
from and how to fix it.


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-11-07 11:39 ` fxcoudert at gcc dot gnu.org
@ 2011-11-07 12:01 ` ktietz at gcc dot gnu.org
  2011-11-07 12:19 ` ktietz at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ktietz at gcc dot gnu.org @ 2011-11-07 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Kai Tietz <ktietz at gcc dot gnu.org> 2011-11-07 12:00:49 UTC ---
The issue is caused by bitfield layout.  For mingw targets the -mms-bitfields
option is for 4.7 active by default.

So  the mixture of different sized types in union is leading to this behavior.
You can see that result becomes ok, if you are specifying to union/struct the
attribute gcc_struct.

Cheers,
Kai


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-11-07 12:01 ` ktietz at gcc dot gnu.org
@ 2011-11-07 12:19 ` ktietz at gcc dot gnu.org
  2011-11-07 12:42 ` fxcoudert at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ktietz at gcc dot gnu.org @ 2011-11-07 12:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Kai Tietz <ktietz at gcc dot gnu.org> 2011-11-07 12:19:09 UTC ---
Suggested patch for this issue

ChangeLog

        * quadmath-imp.h (ieee854_float128): Adjust
        for ms-bitfield layout.

Index: quadmath-imp.h
===================================================================
--- quadmath-imp.h      (revision 180840)
+++ quadmath-imp.h      (working copy)
@@ -48,6 +48,11 @@
   __float128 value;

   struct
+#ifdef __MINGW32__
+  /* On mingw targets ms-bitfields option is active by default.
+     Therefore enforce gnu-bitfield style.  */
+  __attribute__ ((gcc_struct))
+#endif
   {
 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
     unsigned negative:1;
@@ -89,6 +94,10 @@
   } words32;

   struct
+#ifdef __MINGW32__
+  /* Make sure we are using gnu-style bitfield handling.  */
+  __attribute__ ((gcc_struct))
+#endif
   {
 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
     unsigned negative:1;


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2011-11-07 12:19 ` ktietz at gcc dot gnu.org
@ 2011-11-07 12:42 ` fxcoudert at gcc dot gnu.org
  2011-11-07 15:31 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2011-11-07 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |jakub at redhat dot com

--- Comment #6 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> 2011-11-07 12:42:26 UTC ---
(In reply to comment #4)
> So  the mixture of different sized types in union is leading to this behavior.
> You can see that result becomes ok, if you are specifying to union/struct the
> attribute gcc_struct.

Indeed, I confirm that your patch fixes the issue (and the original Fortran
testcase reported on comp.lang.fortran now works fine). Both Tobias and Jakub
(Cc'ed) are libquadmath maintainers and can approve it.


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

* [Bug target/51007] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2011-11-07 12:42 ` fxcoudert at gcc dot gnu.org
@ 2011-11-07 15:31 ` burnus at gcc dot gnu.org
  2011-11-07 19:32 ` [Bug target/51007] [4.7 Regression] " burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-11-07 15:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-07 15:29:52 UTC ---
(In reply to comment #5)
> ChangeLog
> 
>         * quadmath-imp.h (ieee854_float128): Adjust
>         for ms-bitfield layout.
> 
> +#ifdef __MINGW32__
> +  /* On mingw targets ms-bitfields option is active by default.
> +     Therefore enforce gnu-bitfield style.  */
> +  __attribute__ ((gcc_struct))
> +#endif

The patch looks fine to me - except that I would put an "the" before
"ms-bitfields option".


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

* [Bug target/51007] [4.7 Regression] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2011-11-07 15:31 ` burnus at gcc dot gnu.org
@ 2011-11-07 19:32 ` burnus at gcc dot gnu.org
  2011-11-07 22:06 ` ktietz at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-11-07 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.7.0
            Summary|Quadmath I/O doesn't work   |[4.7 Regression] Quadmath
                   |on MinGW                    |I/O doesn't work on MinGW


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

* [Bug target/51007] [4.7 Regression] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2011-11-07 19:32 ` [Bug target/51007] [4.7 Regression] " burnus at gcc dot gnu.org
@ 2011-11-07 22:06 ` ktietz at gcc dot gnu.org
  2011-11-07 22:09 ` ktietz at gcc dot gnu.org
  2012-05-31 18:58 ` bkoz at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: ktietz at gcc dot gnu.org @ 2011-11-07 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Kai Tietz <ktietz at gcc dot gnu.org> 2011-11-07 22:04:00 UTC ---
Author: ktietz
Date: Mon Nov  7 22:03:51 2011
New Revision: 181125

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181125
Log:
        PR target/51007
        * quadmath-imp.h (ieee854_float128): Adjust
        for ms-bitfield layout.


Modified:
    trunk/libquadmath/ChangeLog
    trunk/libquadmath/quadmath-imp.h


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

* [Bug target/51007] [4.7 Regression] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2011-11-07 22:06 ` ktietz at gcc dot gnu.org
@ 2011-11-07 22:09 ` ktietz at gcc dot gnu.org
  2012-05-31 18:58 ` bkoz at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: ktietz at gcc dot gnu.org @ 2011-11-07 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

Kai Tietz <ktietz at gcc dot gnu.org> changed:

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

--- Comment #9 from Kai Tietz <ktietz at gcc dot gnu.org> 2011-11-07 22:05:31 UTC ---
Applied with suggested "the" before ms-bitfield option.
Fixed.


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

* [Bug target/51007] [4.7 Regression] Quadmath I/O doesn't work on MinGW
  2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2011-11-07 22:09 ` ktietz at gcc dot gnu.org
@ 2012-05-31 18:58 ` bkoz at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: bkoz at gcc dot gnu.org @ 2012-05-31 18:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Benjamin Kosnik <bkoz at gcc dot gnu.org> 2012-05-31 18:51:34 UTC ---
Author: bkoz
Date: Thu May 31 18:51:27 2012
New Revision: 188076

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188076
Log:
2012-05-31  Benjamin Kosnik  <bkoz@redhat.com>

        PR libstdc++/51007
        * configure.ac: Allow gnu, gnu* variants for --enable-symvers argument.
        * configure: Regenerated.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/configure
    trunk/libgfortran/configure.ac
    trunk/libquadmath/ChangeLog
    trunk/libquadmath/configure
    trunk/libquadmath/configure.ac
    trunk/libssp/ChangeLog
    trunk/libssp/configure
    trunk/libssp/configure.ac


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

end of thread, other threads:[~2012-05-31 18:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-07 10:57 [Bug target/51007] New: Quadmath I/O doesn't work on MinGW fxcoudert at gcc dot gnu.org
2011-11-07 10:58 ` [Bug target/51007] " fxcoudert at gcc dot gnu.org
2011-11-07 11:03 ` fxcoudert at gcc dot gnu.org
2011-11-07 11:30 ` fxcoudert at gcc dot gnu.org
2011-11-07 11:39 ` fxcoudert at gcc dot gnu.org
2011-11-07 12:01 ` ktietz at gcc dot gnu.org
2011-11-07 12:19 ` ktietz at gcc dot gnu.org
2011-11-07 12:42 ` fxcoudert at gcc dot gnu.org
2011-11-07 15:31 ` burnus at gcc dot gnu.org
2011-11-07 19:32 ` [Bug target/51007] [4.7 Regression] " burnus at gcc dot gnu.org
2011-11-07 22:06 ` ktietz at gcc dot gnu.org
2011-11-07 22:09 ` ktietz at gcc dot gnu.org
2012-05-31 18:58 ` bkoz 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).