Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!akgua!mcnc!idis!mi-cec!dvk From: dvk@mi-cec.UUCP (Dan Klein) Newsgroups: net.lang.c Subject: C "optimization" (2 of 8) Message-ID: <204@mi-cec.UUCP> Date: Tue, 14-Feb-84 14:20:32 EST Article-I.D.: mi-cec.204 Posted: Tue Feb 14 14:20:32 1984 Date-Received: Fri, 17-Feb-84 04:21:42 EST Lines: 56 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