In my digital electronics project I need to calculate dot product of two vectors a and b (256 length of each). Following the basic concept, I need to calculate $\sum_{k=1}^{256} a_kb_k$. Each element of vectors is 4-bit binary number. This doesn't seems to a difficult task in verilog where I can implement this as in XILINX ISE.

sum=0;

for(i=0,i<256,i=i+1)

sum=sum+ $a_ib_i$

Furthur I need to implement this on FPGA. But here I got confused in two concept:

1. Do I need to write the module for 'full adder' and added the inputs previous sum and $a_i b_i$ bit by bit and store output in sum. Or simply xilinx will automatically implement the full adder during synthsize.

2. Is it valid to use for loop insted of writing always@(condition) beacause on FPGA we have clock as a control signal. Or in this case also xilinx itself will implement/control the for loop by clock signal.

• Loops and HDL do not go hand in hand. Forget everything you know about procedural programming languages and start thinking in RTL. Nov 28, 2015 at 18:40
• What Xilinx tool? Xilinx is a company with many tools: ISE, Vivado, DSP tools, HLS, ... If you implement your dot-product in a loop it will synthesize but the clock frequency will be in the low MHz or kHz range! So you will need pipelining which need manual clock control / hand written HDL code. Nov 28, 2015 at 18:55
• @TomCarpenter I agree with you that I need to implement at RTl level. But do need to added the two 4-bit number bit by bit or xilinx will do it by '+' sign. Nov 28, 2015 at 18:56
• @Paebbels It's ISE. Nov 28, 2015 at 19:01
• Also, Verilog uses 0 indexing, so that for loop (which you shouldn't use) would be for(i=0;i<256;i=i+1) Nov 28, 2015 at 19:03