VHDL: use the length of an integer generic to determine number of select lines

前端 未结 5 1563
-上瘾入骨i
-上瘾入骨i 2021-02-08 08:34

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

5条回答
  •  醉梦人生
    2021-02-08 09:08

    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.

提交回复
热议问题