public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/30447]  New: Evaluate complex math functions at compile-time
@ 2007-01-12 16:16 ghazi at gcc dot gnu dot org
  2007-01-12 16:38 ` [Bug middle-end/30447] " ghazi at gcc dot gnu dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2007-01-12 16:16 UTC (permalink / raw)
  To: gcc-bugs

We should evaluate complex math functions (csin, catan, etc) at compile-time if
they have constant arguments.

There is a package called MPC (available at
http://www.lix.polytechnique.fr/Labo/Andreas.Enge/Mpc.html or
http://www.loria.fr/~zimmerma/software/mpc.html) that works with MPFR and may
be suitable.  At the moment in version 0.4.5, it doesn't have all of the
complex transcendental functions implemented.  In fact it has only sqrt and exp
so far.  But it may be extended or serve as a base for further improvements,
and one day usable by GCC.


-- 
           Summary: Evaluate complex math functions at compile-time
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: middle-end
        AssignedTo: ghazi at gcc dot gnu dot org
        ReportedBy: ghazi at gcc dot gnu dot org


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
@ 2007-01-12 16:38 ` ghazi at gcc dot gnu dot org
  2007-01-12 19:03 ` rguenth at gcc dot gnu dot org
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2007-01-12 16:38 UTC (permalink / raw)
  To: gcc-bugs



-- 

ghazi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-01-12 16:38:37
               date|                            |


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
  2007-01-12 16:38 ` [Bug middle-end/30447] " ghazi at gcc dot gnu dot org
@ 2007-01-12 19:03 ` rguenth at gcc dot gnu dot org
  2007-01-12 19:12 ` kargl at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-01-12 19:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2007-01-12 19:02 -------
We can implement the complex variants in term of the real ones in mpfr, no?  I
don't like the idea of another build-dependency ;)


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
  2007-01-12 16:38 ` [Bug middle-end/30447] " ghazi at gcc dot gnu dot org
  2007-01-12 19:03 ` rguenth at gcc dot gnu dot org
@ 2007-01-12 19:12 ` kargl at gcc dot gnu dot org
  2007-01-13  5:17 ` ghazi at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kargl at gcc dot gnu dot org @ 2007-01-12 19:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kargl at gcc dot gnu dot org  2007-01-12 19:12 -------
(In reply to comment #1)
> We can implement the complex variants in term of the real ones in mpfr, no?  I
> don't like the idea of another build-dependency ;)
> 

Yes, you can.  gfortran does this already for several Fortran
intrinsic functions.  See fortran/simplify.c.


-- 

kargl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu dot org


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-01-12 19:12 ` kargl at gcc dot gnu dot org
@ 2007-01-13  5:17 ` ghazi at gcc dot gnu dot org
  2007-01-13  6:09 ` sgk at troutmask dot apl dot washington dot edu
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2007-01-13  5:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from ghazi at gcc dot gnu dot org  2007-01-13 05:17 -------
(In reply to comment #2)
> (In reply to comment #1)
> > We can implement the complex variants in term of the real ones in mpfr, no?  I
> > don't like the idea of another build-dependency ;)
> > 
> Yes, you can.  gfortran does this already for several Fortran
> intrinsic functions.  See fortran/simplify.c.

Yes, but think of the waste of creating all these complex functions only to
hide them inside GCC.  In a perfect world, these would exist inside MPFR or MPC
and I'd have more confidence they'd have less bugs.

Sigh, in the real world I guess it'll have to be a one-off for GCC and hope I
don't hose all the corner cases.  I'm not a wiz at this exact precision
calculation hooha.  Hopefully someone will stop me before I shoot myself. :-)


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-01-13  5:17 ` ghazi at gcc dot gnu dot org
@ 2007-01-13  6:09 ` sgk at troutmask dot apl dot washington dot edu
  2007-01-19 14:45 ` ghazi at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: sgk at troutmask dot apl dot washington dot edu @ 2007-01-13  6:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from sgk at troutmask dot apl dot washington dot edu  2007-01-13 06:09 -------
Subject: Re:  Evaluate complex math functions at compile-time

On Sat, Jan 13, 2007 at 05:17:11AM -0000, ghazi at gcc dot gnu dot org wrote:
> 
> ------- Comment #3 from ghazi at gcc dot gnu dot org  2007-01-13 05:17 -------
> 
> Yes, but think of the waste of creating all these complex functions
> only to hide them inside GCC.  In a perfect world, these would exist
> inside MPFR or MPC and I'd have more confidence they'd have less bugs.

Well, mpfr doesn't have a complex type, and you've already broached
the possible negative effect of requiring another 3rd party library
to build GCC.  From watching the mailing lists, you already caught
enough crap for using mpfr.  I still don't understand why so many
people got bent out of shape.

> Sigh, in the real world I guess it'll have to be a one-off for GCC
> and hope I don't hose all the corner cases.  I'm not a wiz at this
> exact precision calculation hooha.  Hopefully someone will stop me
> before I shoot myself. :-)

