Forums

TigerSHARC efficiency : multiply or shift?

Started by moschops October 16, 2007
I'm remarkably new to DSPs, and I've got this TigerSHARC. Well, four of 
them, but I'm just fiddling with one at the moment. I'm used to coding 
for desktop apps, and whilst my C code runs fine I'm not sure about how 
long various operations take in terms of clock cycles on this T'SHARC.

Looking through the various manuals, I note it has a nice bit barrel and 
also a multiplication unit. I tend to turn multiplications into bit 
shift in my code, but I realise now that I don't know which is more 
efficient in clock cycles on a T'SHARC, multiplying or bit shifting. 
Maybe a single bit shift is faster than multiplying by two, but what 
about two or three or four bit shifts? Can I trust the compiler to work 
out the most efficient version for me?

Does anyone know? I have various manuals and guides, but the information 
is spread across them all. I suppose I could look at the disassembler 
code (using Analog's VDSP++ across a JTAG to code with) but I'm also new 
to assembler.

Can anyone help me out? I've had a trawl of the web but haven't found 
what I'm looking for.

Moschops
moschops wrote:
> I'm remarkably new to DSPs, and I've got this TigerSHARC. Well, four of > them, but I'm just fiddling with one at the moment. I'm used to coding > for desktop apps, and whilst my C code runs fine I'm not sure about how > long various operations take in terms of clock cycles on this T'SHARC. > > Looking through the various manuals, I note it has a nice bit barrel and > also a multiplication unit. I tend to turn multiplications into bit > shift in my code, but I realise now that I don't know which is more > efficient in clock cycles on a T'SHARC, multiplying or bit shifting. > Maybe a single bit shift is faster than multiplying by two, but what > about two or three or four bit shifts? Can I trust the compiler to work > out the most efficient version for me? > > Does anyone know? I have various manuals and guides, but the information > is spread across them all. I suppose I could look at the disassembler > code (using Analog's VDSP++ across a JTAG to code with) but I'm also new > to assembler. > > Can anyone help me out? I've had a trawl of the web but haven't found > what I'm looking for.
Doesn't the processor manual have instruction times? In any touted DSP, both multiplies and shifts in any amount take one instruction cycle in the pipeline. Jerry -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Jerry Avins wrote:
> moschops wrote: >> Looking through the various manuals, I note it has a nice bit barrel >> and also a multiplication unit. I tend to turn multiplications into >> bit shift in my code, but I realise now that I don't know which is >> more efficient in clock cycles on a T'SHARC, multiplying or bit >> shifting. Maybe a single bit shift is faster than multiplying by two, >> but what about two or three or four bit shifts? Can I trust the >> compiler to work out the most efficient version for me? >>
[snip]
> > Doesn't the processor manual have instruction times? In any touted DSP, > both multiplies and shifts in any amount take one instruction cycle in > the pipeline.
This is true of the TS as well. The barrel shifter can shift by any amount in a single cycle, and multiplies execute in a single cycle. In other words, a single (or double, or triple, or...) bit shift has the same execution time as a multiply on the TS. I'd code it up with multiplies because it makes the code easier to read. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536 Failure is always an option
"Jim Thomas" <jthomas@bittware.com> wrote in message
news:13hc34hekt1c37@corp.supernews.com...
> > The barrel shifter can shift by any > amount in a single cycle, and multiplies execute in a single cycle. > In other words, a single (or double, or triple, or...) bit shift has the > same execution time as a multiply on the TS.
Shift instead of multiplication makes a lot of sense if you deal with the multi precision words.
> I'd code it up with multiplies because it makes the code easier to read.
Agreed. The original post looks to me like an attempt of the premature optimization. Vladimir Vassilevsky DSP and Mixed Signal Consultant www.abvolt.com

I'm with Knuth when it comes to premature optimisation, but in this case 
it isn't; I've got bitfields, 8 bit, 16 bit, 18 bit, 32 bit and 64 bit 
data sets packed into consecutive 32 bit words, requiring a stack of 
masks, bitwise ops and shifting to turn into meaningful structures - in 
this case, using multiplies instead of bitshifting would make the code 
harder to understand, rather than easier.

Thanks for the pointers, chaps; following your commetns I've found the 
appropriate sections of the processor manual and determined that, as you 
say, the bitshift operations take only one clock cycle with these T'SHARCS.

'Chops