Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  IPC::Locker
  Parallel::Forker
  Voneline
General Info
  Papers

Problem while trying to use generate with for statement

Added by Arthur de Araújo Farias over 4 years ago

I was trying to simulate following module

module bitadder
(

    input [input_length-1:0] in,
    output [output_length-1:0] out

);

parameter input_length = 8;
parameter output_length = 4; // floor(log2(input_length)+1);

wire [output_length:0] sum [input_length:0];

genvar i;
generate for (i=0;(i*2+1)<input_length;i = i+1) begin : genblock
    assign sum[i+1] = sum[i]+in[i];
end endgenerate

assign out = sum[input_length];

endmodule

This is the toplevel entity

module Test (

input reg clk

);

reg [31:0] cnt;
reg [31:0] out;

initial begin

    cnt = 0;

end

always@(posedge clk) begin

    if ( cnt <= 255 )
    begin
        $display( "%d %d", cnt, out );
        cnt = cnt + 1;
    end else
        $finish;
end

bitadder BITADDER0 ( .in(cnt), .out(out) );

endmodule

This is the testbench

#include "VTest.h" 
#include "verilated.h" 

//vcd traces
#include "verilated_vcd_c.h" 

//cout
#include <iostream>

VTest *top; // Instantiation of module

unsigned int main_time = 0; // Current simulation time

double sc_time_stamp () { // Called by $time in Verilog
  return main_time;
}

int main(int argc, char** argv) {
  Verilated::commandArgs(argc, argv);
  top = new VTest;

  while (!Verilated::gotFinish()) {
    top->clk = ~top->clk;
    top->eval(); // Evaluate model
    main_time++; // Time passes...
  } //while

  delete top;
  exit(0);
}

This is the console output (I'm using zsh)

➜  source_files git:(assynchronous-gf8-multiplier) ✗ verilator --cc Test.bitadder.v --exe Test.cpp --converge-limit 100000
%Error: bitadder.v:15: Unsupported: Can't unroll generate for; no variable on rhs of condition
%Error: bitadder.v:15: For loop doesn't have genvar index, or is malformed
%Error: Internal Error: bitadder.v:15: ../V3Param.cpp:329: GENFOR should have been wrapped in BEGIN
%Error: Internal Error: See the manual and http://www.veripool.org/verilator for more assistance.
%Error: Command Failed /usr/local/verilator/3.877/bin/verilator_bin --cc Test.bitadder.v --exe Test.cpp --converge-limit 100000
➜  source_files git:(assynchronous-gf8-multiplier) ✗ verilator --version
Verilator 3.877 devel rev verilator_3_876-8-gd0653f7

Is this a bug or I'm doing something wrong?


Replies (1)

RE: Problem while trying to use generate with for statement - Added by Jie Xu over 4 years ago

If you change the line
generate for (i=0;(i*2+1)<input_length;i = i+1) begin : genblock
to
generate for (i=0;i<(input_length-1)/2;i = i+1) begin : genblock

Then it will work. Verilator currently only support very simple condition statements in the for loop. See the bug677.

    (1-1/1)