C "optimization" (2 of 8)
Dan Klein
dvk at mi-cec.UUCP
Wed Feb 15 05:20:32 AEST 1984
This is a continuation of my diatribe on "C doesn't optimize, it neatens".
In this and other articles, I compare a true optimizing compiler (Bliss-32
running under VMS) to a code neatener (C running under BSD 4.1c). Any and
all counterexamples are welcome. However, this is NOT a comparison of the
languages. Both C and Bliss have their good and bad points. This is simply
a comparison of the code they generate. As in all examples, the source
code and uncensored assembly code is presented. In all examples, the C source
and Bliss source are as nearly identical as language differences permit. I
have not taken advantage of any "tricks" to get either language to perform
better or worse than the other. The optimizer was enabled for both languages.
-Dan Klein, Mellon Institute, Pittsburgh (412)578-3382
=============================================================================
In this example I show what the compilers do when given two blocks of code
that are nearly identical (i.e. they are "tail identical"). Only the head
is different (namely whether the first argument pushed to "alpha" is a 0
or a 1. Both compilers behave well in that they share the tail identical code
between the two conditions. The only complaint I have against C is that
it uses 4 PUSHL instructions to pass the remaining arguments, rather than a
more speed/space effifient two MOVQ instructions. If you were sure you were
not going to run on an 11/730, you could further reduce this to a single MOVO
instruction, but that is an unreasonable request.
----------------------------------------+-------------------------------------
external routine alpha; | extern int alpha();
|
routine test(p,q,r,s,t) : NoValue = | test(p,q,r,s,t)
begin | {
| if (t!=0)
if .t neq 0 then | alpha(p,q,r,s,0);
alpha(.p,.q,.r,.s,0) | else
else | alpha(p,q,r,s,1);
alpha(.p,.q,.r,.s,1); | }
end; |
|
|
.TITLE FOO | .data
| .text
.EXTRN ALPHA | LL0: .align 1
| .globl _test
.PSECT $CODE$,NOWRT,2 | .set L13,0x0
| .data
TEST: .WORD ^M<> | .text
TSTL 20(AP) | _test: .word L13
BEQL 1$ | tstl 20(ap)
CLRL -(SP) | jeql L17
BRB 2$ | pushl $0
1$: PUSHL #1 | jbr L200004
2$: MOVQ 12(AP), -(SP) | L17: pushl $1
MOVQ 4(AP), -(SP) | L200004:pushl 16(ap)
CALLS #5, W^ALPHA | pushl 12(ap)
RET | pushl 8(ap)
| pushl 4(ap)
| calls $5,_alpha
| ret
More information about the Comp.lang.c
mailing list