ProtectedMemoryWriteMerger<T extends Logic> constructor

ProtectedMemoryWriteMerger<T extends Logic>({
  1. required T oldData,
  2. required T newData,
  3. required Logic laneMask,
  4. required int laneWidth,
  5. String name = 'protected_memory_write_merger',
})

Creates a lane-granular masked merge.

Implementation

ProtectedMemoryWriteMerger({
  required T oldData,
  required T newData,
  required Logic laneMask,
  required int laneWidth,
  super.name = 'protected_memory_write_merger',
}) : super(
        definitionName: schemaQualifiedDefinitionName(
          'ProtectedMemoryWriteMerger_W${oldData.width}_L${laneWidth}_',
          [oldData, newData],
        ),
      ) {
  if (!rohdPayloadsCompatible([oldData, newData], allowRenamedClones: true) ||
      laneWidth < 1 ||
      oldData.width % laneWidth != 0 ||
      laneMask.width != oldData.width ~/ laneWidth) {
    throw ArgumentError(
        'Data schemas must match and laneMask must select complete lanes.');
  }

  final oldInput = addTypedInput('oldData', oldData);
  final newInput = addTypedInput('newData', newData);
  final maskInput = addInput('laneMask', laneMask, width: laneMask.width);
  final mergedLanes = <Logic>[];
  for (var lane = 0; lane < laneMask.width; lane++) {
    final high = (lane + 1) * laneWidth - 1;
    final low = lane * laneWidth;
    mergedLanes.add(mux(maskInput[lane], newInput.packed.slice(high, low),
        oldInput.packed.slice(high, low)));
  }
  result = addTypedPayloadOutput(this, 'result', oldInput);
  connectPackedPayload(result, mergedLanes.rconcat());
}