Forum Discussion
6 Replies
- Altera_Forum
Honored Contributor
like log base 2?
this function will return the nearest log2 of a number (but I wouldnt recommend synthesising as a real time function) Its useful for determining how many bits you need for a vector.function log2(x : integer) return integer is variable temp : integer :=x; variable n : integer := 1; begin while temp > 1 loop temp := temp/2; n := n + 1; end loop; return n; end function log2; - Altera_Forum
Honored Contributor
--- Quote Start --- like log base 2? this function will return the nearest log2 of a number (but I wouldnt recommend synthesising as a real time function) Its useful for determining how many bits you need for a vector.
--- Quote End --- Think you very much for your reply, ok for this function it is clear, but that i need is a function that can execute during a minimum of clock cycle. ThAnk youfunction log2(x : integer) return integer is variable temp : integer :=x; variable n : integer := 1; begin while temp > 1 loop temp := temp/2; n := n + 1; end loop; return n; end function log2; - Altera_Forum
Honored Contributor
if you need a synthesisable version, I suggest you use a look-up table.
- Altera_Forum
Honored Contributor
--- Quote Start --- if you need a synthesisable version, I suggest you use a look-up table. --- Quote End --- Ok thank you, already i use LUT, but i search if it is possible to find a synthetisable code for log. - Altera_Forum
Honored Contributor
LUT is the easiest. But you should be able to generate the table using a function.
- Altera_Forum
Honored Contributor
--- Quote Start --- LUT is the easiest. But you should be able to generate the table using a function. --- Quote End --- I generate the LUT through Matlab. And i initialize memory with the generated data.