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

## Sergey Solyanik <ssolyanik@icdc.com>

9 Nov 1997 12:06:15 -0500

*From comp.compilers*

| List of all articles for this month |

**From: ** | Sergey Solyanik <ssolyanik@icdc.com> |

**Newsgroups: ** | comp.compilers |

**Date: ** | 9 Nov 1997 12:06:15 -0500 |

**Organization: ** | Bentley Systems, Inc. |

**References: ** | 97-11-038 |

**Keywords: ** | arithmetic, optimize |

Vincent Lefevre wrote:

*>*

*> Some compilers (including gcc) are able to convert a "multiply by a*

*> constant" operation into a sequence of shifts and adds/subtracts.*

The method I am using for our JIT compiler is memoizing dynamic

algorithm that uses a dag of best match sequences. I cannot share the

source code because it is commercial product, but I've put algorithm

description and compiled program (win32) that uses it at:

http://w3.icdc.com/~solyanik/decomp.html

This algorithm is a "smart brute force" (as any dynamic algorithm),

but it seems to work and it turned out to be fast enough for JIT

environment.

I would be very interested to seem smarter implementation.

Regards -

Sergey Solyanik

Software Developer

Bentley Systems, Inc

--

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.