DSPRelated.com
Forums

faster way to implement a circular buffer

Started by Unknown September 2, 2006
Oli Filth wrote:

> robert bristow-johnson said the following on 02/09/2006 15:46: >> >> Hans S�rensen wrote: >> >>> Right now it's implemented like this (but it's slooooooooow): >> >> that's because "%" is often as slow as "/". >> >>> CyclicCounter=CyclicCounter%256; > ... >> in general, for C, the faster way is to mask: >> >> CyclicCounter=CyclicCounter&0xFF; > > Wouldn't a decent compiler perform this sort of optimisation > automatically? (Just as it might optimise x/2 to x>>1, etc.). >
On Blackfin, VisualDSP would (or should) automagically set-up and use a circular buffer when '%' is used. Or at least if the 'CyclicCounter' would be the counter in for-loop instead of 'i' (I don't know how naive the compiler is). In addition there is pragmas or instrics in VisualDSP++ which can be used to tell the compiler to generate a circular buffer for the given for-loop. -- Jani Huhtanen