Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logarithm in Verilog

I've a statement in verilog looking like integer level = log(N) (Where N is a parameter and level is to be determined) But I understand I cannot do complex math statements in verilog, so I'm wondering if there is an alternative solution to the above problem?

Any feedback appreciated!

like image 482
Max Eastman Avatar asked Apr 09 '11 00:04

Max Eastman


People also ask

How do you do log2 in Verilog?

If it is a logarithm base 2 you are trying to do, you can use the built-in function $clog2() .

What does == mean in Verilog?

In Verilog: == tests logical equality (tests for 1 and 0, all other will result in x) === tests 4-state logical equality (tests for 1, 0, z and x)

How do you write powers in Verilog?

Verilog Arithmetic OperatorsThe result will be 1 if the second operand of a power operator is 0 (a0). An example of how arithmetic operators are used is given below. ncsim> run Add + = 54 Sub - = 36 Mul * = 149 Div / = 5 Mod % = 0 Pow ** = 81 ncsim: *W,RNQUIE: Simulation is complete.


1 Answers

If it is a logarithm base 2 you are trying to do, you can use the built-in function $clog2().

like image 93
abettino Avatar answered Nov 14 '22 13:11

abettino