Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Semantics o...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 13 of 15 Topic 5622 of 5828
Post > Topic >>

Re: Semantics of statement reordering relevant to Ada.Real_Time

by Robert A Duff <bobduff@[EMAIL PROTECTED] > Mar 30, 2008 at 02:59 PM

Eric Hughes <eric.eh9@[EMAIL PROTECTED]
> writes:

> On Mar 29, 7:51 am, kongra <kon...@[EMAIL PROTECTED]
> wrote:
>>    Start_T := Ada.Real_Time.Clock;
>>    for K in 1 .. 10 loop
>>       for I in 1 .. 10_000_000 loop
>>          Val := Val + I;
>>       end loop;
>>    end loop;
>>    End_T   := Ada.Real_Time.Clock;
>
> I have a question about this piece of the program.  Because the middle
> uses only variables 'K', 'I', and 'Val', and the side-effects of
> modifying these variables are entirely local, and because there's no
> inter-dependency of these variables upon either the first or last
> statements, aren't the following reorderings legal for code
> generation?  To wit:
>
>     Long_Statement ;
>     Start_T := Ada.Real_Time.Clock ;
>     End_T   := Ada.Real_Time.Clock ;
>
>     Start_T := Ada.Real_Time.Clock ;
>     End_T   := Ada.Real_Time.Clock ;
>     Long_Statement ;
>
> Irrelevant to the quirks mentioned earlier, isn't it legal operation
> for the interval to come out zero?

Yes.

For example, I can calculate the final value of Val with pencil and
paper, so I guess I could teach an optimizer to do it at compile time.
;-)

>...It seems that for known-correct
> operation for all possible compilers you'd need to manually serialize
> these operations in the order desired.

The only thing that's guaranteed is I/O behavior, so you have to do some
I/O.  And you should inspect the generated machine code to see if you're
measuring what you think you're measuring.  In other words, this sort of
thing is pretty much outside the language definition.  Also, it might be
better to measure using outside tools, like the Unix 'time' command, or
perhaps a stopwatch.

- Bob
 




 15 Posts in Topic:
Ada.Real_Time behavior with GNAT
kongra <kongra@[EMAIL   2008-03-29 06:51:58 
Re: Ada.Real_Time behavior with GNAT
george.priv@[EMAIL PROTEC  2008-03-29 09:50:56 
Re: Ada.Real_Time behavior with GNAT
Georg Bauhaus <rm.tsoh  2008-03-29 18:29:48 
Re: Ada.Real_Time behavior with GNAT
Simon Wright <simon.j.  2008-03-29 18:11:29 
Re: Ada.Real_Time behavior with GNAT
"Dmitry A. Kazakov&q  2008-03-29 19:25:05 
Re: Ada.Real_Time behavior with GNAT
george.priv@[EMAIL PROTEC  2008-03-29 12:06:38 
Re: Ada.Real_Time behavior with GNAT
Konrad Grzanek <kongra  2008-03-29 12:15:41 
Re: Ada.Real_Time behavior with GNAT
Konrad Grzanek <kongra  2008-03-29 12:46:16 
Re: Ada.Real_Time behavior with GNAT
Georg Bauhaus <rm.tsoh  2008-03-30 01:14:29 
Re: Ada.Real_Time behavior with GNAT
george.priv@[EMAIL PROTEC  2008-03-29 14:21:45 
Re: Ada.Real_Time behavior with GNAT
Konrad Grzanek <kongra  2008-03-29 14:49:16 
Semantics of statement reordering relevant to Ada.Real_Time
Eric Hughes <eric.eh9@  2008-03-30 10:12:25 
Re: Semantics of statement reordering relevant to Ada.Real_Time
Robert A Duff <bobduff  2008-03-30 14:59:21 
Re: Semantics of statement reordering relevant to Ada.Real_Time
Eric Hughes <eric.eh9@  2008-03-30 14:12:20 
Re: Semantics of statement reordering relevant to Ada.Real_Time
Robert A Duff <bobduff  2008-03-30 17:28:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 14:42:30 CDT 2008.