jans@mako.UUCP (Jan Steinman) (06/21/85)
In article <254@greipa.UUCP> paul@greipa.UUCP (Paul A. Vixie) writes: >Not being a compiler writer (yet :-), anyway) I don't see many other things >a compiler could optimize for (except the "muld 2, tos" which could have been >"ashd 1, tos" but only vax-11 C from DEC does this). Note that if one operand is a constant small integer and the other is in a register, the following multiplies are shorter and quicker: Instruction Function Clocks Size (w/MMU) (Bytes) addd rx,rx ; 2*rx (destructive) 4 2 addr rx[rx:b],ry ; 2*rx 13 2 addr rx[rx:w],ry ; 3*rx 15 2 addr @0[rx:d],ry ; 4*rx 15 3 addr rx[rx:d],ry ; 5*rx 16 2 addr @0[rx:q],ry ; 8*rx 17 3 addr rx[rx:q],ry ; 9*rx 18 2 compared with: ashd 1,rx ; 2*rx (destructive) 23 7 muld 2,rx ; 2*rx (destructive) 85 7 It's so much quicker, that the 9 clocks required to move the operand from the stack into a register still keep it faster and smaller than the shifted vers. I've noticed that the C compiler on our 6000 series boxes generate at least a few of these. (This will all change when the 32?32 with the barrell shifter arrives!) I disagree with Henry Spencer in saying that multiplies are uncommon. In particular, the small integer multiply operation is used in index scaling, particularly whenever index math is performed, and it is important that a compiler do its best on these, as they are often inside loops. -- :::::: Jan Steinman Box 1000, MS 61-161 (w)503/685-2843 :::::: :::::: tektronix!tekecs!jans Wilsonville, OR 97070 (h)503/657-7703 ::::::
henry@utzoo.UUCP (Henry Spencer) (06/24/85)
> I disagree with Henry Spencer in saying that multiplies are uncommon. In > particular, the small integer multiply operation is used in index scaling, > particularly whenever index math is performed, and it is important that a > compiler do its best on these, as they are often inside loops. Guilty. I forgot about that. Although I would speculate that most arrays (particularly in C) are one-dimensional and their members are one of the primitive data types, a situation that would seem tailor-made for indexed addressing modes to do all the work. Yes, I know there are programs that use multidimensional arrays with complicated members, and whose running times might be seriously affected by slow multiplies. I merely conjecture that they are in the minority. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry
bcase@uiucdcs.Uiuc.ARPA (07/10/85)
The multiplies associated with indexing/scaling are nearly always computing the product of a variable and a small constant. In this case, a short sequence of shifts and adds will do the trick and probably more quickly than a microcoded mutiply (of course, if you want to throw a parallel mutiplier at it, that is a different matter). In addition, if the index calculation is in a loop, then elimination of the induction variable and strength reduction can change the mutiply into an add. In this last case, even a parllel multiplier will not help you. Optimizing compilers can do a lot. bcase