From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5759 invoked by alias); 24 Sep 2004 08:37:05 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 5486 invoked from network); 24 Sep 2004 08:37:01 -0000 Received: from unknown (HELO polimi.it) (131.175.12.3) by sourceware.org with SMTP; 24 Sep 2004 08:37:01 -0000 Received: from gnu.org (paride.rett.polimi.it [131.175.65.135]) by polimi.it (8.13.1/8.13.1) with ESMTP id i8O8as1Z019736; Fri, 24 Sep 2004 10:36:56 +0200 Message-ID: <4153DDDE.90204@gnu.org> Date: Fri, 24 Sep 2004 11:29:00 -0000 From: Paolo Bonzini User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) MIME-Version: 1.0 Newsgroups: gmane.comp.gcc.devel To: Uros Bizjak CC: jakub@redhat.com, gcc@gcc.gnu.org, libc-hacker@sources.redhat.com Subject: Re: Updating glibc mathinlines.h to reflect additional GCC builtins ? References: <200409240418.i8O4ID4M012232@caip.rutgers.edu> <4153BBAF.8050903@kss-loka.si> In-Reply-To: <4153BBAF.8050903@kss-loka.si> Content-Type: multipart/mixed; boundary="------------040408030104040205030407" X-PMX-Version: 4.7.0.111621, Antispam-Engine: 2.0.1.0, Antispam-Data: 2004.9.23.6 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='__BAT_BOUNDARY 0, __CT 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0, __HAS_MSGID 0, __LINES_OF_YELLING 0, __MIME_VERSION 0, __SANE_MSGID 0' X-SW-Source: 2004-09/txt/msg01416.txt.bz2 Message-ID: <20040924112900.1VAyp3pN9f9mjzNwPQkZU1EcCHnfQw5aN_9O9Hn2tkk@z> This is a multi-part message in MIME format. --------------040408030104040205030407 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 897 > Regarding sincos(), a patch was submitted to gcc-patches > (http://gcc.gnu.org/ml/gcc-patches/2004-04/msg00555.html). It used > soon-to-be-obsoleted ADDRESSOF optimization in sincos expander > (http://gcc.gnu.org/ml/gcc-patches/2004-04/msg00653.html), so it was not > commited to CVS. As fsincos is generated automatically, it was somehow > put on hold... Just FYI (I don't think this is appropriate for stage3, and I haven't bootstrapped/regtested it yet), here is a patch that does what I suggested in the message Uros cited above. Some magic is needed to avoid bad interaction with the cos (-x) => cos (x) optimization, but the patch is quite simple. Paolo 2004-09-24 Paolo Bonzini * builtins.c (fold_builtin_sincos): New. (fold_builtin): Call it. 2004-09-24 Paolo Bonzini * gcc.dg/i386-387-9.c, gcc.dg/builtins-47.c: New testcases. --------------040408030104040205030407 Content-Type: text/plain; name="fold-builtin-sincos.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fold-builtin-sincos.patch" Content-length: 5692 Index: testsuite/gcc.dg/builtins-47.c =================================================================== RCS file: testsuite/gcc.dg/builtins-47.c diff -N testsuite/gcc.dg/builtins-47.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gcc.dg/builtins-47.c 24 Sep 2004 08:35:35 -0000 @@ -0,0 +1,43 @@ +/* Copyright (C) 2004 Free Software Foundation. + + Check that the sincos, sincosf, sincosl + built-in functions compile. + + Written by Paolo Bonzini, 24th Sep 2004. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math" } */ + +float sf, cf; +double sd, cd; +long double sl, cl; + +void f1 (float x) +{ + __builtin_sincosf (x, &sf, &cf); +}; + +void f2 (double x) +{ + __builtin_sincos (x, &sd, &cd); +}; + +void f3 (long double x) +{ + __builtin_sincosl (x, &sl, &cl); +}; + +void g1 (float x) +{ + __builtin_sincosf (-x, &sf, &cf); +}; + +void g2 (double x) +{ + __builtin_sincos (-x, &sd, &cd); +}; + +void g3 (long double x) +{ + __builtin_sincosl (-x, &sl, &cl); +}; Index: testsuite/gcc.dg/i386-387-9.c =================================================================== RCS file: testsuite/gcc.dg/i386-387-9.c diff -N testsuite/gcc.dg/i386-387-9.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gcc.dg/i386-387-9.c 24 Sep 2004 08:35:35 -0000 @@ -0,0 +1,39 @@ +/* Verify that 387 fsincos instruction is generated from __builtin_sincos. */ +/* { dg-do compile { target "i?86-*-*" } } */ +/* { dg-options "-O2 -ffast-math -march=i686" } */ +/* { dg-final { scan-assembler "fsincos" } } */ +/* { dg-final { scan-assembler-not "call" } } */ + +float sf, cf; +double sd, cd; +long double sl, cl; + +void f1 (float x) +{ + __builtin_sincosf (x, &sf, &cf); +}; + +void f2 (double x) +{ + __builtin_sincos (x, &sd, &cd); +}; + +void f3 (long double x) +{ + __builtin_sincosl (x, &sl, &cl); +}; + +void g1 (float x) +{ + __builtin_sincosf (-x, &sf, &cf); +}; + +void g2 (double x) +{ + __builtin_sincos (-x, &sd, &cd); +}; + +void g3 (long double x) +{ + __builtin_sincosl (-x, &sl, &cl); +}; Index: builtins.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/builtins.c,v retrieving revision 1.387 diff -u -p -r1.387 builtins.c --- builtins.c 23 Sep 2004 06:16:08 -0000 1.387 +++ builtins.c 24 Sep 2004 08:35:37 -0000 @@ -154,6 +154,7 @@ static tree fold_builtin_cbrt (tree, tre static tree fold_builtin_pow (tree, tree, tree); static tree fold_builtin_sin (tree); static tree fold_builtin_cos (tree, tree, tree); +static tree fold_builtin_sincos (tree, tree); static tree fold_builtin_tan (tree); static tree fold_builtin_atan (tree, tree); static tree fold_builtin_trunc (tree); @@ -6757,6 +6758,82 @@ fold_builtin_cos (tree arglist, tree typ return NULL_TREE; } +/* Fold function call to builtin cos, cosf, or cosl. Return + NULL_TREE if no simplification can be made. */ +static tree +fold_builtin_sincos (tree arglist, tree fndecl) +{ + tree arg, arg1, arg2, sin_fn, cos_fn, sin_modify, cos_modify; + tree sin_fndecl, cos_fndecl; + enum machine_mode mode; + bool negate_sin; + + if (!validate_arglist (arglist, + REAL_TYPE, POINTER_TYPE, POINTER_TYPE, VOID_TYPE)) + return NULL_TREE; + + /* Check if sincos insn is available, otherwise fallback + to usual builtin. */ + arg = TREE_VALUE (arglist); + mode = TYPE_MODE (TREE_TYPE (arg)); + if (sincos_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing) + return NULL_TREE; + + switch (DECL_FUNCTION_CODE (fndecl)) + { + case BUILT_IN_SINCOS: + sin_fndecl = implicit_built_in_decls[BUILT_IN_SIN]; + cos_fndecl = implicit_built_in_decls[BUILT_IN_COS]; + break; + + case BUILT_IN_SINCOSF: + sin_fndecl = implicit_built_in_decls[BUILT_IN_SINF]; + cos_fndecl = implicit_built_in_decls[BUILT_IN_COSF]; + break; + + case BUILT_IN_SINCOSL: + sin_fndecl = implicit_built_in_decls[BUILT_IN_SINL]; + cos_fndecl = implicit_built_in_decls[BUILT_IN_COSL]; + break; + + default: + gcc_unreachable (); + } + + /* Avoid that cos(-x) is optimized into cos (x) and sincos_optab + cannot be used anymore. */ + if (TREE_CODE (arg) == NEGATE_EXPR) + { + arg = TREE_OPERAND (arg, 0); + negate_sin = true; + } + else + negate_sin = false; + + arg1 = TREE_VALUE (TREE_CHAIN (arglist)); + sin_fn = build_function_call_expr (sin_fndecl, + build_tree_list (NULL_TREE, arg)); + if (negate_sin) + sin_fn = build1 (NEGATE_EXPR, TREE_TYPE (sin_fn), sin_fn); + + sin_modify = + build2 (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (arg1)), + build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (arg1)), arg1), + fold_convert (TREE_TYPE (TREE_TYPE (arg1)), sin_fn)); + + arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); + cos_fn = build_function_call_expr (cos_fndecl, + build_tree_list (NULL_TREE, arg)); + cos_modify = + build2 (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (arg2)), + build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (arg2)), arg2), + fold_convert (TREE_TYPE (TREE_TYPE (arg2)), cos_fn)); + + return build1 (NOP_EXPR, void_type_node, + build2 (COMPOUND_EXPR, TREE_TYPE (sin_modify), + cos_modify, sin_modify)); +} + /* Fold function call to builtin tan, tanf, or tanl. Return NULL_TREE if no simplification can be made. */ static tree @@ -8288,6 +8365,11 @@ fold_builtin_1 (tree exp, bool ignore) case BUILT_IN_COSL: return fold_builtin_cos (arglist, type, fndecl); + case BUILT_IN_SINCOS: + case BUILT_IN_SINCOSF: + case BUILT_IN_SINCOSL: + return fold_builtin_sincos (arglist, fndecl); + case BUILT_IN_EXP: case BUILT_IN_EXPF: case BUILT_IN_EXPL: --------------040408030104040205030407--