Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: Re: fast code and no morals Message-ID: <978@brl-smoke.ARPA> Date: Sun, 16-Feb-86 00:26:33 EST Article-I.D.: brl-smok.978 Posted: Sun Feb 16 00:26:33 1986 Date-Received: Tue, 18-Feb-86 04:21:44 EST References: <842@megaron.UUCP> <1820@brl-tgr.ARPA> Reply-To: gwyn@brl.ARPA Organization: /usr/local/lib/news/organization Lines: 35 >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. Neither of these examples uses obscure code (except for your redefining C keywords for no good reason). Also, neither one is the best implementation of bcopy() on most machines. One can do much better than byte transfers within a loop. If you're going to worry about efficiency, do it right; use the memcpy() library routine which some system programmer has tuned for fastest possible block transfer, rather than writing your own.