Group: comp.lang.verilog


Subject: clogb2
From: John_H
Date: 9/27/2007 10:10:19 AM
<sharp@cadence.com> wrote in message news:1190911742.556630.61000@w3g2000hsg.googlegroups.com... > > The most common use I have seen is determining the number of address > bits required, given the number of elements in a memory. That matches > what you are looking for, and is ceil(log2(x)). > > The version of clogb2 used as an example in the Verilog-2001 LRM was > wrong in the printed version also. In that case, I am pretty certain > it was just a programming bug. So I am suspicious of claims that an > error in another version was intentional. People just seem to have > trouble writing a correct implementation of this function :-) > > In Verilog-2005, we added a built-in system function $clog2 that can > be used in constant expressions, so that users wouldn't have to write > their own. I don't know that this has been widely implemented though, > with all the attention going to SystemVerilog features. So does the Verilog-2005 built-in function return $clog2(8)==3 or ==4? 8 memory elements require 3 address bits but the number 8 requires 4 bits.