From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24606 invoked by alias); 8 Jun 2004 17:26:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 24578 invoked from network); 8 Jun 2004 17:26:22 -0000 Received: from unknown (HELO book.moene.indiv.nluug.nl) (195.109.255.217) by sourceware.org with SMTP; 8 Jun 2004 17:26:22 -0000 Received: from local ([127.0.0.1] helo=moene.indiv.nluug.nl) by book.moene.indiv.nluug.nl with esmtp (Exim 3.36 #1 (Debian)) id 1BXkTk-0006ja-00; Tue, 08 Jun 2004 19:33:40 +0200 Message-ID: <40C5F85F.80006@moene.indiv.nluug.nl> Date: Tue, 08 Jun 2004 18:56:00 -0000 From: Toon Moene Organization: Moene Computational Physics, Maartensdijk, NL User-Agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.6) Gecko/20040414 Debian/1.6-5 MIME-Version: 1.0 To: gfortran CC: "gcc-patches@gcc.gnu.org" Subject: [gfortran] Compute x**(-n) as (1/x)**n Content-Type: multipart/mixed; boundary="------------070206030800040600010501" X-SW-Source: 2004-06/txt/msg00436.txt.bz2 This is a multi-part message in MIME format. --------------070206030800040600010501 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1056 The following change, which I bootstrapped on powerpc-unknown-linux-gnu (C and f95) without regressions, leads the Fortran front-end to generate expressions x**(-n) with n constant as if they were written (1/x)**n. This will enable more opportunities for CSE in case multiple powers of the same base are needed in an expression. E.g., the following: function force(d) force = d**(-2) + d**(-6) + d**(-8) + d**(-12) end will lead to the following floating point operations (when using -ffast-math, whereas the current method needs four divisions and uses no fused multiply-add. fdivs 1,1,13 fmuls 0,1,1 fmuls 1,1,0 fmuls 13,0,0 fmuls 1,1,1 fadds 0,0,1 fmadds 13,13,13,0 fmadds 1,1,1,13 Paul, is this OK ? -- Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290 Saturnushof 14, 3738 XG Maartensdijk, The Netherlands Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html GNU Fortran 95: http://gcc.gnu.org/fortran/ (under construction) --------------070206030800040600010501 Content-Type: text/plain; name="rexpnegint.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rexpnegint.patch" Content-length: 917 2004-06-08 Toon Moene * trans-expr.c (gfc_conv_cst_int_power): Compute x**(-n) by converting it to (1/x)**n instead of 1/x**n. *** trans-expr.c.orig Sat Jun 5 13:45:07 2004 --- trans-expr.c Sat Jun 5 13:48:38 2004 *************** gfc_conv_cst_int_power (gfc_se * se, tre *** 526,538 **** memset (vartmp, 0, sizeof (vartmp)); vartmp[1] = lhs; - - se->expr = gfc_conv_powi (se, n, vartmp); if (sgn == -1) { tmp = gfc_build_const (type, integer_one_node); ! se->expr = build (RDIV_EXPR, type, tmp, se->expr); } return 1; } --- 526,539 ---- memset (vartmp, 0, sizeof (vartmp)); vartmp[1] = lhs; if (sgn == -1) { tmp = gfc_build_const (type, integer_one_node); ! vartmp[1] = build (RDIV_EXPR, type, tmp, vartmp[1]); } + + se->expr = gfc_conv_powi (se, n, vartmp); + return 1; } --------------070206030800040600010501--