Let's say that I have the following Generic part of entity declaration:
Entity Example is
Generic
(G_INTEGER_A : integer range C_INT_LEFT_A to C_INT_RIGHT_A;
G_INTEGER_B : integer range C_INT_LEFT_B to C_INT_RIGHT_B);
Port
(...)
Is there a straightforward way to use that integer range attribute to determine the equivalent bit size to dimension an std_logic_vector or unsigned array to represent values within this range?
I would like to use it only at elaboration time, to define in a generic way size of counters , etc in a way like this:
constant C_A_SIZE: integer := f_int_size(G_INTEGER_A'range);
signal s_bit_cnt : unsigned(C_A_SIZE - 1 downto 0);
Where f_int_size would be a user function, maybe defined in an external package. Is there a way to do this?