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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c6acbb9f2027b8c9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!solnet.ch!solnet.ch!news-zh.switch.ch!switch.ch!news.hispeed.ch!linux2.krischik.com!news From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: volatile vs aliased Date: Fri, 07 Oct 2005 08:33:06 +0200 Organization: Cablecom Newsserver Message-ID: <21305827.4TOYkjRP7N@linux1.krischik.com> References: <1128525722.605730.281980@g43g2000cwa.googlegroups.com> <87mzlnomca.fsf@ludovic-brenta.org> <1421562.dbAHjS9XJS@linux1.krischik.com> <1128598604.142021.239190@g44g2000cwa.googlegroups.com> NNTP-Posting-Host: 80-218-113-178.dclient.hispeed.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.hispeed.ch 1128667501 2324 80.218.113.178 (7 Oct 2005 06:45:01 GMT) X-Complaints-To: news@hispeed.ch NNTP-Posting-Date: Fri, 7 Oct 2005 06:45:01 +0000 (UTC) User-Agent: KNode/0.9.2 Xref: g2news1.google.com comp.lang.ada:5484 Date: 2005-10-07T08:33:06+02:00 List-Id: 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