comp.lang.ada
 help / color / mirror / Atom feed
From: Duncan Sands <baldrick@free.fr>
To: comp.lang.ada@ada-france.org
Cc: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: GNAT Optimization of Constant Expressions
Date: Fri, 18 May 2007 13:32:22 +0200
Date: 2007-05-18T13:55:06+02:00	[thread overview]
Message-ID: <mailman.150.1179489279.18371.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <87k5v631kp.fsf@mid.deneb.enyo.de>

> ...  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.



  reply	other threads:[~2007-05-18 11:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-16 22:37 GNAT Optimization of Constant Expressions David Smith
2007-05-17  4:50 ` Randy Brukardt
2007-05-17 20:03   ` Gautier
2007-05-17 20:46     ` Randy Brukardt
2007-05-17 22:49       ` David Smith
2007-05-17 23:38         ` Randy Brukardt
2007-05-18  7:58           ` Dmitry A. Kazakov
2007-05-18 11:27           ` Georg Bauhaus
2007-05-18 17:28             ` Randy Brukardt
2007-05-18 16:25       ` Ray Blaak
2007-05-18 17:40         ` Randy Brukardt
2007-05-18 22:51           ` Adam Beneschan
2007-05-19  2:44             ` Randy Brukardt
2007-05-18  9:05   ` Markus E Leypold
2007-05-18  9:47   ` Florian Weimer
2007-05-18 11:32     ` Duncan Sands [this message]
2007-05-18 17:20     ` Randy Brukardt
2007-05-18 17:35       ` Duncan Sands
     [not found]       ` <200705181935.23877.baldrick@free.fr>
2007-05-18 17:49         ` Duncan Sands
2007-05-17  5:30 ` Martin Krischik
2007-05-18  9:56 ` Duncan Sands
2007-05-18 15:39   ` David Smith
2007-05-18 17:08     ` Duncan Sands
     [not found]     ` <200705181908.54920.baldrick@free.fr>
2007-05-18 17:32       ` Duncan Sands
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox