decodeWordStatus method
- Logic protectedWord
Decodes and aggregates per-lane correction status.
The syndrome is the bitwise OR across lanes. The correction count sums corrected lanes' counts, but is zero if any lane is uncorrectable.
Implementation
BlockDecodeStatus<Logic>? decodeWordStatus(Logic protectedWord) {
final decoder = laneCodec.decodeStatus;
if (decoder == null) {
return null;
}
if (protectedWord.width != protectedWidth) {
throw RohdHclException(
'Protected word width must equal $protectedWidth bits.');
}
final bits = protectedWord.packed;
final statuses = [
for (var lane = 0; lane < laneCount; lane++)
decoder(bits.slice((lane + 1) * laneCodec.protectedWidth - 1,
lane * laneCodec.protectedWidth)),
];
final countWidth = statuses
.map((lane) => (BigInt.one << lane.correctionCount.width) - BigInt.one)
.reduce((a, b) => a + b)
.bitLength;
final status = BlockDecodeStatus(
Logic(name: 'data', width: logicalWidth)
..gets(statuses.map((lane) => lane.data.packed).toList().rconcat()),
syndromeWidth: statuses.first.syndrome.width,
correctionCountWidth: countWidth,
);
status.syndrome <=
statuses.map((value) => value.syndrome).reduce((a, b) => a | b);
final uncorrectable =
statuses.map((lane) => lane.uncorrectable).reduce((a, b) => a | b);
final corrected =
statuses.map((lane) => lane.corrected).reduce((a, b) => a | b);
final totalCount = statuses
.map((lane) => lane.correctionCount.zeroExtend(countWidth))
.reduce((a, b) => a + b);
status.uncorrectable <= uncorrectable;
status.corrected <= corrected & ~uncorrectable;
status.errorDetected <= corrected | uncorrectable;
status.correctionCount <=
mux(uncorrectable, Const(0, width: countWidth), totalCount);
return status;
}