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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d89e2d213646aec8 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Mneson announcement and help request Date: Thu, 03 Jun 2004 11:02:49 +0200 Organization: AdaCL Message-ID: <2115922.H9sZyWkzVU@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1086254736 04 8515 Z1D9GJ86m9TUUwe 040603 09:25:36 X-Complaints-To: usenet-abuse@t-online.de X-ID: Xu+AvMZGrezXPbEggNuTn3oxyduOyU6G6gDRF3uSJ2JVCPpQZPY-rD User-Agent: KNode/0.7.7 Xref: g2news1.google.com comp.lang.ada:1060 Date: 2004-06-03T11:02:49+02:00 List-Id: Jeffrey Carter wrote: > Martin Dowie wrote: > >> Standard idiom: MAA Idiom: >> >> while not End_Of_File (Current_Input) begin >> loop loop >> Get_Immediate (C); Get_Immediate (C); >> end loop; end loop; >> exception >> when End_Error => >> null; -- End of file >> end; > > The standard idiom should be > > loop > exit when End_Of_File (Current_Input); > > Get_Immediate (C); > end loop; > > which eliminates the calls to "not". In addition, it uses positive > logic, rather than the negative logic required by while, which is easier > to read and understand. I once tried a "loop optimization" with MS-C 6.00. Tried various options and looked at the assembler output. Guess what: "do while", "while" and "for" all redered the very same result in assembler. Starting with: loop Instructions_1; exit when Condition; Instructions_2; end loop; or alternative: Instructions_1; while not Condition loop Instructions_2; Instructions_1; end loop; I got something like this: goto center; loop Instructions_2; <
> Instructions_1; while not Condition; Disclaimers: 1) I know that Ada does not allow a goto into a loop; 2) I know that Ada does not have a while at the and of a loop. I never ever tried to optimize a loop again. I just write it down so I can read it nicely. On a side note: At the same time I also made a "if case" optimization. There where several small groups with large holes in between. Again no matter if I used "if" or "case" the asembler result was the same: A binary tree search for the holes and jump tables for the groups. And that was MSC-6 more then 10 year ago. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com