Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!gatech!purdue!i.cc.purdue.edu!j.cc.purdue.edu!pur-ee!hankd From: hankd@pur-ee.UUCP (Hank Dietz) Newsgroups: comp.arch Subject: Re: RISC is a nasty no-no! Message-ID: <7649@pur-ee.UUCP> Date: 1 Mar 88 04:48:40 GMT References: <179@wsccs.UUCP: <696@nuchat.UUCP> <284@scdpyr.UUCP> <11199@duke.cs.duke.edu> Organization: Purdue University Engineering Computer Network Lines: 21 Summary: Multiply by const is often faster as add/shift expansion In article <11199@duke.cs.duke.edu>, dfk@duke.cs.duke.edu (David Kotz) writes: > > confusing. Since they (read SPARC or equivalent) have no integer multiply > > instructions, any code which has a fair number of these is going to > > be slow. This would include any program which had access to 2-D arrays [stuff] > Multiplication is not necessary to access 2-D arrays if the array is > set up like most arrays in C, where each row is a typical vector and > the 2-D array is just a vector of pointers to each row vector. Then > double-indirection is necessary, rather than multiplication. I won't Indirection isn't pretty in a lot of ways (because it is random addressing unless you're very clever), but that's not the point. The multiply for indexing is, first of all, often converted into bumping pointers if you have a good optimizing compiler and, secondly, unless you have a VERY FAST multiply, multiplying by VIRTUALLY ANY compile-time CONSTANT (e.g., sizeof an element) is faster using shift and add/subtract instructions. For example, a multiply by 7 (not a nice power of 2) is really shift to multiply by 8 and then subtract the original number. This sort of thing is widely known by compiler writers -- references are available -- and the big disadvantage to it is that it may require the use of more registers for temporaries.