From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: Mneson announcement and help request
Date: Thu, 03 Jun 2004 11:02:49 +0200
Date: 2004-06-03T11:02:49+02:00 [thread overview]
Message-ID: <2115922.H9sZyWkzVU@linux1.krischik.com> (raw)
In-Reply-To: Xyxvc.19956$Tn6.3068@newsread1.news.pas.earthlink.net
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;
<<center>>
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
next prev parent reply other threads:[~2004-06-03 9:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-01 15:56 Mneson announcement and help request Marius Amado Alves
2004-06-02 2:26 ` Jeff C,
2004-06-02 3:06 ` Marius Amado Alves
2004-06-02 11:19 ` Georg Bauhaus
2004-06-02 11:41 ` Marius Amado Alves
[not found] ` <c9l0vo$pq3$1@sparta.btinternet.com>
2004-06-02 17:47 ` Marius Amado Alves
2004-06-02 19:46 ` Martin Dowie
2004-06-02 22:10 ` Randy Brukardt
2004-06-03 5:58 ` Martin Dowie
2004-06-04 3:21 ` Randy Brukardt
2004-06-04 5:55 ` Martin Dowie
2004-06-04 7:30 ` Jean-Pierre Rosen
2004-06-04 14:11 ` Larry Kilgallen
2004-06-03 4:12 ` Jeffrey Carter
2004-06-03 5:48 ` Martin Dowie
2004-06-03 9:02 ` Martin Krischik [this message]
2004-06-02 11:41 ` Georg Bauhaus
2004-06-02 13:14 ` Marius Amado Alves
2004-06-03 4:09 ` Jeffrey Carter
2004-06-03 11:24 ` Georg Bauhaus
2004-06-02 3:21 ` Marius Amado Alves
2004-06-22 20:49 ` Jacob Sparre Andersen
2004-06-23 9:36 ` Marius Amado Alves
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox