Skip to content

Record Packing and SizeOf

Is your capability/feature request related to a problem?

Often record types are stored in things like FIFOs. In order to do this users by-hand write to_slv and from_slv functions for their record type. This is unnecessary for a human to do. In fact, several places I've worked have had company internal scripts generating VHDL packages with to/from slv functions for record types.

Describe the solution you'd like

SystemVerilog has a way of tagging their structs (equivalent of VHDL records) as packed. This indicates to the tool that constructing or parsing a bit vector to/from a type is done by simply packing together all of the fields in the struct, in the order listed. Similar to some C software struct packing attributes.

VHDL should adopt this as well. There should be some way for a user to tag/attribute etc their record definition(/instance?) as 'packed', thus inferring to and from slv functions for the user.

Example:

type t_FROM_FIFO is record
 wr_full  : std_logic;                
 rd_empty : std_logic;                
 rd_dv    : std_logic;
 rd_data  : std_logic_vector(7 downto 0);
end record t_FROM_FIFO;
signal my_record : t_FROM_FIFO;
signal my_slv : std_logic_vector(...TBD how to size...);

I dont have strong opinions on how the syntax looks. I am mainly just tired of maintaining the extra scripts to generate these functions at each company I work for, when can be inferred by record definition directly.

-- Options?
attribute PACKED of t_FROM_FIFO : record is "TRUE"; -- Needed/wanted?
 
my_slv := t_FROM_FIFO'SLV(my_record); -- a SLV representation of my_signal that is of type t_FROM_FIFO.

my_slv := to_slv(my_record); -- auto generated function instead of hand written

-- etc for opposite from_slv direction too

Note also the TBD on how to essentially ask 'how many bits are in the packed record type?', i.e. some kind of sizeof is also needed. SV called this the $bits() function.

signal my_slv : std_logic_vector(t_FROM_FIFO'range);  --Maybe?

Thanks for your time! (Apologies if this is a duplicate issue somewhere, did try to search)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information