Page 1 of 2
DSP 32×32 64bit MAC ?
Posted: Wed Oct 13, 2010 6:07 pm
by williamk
Guys, I have read the whole XC programming manual, but there's no reference about this:
Support for DSP with 32×32 64bit MAC
What is that exactly? Or am I missing something?
Sorry if this is a stupid question... :oops:
Wk
Re: DSP 32×32 64bit MAC ?
Posted: Wed Oct 13, 2010 6:20 pm
by Bianco
Re: DSP 32×32 64bit MAC ?
Posted: Wed Oct 13, 2010 6:21 pm
by Andy
It's a single cycle multiple-accumulate instruction that is often used in DSP calculations, such as filters.
See here for more info:
http://en.wikipedia.org/wiki/Multiply-accumulate
Re: DSP 32×32 64bit MAC ?
Posted: Wed Oct 13, 2010 6:27 pm
by williamk
Thanks guys. But what sort of code I need to use in order to make use of this? Or its something the compiler takes care of? I'm used to assembly, so I guess I need to use inline asm for that?
Wk
Re: DSP 32×32 64bit MAC ?
Posted: Wed Oct 13, 2010 7:08 pm
by Andy
williamk wrote:Thanks guys. But what sort of code I need to use in order to make use of this? Or its something the compiler takes care of? I'm used to assembly, so I guess I need to use inline asm for that?
Wk
It's available in XC using the macs() function:
Code: Select all
/**
* Multiplies two signed words and adds the double word result to a double
* word. The high word and the low word of the result are returned. The
* calculation performed is:
* \code
* (int64_t)a * (int64_t)b + (int64_t)c<<32 + (int64_t)d
* \endcode
* \return The high and low halves of the calculation respectively.
* \sa lmul
* \sa mac
*/
{signed, unsigned} macs(signed a, signed b, signed c, unsigned d);
See this thread for calling from C:
http://xcore.com/forum/viewtopic.php?f=11&t=297
Re: DSP 32×32 64bit MAC ?
Posted: Wed Oct 13, 2010 7:10 pm
by williamk
Perfect, thanks, I get it now. ;-)
Wk
Re: DSP 32×32 64bit MAC ?
Posted: Thu Oct 14, 2010 9:17 am
by lilltroll
And you can write an 2:nd order IIR filtersection like this:
Code: Select all
static inline int filtersection(const unsigned int I,int IN,struct_iir_fixed32 &f,int s[]){
int h,l;
{h, l} = macs(f.B[I][0], IN , 0 , 0);
{h, l} = macs(f.B[I][1], s[0] , h, l);
{h, l} = macs(f.B[I][2], s[1] , h, l);
{h, l} = macs(f.A[I][0], s[2] , h, l);
{h, l} = macs(f.A[I][1], s[3]>>1 , h, l);
s[1]=s[0];
s[0]=IN;
s[3]=s[2];
s[2]=(h<<2) + (l>>30);
return (s[2]);
}
And a high order IIR filter like this:
Code: Select all
#pragma loop unroll
for (int i = 0; i < BANKS; i++)
x=filtersection(i,x>>1,f,Init[i]);
The inline will translate the struct to constants in the asm code, so there is no penalty of using a struct - it translates to very few asm lines, using O(3) - I hope :oops:
Re: DSP 32×32 64bit MAC ?
Posted: Thu Oct 14, 2010 7:33 pm
by bsmithyman
lilltroll wrote:And you can write an 2:nd order IIR filtersection like this...
Hi lilltroll,
I'll admit I'm a little lost; though interested :) What form does the struct take exactly (or is this part of a standard library that I'm not familiar with)?
Thanks!
Re: DSP 32×32 64bit MAC ?
Posted: Thu Oct 14, 2010 9:04 pm
by lilltroll
Like this:
Code: Select all
typedef struct{
const int B[BANKS][3];
const int A[BANKS][2];
}struct_iir_fixed32;
And a 8:th order LP example may look like this:
Code: Select all
...
struct_iir_fixed32 f={
{
{75292298,-146900632,75292298} ,
{317830040,-630042764,317830040} ,
{14049805,-23188879,14049805} ,
{563467433, -1113707583, 563467433}
},
{
{2105156846,-2067797194} ,
{2131048389,-2126062499} ,
{2095759260,-2045821778} ,
{2119115303,-2099678891}
}
};
...
Re: DSP 32×32 64bit MAC ?
Posted: Thu Oct 14, 2010 11:07 pm
by bsmithyman
lilltroll wrote:Like this...
Thanks!