widthFor function

int widthFor(
  1. int val
)

Returns the minimum number of bits needed to represent val distinct values, with a minimum of 1 (since 0-width signals are not valid in hardware).

Equivalent to max(1, log2Ceil(val)).

Implementation

int widthFor(int val) => max(1, log2Ceil(val));