You don't have to be a whiz.  IEEE 754 requires exact results for
only sqrt() for floating point types.  For all other libm functions
one strives for results that are correct to less than or equal to
0.5 ULP.  The most important item is a good understand of complex
analysis and in particular branch cuts (see the glibc csqrt bug).

Another thing to note, mpfr returns the correct result to 
whatever precision you requested.  Internally, mpfr may, 
and often does, compute that result with much higher precision.


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-01-13  6:09 ` sgk at troutmask dot apl dot washington dot edu
@ 2007-01-19 14:45 ` ghazi at gcc dot gnu dot org
  2007-01-25  4:16 ` ghazi at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2007-01-19 14:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from ghazi at gcc dot gnu dot org  2007-01-19 14:45 -------
Patch for __complex__ builtins infrastructure and csin posted here:
http://gcc.gnu.org/ml/gcc-patches/2007-01/msg01610.html


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2007-01-19 14:45 ` ghazi at gcc dot gnu dot org
@ 2007-01-25  4:16 ` ghazi at gcc dot gnu dot org
  2009-04-11 15:55 ` ghazi at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2007-01-25  4:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from ghazi at gcc dot gnu dot org  2007-01-25 04:15 -------
Subject: Bug 30447

Author: ghazi
Date: Thu Jan 25 04:15:26 2007
New Revision: 121163

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121163
Log:
        PR middle-end/30447
        * builtins.c (fold_builtin_cabs): Use MPFR to evaluate a
        constant argument to cabs and do it without checking for
        -funsafe-math-optimizations.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2007-01-25  4:16 ` ghazi at gcc dot gnu dot org
@ 2009-04-11 15:55 ` ghazi at gcc dot gnu dot org
  2009-09-20 16:22 ` ghazi at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2009-04-11 15:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from ghazi at gcc dot gnu dot org  2009-04-11 15:55 -------
Patches to integrate the MPC library posted here:
http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00671.html
http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00672.html
http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00673.html
http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00674.html
http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00675.html

They require some updating for current mainline.


MPC version 0.6 has been reported to work on all of GCC's primary and secondary
platforms, as well as many others:
http://www.multiprecision.org/index.php?prog=mpc&page=platforms


-- 

ghazi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2007-01-12 16:38:37         |2009-04-11 15:55:05
               date|                            |


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2009-04-11 15:55 ` ghazi at gcc dot gnu dot org
@ 2009-09-20 16:22 ` ghazi at gcc dot gnu dot org
  2009-10-14  1:57 ` ghazi at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2009-09-20 16:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from ghazi at gcc dot gnu dot org  2009-09-20 16:21 -------
Current GCC mainline incorporates all the complex math functions included with
mpc-0.7.  All that's left are the complex "arc" functions which are expected in
a future MPC release, possibly mpc-0.8.


-- 

ghazi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |40302
OtherBugsDependingO|40302                       |
              nThis|                            |
   Last reconfirmed|2009-04-11 15:55:05         |2009-09-20 16:21:55
               date|                            |


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2009-09-20 16:22 ` ghazi at gcc dot gnu dot org
@ 2009-10-14  1:57 ` ghazi at gcc dot gnu dot org
  2009-10-14  2:28 ` joseph at codesourcery dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2009-10-14  1:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from ghazi at gcc dot gnu dot org  2009-10-14 01:57 -------
Support for the "arc" functions is done in the mpc svn repository which will be
released as mpc-0.8 at the end of October.  Use of these functions has been
checked into mainline.  All C99 builtin complex math functions are done; well,
except for cproj because that has a wierd non-c99 implementation in glibc.

TODO:
Wait for mpc-0.8 to be released.
Update gcc's configure to look for mpc-0.8.
Hard require MPC.
Do remaining stuff from PR40302.


-- 

ghazi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2009-09-20 16:21:55         |2009-10-14 01:57:26
               date|                            |


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2009-10-14  1:57 ` ghazi at gcc dot gnu dot org
@ 2009-10-14  2:28 ` joseph at codesourcery dot com
  2009-10-14  6:15 ` ghazi at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: joseph at codesourcery dot com @ 2009-10-14  2:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from joseph at codesourcery dot com  2009-10-14 02:27 -------
