🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #38491

"Efficient" C programming - was Re: New Mac Rumours

#38491
From: Jonathan Pratt
Date: Tue, 28 Feb 1989 12:09
38 lines
2421 bytes
In article <15682@versatc.UUCP> peter@versatc.UUCP (Peter Tapscott ) writes:
...
>It is also possible to write the c-code to produce optimum execution speed.
>For example, the following four lines of code execute 4X faster than
>the two lines using a FOR loop:
>
>Fast While Loop:
>        i = char_count;
>        while(i--)
>            destn_buffer[i] = *(source_buffer + i);
>        *destn_buffer = *source_buffer;  /* get the zeroth element */.
>
>Slow For Loop:
>		for (i = 0; i <= char_count; i++)
>              destn_buffer[i] = *(source_buffer + i);
>
I decided to take issue with this particular generalization, so I coded
these two code fragments and examined the resulting assembly language
from two compilers (LSC 3 and MPW).  In each case the supposedly slow
for loop generated shorter and slightly faster code.  My point is that
a great deal depends on the compilers involved.  It's pushing things
too far to make a "4x faster" generalization for such similar code.

>This is because the while loop makes use of the DBNE (decrement and

In my trial cases neither compiler was smart enough to use DBxx
instructions.  I'd say that beyond the obvious things, like using the
best algorithm and using pointers/registers instead of random indexing,
your best bet for writing efficient HLL code is to be well acquainted
with your compiler.  Opinions, for/against?  Note followups to *.programmer.

Jonathan


/* Jonathan Pratt          Internet: pratt@boulder.colorado.edu     *
 * Campus Box 525              uucp: ..!{ncar|nbires}!boulder!pratt *
 * University of Colorado                                           *
 * Boulder, CO 80309          Phone: (303) 492-4293                 */
Technical Details
Message-ID: <6992@boulder.Colorado.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!ncar!boulder!pratt
References: <IY0io5y00UgPAM2b4a@andrew.cmu.edu> <41a2364a.a590@mag.engin.umich.edu> <70755@ti-csl.csc.ti.com> <41aa5eaa.a590@mag.engin.umich.edu> <15682@versatc.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!ncar!boulder!pratt
From: pratt@boulder.Colorado.EDU (Jonathan Pratt)
Newsgroups: comp.sys.mac
Subject: "Efficient" C programming - was Re: New Mac Rumours
Summary: LSC & MPW say otherwise
Message-ID: <6992@boulder.Colorado.EDU>
Date: 28 Feb 89 12:09:25 GMT
References: <IY0io5y00UgPAM2b4a@andrew.cmu.edu> <41a2364a.a590@mag.engin.umich.edu> <70755@ti-csl.csc.ti.com> <41aa5eaa.a590@mag.engin.umich.edu> <15682@versatc.UUCP>
Sender: news@boulder.Colorado.EDU
Reply-To: pratt@boulder.Colorado.EDU (Jonathan Pratt)
Followup-To: comp.sys.mac.programmer
Organization: University of Colorado, Boulder
Lines: 38