This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] implement asin() and acos() as built-in x87 function
- From: Roger Sayle <roger at eyesopen dot com>
- To: Uros Bizjak <uros at kss-loka dot si>
- Cc: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>, <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 20 Apr 2004 13:04:35 -0600 (MDT)
- Subject: Re: [PATCH] implement asin() and acos() as built-in x87 function
On Tue, 20 Apr 2004, Uros Bizjak wrote:
> 2004-04-20 Uros Bizjak <uros@kss-loka.si>
>
> * optabs.h (enum optab_index): Add new OTI_asin and OTI_acos.
> (asin_optab, acos_optab): Define corresponding macros.
> * optabs.c (init_optabs): Initialize asin_optab and acos_optab.
> * genopinit.c (optabs): Implement asin_optab and acos_optab
> using asin?f2 and acos?f2 patterns.
> * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_ASIN{,F,L}
> using asin_optab, and BUILT_IN_ACOS{,F,L} using acos_optab.
> (expand_builtin): Expand BUILT_IN_ASIN{,F,L} and BUILT_IN_ACOS{,F,L}
> using expand_builtin_mathfn if flag_unsafe_math_optimizations is set.
>
> * config/i386/i386.md (asindf2, asinsf2, asinxf2, acosdf2,
> acossf2, acosxf2): New expanders to implement asin, asinf, asinl,
> acos, acosf and acosl built-ins as inline x87 intrinsics.
>
> * gcc.dg/builtins-39.c: New test.
This is OK for mainline. I've committed it to CVS after confirming
there are no testsuite regressions following an i686-pc-linux-gnu
bootstrap.
Thanks.
> BTW (for bonus points ;-) : calculating both asin() and acos() of the
> same parameter produces quite optimized code. Optimizers detect, that
> only one parameter load, one multiplication and one call to fsqrt is
> needed:
Here's another nice one.
double pi = acos(-1.0);
evaluates the square, addition and square root at compile-time, and
generates the inline equivalent of "double pi = atan2(0.0,-1.0)".
Richard Guenther's points on optimize_size are well taken. We need
to devise a "model system" where we can evaluate the size differences
of these intrinsics as used in a typical environment. For example,
comparing "double foo(double x) { return acos(x); }" with and without
-Os is a bad metric, as GCC will optimize this code into a tailcall
which is unrepresentative of most math function call sites. Similarly
concerns over call-clobbered spills, availability of operands in FP
registers, etc... Once we have a suitable measure, we can evaluate
and correct all of GCC's x87 intrinsics at the same time.
Roger
--