Package prim_util_pkg

Functions

_clog2(integer value)

Math function

$clog2 as specified in Verilog-2005

Do not use this function if $clog2() is available.

clog2 = 0 for value == 0 ceil(log2(value)) for value >= 1

This implementation is a synthesizable variant of the $clog2 function as specified in the Verilog-2005 standard (IEEE 1364-2005).

To quote the standard

The system function $clog2 shall 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.

Parameters:

value (integer)

vbits(integer value)

Math function

Number of bits needed to address |value| items.

0 for value == 0 vbits = 1 for value == 1 ceil(log2(value)) for value > 1

The primary use case for this function is the definition of registers/arrays which are wide enough to contain |value| items.

This function identical to $clog2() for all input values except the value 1; it could be considered an "enhanced" $clog2() function.

Example 1

parameter Items = 1; localparam ItemsWidth = vbits(Items); // 1 logic [ItemsWidth-1:0] item_register; // items_register is now [0:0]

Example 2

parameter Items = 64; localparam ItemsWidth = vbits(Items); // 6 logic [ItemsWidth-1:0] item_register; // items_register is now [5:0]

Note

If you want to store the number "value" inside a register, you need

a register with size vbits(value + 1), since you also need to store the number 0.

Example 3

logic [vbits(64)-1:0] store_64_logic_values; // width is [5:0] logic [vbits(64 + 1)-1:0] store_number_64; // width is [6:0]

Parameters:

value (integer)