SummationBase constructor

SummationBase(
  1. List<SumInterface> interfaces, {
  2. dynamic initialValue = 0,
  3. dynamic maxValue,
  4. dynamic minValue = 0,
  5. bool saturates = false,
  6. bool generateOverflowedOutput = true,
  7. bool generateUnderflowedOutput = true,
  8. int? width,
  9. String name = 'unnamed_module',
  10. bool reserveName = false,
  11. bool reserveDefinitionName = false,
  12. String? definitionName,
})

Sums the values across the provided interfaces within the bounds of the saturates behavior, initialValue, maxValue, and minValue, with the specified width, if provided.

Implementation

SummationBase(List<SumInterface> interfaces,
    {dynamic initialValue = 0,
    dynamic maxValue,
    dynamic minValue = 0,
    this.saturates = false,
    bool generateOverflowedOutput = true,
    bool generateUnderflowedOutput = true,
    int? width,
    super.name,
    super.reserveName,
    super.reserveDefinitionName,
    String? definitionName})
    : width =
          _inferWidth([initialValue, maxValue, minValue], width, interfaces),
      super(
          definitionName: definitionName ??
              'SummationBase_L${interfaces.length}_W$width') {
  if (interfaces.isEmpty) {
    throw RohdHclException('At least one interface must be provided.');
  }

  this.interfaces = interfaces
      .mapIndexed((i, e) => addPairInterfacePorts(e, PairRole.consumer,
          uniquify: (original) => '${original}_$i'))
      .toList();

  initialValue ??= 0;
  maxValue ??= biggestVal(this.width);
  minValue ??= 0;

  final configuredMaxValue = configuredValue(maxValue);
  final configuredMinValue = configuredValue(minValue);

  if (configuredMaxValue is! Logic) {
    constantMaxValue = LogicValue.ofInferWidth(configuredMaxValue).toBigInt();
  } else {
    constantMaxValue = null;
  }

  if (configuredMinValue is! Logic) {
    constantMinValue = LogicValue.ofInferWidth(configuredMinValue).toBigInt();
  } else {
    constantMinValue = null;
  }

  if (constantMaxValue != null &&
      constantMinValue != null &&
      constantMaxValue! < constantMinValue!) {
    throw RohdHclException(
        'Max value must be greater or equal to min value.');
  }

  initialValueLogic = _dynamicInputToLogic('initialValue', initialValue);
  minValueLogic = _dynamicInputToLogic('minValue', minValue);
  maxValueLogic = _dynamicInputToLogic('maxValue', maxValue);

  if (generateOverflowedOutput) {
    addOutput('overflowed');
  }
  if (generateUnderflowedOutput) {
    addOutput('underflowed');
  }
  addOutput('equalsMax');
  addOutput('equalsMin');
}