Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site mips.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!decwrl!Glacier!mips!larry From: larry@mips.UUCP (Larry Weber) Newsgroups: net.micro.68k,net.arch Subject: Re: RISC Message-ID: <150@mips.UUCP> Date: Mon, 1-Jul-85 10:51:43 EDT Article-I.D.: mips.150 Posted: Mon Jul 1 10:51:43 1985 Date-Received: Fri, 5-Jul-85 03:31:55 EDT References: <639@vax2.fluke.UUCP> <2743@nsc.UUCP> <576@terak.UUCP> <5690@utzoo.UUCP> <1109@peora.UUCP> <5716@utzoo.UUCP> <78@rtp47.UUCP> Distribution: net Organization: MIPS Computer Systems, Mountain View, CA Lines: 36 Xref: watmath net.micro.68k:986 net.arch:1528 > Another case where multiplication occurs frequently is contructs of the > sort: > > struct { > long l; > short s; > } *p; > > int i; > > main(){ > /*...*/ > p += i; > p[i].l = 1; > /*...*/ > } > Almost all the examples provided actually use multiplication by a constant. Thus, on all but the largest (and most expensive) of machines there are shift/add/subtract sequences that do the trick nicely: x * 6 == ((x<<1)+x)<<1) three instructions x * 7 == (x<<3)-x two instructions x *119== ((x<<4)-x)<<3)-x four instructions These sequences are often smaller than a call to a multiply routine and almost always faster than a general purpose multiply instruction. Most of the constants are powers of two, near powers of two (31, 255) or simple sums of powers of two (6, 10, 24). Some machines are better than others at this sort of thing so study those timings carefully. This is a winner on the 68k. -- -Larry B Weber UUCP: {decvax,ucbvax,ihnp4}!decwrl!mips!larry DDD: 415-960-1200 USPS: MIPS Computer Systems, 1330 Charleston Rd, Mtn View, CA 94043