This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Perform constant folding of math builtins

On Mon, 26 Aug 2002, Kaveh R. Ghazi wrote:
>  > From: Roger Sayle <roger at eyesopen dot com>
>  > The following patch implements the following optimizations:
>  >
>  >     sqrt(0.0) = 0.0
>  >     sqrt(1.0) = 1.0
>  >     log(1.0) = 0.0
>  >     exp(0.0) = 1.0
> Why just these cases, can't you fold all calls where the argument is
> constant?  (Ditto for the trig functions?)

Hi Kaveh,

I'd love to be able to perform constant folding for all values and
also for the trigonometric functions.  There are two issues.  The
first is that "cc1" is not currently linked against -lm, so the host
libm functions aren't available to the compiler.  The second is that
these values need to be calculated in the precision required for the
target, so shouldn't use the host functions anyway.  These issues
could be solved by adding support into GCC's floating point emulation
in "real.c", but this hasn't been done yet.  For the time being, the
best that can be done is the set of fixed point values listed above,
that are easily handled by comparing against and returing specific

Of course, I could also add "cos(0.0) = 1.0" and "sin(0.0) = 0.0" with
the existing infrastructure.

Roger Sayle,                         E-mail:
OpenEye Scientific Software,         WWW:
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]