I\'m trying to create a reusable barrel shifter; it takes an input array of bits and shifts them a certain number of positions (determined by another input). I want to parameter
Two alternative approaches:
You could work it backwards and have the generic
as shift_bits
- then calculate the width of the input and output vectors from that:
generic ( shift_bits: integer :=3);
Port ( INPUT : in std_logic_vector ((2**shift_bits)-1 downto 0);
OUTPUT : out std_logic_vector ((2**shift_bits)-1 downto 0);
SHIFT_CNT : in std_logic_vector (shift_bits-1 downto 0)
);
Or treat the count as a number:
generic ( NUMBITS : integer :=8);
Port ( INPUT : in std_logic_vector (NUMBITS-1 downto 0);
OUTPUT : out std_logic_vector (NUMBITS-1 downto 0);
SHIFT_CNT : in integer range 0 to numbits-1
);
and let the tools figure it out for you.