From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,acba876b1e3c9639 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!cleanfeed3-a.proxad.net!nnrp8-1.free.fr!not-for-mail Return-Path: From: Duncan Sands To: comp.lang.ada@ada-france.org Subject: Re: GNAT Optimization of Constant Expressions Date: Fri, 18 May 2007 19:49:53 +0200 User-Agent: KMail/1.9.6 References: <1179355028.624745.258370@q75g2000hsh.googlegroups.com> <200705181935.23877.baldrick@free.fr> In-Reply-To: <200705181935.23877.baldrick@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: amavisd-new at ada-france.org Cc: Randy Brukardt X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.9rc1 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.ada Message-ID: X-Leafnode-NNTP-Posting-Host: 88.191.17.134 Organization: Guest of ProXad - France NNTP-Posting-Date: 18 May 2007 19:50:09 MEST NNTP-Posting-Host: 88.191.14.223 X-Trace: 1179510609 news-2.free.fr 25709 88.191.14.223:48015 X-Complaints-To: abuse@proxad.net Xref: g2news1.google.com comp.lang.ada:15840 Date: 2007-05-18T19:50:09+02:00 > while what you say is very logical, unfortunately it seems to be wrong: I > checked and these functions are not being marked pure. So how come declaring > a constant helps? I don't know - I didn't look into it yet. I took a quick look. At -O2 defining constants makes no difference (in the C case "const" functions are hoisted out of the loop at -O2) but with -O3 the calls are hoisted. This is presumably because gcc inlines the bodies for sin etc at -O3 and sees that in fact they have no side-effects, but for some reason doesn't hoist them unless the constants have been defined. Ciao, Duncan.