public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/30599]  New: long double declaration rounds to double instead
@ 2007-01-26 16:20 whaley at cs dot utsa dot edu
  2007-01-26 16:21 ` [Bug target/30599] " whaley at cs dot utsa dot edu
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: whaley at cs dot utsa dot edu @ 2007-01-26 16:20 UTC (permalink / raw)
  To: gcc-bugs

Hi,

Since bug 30255 has been declared as never going to be fixed, I've been
enjoying going through half a million lines of code looking for places where I
have to declare things long double to keep gcc from arbitrarily rounding down
intermediate results.  The problem now is that I have come across a case where
the exact opposite occurs: If I declare a variable long double, gcc inserts a
round to double before computing the square root, where it does not if I
declare it double.  I will upload the file seperately, but here's the section
of code:

   for (i=0; i < N; i++) t0 += X[i]*X[i];
   t0 = sqrt(t0);

When compiled with t0 declared as double, no spills are performed by gcc, and
80-bit accuracy is maintained throughout the computation (critical to avoid
overflow).  When declared as long double, however, the following code is
inserted:
        fstpl   16(%rsp)
        fldl    16(%rsp)
        fld     %st(0)
        fsqrt
So, a long double is rounded to double by gcc, even though there is no store in
the algorithm.  Any idea what is going on, and is there anything to be done?  I
will post the short file seperately.  You can gen both assemblies to see the
difference with
   gcc -O -mfpmath=387 -S nrm2.c  # gen double declaration
   gcc -O -mfpmath=387 -DLD_ -S nrm2.c # gen long double variant

Thanks,
Clint


-- 
           Summary: long double declaration rounds to double instead
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: whaley at cs dot utsa dot edu


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
@ 2007-01-26 16:21 ` whaley at cs dot utsa dot edu
  2007-01-26 17:49 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: whaley at cs dot utsa dot edu @ 2007-01-26 16:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from whaley at cs dot utsa dot edu  2007-01-26 16:21 -------
Created an attachment (id=12963)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12963&action=view)
Can be compiled to .s as described in report to duplicate error


-- 


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
  2007-01-26 16:21 ` [Bug target/30599] " whaley at cs dot utsa dot edu
@ 2007-01-26 17:49 ` pinskia at gcc dot gnu dot org
  2007-06-20 21:52 ` whaley at cs dot utsa dot edu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-26 17:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-01-26 17:49 -------
Use sqrtl then if you don't want the rounding.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
  2007-01-26 16:21 ` [Bug target/30599] " whaley at cs dot utsa dot edu
  2007-01-26 17:49 ` pinskia at gcc dot gnu dot org
@ 2007-06-20 21:52 ` whaley at cs dot utsa dot edu
  2007-06-20 22:04 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: whaley at cs dot utsa dot edu @ 2007-06-20 21:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from whaley at cs dot utsa dot edu  2007-06-20 21:52 -------
Turns out the proposed solution of using sqrtl is not portable.  In particular,
all code using it fails to link on Windows using cygwin.  Any idea how to make
this work portably?  I still don't understand why it is OK for a double
accumulator to get an 80-bit sqrt, whereas a long double accumulator gets
rounded.


-- 

whaley at cs dot utsa dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
                   ` (2 preceding siblings ...)
  2007-06-20 21:52 ` whaley at cs dot utsa dot edu
@ 2007-06-20 22:04 ` pinskia at gcc dot gnu dot org
  2007-06-20 22:17 ` whaley at cs dot utsa dot edu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-20 22:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-06-20 22:04 -------
sqrtl is C99 so it is portable, just not to cygwin.  That is not our fault that
cygwin does not provide a C99 math library.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
                   ` (3 preceding siblings ...)
  2007-06-20 22:04 ` pinskia at gcc dot gnu dot org
@ 2007-06-20 22:17 ` whaley at cs dot utsa dot edu
  2007-06-20 23:17 ` whaley at cs dot utsa dot edu
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: whaley at cs dot utsa dot edu @ 2007-06-20 22:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from whaley at cs dot utsa dot edu  2007-06-20 22:17 -------
It may be C99, but since it doesn't work on 90% of the machines in the world,
it is a bit of a stretch to call it portable.  My point is no standard mandates
you round down a long double (where you don't round down a double), and that
would provide a solution that *would* port to cygwin.  

So I ask again, why do you need to round down a long double, but not a double
accumulator?  Note that none of this would be necessary if gcc didn't randomly
round down doubles upon spills; remember that I switched to long double because
*you* declared it to be a solution since you did not plan to fix the original
spill/rounding bug.  I am trying to get a math library working portably despite
these problems, but it seems I'm going to be prevented by interdependent gcc
bugs that will never be fixed.


-- 

whaley at cs dot utsa dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
                   ` (4 preceding siblings ...)
  2007-06-20 22:17 ` whaley at cs dot utsa dot edu
@ 2007-06-20 23:17 ` whaley at cs dot utsa dot edu
  2007-06-20 23:32 ` dannysmith at users dot sourceforge dot net
  2007-06-21  9:15 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: whaley at cs dot utsa dot edu @ 2007-06-20 23:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from whaley at cs dot utsa dot edu  2007-06-20 23:17 -------
Anybody have enough __asm__ foo to write a inline assembly macro taking a long
double operand and returning one, which I can use to call fsqrt directly in
inline assembly?  I'm scoping the docs, but have never found inline assembly
constraints that intuitive, and with the need for x87 registers on the stack,
less so.  If I can write such a macro, I can call it on Windows instead of
sqrtl.  The long double accumulator is on the stack, fsqrt takes a stack arg,
so it should be easy to do, I would think . . .

Thanks,
Clint


-- 


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
                   ` (5 preceding siblings ...)
  2007-06-20 23:17 ` whaley at cs dot utsa dot edu
@ 2007-06-20 23:32 ` dannysmith at users dot sourceforge dot net
  2007-06-21  9:15 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2007-06-20 23:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dannysmith at users dot sourceforge dot net  2007-06-20 23:32 -------
(In reply to comment #6)
> Anybody have enough __asm__ foo to write a inline assembly macro taking a long
> double operand and returning one, which I can use to call fsqrt directly in
> inline assembly?  

http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/mingw/mingwex/math/sqrtl.c?cvsroot=src

should help.  You could use __builtin_nan to replace the external reference 
Danny


-- 


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


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

* [Bug target/30599] long double declaration rounds to double instead
  2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
                   ` (6 preceding siblings ...)
  2007-06-20 23:32 ` dannysmith at users dot sourceforge dot net
@ 2007-06-21  9:15 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-21  9:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2007-06-21 09:15 -------
But again, even if sqrtl is not part of the library, this is not a GCC issue. 
We provide builtins for faster usage and not to get around libc not including
the function.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2007-06-21  9:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-26 16:20 [Bug target/30599] New: long double declaration rounds to double instead whaley at cs dot utsa dot edu
2007-01-26 16:21 ` [Bug target/30599] " whaley at cs dot utsa dot edu
2007-01-26 17:49 ` pinskia at gcc dot gnu dot org
2007-06-20 21:52 ` whaley at cs dot utsa dot edu
2007-06-20 22:04 ` pinskia at gcc dot gnu dot org
2007-06-20 22:17 ` whaley at cs dot utsa dot edu
2007-06-20 23:17 ` whaley at cs dot utsa dot edu
2007-06-20 23:32 ` dannysmith at users dot sourceforge dot net
2007-06-21  9:15 ` pinskia at gcc dot gnu dot 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).