From: Dmitry A. Kazakov on
On Fri, 5 Mar 2010 00:16:52 -0800 (PST), deadlyhead wrote:

> On Mar 4, 11:55�pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de>
> wrote:
>>
>> This is an ancient bug, which managed to survive a number of GNAT compiler
>> versions.
>>
>> As a workaround, add delay 0.0 at the beginning of your program:
>>
>>> ----------------------------------------------------------------------
>>
>>> -- �A test of the cost of conditionals
>>
>>> with Ada.Text_IO; �use Ada.Text_IO;
>>> with Ada.Real_Time; use Ada.Real_Time;
>>> procedure Conditional_Test is
>>
>
> Exactly what was needed. Thank you!
>
> Do you happen to know if this bug has been fixed in the current
> development branch? (At home I compile GNAT based on GCC 4.4, but
> haven't done any real-time tests with it yet.)

AFAIK it is still present in GNAT Pro 6.3.1, which is the latest version of
GNAT.

> This seems like an
> unfortunate bug to have lying around in an otherwise respected
> compiler.

Yes, but in real-life applications it does not show itself, because tasking
stuff somehow wakes the RTL up. That is probably the reason, I suggest, why
none of paying customers had yet reported it to AdaCore.

> BTW, my test results with -O3 and -Os, there is no difference in
> performance between the two loops, and -Os produces code that is about
> 33% faster than -O3. With -O0, the second loop is faster by an
> average of 10%. I would have thought the extra conditional would have
> been costlier.

Niklas has posted an excellent comment regarding performance measures. It
is quite difficult to do time measurements right in presence of -O2/3.

As a small addition, here is a technique I am using to subtract looping
overhead:

T := Clock;
for I in 1..N loop
... -- measured stuff
end loop;
D1 := Clock - T;

T := Clock;
for I in 1..N loop
... -- measured stuff
... -- measured stuff (do it twice)
end loop;
D2 := Clock - T;

(D2 - D1) / N is the average time spent on measured stuff without the
overhead caused by looping. Important, as Niklas has pointed out, to fool
the compiler so, that it will not optimize out the things you are
measuring...

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Dmitry A. Kazakov on
On Fri, 5 Mar 2010 00:33:54 -0800 (PST), Ludovic Brenta wrote:

> Dmitry A. Kazakov wrote on comp.lang.ada:
>> On Thu, 4 Mar 2010 22:34:47 -0800 (PST), deadlyhead wrote:
>>> The problem I'm having, though, is that the timing just isn't
>>> happening. �This code will run for 15 seconds and when I examine the
>>> time span, it tells me that no time passed.
>>
>> This is an ancient bug, which managed to survive a number of GNAT compiler
>> versions.
>>
>> As a workaround, add delay 0.0 at the beginning of your program:
> [...]
>> delay 0.0; -- Wake up that dozing Ada RTL!
>
> I was not aware of this bug; is there a PR in Bugzilla for it?

As an active member of c.l.a. you should remember it discussed here several
times in recent years. Each time I thought - well, the next version will
certainly fix it, somebody had already reported it... (:-))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Alex Mentis on
On Mar 5, 3:49 am, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de>
wrote:
> On Fri, 5 Mar 2010 00:16:52 -0800 (PST), deadlyhead wrote:
> > On Mar 4, 11:55 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de>
> > wrote:
>
> >> This is an ancient bug, which managed to survive a number of GNAT compiler
> >> versions.
>
> >> As a workaround, add delay 0.0 at the beginning of your program:
>
> >>> ----------------------------------------------------------------------
>
> >>> --  A test of the cost of conditionals
>
> >>> with Ada.Text_IO;  use Ada.Text_IO;
> >>> with Ada.Real_Time; use Ada.Real_Time;
> >>> procedure Conditional_Test is
>
> > Exactly what was needed.  Thank you!
>
> > Do you happen to know if this bug has been fixed in the current
> > development branch? (At home I compile GNAT based on GCC 4.4, but
> > haven't done any real-time tests with it yet.)
>
> AFAIK it is still present in GNAT Pro 6.3.1, which is the latest version of
> GNAT.
>
> > This seems like an
> > unfortunate bug to have lying around in an otherwise respected
> > compiler.
>
> Yes, but in real-life applications it does not show itself, because tasking
> stuff somehow wakes the RTL up. That is probably the reason, I suggest, why
> none of paying customers had yet reported it to AdaCore.
>
> > BTW, my test results with -O3 and -Os, there is no difference in
> > performance between the two loops, and -Os produces code that is about
> > 33% faster than -O3.  With -O0, the second loop is faster by an
> > average of 10%.  I would have thought the extra conditional would have
> > been costlier.
>
> Niklas has posted an excellent comment regarding performance measures. It
> is quite difficult to do time measurements right in presence of -O2/3.
>
> As a small addition, here is a technique I am using to subtract looping
> overhead:
>
> T := Clock;
> for I in 1..N loop
>    ... -- measured stuff
> end loop;
> D1 := Clock - T;
>
> T := Clock;
> for I in 1..N loop
>    ... -- measured stuff
>    ... -- measured stuff (do it twice)
> end loop;
> D2 := Clock - T;
>
> (D2 - D1) / N is the average time spent on measured stuff without the
> overhead caused by looping. Important, as Niklas has pointed out, to fool
> the compiler so, that it will not optimize out the things you are
> measuring...
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Confirmed: the bug is still present in GNAT GPL 2009. The same code,
timed using Ada.Calendar seems to work just fine, though.
Interesting, and good to know about.
From: Simon Wright on
I found the same results as Niklas, the compiler I'm running
is gcc version 4.5.0 20100221 (experimental) [trunk revision 156937]
(GCC) for x86_64-apple-darwin10.2.0.

I just added

Junk_In : Natural := 0;
pragma Volatile (Junk_In); -- <=====

after which -O[0123] all gave pretty similar results.

I didn't have to add 'delay 0.0;' to get the timings.

I did set

Test_Dur : constant := 10_000;

and the timings on this Macbook Pro (2.4 GHz Core 2 Duo are of order
0.292 with -gnato, 0.254 without. The second loop is quicker with -O0.
From: Jeffrey R. Carter on
Alex Mentis wrote:
>
> Confirmed: the bug is still present in GNAT GPL 2009. The same code,
> timed using Ada.Calendar seems to work just fine, though.
> Interesting, and good to know about.


This error does not appear in GNAT Pro 6.3.0w, at least using

-gnaton -O2 -fstack-check

--
Jeff Carter
"It's all right, Taggart. Just a man and a horse being hung out there."
Blazing Saddles
34