Function of $Clog2(N) in Mojo Ide
I Am a Beginner in This, but I Was Wondering What Exactly Is the Function of $Clog2(N) in General? Some Websites Say That It Is the Number of Address Bits...
I am a beginner in this, but I was wondering what exactly is the function of $clog2(N) in general? Some websites say that it is the number of address bits needed for a memory of size N and not the number of bits needed to express the value N. What does that mean?
1 Answer
IEEE Std 1800-2012 § 20.8.1 Integer math functions
The system function
$clog2shall return the ceiling of the log base 2 of the argument (the log rounded up to an integer value). The argument can be an integer or an arbitrary sized vector value. The argument shall be treated as an unsigned value, and an argument value of 0 shall produce a result of 0.This system function can be used to compute the minimum address width necessary to address a memory of a given size or the minimum vector width necessary to represent a given number of states.
For example:
integer result; result = $clog2(n);