Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

Issue #1467

Constant function evaluator incorrect on return of function var

Added by Roman Popov about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
WrongRuntimeResult
% Done:

0%


Description

Trying to debug the root cause of multiple errors. Here is a minimal example I've managed to extract:

module dut #(
    parameter DEPTH = 16,
    parameter WIDTH = 32,
    parameter RAM_SPLIT_WIDTH = 16
)
(
    output logic [WIDTH-1:0] ram_dataout
);

localparam RAM_ADDR_WIDTH = $clog2(DEPTH);
localparam NUM_RAM_BLOCKS = WIDTH/RAM_SPLIT_WIDTH + (WIDTH%RAM_SPLIT_WIDTH > 0);
typedef logic [NUM_RAM_BLOCKS:0][31:0] block_index_t;

function automatic block_index_t index_calc(input int WIDTH, NUM_RAM_BLOCKS);
    index_calc[0] = '0;
    for(int i = 0; i < NUM_RAM_BLOCKS; i++) index_calc[i+1] = WIDTH/NUM_RAM_BLOCKS + (i < (WIDTH%NUM_RAM_BLOCKS));
    for(int i = 0; i < NUM_RAM_BLOCKS; i++) index_calc[i+1] = index_calc[i+1] + index_calc[i];
    return index_calc;
endfunction

localparam block_index_t RAM_BLOCK_INDEX = index_calc(WIDTH, NUM_RAM_BLOCKS);

generate
    begin : ram_dataout_gen
        for (genvar i = 0; i < NUM_RAM_BLOCKS; i++) begin
                always_comb ram_dataout[RAM_BLOCK_INDEX[i+1]-1:RAM_BLOCK_INDEX[i]] = 0;
        end
    end
endgenerate

endmodule

module top (
    input clk,
    output logic [31:0] ram_dataout    
);

dut dut0(.*);

endmodule
%Warning-WIDTH: top.sv:11: Operator ADD expects 32 or 6 bits on the RHS, but RHS's GTS generates 1 bits.
%Warning-WIDTH: Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.
%Warning-WIDTH: top.sv:16: Operator ADD expects 32 bits on the RHS, but RHS's LTS generates 1 bits.
%Error: top.sv:26: [-1:0] Range extract has backward bit ordering, perhaps you wanted [0:-1]

So Verilator incorrectly evaluates RAM_BLOCK_INDEX1 to 0. Works fine in VCS/DC.

verilator --lint-only -sv -top-module top top.sv

History

#1 Updated by Wilson Snyder about 1 month ago

  • Description updated (diff)
  • Status changed from New to Confirmed

Well, this one is entertaining. Basically this:

return index_calc;

The function is already using index_calc as the variable, so this return which should be trivial hits a bug.

Will get to a fix shortly, but you can comment out the return for the moment.

#2 Updated by Wilson Snyder about 1 month ago

  • Subject changed from Constant function evaluator produces incorrect results to Constant function evaluator incorrect on return of function var
  • Status changed from Confirmed to Resolved

Thanks for the good test case.

Fixed in git towards 4.015.

#3 Updated by Wilson Snyder about 1 month ago

  • Status changed from Resolved to Closed

In 4.016.

Also available in: Atom