title: VHDL: use the length of an integer generic to determine number of select lines
body: <p>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 parameterize the module so that it works for any <code>n</code>.</p>
  
  <p>The number of select lines required is determined by <code>n</code> --> i.e., <code>SHIFT_CNT = log2(NUMBITS-1)+1</code> in the code below. It's considered bad form in my organization (and I think overall) to have ports that are not of <code>std_logic_vector</code> or <code>std_logic</code>, so I used a <code>std_logic_vector</code> for the number of select lines. I need to adjust the length of the <code>std_logic_vector</code> based on the input generic. Is there a way to do this without using a second generic? I've seen <a href="https://stackoverflow.com/questions/5195242/vhdl-finding-out-reporting-bit-width-length-of-integer-vs-std-logic-vector">this</a> post, but it doesn't deal with generics. <a href="https://stackoverflow.com/questions/5891700/use-a-generic-to-determine-demux-size-in-vhdl">This</a> post eliminates the generics entirely or uses the log value as the generic, which isn't as intuitive to future users (and could cause problems if the <code>INPUT</code> is not a power of two).</p>
  
  <p>The declaration of <code>SHIFT_CNT</code> below is definitely incorrect; is there a way to automatically generate the length in the entity declaration without using a second generic?</p>
  
  <pre><code>entity BarrelShifter is
  
  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   std_logic_vector ((NUMBITS-1)'length downto 0)                 
          );                                                               
  end BarrelShifter;
  </code></pre>