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,d0310bb11aeb7260 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.15.105 with SMTP id w9mr25520529pbc.7.1321421641442; Tue, 15 Nov 2011 21:34:01 -0800 (PST) MIME-Version: 1.0 Path: h5ni59971pba.0!nntp.google.com!news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!news-transit.tcx.org.uk!aioe.org!.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: GNAT 4.4.5 order of conditional processing? Date: Wed, 16 Nov 2011 05:33:59 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <8f003611-8375-4de7-bfd0-1d6b3f910c30@m13g2000prl.googlegroups.com> NNTP-Posting-Host: Lf0Nl3CcQzx+ocHx9cmuGg.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Tom's custom newsreader Xref: news1.google.com comp.lang.ada:18940 Date: 2011-11-16T05:33:59+00:00 List-Id: > > Note that the short circuit forms should not be considered optimizations. > > With modern processors, unnecessary short-circuit forms may sometimes be > > slower than the regular equivalents. > > Yeah, but the compiler should be able to figure it out and generate > the best code. No matter what the Ada language says, if you write "A > and then B" and A and B are Boolean variables, it's perfectly legal > for the compiler to generate an instruction that reads the register > that currently contains B. (I mean a normal register, not a memory- > mapped I/O register.) The only time it should be necessary to use > "and" instead of "and then" (on Boolean operands) is if the right side > contains a function call (or, perhaps, a read of a variable that's > mapped to some special hardware address) that you absolutely want to > take place regardless of the left side. "Portability and Style in Ada" (1984) says: Short-circuit control forms should not be used unless logically necessary. ... If used to increase efficiency of execution, there should be a comment to this effect. Note that the short-circuit form forces a procedural view (rather than a functional/static view) of the expression in which it occurs, which is somewhat undesirable. while "Ada Quality and Style" (1989) says: Use short-circuit forms of the logical operators. ... The use of short-circuit control forms prevents a class of data-dependent errors or exceptions that can occur as a result of expression evaluation. I would add that "if N > 0 and then Tally > 0 then ..." may lead the maintenance programmer to think N is somehow more important or primary than Tally, which may not be the case.