[comp.sys.dec] summary, Re: Is multiplying by one faster ???

hirsch@pioneer.arc.nasa.gov (Bob Hirsch) (03/06/91)

Apropos of multiplying by one, I asked:

>Theory "A" suggests that the computer can plainly tell that the
>multiplier has a value of one and can therefore save time by treating
>the command as a no-op.

>Theory "B" claims that applying the above test for every multiply
>operation ever performed would be far more costly than the saving
>obtained on the rare occasions when it applied.

Several correspondents had useful comments:

. . . . . . . . . . . . . . . .

From: terry@venus.sunquest.com 
 
I can't really see anyone wasting the hardware to look to see if the multiply
is being done by zero or one - for one thing, it would add an extra clock to
an already long instruction, and for practically zero gain.

From: jack@cwi.nl
This all depends on your machine ... [some] machines 
multiply all 32 bits regardless of which ones are zeroes, others stop
as soon as the multiplier (the value being shifted) is 0. In that case
a multiply by 1 will be cheaper than a multiply by another value.
 
From: motcsd!dms!petrick@apple.com
 
The compiler settings (/[no]optimize) would probably
make some difference.  
 
From: Magnus Olsson <magnus@thep.lu.se>
 
Why not try compiling a program with FORTRAN/LIST/MACHINE_CODE and have
a look at the code it generates? 

. . . . . . . . . . . . . . . .

A tiny test program with assignment statements such as 
I = I * 1
X = X * 1.0
reveals no difference at the compiled code level.
I was amused to see that in the absence of using I or X in a PRINT or
WRITE statement, the compiler optimized the above statements out of
existence!

The conclusion seems to be that at least in terms of software there is
no special case for multiplying by one.

Bob Hirsch  --  Sterling ZeroOne  --  NASA Ames Research Center
hirsch@ames.arc.nasa.gov              Mail Stop 233-3
415/604-4807                          Moffett Field, CA 94035
**The preceding has been an opinion by a concerned citizen.**