Phần C code cũng tương tự như bạn đã đưa lên, nhưng phần implementation lại nhắm vào ASIC, nên không thể nói rằng những biến thể đó là parallel vs semi-parallel vs serial architecture trên FPGA.
Nếu có thể thì bạn làm một high level synthesis demonstration cho FPGA. Demo của Mentor không nhắm vào FPGA cho nên chưa được convincing lắm.
Nếu có thể thì bạn làm một high level synthesis demonstration cho FPGA. Demo của Mentor không nhắm vào FPGA cho nên chưa được convincing lắm.
Ví dụ cho DSP của Xilinx
Code:
#include "fir_filter.h" #pragma map_to_operator dsp_cell void dsp_cell(d_t xin, d_t h, acc_t yin, acc_t &yout) { yout = (xin * h) + yin; } #pragma design top void fir_filter (d_t *input, c_t coeffs[NUM_TAPS], d_t *output ) { static d_t regs[NUM_TAPS]; acc_t temp = 0; int i; SHIFT:for ( i = NUM_TAPS-1; i>=0; i--) { if ( i == 0 ) regs[i] = *input; else regs[i] = regs[i-1]; } MAC:for ( i = NUM_TAPS-1; i>=0; i--) { dsp_cell(regs[i], coeffs[i], temp, temp); } *output = temp>>7; }
Code:
#include "fir_filter.h" #pragma map_to_operator dsp_cell acc_t dsp_cell(d_t xin[4], d_t h[4]) { acc_t temp = 0; #pragma unroll yes MAC:for ( int i=3; i>=0; i--) temp += xin[i]*h[i]; return temp;; } #pragma design top void fir_filter (d_t *input, d_t coeffs[NUM_TAPS], d_t *output ) { static d_t regs[NUM_TAPS]; acc_t temp = 0; d_t r[4], h[4]; #pragma unroll yes for (int i=NUM_TAPS-1; i>=0; i--) if (i==0) regs[i] = *input; else regs[i] = regs[i-1]; for (int j=(NUM_TAPS/4)-1; j>=0; j--) { #pragma unroll yes for (int i=3; i>=0; i--) { r[i] = regs[(j*4)+i]; h[i] = coeffs[(j*4)+i]; } temp += dsp_cell(r,h); } *output = temp>>(NUM_TAPS-1); }
Leave a comment: