From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 12 Apr 93 18:38:06 GMT From: sampson@cod.nosc.mil (Charles H. Sampson) Subject: Re: and then Message-ID: <1993Apr12.183806.1003@nosc.mil> List-Id: In article <1q3vtq$2lt@travis.csd.harris.com> danr@ada1.ssd.csd.harris.com (Dan Rittersdorf) writes: >In article <1993Apr7.162133.3564@nosc.mil> sampson@nosc.mil (me) writes: >> >> Unfortunately, that style can conflict with efficiency considerations. >>Ada compiler writers appear to have abdicated their responsibility and make >>no attempt to determine when boolean operations can be optimized as short- >>circuit. (Somebody contradict me, please.) They apparently feel that if >>the programmer wants short-circuit he can ask for it. In addition, there >>are cases when it is unreasonable to expect such an optimization; when the >>second operand contains a function reference, for example. > > Some vendors, especially those that have concentrated on excellent > optimization, like (blatant plug alert) Harris, do make this > optimization when it can be determined that the operands of > the boolean operator have no side effects. Someone else also stated > that the LRM requires the evaluation of the operands, but I think > several people have done a good job of arguing that one to the > ground, so I won't. > > I find it odd, though, that you feel a vendor has some *responsibility* > to provide this optimization. Each possible optimization has a cost and > a benefit -- to the vendor and the user, and each vendor decides what > optimizations they can afford to provide, given the benefit (profit) > that can be obtained. That's business. If a vendor decides that benefits > of providing short circuit boolean optimizations don't outweigh their > investment, they may well decide not to provide it. They have no > responsibility to provide it -- just the option. If you want it, > let your vendor know. They can't know what the customer wants if the > customer doesn't tell them. If they're unresponsive, remember that > they still have to weigh the benefit to their entire user community > against the cost to the same. Sometimes one user's request can't be > granted if the impact to the entire user community would be deemed > too great (for example, if the requested optimization were to require > adding a new, time consuming pass to the compiler which would increase > everybody's compile times). These are all good points and I find it difficult to argue with them. I will explain a bit what I meant by "abdicating responsibility". In the pre-Ada world, not so long ago, evaluating boolean expressions in short-circuit form was so common that I doubt that many compiler writers considered it to be an optimization. I certainly didn't for the compiler I worked on. It was just considered code generation, in roughly the same bag of tricks as a decent register assignment algorithm. In the FORTRAN world, short-circuit was common but not universal, which had interesting impact on FORTRAN's vaunted transportability. Then along came Ada, which specified precisely the semantics of bool- ean expressions. As I have looked at code from a number of Ada compilers and not seen any short-circuit, I leaped to the conclusion that the imple- menter were saying something like, "Heck, it's easy to do short-circuit, but first we have to verify that we're not changing the semantics. Forget it. If the programmer wants short-circuit he can ask for it." I consider it a "responsibility" of Ada compiler writers to generate code roughly as good as the code for similar constructs in other languages, provided the LRM doesn't prevent it, therefore roughly as good as a FORTRAN compiler. Certainly that "responsibility" is not a moral imperative; it's tempered by all of the considerations stated by Mr. Rittersdorf. I'm happy to report that a number of implementors have responded to my request to be contradicted. Apparently many have now decided to do the extra work required to implement this "optimization". Charlie