C "optimization" (6 of 8)

Dan Klein dvk at mi-cec.UUCP
Wed Feb 15 05:28:00 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 how both compilers are smart enough to do compile
time testing of constant expressions.  This is included to be fair to C,
which does a generally "good" job of generating code.  It just ain't "great".

As can be seen, the generated code is effectively equivalent.  However, here
I raise a gripe to the template nature of the C compiler.  Since it assumes
there to be a data and a text portion to every routine/program, it emits a
".data" pseudo op, outputs the data, emits a ".text" pseudo op, and outputs
the text.  What results is two (count 'em) superfluous ".data" / ".text"
pseudo ops.  Now, this doesn't slow down the assembler a whole lot, but on
a loaded system, every little bit helps.  Likewise, where in the hell is
the label "LL0" ever used?  If you don't use it (and certainly, with a name
like "LL0", it is local), don't emit it.  The same thing holds true for
the routine entry mask being stored in "L13".  What ever for?  You only
use it once, so why clutter the symbol table with it?  C takes 10 lines
of assembly code to do what Bliss does in 5 lines.
literal P1 = 3,				|	#define P1	3
	P2 = 5;				|	#define P2	5
routine test =				|	extern int alpha();
begin					|
    if P1 lss P2			|	test()
	then return 0			|	{
	else return 1			|	    if (P1 < P2)
end;					|		return 0;
					|	    else
					|		return 1;
					|	}
	.TITLE  FOO			|		.data
					|		.text
	.PSECT  $CODE$,NOWRT,2		|	LL0:	.align  1
					|		.globl  _test
TEST:	.WORD	^M<>			|		.set	L13,0x0
	CLRL	R0			|		.data
	RET				|		.text
					|	_test:  .word	L13
					|		clrl	r0
					|		ret

More information about the Comp.lang.c mailing list