ReadyValidIndexPool constructor
- required Logic clk,
- required Logic reset,
- required ReadyValidInterface<
Logic> allocation, - required ReadyValidInterface<
TagRelease> release, - required int capacity,
- List<
int> ? initiallyAvailableIndices, - IndexAllocationGenerator allocationGenerator = lowestFreeIndexAllocationGenerator,
- String allocationPolicyName = 'lowestFree',
- String name = 'ready_valid_index_pool',
Creates an index pool with lowest-index-first allocation.
Implementation
ReadyValidIndexPool(
{required Logic clk,
required Logic reset,
required ReadyValidInterface<Logic> allocation,
required ReadyValidInterface<TagRelease> release,
required this.capacity,
List<int>? initiallyAvailableIndices,
IndexAllocationGenerator allocationGenerator =
lowestFreeIndexAllocationGenerator,
this.allocationPolicyName = 'lowestFree',
super.name = 'ready_valid_index_pool'})
: indexWidth = max(1, capacity.log2Ceil),
super(
definitionName: _definitionName(
capacity, initiallyAvailableIndices, allocationPolicyName)) {
if (capacity < 1) {
throw ArgumentError.value(capacity, 'capacity', 'Must be positive.');
}
if (!RegExp(r'^[A-Za-z][A-Za-z0-9_]*$').hasMatch(allocationPolicyName)) {
throw ArgumentError.value(allocationPolicyName, 'allocationPolicyName',
'Must be a valid SystemVerilog identifier fragment.');
}
if (!identical(allocationGenerator, lowestFreeIndexAllocationGenerator) &&
allocationPolicyName == 'lowestFree') {
throw ArgumentError.value(allocationPolicyName, 'allocationPolicyName',
'A custom allocation generator requires a distinct policy name.');
}
final initialAvailability = initiallyAvailableIndices ??
List<int>.generate(capacity, (index) => index);
if (initialAvailability.toSet().length != initialAvailability.length ||
initialAvailability.any((index) => index < 0 || index >= capacity)) {
throw ArgumentError.value(
initiallyAvailableIndices,
'initiallyAvailableIndices',
'Must contain unique indices in the configured capacity.');
}
if (allocation.data.width != indexWidth ||
release.data.tag.width != indexWidth) {
throw ArgumentError(
'Allocation and release index widths must both be $indexWidth.');
}
release.requireProviderComposableWith(ReadyValidContract.readyAndValid,
consumerName: name);
allocation.requireConsumerComposableWith(ReadyValidContract.irrevocable,
providerName: name);
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
this.allocation = addPairInterfaceFrom(
IrrevocableReadyValidInterface<Logic>(allocation.data.clone()),
allocation,
PairRole.provider,
uniquify: (original) => 'allocation_$original',
);
this.release = addPairInterface(release, PairRole.consumer,
uniquify: (original) => 'release_$original');
final countWidth = max(1, (capacity + 1).log2Ceil);
addOutput('allocatedCount', width: countWidth);
addOutput('allocatedMask', width: capacity);
addOutput('allocatedMaskAfterReleases', width: capacity);
addOutput('availableCount', width: countWidth);
addOutput('exhausted');
addOutput('invalidRelease');
addOutput('doubleRelease');
final restore = ReadyAndValidInterface(Logic(width: capacity));
restore.valid <= Const(0);
restore.data <= Const(0, width: capacity);
final pool = ReadyValidMultiIndexPool(
clk: localClk,
reset: localReset,
quiesce: Const(0),
allocations: [this.allocation],
releases: [this.release],
restore: restore,
capacity: capacity,
initiallyAvailableIndices: initiallyAvailableIndices,
allocationGenerator: allocationGenerator,
allocationPolicyName: allocationPolicyName,
selectionMode: IndexAllocationSelectionMode.scalarCompatibility,
name: '${name}_pool',
);
allocatedCount <= pool.allocatedCount;
allocatedMask <= pool.allocatedMask;
allocatedMaskAfterReleases <= pool.allocatedMasksAfterAllocationPrefixes[0];
availableCount <= pool.availableCount;
exhausted <= pool.exhausted;
invalidRelease <= pool.invalidReleases;
doubleRelease <= pool.doubleReleases;
}