[sdiy] SHARC DSP programming

Richie Burnett rburnett at richieburnett.co.uk
Sat Sep 24 19:05:01 CEST 2016

> SHARC seems to be heavily optimized for high level languages. Do they
have a library of intrinsics you can use from C? If so perhaps you'll
find the optimum implementation in that?

I spent about a week trying to get a Chamberlain state-variable filter 
working in C using assembler intrinsics and was getting nowhere (>.<)  Then 
I tried a bit of inline assembly and got it working in 5 mins.  Someone 
where I'm working showed me how VisualDSP++ lets you conveniently combine 
assembly source and C source files in the same project, so I've just written 
most of the brute-force DSP stuff in bare-metal assembly, but used C to call 
it and declare the variables.

I did eventually manage to get the SVF to work in C, but when I looked at 
the compiled assembly code it wasn't keeping the two integrator states of 
the SVF in the two MAC accumulators, but swapping data around between 
general-purpose registers.  Keeping the integrator states as 
double-precision values in the accumulators is something I liked to do on 
the dsPIC because it's like getting "fraction saving" for free.  I guess 
it's not so important on a 32-bit fixed point architecture, but old habits 
die hard!  Incidentally the C implementation compiled to 65 assembly 
instructions for the SVF.  When I turned on the compiler optimisations this 
went up to 69 instructions, and it sounded decidedly glitchy.  Everything 
I've done since has been in assembly.  It's a ADSP-21469 450MHz with SIMD 
MAC instructions, so it's blazingly  fast when programmed in assembly.  It's 
not too much of a departure from dsPIC code, but ADI have different 
terminology for things with the SHARC, which makes the learning curve seem a 
bit steeper.

> Interesting omission if it *doesn't* have that. The accumulator scaling
& saturation operations in the dsPIC architecture were one of its nicer

That's why I thought I must have missed it.  But I'm thinking that it is 
maybe omitted with the assumption that everyone uses the floating-point 
support anyway.  As you said, the accumulator scaling and saturation on the 
dsPIC was a really nice feature if you just wanted to make up some gain on a 
signal that sounded a little quiet, and didn't care if the occasional peak 
got clipped.

I can't even get what shift instructions I've found on the SHARC to saturate 
instead of overflow!!! ...and this seems decidedly wrong for a DSP.  I must 
be doing something wrong, so I'll wait patiently and hopefully a SHARC 
expert can put me straight.


More information about the Synth-diy mailing list