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!news4.google.com!news.germany.com!news.belwue.de!news.tiscali.de!tiscali!newsfeed1.ip.tiscali.net!proxad.net!cleanfeed1-a.proxad.net!nnrp17-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 13:32:22 +0200 User-Agent: KMail/1.9.6 References: <1179355028.624745.258370@q75g2000hsh.googlegroups.com> <87k5v631kp.fsf@mid.deneb.enyo.de> In-Reply-To: <87k5v631kp.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 at math.u-psud.fr X-Virus-Scanned: amavisd-new at ada-france.org Cc: Florian Weimer 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 13:55:06 MEST NNTP-Posting-Host: 88.191.14.223 X-Trace: 1179489306 news-1.free.fr 22641 88.191.14.223:34044 X-Complaints-To: abuse@proxad.net Xref: g2news1.google.com comp.lang.ada:15830 Date: 2007-05-18T13:55:06+02:00 > ... Ideally, GNAT would translate the function calls to GCC > built-in calls, so that they can be expanded at compile time. This > optimization probably kicks in for C and Fortran, whose front ends are > more closely aligned with the rest of the compiler. This seems to be close to the truth. If I use llvm-gcc to compile the testcase (at -O3) then the calls to sin etc are removed altogether: they are evaluated at compile time. Why? Well, because llvm-gcc doesn't handle inline floating point assembler on x86, I modified the elementary functions package to call the implementations of sin etc in the C library. The LLVM optimizers recognize these C library functions and precompute them. So why doesn't GNAT use the C library functions? Presumably because they don't satisfy the accuracy requirements of the Ada standard [*]. Instead, for each platform, GNAT implements them itself, hopefully more accurately. This usually means reducing arguments down to a range in which the processor's floating point instructions give accurate results, then executing that instruction. I think the GNAT approach is a mistake: instead of using inline assembler, it should call the corresponding C library function at that point. Thus it would do range reduction then call the C routine. This means that constants would be evaluated at compile time etc for free, while keeping accuracy. Ciao, Duncan. [*] It is not clear to me if this is true nowadays. A quick peek shows the C routines using a quick but maybe inaccurate implementation only if "fast math" is enabled.