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
DSP 32×32 64bit MAC ?
-
- Experienced Member
- Posts: 114
- Joined: Fri Oct 01, 2010 7:47 pm
-
- XCore Expert
- Posts: 754
- Joined: Thu Dec 10, 2009 6:56 pm
-
- Respected Member
- Posts: 279
- Joined: Fri Dec 11, 2009 1:34 pm
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
See here for more info:
http://en.wikipedia.org/wiki/Multiply-accumulate
-
- Experienced Member
- Posts: 114
- Joined: Fri Oct 01, 2010 7:47 pm
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
Wk
-
- Respected Member
- Posts: 279
- Joined: Fri Dec 11, 2009 1:34 pm
It's available in XC using the macs() function: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
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);
-
- Experienced Member
- Posts: 114
- Joined: Fri Oct 01, 2010 7:47 pm
Perfect, thanks, I get it now. ;-)
Wk
Wk
-
- XCore Expert
- Posts: 956
- Joined: Fri Dec 11, 2009 3:53 am
- Location: Sweden, Eskilstuna
And you can write an 2:nd order IIR filtersection like this:
And a high order IIR filter like this:
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:
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]);
}
Code: Select all
#pragma loop unroll
for (int i = 0; i < BANKS; i++)
x=filtersection(i,x>>1,f,Init[i]);
Probably not the most confused programmer anymore on the XCORE forum.
-
- Experienced Member
- Posts: 126
- Joined: Fri Feb 12, 2010 10:31 pm
Hi lilltroll,lilltroll wrote:And you can write an 2:nd order IIR filtersection like this...
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!
-
- XCore Expert
- Posts: 956
- Joined: Fri Dec 11, 2009 3:53 am
- Location: Sweden, Eskilstuna
Like this:
And a 8:th order LP example may look like this:
Code: Select all
typedef struct{
const int B[BANKS][3];
const int A[BANKS][2];
}struct_iir_fixed32;
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}
}
};
...
Probably not the most confused programmer anymore on the XCORE forum.
-
- Experienced Member
- Posts: 126
- Joined: Fri Feb 12, 2010 10:31 pm
Thanks!lilltroll wrote:Like this...