comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: GNAT 4.4.5 order of conditional processing?
Date: Wed, 16 Nov 2011 05:33:59 +0000 (UTC)
Date: 2011-11-16T05:33:59+00:00	[thread overview]
Message-ID: <j9vi06$h8d$1@speranza.aioe.org> (raw)
In-Reply-To: 8f003611-8375-4de7-bfd0-1d6b3f910c30@m13g2000prl.googlegroups.com

> > 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.



  reply	other threads:[~2011-11-16  5:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-15 20:30 GNAT 4.4.5 order of conditional processing? awdorrin
2011-11-15 20:54 ` Niklas Holsti
2011-11-15 21:07   ` awdorrin
2011-11-15 21:23     ` Vinzent Hoefler
2011-11-15 21:49       ` awdorrin
2011-11-16 21:31         ` Gautier write-only
2011-11-16 22:40           ` Adam Beneschan
2011-11-17  0:00             ` Adam Beneschan
2011-11-15 23:08 ` Jeffrey Carter
2011-11-16  1:18   ` Adam Beneschan
2011-11-16  5:33     ` tmoran [this message]
2011-11-16 17:52       ` awdorrin
2011-11-16 20:01         ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox