MemoryAddressMatcher constructor
Creates a byte-aware parallel address matcher.
Implementation
MemoryAddressMatcher({
required Logic queryAddress,
required Logic queryByteEnable,
required Logic candidateValid,
required List<Logic> candidateAddresses,
required List<Logic> candidateByteEnables,
super.name = 'memory_address_matcher',
}) : entryCount = candidateValid.width,
super(
definitionName: 'MemoryAddressMatcher_E${candidateValid.width}_'
'A${queryAddress.width}_B${queryByteEnable.width}',
) {
if (entryCount < 1 ||
candidateAddresses.length != entryCount ||
candidateByteEnables.length != entryCount ||
candidateAddresses
.any((address) => address.width != queryAddress.width) ||
candidateByteEnables
.any((enable) => enable.width != queryByteEnable.width)) {
throw ArgumentError(
'Each valid bit requires matching address and byte-enable inputs.');
}
final localQueryAddress =
addInput('queryAddress', queryAddress, width: queryAddress.width);
final localQueryByteEnable = addInput('queryByteEnable', queryByteEnable,
width: queryByteEnable.width);
final localCandidateValid =
addInput('candidateValid', candidateValid, width: entryCount);
final localAddresses = [
for (var index = 0; index < entryCount; index++)
addInput('candidateAddress$index', candidateAddresses[index],
width: queryAddress.width)
];
final localByteEnables = [
for (var index = 0; index < entryCount; index++)
addInput('candidateByteEnable$index', candidateByteEnables[index],
width: queryByteEnable.width)
];
final matches = <Logic>[];
final overlaps = <Logic>[];
final covers = <Logic>[];
for (var index = 0; index < entryCount; index++) {
final addressMatch = (localCandidateValid[index] &
localAddresses[index].eq(localQueryAddress))
.named('${name}_address_match_$index');
final overlap =
(addressMatch & (localByteEnables[index] & localQueryByteEnable).or())
.named('${name}_byte_overlap_$index');
final coversAll = (addressMatch &
(localByteEnables[index] & localQueryByteEnable)
.eq(localQueryByteEnable))
.named('${name}_full_coverage_$index');
matches.add(addressMatch);
overlaps.add(overlap);
covers.add(coversAll);
}
final overlapVector = overlaps.rconcat();
addOutput('addressMatches', width: entryCount) <= matches.rconcat();
addOutput('byteOverlaps', width: entryCount) <= overlapVector;
addOutput('fullCoverage', width: entryCount) <= covers.rconcat();
addOutput('multipleOverlaps') <= (overlapVector & (overlapVector - 1)).or();
}