title: log value in verilog
body: <p>Can anyone tel me how to calculate the log value of a parameter in a <strong>design</strong> file?</p>
  
  <p>I am coming across such a situation where I have a generate for a loop like this:</p>
  
  <pre><code>parameter N=8;
  
  genvar i,m;
  
  generate
  for(m=1;m&lt;N;m=m*2)
  begin :m_loop
  
      // I have an instance here
      // "in" is an input of N bits, "out" is an output N bits
  
      Inst u(in(i+log2(m)),in(i+1+log2(m)),out(i+log2(m)));     
  end
  endgenerate
  </code></pre>
  
  <p>Is there a way to do log2(m), where m varies as powers of 2 (2^0,2^1,2^2, till N)? If not, </p>
  
  <p>I was thinking of introducing a new variable, m1, say, which is 0,1,2,... (i.e log2(m)). </p>
  
  <p>In such a case m1 should vary with simultaneously every m, ie, when m=1,m1=0; m=2,m1=1; </p>
  
  <p>m=4,m1=2; m=8,m1=3 and so on.</p>