structure and array and string comparisons

donn at sdchema.UUCP donn at sdchema.UUCP
Mon Mar 26 17:43:49 AEST 1984


This debate is over the wrong issues.

What I hear some people saying is, 'Wow!  My machine has a whiz-bang
block compare instruction!  If only my compiler could generate it, my
code would be SO much faster!'  People on the one side of the fence
seem to think that the only way to get this into the compiler is to
make a built-in language construct like structure comparison, while
people on the other side are willing to live with a function call if it
means keeping the syntax of C safe from questionable additions.

How about meeting halfway?  The Berkeley folks often use a
post-processing 'sed' script which takes nasty things like splx() and
ntohl() and produces in-line code.  While I'm sure we all groan at the
grossness of this kind of intervention, why not take the grossness away
and let the compiler have access to a 'library' of in-line assembly
language functions?

A macro-like syntax for these functions could be developed so that
there would be a standard way of adding to the library when desired.
No C compiler would be required to implement the functions in-line;
thus no C syntax or semantics would change.  Any compiler that didn't
implement in-line functions would simply cause programs to use the
standard C library.

Thus we might see pseudo-C definitions like:

/*
 * strlen( s ) -- Return length of s.  VAX inline code.
 */
inline int strlen( s ) {
	register r

	movl	s,r
	locc	$0,$0x7fffffff,(r)	/* Search for null char in s */
	subl2	r,r0			/* Subtract s from addr of end of s */
}

(The intent of the 'register' declaration would be to ask the compiler
to make a register available, by using one that is free or by saving
one on the stack and restoring it later.)

This would make string manipulating 'functions' just as fast as the
proposed string operators, but the idea is more general and C's syntax
doesn't suffer.  Structure comparisons would be done quickly by a
simple bcmp(), which might cause an in-line 'cmpc3' instruction to be
emitted on a VAX or a subroutine call on a PDP11.  (Or a tight loop --
the arrangement is flexible enough that anything you could code
yourself in assembler, you could make available to the compiler to
improve your C code.)  No smarts are needed in the compiler to spot
loops that could be compiled into exotic instructions.

I was hoping to hear that this sort of thing was possible with PCC 2
when I went to Steve (?) Johnson's talk at Uniforum, since there was
something in the abstract that looked like it might be it.  Nothing
came up in the talk and things were too busy afterwards for me to get
to buttonhole him in the hall.  Is anyone out there familiar enough
with PCC 2 to say whether in-line assembler functions are present?

Too much wishful thinking,

Donn Seeley    UCSD Chemistry Dept.       ucbvax!sdcsvax!sdchema!donn



More information about the Comp.lang.c mailing list