BitwiseMux constructor
Creates per-bit selection hardware among inputs, controlled by
selects.
Implementation
BitwiseMux(
List<Logic> selects,
List<Logic> inputs, {
super.name = 'bitwise_mux',
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
}) : super(
definitionName: definitionName ??
'BitwiseMux_N${inputs.length}_W'
'${inputs.isEmpty ? 0 : inputs.first.width}',
) {
if (inputs.isEmpty) {
throw RohdHclException('BitwiseMux requires at least one input.');
}
if (selects.length != inputs.length) {
throw RohdHclException(
'BitwiseMux needs one select per input, got ${selects.length} '
'selects for ${inputs.length} inputs.',
);
}
final width = inputs.first.width;
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].width != width || selects[i].width != width) {
throw RohdHclException(
'BitwiseMux selects and inputs must all have width $width, got '
'select $i width ${selects[i].width} and input $i width '
'${inputs[i].width}.',
);
}
}
final addedSelects = [
for (var i = 0; i < selects.length; i++)
addInput('select$i', selects[i], width: width),
];
final addedInputs = [
for (var i = 0; i < inputs.length; i++)
addInput('input$i', inputs[i], width: width),
];
final terms = [
for (var i = 0; i < addedInputs.length; i++)
addedInputs[i] & addedSelects[i],
];
addOutput('out', width: width) <= terms.reduce((acc, t) => acc | t);
}