We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for
Did you mean:
Highlighted
8,005 Views
Registered: ‎03-15-2012

## coding style: MAC

hi,

i'm struggling with describing an multiply accumulate. The line is similar to

...

accu[i] += a*b[i];

...

the code is work, even in VHDL, but the resources are used suboptimal. I'm using a V6 but the DSP48E1 are only used for the multiplication not for the accumulation too. The accumulation is done by seperate logic.

The next: it would be nice, if i can cascade the DSP48E1 to use the ACOUT/ACIN (or BCOUT/BCIN) as shift-register. Actually, this will be also implement as seperate logic.

Does anyone know, how to code it correctly?

thanks

1 Solution

Accepted Solutions
12,277 Views
Registered: ‎03-15-2012

## Re: coding style: MAC

The solution seems to be found.

Althought declared as static, the accu wasn't registered and therefore not pulled into the DSP48E1.

The following code worked as expected:

template<class T>
T Reg(T in)
{
#pragma HLS PIPELINE
#pragma HLS INLINE off
#pragma HLS INTERFACE port=return register
return in;
}

int mac(short a_in, short b_in)
{
static int c = 0;

c = Reg(c + a_in * b_in);
return c;

}

thanks @all

7 Replies
Moderator
7,997 Views
Registered: ‎04-17-2011

## Re: coding style: MAC

Are you writing this code in C?
Regards,
Debraj
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
7,996 Views
Registered: ‎03-15-2012

## Re: coding style: MAC

at the moment i'm using the c++ compiler without classes

Xilinx Employee
7,990 Views
Registered: ‎08-01-2008

## Re: coding style: MAC

you can use dsp48 macro core for your application

Here is AR which tell you How to connect up the PCIN when it is not connected to the PCOUT of an adjacent DSP48 slice?

Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
Xilinx Employee
7,987 Views
Registered: ‎08-01-2008

## Re: coding style: MAC

#include "array_arith.h"

void array_arith (dio_t d[5]) {
static int acc = 0;
int i;

for (i=0;i<4;i++) {
acc += d[i+1];
d[i] = acc;
}
}

Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
Xilinx Employee
7,984 Views
Registered: ‎03-24-2010

## Re: coding style: MAC

It's possible to be put into DSP and post-adder if width(accu[i])<=48, width(a,b[i])<=(18,25) and width(a+b[i])<=width(accu[i]).

Regards,
brucey
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
7,981 Views
Registered: ‎03-15-2012

## Re: coding style: MAC

this conditions are met
a, b = 8 bit ns
accu = 30 bit ns

Maybe due to the fact, that multiplications are done in a separate component, the XST does not interfere a MAC. Even if hierarchy is turned off.
12,278 Views
Registered: ‎03-15-2012

## Re: coding style: MAC

The solution seems to be found.

Althought declared as static, the accu wasn't registered and therefore not pulled into the DSP48E1.

The following code worked as expected:

template<class T>
T Reg(T in)
{
#pragma HLS PIPELINE
#pragma HLS INLINE off
#pragma HLS INTERFACE port=return register
return in;
}

int mac(short a_in, short b_in)
{
static int c = 0;

c = Reg(c + a_in * b_in);
return c;

}

thanks @all