# Re: Multiply by a constant --> shift-and-adds algorithm?

## preston@cs.rice.edu (Preston Briggs)9 Nov 1997 12:05:45 -0500

From comp.compilers

Related articles
Multiply by a constant --> shift-and-adds algorithm? Vincent.Lefevre@ens-lyon.fr (Vincent Lefevre) (1997-11-07)
Re: Multiply by a constant --> shift-and-adds algorithm? rweaver@ix.netcom.com (1997-11-09)
Re: Multiply by a constant --> shift-and-adds algorithm? preston@cs.rice.edu (1997-11-09)
Re: Multiply by a constant --> shift-and-adds algorithm? ssolyanik@icdc.com (Sergey Solyanik) (1997-11-09)
Multiply by a constant --> shift-and-adds algorithm? txr@alumni.caltech.edu (Tim Rentsch) (1997-11-09)
Re: Multiply by a constant --> shift-and-adds algorithm? n8tm@aol.com (1997-11-11)
Re: Multiply by a constant --> shift-and-adds algorithm? dube@brachio.IRO.UMontreal.CA (Danny Dube) (1997-11-11)
Re: Multiply by a constant --> shift-and-adds algorithm? cdg@nullstone.com (Christopher Glaeser) (1997-11-13)
Re: Multiply by a constant --> shift-and-adds algorithm? ssolyanik@icdc.com (Sergey Solyanik) (1997-11-14)
[3 later articles]
| List of all articles for this month |

 From: preston@cs.rice.edu (Preston Briggs) Newsgroups: comp.compilers Date: 9 Nov 1997 12:05:45 -0500 Organization: Rice University References: 97-11-038 Keywords: arithmetic, theory

Vincent Lefevre <Vincent.Lefevre@ens-lyon.fr> wrote:
>Some compilers (including gcc) are able to convert a "multiply by a
>constant" operation into a sequence of shifts and adds/subtracts.
> [ what's the best way to set up such a sequence? ]

The best paper on the subject is

title="Multiplication by Integer Constants",
author="Robert L. Bernstein",
journal=spe,
volume=16,
number=7,
month=jul,
year=1986,
pages="641--652",

Unfortunately, it suffers from some typos in the code.
You can get a version that I wrote with Tim Harvey via anonymous
ftp from

ftp.cs.rice.edu

in the directory

public/preston/optimizer

in the file multiply.ps

Preston
--

Post a followup to this message