Log2Ceil constructor
Constructs a Log2Ceil of inp.
Implementation
Log2Ceil(Logic inp,
{super.name = 'log2Ceil',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(definitionName: definitionName ?? 'Log2Ceil_W${inp.width}') {
inp = addInput('inp', inp, width: inp.width);
final w = inp.width;
final outWidth = w.bitLength;
final log = addOutput('log', width: outWidth);
final predecessor =
mux(inp.eq(0), Const(0, width: w), inp - Const(1, width: w));
final leadingZeros = CountLeadingZeros(predecessor).count;
log <=
(Const(w, width: outWidth) - leadingZeros.slice(outWidth - 1, 0))
.slice(outWidth - 1, 0);
}