This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: PR29335 use MPFR for two-argument math builtins (pow, atan2, hypot)
- From: Roger Sayle <roger at eyesopen dot com>
- To: "Kaveh R. GHAZI" <ghazi at caip dot rutgers dot edu>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 28 Oct 2006 11:59:24 -0600 (MDT)
- Subject: Re: [PATCH]: PR29335 use MPFR for two-argument math builtins (pow, atan2, hypot)
Hi Kaveh,
On Sat, 28 Oct 2006, Kaveh R. GHAZI wrote:
> hypot(x,0) -> fabs(x)
> hypot(0,y) -> fabs(y)
> hypot(x,x) -> x*sqrt(2)
> hypot(-x,y) -> hypot(x,y)
> hypot(x,-y) -> hypot(x,y)
> hypot(-x,-y) -> hypot(x,y)
Cool!
> 2006-10-27 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
>
> PR middle-end/29335
> * builtins.c (do_mpfr_arg2, fold_builtin_hypot): New.
> (fold_builtin_pow): Evaluate constant arguments at compile-time
> using MPFR.
> (fold_builtin_1): Handle BUILT_IN_ATAN2 and BUILT_IN_HYPOT.
> (do_mpfr_ckconv): New helper function.
> (do_mpfr_arg1): Use do_mpfr_ckconv.
> (do_mpfr_arg2): New.
>
> testsuite:
> * gcc.dg/builtins-20.c: Add tests for hypot.
> * gcc.dg/torture/builtin-math-2.c (TESTIT2): New. Add tests for
> two-argument builtins.
> * gcc.dg/torture/builtin-math-3.c (TESTIT_R): Renamed from
> TESTIT2. Update all callers.
> (TESTIT2, TESTIT2_R): New helper macros.
> Add testcases for pow, hypot and atan2.
This is OK for mainline.
> + tree narg0 = TREE_CODE (arg0) == NEGATE_EXPR ? TREE_OPERAND (arg0, 0) : arg0;
> + tree narg1 = TREE_CODE (arg1) == NEGATE_EXPR ? TREE_OPERAND (arg1, 0) : arg1;
Though these long lines might need wrapping. In fact, you could
probably also generalize this code to also handle:
hypot(fabs(x),y) = hypot(x,y)
hypot(x,fabs(y)) = hypot(x,y)
...
hypot(-fabs(x),-fabs(y)) = hypot(x,y)
by also testing for ABS_EXPR. This would require the above expressions
to be slightly rewriten anyway. Perhaps best left as a follow-up patch,
as you appear to be on a roll.
Nice clean-up with do_mpfr_ckconv. Thanks.
Roger
--