DSP 32×32 64bit MAC ?

New to XMOS and XCore? Get started here.
User avatar
williamk
Experienced Member
Posts: 114
Joined: Fri Oct 01, 2010 7:47 pm

DSP 32×32 64bit MAC ?

Post 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


Wusik Dot Com (http://www.Wusik.com)
William-K.com (http://www.William-K.com)
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm
Contact:

Post by Bianco »

User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post 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
User avatar
williamk
Experienced Member
Posts: 114
Joined: Fri Oct 01, 2010 7:47 pm

Post 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
Wusik Dot Com (http://www.Wusik.com)
William-K.com (http://www.William-K.com)
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post 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
User avatar
williamk
Experienced Member
Posts: 114
Joined: Fri Oct 01, 2010 7:47 pm

Post by williamk »

Perfect, thanks, I get it now. ;-)

Wk
Wusik Dot Com (http://www.Wusik.com)
William-K.com (http://www.William-K.com)
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post 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:
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
bsmithyman
Experienced Member
Posts: 126
Joined: Fri Feb 12, 2010 10:31 pm
Contact:

Post 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!
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post 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}

	 		}
	 };
...
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
bsmithyman
Experienced Member
Posts: 126
Joined: Fri Feb 12, 2010 10:31 pm
Contact:

Post by bsmithyman »

lilltroll wrote:Like this...
Thanks!
Post Reply