for...generate loop with generics, constants (vhdl)

Oct 01, 2005 2 Replies

suppose I want calculate the log2(N) were N is an integer valued generic or constant parameter in my design, now, lets say i would like to use log2(N) as an upper bound in a for ... generate statement, is there a way to do this? I dont want the log2(N) to be synthesized into my hardware, i just want to use the result in a loop


-- Geoffrey Wall Masters Student in Electrical/Computer Engineering Florida State University, FAMU/FSU College of Engineering snipped-for-privacy@eng.fsu.edu Cell Phone:



850.339.4157

ECE Machine Intelligence Lab

formatting link
MIL Office Phone:



850.410.6145

Center for Applied Vision and Imaging Science

formatting link
CAVIS Office Phone:



850.645.2257

You can have a look at the CORDIC algorithm. Its got a good way of calculating log of a number . Nitesh

Would something like this be what you are looking for? This function can be placed in the declaration section before the begin line, and will generate values that are used to define constants, or specify slv widths, etc.

-- The ceil_log2 function returns the minimum register -- width required to hold the supplied integer.

function ceil_log2 (x : in natural) return natural is variable retval : natural; begin retval := 1; while 2**retval < x loop retval := retval + 1; end loop; return retval; end ceil_log2;

constant COUNTER_BITS : integer := ceil_log2(Counter_Threshold - 1);

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required