Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21615 Discussions

VHDL code for logarithme

Altera_Forum
Honored Contributor II
4,672 Views

Hi, 

 

There are somoene that release a vhdl code for log or have any idea about it. 

I need any tutorial or helps to start release it. 

 

Thank you.
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
3,408 Views

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;
0 Kudos
Altera_Forum
Honored Contributor II
3,409 Views

 

--- 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. 

 

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;  

--- 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 you
0 Kudos
Altera_Forum
Honored Contributor II
3,408 Views

if you need a synthesisable version, I suggest you use a look-up table.

0 Kudos
Altera_Forum
Honored Contributor II
3,409 Views

 

--- 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.
0 Kudos
Altera_Forum
Honored Contributor II
3,409 Views

LUT is the easiest. But you should be able to generate the table using a function.

0 Kudos
Altera_Forum
Honored Contributor II
3,409 Views

 

--- 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.
0 Kudos
Reply