title: Efficiently derive parameter from generics vhdl
body: <p>I have two generics on my entity:</p>
  
  <pre><code>clk_freq, io_delay: integer
  </code></pre>
  
  <p>From this, I want to calculate the number of cycles required for <code>io_delay</code> which is in ms. I also want to store this counter value in an unsigned variable so I'm not wasting loads of resources on an integer type. So I've implemented the following to do this:</p>
  
  <pre><code>constant COUNT_MAX_I: integer := integer(ceil(real(io_delay) * 0.001 * real(clk_freq)));
  constant COUNTER_WIDTH: integer := integer(ceil(log2(real(COUNT_MAX_I))));
  constant COUNT_HIGH: integer := unsigned(COUNTER_WIDTH - 1 downto 0) := to_unsigned(COUNT_MAX_I, COUNTER_WIDTH);
  </code></pre>
  
  <p>However, just looking at it that looks hugely inefficient. So my question is this:</p>
  
  <p>Is there a more efficient way to do this and will the synthesis tools get rid of <code>COUNT_MAX_I</code> as it's only used in the calculation of other constants?</p>