4

I created a module to soemthing simple like add some pipeline delay. I made the data type a parameter so it could handle complex things like structs. I have something like this:

module pipe
   #(parameter type T = int,
     parameter DELAY = 0)
   (
    input clk,
    input T data_in,
    output T data_out);

   T pipe[DELAY];
   always_ff @(posedge clk) begin
     pipe[0] <= data_in;
     for(int i = 1; i<DEPTH; i++) begin
       pipe[i] <= pipe[i-1];
     end
   end
   assign data_out = pipe[DELAY-1];
endmodule

This works great but then I found myself wanting to use it with an unpacked array and I couldn't figure out how to instance it. It would look something like this, but I don't think this is right:

logic [7:0] my_data [16];
logic [7:0] my_data_delayed [16];
pipe #(.T(logic [7:0] [16]), .DELAY(2)) i_pipe
  (
   .clk(clk),
   .data_in(my_data),
   .data_out(my_data_delayed)
  );

Is there a way to get the type of a variable so it can be passed to this parameter?

2 Answers 2

3

You can use typedef do define the data type:

typedef logic [7:0] my_type [16];
my_type my_data;
my_type my_data_delayed;
pipe #(.T(my_type), .DELAY(2)) i_pipe
  (
   .clk(clk),
   .data_in(my_data),
   .data_out(my_data_delayed)
  );

The remaining question is if it will work with your simulator. I tried it out at EDAplayground, worked with VCS but not Riviera-PRO (got a "not supported in this release" message)


I was able to get typedef struct { logic [7:0] data [16]; } my_type; to work. Less clean but it is a workaround.

Sign up to request clarification or add additional context in comments.

3 Comments

Cadence Incisive 14.2 says "Currently type parameter override is not supported for this datatype"
@nguthrie , did using a struct help at all?
That did it, but yeah, getting a bit ugly. I'll stick with my current workaround with an instance array. Hopefully the type operator will be supported one day since it seems most useful.
2

While typing the question I figured out one answer. The type operator (section 6.23 in IEEE 1800-2012) spec does what I need. So my instance would look like this:

logic [7:0] my_data [16];
logic [7:0] my_data_delayed [16];
pipe #(.T(type(my_data)), .DELAY(2)) i_pipe
  (
   .clk(clk),
   .data_in(my_data),
   .data_out(my_data_delayed)
  );

Of course this results in a compile error in my tool so it doesn't look to be universally supported.

My work-around is going to be to make an array of instances of the pipe module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.