Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site proper.UUCP Path: utzoo!watmath!clyde!floyd!vax135!cornell!uw-beaver!tektronix!zehntel!dual!proper!geoff From: geoff@proper.UUCP (Geoff Kuenning) Newsgroups: net.lang Subject: Re: Self-modifying code - (nf) Message-ID: <1033@proper.UUCP> Date: Wed, 22-Feb-84 23:51:33 EST Article-I.D.: proper.1033 Posted: Wed Feb 22 23:51:33 1984 Date-Received: Tue, 28-Feb-84 22:32:57 EST References: <116@iuvax.UUCP> Organization: Proper UNIX, San Leandro, CA Lines: 23 > I found another use for self-modifying code: speed. I wrote a graphics > package (a pretty simple-minded one) for the IBM PC, and found that my > line-drawing routine had two spots where one of three things needed doing: > increment x (or y), > decrement x (or y), > do nothing to x (or y). > > I could have loaded the proper add-on value (-1, 0, or 1) into a > memory location or register and used an add instruction, but it was MUCH > faster to have the program "poke" an increment, decrement, or NOP > instruction into the appropriate spot. One (inprecise) comparison > (timed with a watch) showed a 20% speed increase (approx. 4 seconds in 20). > -- Allan Pratt Oh, yeah? When I wrote the same routine, I simply used an 8-way "case". The test and branch has to be done anyway to do the self-modifying code, and it's probably cheaper than storing into an instruction anyway. And the loop in question is so short that the amount of space it takes is totally irrelevant in any computer with more than 4K of memory. Geoff Kuenning Callan Data Systems {decvax,ucbvax}!ihnp4!sdcrdcf!trwrb!wlbr!callan!geoff