Subject: Re:  Evaluate complex math functions at
 compile-time

On Wed, 14 Oct 2009, ghazi at gcc dot gnu dot org wrote:

> Support for the "arc" functions is done in the mpc svn repository which will be
> released as mpc-0.8 at the end of October.  Use of these functions has been
> checked into mainline.  All C99 builtin complex math functions are done; well,
> except for cproj because that has a wierd non-c99 implementation in glibc.

I don't see why one particular library having a bug in its implementation 
of cproj should prevent GCC from optimizing that function correctly for 
constant arguments.


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (10 preceding siblings ...)
  2009-10-14  2:28 ` joseph at codesourcery dot com
@ 2009-10-14  6:15 ` ghazi at gcc dot gnu dot org
  2009-12-06 16:11 ` ghazi at gcc dot gnu dot org
  2009-12-07 15:55 ` ghazi at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2009-10-14  6:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from ghazi at gcc dot gnu dot org  2009-10-14 06:15 -------
(In reply to comment #10)
> > except for cproj because that has a wierd non-c99 implementation in glibc.
>
> I don't see why one particular library having a bug in its implementation 
> of cproj should prevent GCC from optimizing that function correctly for 
> constant arguments.

Had it been any other system, I would agree.  But that "one particular library"
is the C lib for the GNU system and I was reluctant to make the GNU compiler
incompatible with the GNU C library.

There is a bug report filed for cproj from July, but nothing appears to have
been done about it.
http://sourceware.org/bugzilla/show_bug.cgi?id=10401

If there is consensus that we don't care what glibc does, I can implement the
cproj opt.  However you may recall I have most of these MPFR/MPC
transformations back out if Inf is passed in.  The main rationale for cproj is
to handle Inf specially.  So it would require hacking the infrastructure to
allow Inf to pass through.  I did this for two-argument calls like mpc_div, but
not one-argument calls like mpc_proj.  Since it's stage3 I'd defer that till
later.

Another (perhaps interim) option would be to do the opt only for finite
numbers.  That would be a one-liner and perhaps suitable for stage3.


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (11 preceding siblings ...)
  2009-10-14  6:15 ` ghazi at gcc dot gnu dot org
@ 2009-12-06 16:11 ` ghazi at gcc dot gnu dot org
  2009-12-07 15:55 ` ghazi at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2009-12-06 16:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from ghazi at gcc dot gnu dot org  2009-12-06 16:11 -------
Subject: Bug 30447

Author: ghazi
Date: Sun Dec  6 16:11:06 2009
New Revision: 155023

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155023
Log:
        PR middle-end/30447
        PR middle-end/30789
        PR other/40302

        * configure.ac: Require MPC.
        * configure: Regenerate.
gcc:
        * doc/install.texi: Document MPC is required.


Modified:
    trunk/ChangeLog
    trunk/configure
    trunk/configure.ac
    trunk/gcc/ChangeLog
    trunk/gcc/doc/install.texi


-- 


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


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

* [Bug middle-end/30447] Evaluate complex math functions at compile-time
  2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
                   ` (12 preceding siblings ...)
  2009-12-06 16:11 ` ghazi at gcc dot gnu dot org
@ 2009-12-07 15:55 ` ghazi at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2009-12-07 15:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from ghazi at gcc dot gnu dot org  2009-12-07 15:55 -------
Done.


-- 

ghazi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


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


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

end of thread, other threads:[~2009-12-07 15:55 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-12 16:16 [Bug middle-end/30447] New: Evaluate complex math functions at compile-time ghazi at gcc dot gnu dot org
2007-01-12 16:38 ` [Bug middle-end/30447] " ghazi at gcc dot gnu dot org
2007-01-12 19:03 ` rguenth at gcc dot gnu dot org
2007-01-12 19:12 ` kargl at gcc dot gnu dot org
2007-01-13  5:17 ` ghazi at gcc dot gnu dot org
2007-01-13  6:09 ` sgk at troutmask dot apl dot washington dot edu
2007-01-19 14:45 ` ghazi at gcc dot gnu dot org
2007-01-25  4:16 ` ghazi at gcc dot gnu dot org
2009-04-11 15:55 ` ghazi at gcc dot gnu dot org
2009-09-20 16:22 ` ghazi at gcc dot gnu dot org
2009-10-14  1:57 ` ghazi at gcc dot gnu dot org
2009-10-14  2:28 ` joseph at codesourcery dot com
2009-10-14  6:15 ` ghazi at gcc dot gnu dot org
2009-12-06 16:11 ` ghazi at gcc dot gnu dot org
2009-12-07 15:55 ` ghazi 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).