1 May 2005 09:24:53 -0400

Related articles |
---|

strength redcution julie.spicer@verizon.net (Vespasian) (2005-04-30) |

Re: strength redcution Danny.Dube@ift.ulaval.ca (2005-05-01) |

Re: strength redcution gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-05-01) |

From: | glen herrmannsfeldt <gah@ugcs.caltech.edu> |

Newsgroups: | comp.compilers |

Date: | 1 May 2005 09:24:53 -0400 |

Organization: | Compilers Central |

References: | 05-04-097 05-05-001 |

Keywords: | optimize |

Posted-Date: | 01 May 2005 09:24:53 EDT |

Danny Dubé wrote:

*> Vespasian <julie.spicer@verizon.net> writes:*

*>>Anyone know how to replace the expression,*

*>>i div c,*

*>>with addition and/or subtraction, where c in a constant and*

*>>i is the index of a loop that increments with a step size of 1*

*>>[Seems to me you'd have to keep a separate counter and each time*

(snip)

*> http://citeseer.ist.psu.edu/granlund94division.html*

This sounds a little bit like that phase accumulator sometimes

used for generating digitized sine waves from a lookup table.

I table of sin(x) evaluated at some binary fraction of a complete

circle, maybe 256ths of a circle is used. One might want a sine wave

where the frequency isn't a multiple of 1/256th of the sample rate.

Adding an appropriate constant to a larger accumulator, maybe 32 bits,

and then using the high bits with the lookup table generates the result

that over the long term has the appropriate periodicity, given

sufficient bits in the accumulator.

To get back to the subject of compilers, I believe that many now

replace fixed point division by a constant with multiplication and

shifting in many cases. It does still seem strange to me, without

testing to make sure the result agrees. Even for floating point

one would want the correctly rounded or truncated result.

-- glen

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.