From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: volatile vs aliased
Date: Fri, 07 Oct 2005 08:33:06 +0200
Date: 2005-10-07T08:33:06+02:00 [thread overview]
Message-ID: <21305827.4TOYkjRP7N@linux1.krischik.com> (raw)
In-Reply-To: 1128598604.142021.239190@g44g2000cwa.googlegroups.com
Rolf wrote:
> Martin Krischik wrote:
>> Ludovic Brenta wrote:
>>
>> > pragma Volatile (Variable) says the compiler must not optimise away
>> > any reads or writes to that variable, and that it may not add extra
>> > reads or writes beyond those you explicitly request in your program
>> > text. You want to use that for hardware registers, where a "read"
>> > operation may have a side effect such as changing the device's state.
>>
>> Interesting! So with pragma Volatile (X) the following two statements
>> are not the same:
>>
>> Y := X * X;
>> Y := X ** 2;
>
> Do we have a difference to C/C++ increment operator here? consider
>
> pragma Volatile (x);
> x := x + 1; -- (1)
> vs.
> x++; -- (2)
>
> In the Ada case (1) we are forced to have "read from memory",
> "increment" and "write to memory" instructions, whereas in C/C++ (2)
> you can get a single "increment memory" instruction (presuming the
> mentioned assembler instructions exist on a given processor)
Well, all machine code I have seen so far only have a INC for registers. And
if you think for it for a sec.: It can't be another way, even if there is a
INC for memory the CPU still has to read the memory increment internally
write back.
The truth is that x++ is a cheat and has allways been. x++ only exists
because it needs less memory to implement then a peep hole optimiser and -
in the light of modern CPU with powerfull MMUs and triple cache - without
any effect anyway.
Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
next prev parent reply other threads:[~2005-10-07 6:33 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-05 15:22 volatile vs aliased REH
2005-10-05 18:22 ` Ludovic Brenta
2005-10-05 18:39 ` REH
2005-10-05 19:46 ` Ludovic Brenta
2005-10-05 20:02 ` REH
2005-10-05 20:11 ` Ludovic Brenta
2005-10-05 20:20 ` REH
2005-10-06 5:21 ` Ludovic Brenta
2005-10-05 20:55 ` Simon Wright
2005-10-06 18:32 ` Jeffrey R. Carter
2005-10-05 23:38 ` Randy Brukardt
2005-10-06 0:02 ` tmoran
2005-10-06 13:40 ` REH
2005-10-06 23:52 ` Randy Brukardt
2005-10-06 18:40 ` Jeffrey R. Carter
2005-10-06 19:37 ` Robert A Duff
2005-10-06 23:56 ` Randy Brukardt
2005-10-06 19:08 ` REH
2005-10-06 19:21 ` Ed Falis
2005-10-06 19:37 ` REH
2005-10-06 19:46 ` Robert A Duff
2005-10-06 8:05 ` Martin Krischik
2005-10-06 8:52 ` Dmitry A. Kazakov
2005-10-06 11:36 ` Rolf
2005-10-06 18:43 ` Björn Persson
2005-10-06 19:03 ` Niklas Holsti
2005-10-07 6:36 ` Martin Krischik
2005-10-07 6:33 ` Martin Krischik [this message]
2005-10-07 15:56 ` Adrian Knoth
2005-10-07 18:48 ` Martin Krischik
2005-10-07 22:44 ` REH
2005-10-08 6:10 ` Simon Wright
2005-10-17 2:16 ` Dave Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox