1

How to pass a constant array as a module parameter?

I want to build a shift register width different shift widths. The possible shift widths should be definable via a module parameter. I tried something like the following, but this not working.

module ShiftReg
#(
  SHIFT_WIDTH = '{1, 2, 4, 8},
  WIDTH = $clog2($size(SHIFT_WIDTH))
)
(
  ...
  input  logic [WIDTH-1:0] shift_rate_i,
  ...
);
  ...
endmodule

This results in following error message:

** Error: shift_reg.sv(3): Illegal concatenation of an unsized constant.

Is such a generic construction of a shift register with different widths possible in SystemVerilog?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Razer
  • 7,843
  • 16
  • 55
  • 103

1 Answers1

1

Not every simulator supports arrayed parameters. For those that do, the array needs to be defined with an array identifier (ex: [], [SIZE]) and a bit width for the entries; int SHIFT_WIDTH [] = '{1, 2, 4, 8} should work.

I tried different combinations on EDAplaygroud. Queued arrays ([$]) was not accepted by any simulator. VCS supported [] arrayed parameters, but it does not accept it with $size() or .size() in a parameter definition. A fixed array size does work on VCS and Riviera-PRO. Declaring the size is an extra step, but it works.

module ShiftReg
#(
  SIZE = 4,
  int SHIFT_WIDTH [SIZE] = '{1, 2, 4, 8},
  WIDTH = $clog2(SIZE)
//WIDTH = $clog2($size(SHIFT_WIDTH)) // <-- this also works if SHIFT_WIDTH is a fixed size
)
(
  ...
  input  logic [WIDTH-1:0] shift_rate_i,
  ...
);
  ...
endmodule
Greg
  • 18,111
  • 5
  • 46
  • 68
  • Just a side question. Will this be synthesizable? I doubt that. – sharvil111 Dec 02 '15 at 01:20
  • 1
    @sharvil111, it *could* synthesize ***if*** the synthesizer implemented it. Most synthesizers probably do not support it right now, but I cannot see any reason why it shouldn't. Just a matter of demand for the feature and time. – Greg Dec 02 '15 at 02:31
  • Yaa I agree. This **should** be made synthesizable. But obviously dynamic/queues arrays must not be accepted. Thanks for the clarification. – sharvil111 Dec 02 '15 at 03:57