Search code examples
verilogfpgaxilinx-ise

How to prevent ISE compiler from optmizing away my array?


I'm new to Verilog, ISE, FPGAs. I'm trying to implement a simple design into an FPGA, but the entire design is being optimized away. It is basically an 2D array with some arbitrary values. Here is the code:

module top(
    output reg out
);

integer i;
integer j;
reg [5:0] array [0:99][0:31];

initial begin
    for(i=0;i<100;i=i+1) begin
            for(j=0;j<32;j=j+1) begin
                    array[i][j] = j;
                    out = array[i][j];
            end
    end
end

endmodule

It passes XST Synthesis fine, but it fails MAP in the Implementation process. Two Errors are given:

ERROR:Map:116 - The design is empty. No processing will be done.
ERROR:Map:52 - Problem encountered processing RPMs.

The entire code is being optimized away in XST. Why? What am I doing wrong?


Solution

  • The reason your design is being synthesized away is because you have not described any logic in your module.

    The only block in your design is an initial block which is typically not used in synthesis except in limited cases; the construct mainly used for testbenches in simulation (running the Verilog through ModelSim or another simluator).

    What you want is to use always blocks or assign statements to describe logic for XST to synthesize into a netlist for the FPGA to emulate. As the module you provided has neither of these constructs, no netlist can be generated, thus nothing synthesized!

    In your case, it is not entirely clear what logic you want to describe as the result of your module will always have out equal to 31. If you want out to cycle through the values 0 to 31, you'll need to add some sequential logic to implement that. Search around the net for some tutorials on digital design so you have the fundamentals down (combinational logic, gates, registers, etc). Then, think about what you want the design to do and map it to those components. Then, write the Verilog that describes that design.

    EDIT IN LIGHT OF COMMENTS:

    The reason you are get no LUT/FF usage on the report is because the FPGA doesn't need to use any resources (or none of those resources) to implement your module. As out is tied to constant 31, it will always have the value of 1, so the FPGA only needs to tie out to Vdd (NOTE that out is not 31 because it is only a 1-bit reg). The other array values are never used nor accesses, so the FPGA synthesized them away (ie, not output needs to know the value of array[0][1] as out is a constant and no other ports exist in the design). In order to preserve the array, you need only use it to drive some output somehow. Heres a basic example to show you:

    module top( input [6:0] i_in, // Used to index the array like i
                input [4:0] j_in, // Used to index the array like j
                output reg [5:0] out // Note, out is now big enough to store all the bits in array
              );
    
      integer i;
      integer j;
      reg [5:0] array[0:99][0:31];
    
      always @(*) begin
        // Set up the array, not necessarily optimal, but it works
        for (i = 0; i < 100; i = i + 1) begin
          for (j = 0; j < 32; j = j + 1) begin
            array[i][j] = j;
          end
        end
    
        // Assign the output to value in the array at position i_in, j_in
        out = array[i_in][j_in];
      end
    
    endmodule
    

    If you connect the inputs i_in and j_in to switches or something and out to 6 LEDs, you should be able to index the array with the switches and get the output on the LEDs to confirm your design.