08-15-2015 06:29 AM
I am working on a Verilog project on a Virtex 7 FPGA requiring several multiplications by constant coefficients and I am wondering which is the cleanest and speed-optmized way to store these coeficients inside the FPGA.
More specifically, I receive 32 16-bit parallel inputs each tick and I have to multiply each of them by a different 16-bit constant coefficient. How can I store them in my Verliog code ?
The cleanest approach seems to store all the coefficeints in a LUT but I don't know how to realize it.
Thank you in advance,
08-15-2015 06:44 AM
If these are truly constants, then they aren't "stored" in the FPGA at all. During synthesis, the constants will be hard-coded into the structure of the RTL, which may include tying signals directly high or low, and/or even simplifying logic by doing Boolean reduction of circuits based on the fact that some inputs are constants. Specifically, the constants themselves don't take any FPGA resources.
Simply code them directly in your RTL code as either numbers, or as parameters (Verilog) or generics (VHDL).
08-16-2015 07:35 AM
Thank you very much for your answer. You made it more clear for me.
I was thinking about entering them as parameters in my Verilog code but since I have about 300 constants, I am looking for a more clean way to do it.
Do you have any suggestions / example code ? Is there for example a ways to hard code them in a two dimensional array ?
08-16-2015 08:07 AM
Any structure that is initialized and not changed will be treated as constants. So, you can declare a Verilog memory (a 2 dimensional array of reg) and initialize them any way that makes sense. When you use them, the constants will be absorbed into the surrounding logic
reg [15:0] my_const [0:299];
// initialize them any way you want here
my_const = 15'h0;
// you can use for loops or any other structure as long as it only use constants and loop indicies within this block
for (i=34; i<=99; i=i+1)
my_const[i] = 33*my_const[i] + my_const[i-17];
You can even use the initialization mechanism for the memory, or $readmem to initialize the values.