fast code and no morals

rex ballard rb at ccivax.UUCP
Tue Feb 11 14:49:11 AEST 1986


In article <6365 at utzoo.UUCP> henry at utzoo.UUCP (Henry Spencer) writes:
>> > Assembler isn't portable, C is. ...
>> 
>> "C" is as portable as Stonehedge!!  At least assembler languages don't
>> pretend to be portable.
>
>How curious.  At U of T we routinely move C code among half a dozen or so
>different processors (more than that if you count different C compilers
>for things like the 68000).  Compile it and it runs.
>
>C's portability is more than just pretense.  Of course, you have to know
>what you're doing when you write the code.

When the same application or small routine has to on an 8085, 8086, 68000,
68010, PDP-11, and a VAX, and is subject to FREQUENT enhancement, and
only two machines run UNIX, the less written in assembler, the better.

Standard practice in this case is to run everything, including libraries
through lint, all 8 compilers (Large and small model 68K on native and
non-native), and be real specific about types.

This is much better than having to maintain 8 different assembler versions.

Even if 'fast but no morals' doesn't optimize as well on the VAX as it does
on the 68K, it still runs.  The examples are common profiler hot spots.
bcopy(dest,src,len)
REG char *dest,*src;
REG USHORT len;
{
while(len--)
   *dest++=*src++;
}

may look prettier than

bcopy(dest,src,len)
REG char *dest,*src;
REG USHORT len;
{
if(len)
do{
  *dest++=*src++;
  }while(--len)
}

but when you are calling bcopy to move 2k before the next
interrupt hits, the extra 10us per iteration (dbgt vs. test,bra)
can get real costly.  Adding automatic backward detection (used in editors)
would be difficult in assembler, but not in C.



More information about the Comp.lang.c mailing list