datatype expression support in Vivado 2018.2
datatype expression support in Vivado 2018.2

I need to derive a local parameter from a data type parameter to obtain the width of a bitfield inside a packed struct. The following is a simplified example code that demonstrates what I am trying to achieve:

typedef struct packed {
logic a;
logic [15:0] b;
} data_1_t;

typedef struct packed {
logic a;
logic [31:0] b;
} data_2_t;

module test #(parameter type DATA_T = integer) ();
localparam DATA_WIDTH = (type(DATA_T) == type(data_2_t)) ? 32 :
(type(DATA_T) == type(data_1_t)) ? 16 : 8;
DATA_T data;
logic [DATA_WIDTH-1:0] c;
assign c= data.b;

endmodule
Vivado 2018.2 complains about the localparam DATA_WIDTH with the following error:

ERROR: [Synth 8-26] datatype expression not implementedIs there a workaround to avoid this error?

Is there a plan to have support for the type operator in synthesizable RTL code?


  • drjohnsmith (Member)

    To avoid ambiguity, what codding language you using there,

  • markcurry (Member)

    I've heard (but not tried yet) that Vivado supports some variants of the SystemVerilog $bits() system function.

    Try

    localparam DATA_WIDTH = $bits( DATA_T ) - 1; // Adjust math as needed.... Regards,

    Mark

  • The structs I used for the example are simplified to demonstrate the problem. My goal is to obtain the width of the sub-field without having to consider what else is inside the struct or maintain the localparam when the struct is changed.