From: Toon Moene <toon@moene.indiv.nluug.nl>
To: gfortran <fortran@gcc.gnu.org>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [gfortran] Compute x**(-n) as (1/x)**n
Date: Tue, 08 Jun 2004 18:56:00 -0000 [thread overview]
Message-ID: <40C5F85F.80006@moene.indiv.nluug.nl> (raw)
[-- Attachment #1: Type: text/plain, Size: 1056 bytes --]
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)
[-- Attachment #2: rexpnegint.patch --]
[-- Type: text/plain, Size: 917 bytes --]
2004-06-08 Toon Moene <toon@moene.indiv.nluug.nl>
* 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;
}
next reply other threads:[~2004-06-08 17:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-08 18:56 Toon Moene [this message]
2004-06-08 19:04 ` Tobias Schlüter
2004-06-08 21:46 ` Toon Moene
2004-06-09 3:00 ` Paul Brook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40C5F85F.80006@moene.indiv.nluug.nl \
--to=toon@moene.indiv.nluug.nl \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).