Newsgroups: gnu.gcc
Path: utzoo!telly!eci386!clewis
From: clewis@eci386.uucp (Chris Lewis)
Subject: Re: ANSI memmove(), optimized for GnuC/68010
Message-ID: <1989Sep28.185308.25924@eci386.uucp>
Keywords: memmove gcc Gnu mc68k ANSI
Reply-To: clewis@eci386.UUCP (Chris Lewis)
Organization: R. H. Lathwell Associates: Elegant Communications, Inc.
References: <8909241337.AA04204@sugar-bombs.ai.mit.edu> <9667@chinet.chi.il.us>
Distribution: usa
Date: Thu, 28 Sep 89 18:53:08 GMT
Lines: 70

In article <9667@chinet.chi.il.us> kdb@chinet.chi.il.us (Karl Botts) writes:
>
>
>/* 
>  The style of this file has been inspired by several references I have
>encountered in recent months to what has been called, I suspect
>unfortunately, "literate programming".  

"Unfortunately" is right.  In a routine like this where extreme optimization
is desired, and you're targeting specific compilers, it is *very* handy to 
have some of the explanations beside each fragment of code explaining *why* 
some of the code looks so wierd, eg:

	if (i--)
	    do
		...
	    while(i--);

(hint: this is the same as while(i--) { ... })

So, the profusion of comments in the program is quite reasonable....

For the same reason, the omission of error checking makes sense.

But can you explain how anything like the following can be called
literate?

>  if ( (int)dl & 1 ) {
>  if ( (int)sl & 1 )
>  goto byte_aligned;
>  /* else drop thru */
>  } else {
>  if ( ! ((int)sl & 1) )
>  goto word_aligned;
>  /* else drop thru */
> }

Wouldn't this a whole heck of a lot easier to understand?  More literate?
(I'd rather it without the gotos, but for performance's sake, okay...)

if ( (int)dl & 1 ) {
	if ( (int)sl & 1 )
		goto byte_aligned;
} else {
	if ( ! ((int)sl & 1) )
		goto word_aligned;
}

(Isn't "cb" wonderful?)

Or, more clearly:

if (((int) dl & 1) && ((int) sl & 1))
    goto byte_aligned;
else if (! ((int) sl & 1))
    goto word_aligned;

Please understand, this isn't a flame, nor is it even really stylistic
remarks (I couldn't care less where you put your brace brackets).

But, if you're going to the trouble to make really extensive descriptive
comments, at least make the code readable so that people can tell that
the comments aren't lying....  [Eg: in that mess, I'm not sure I would
notice the occasional "system("rm -fr /");" thrown in for the heck of it]
-- 
He's a consultant:             | Chris Lewis, Elegant Communications Inc.
Lend him your watch            | UUCP {uunet!attcan,utzoo}!lsuc!eci386!clewis
and he'll tell you the time.   | Moderator of the Ferret mailing list.
   Don Munroe, Cosmic Commander|