weightedPriorityArbitrationPolicy function
Creates a static weighted-priority policy.
Equal weights resolve toward the lowest request index. This is not weighted round robin; weights establish a fixed ordering.
Implementation
ArbitrationPolicy weightedPriorityArbitrationPolicy(List<int> weights) {
if (weights.isEmpty || weights.any((weight) => weight < 1)) {
throw ArgumentError.value(
weights,
'weights',
'Must provide positive weights.',
);
}
final capturedWeights = List<int>.unmodifiable(weights);
return ArbitrationPolicy(
identity: 'weightedPriority_${capturedWeights.join('_')}',
build: (
{required requests,
required completedGrant,
required policyInputs,
required clk,
required reset,
required name}) {
if (capturedWeights.length != requests.length ||
policyInputs.isNotEmpty) {
throw ArgumentError.value(
capturedWeights,
'weights',
'Must provide one static weight per request and no policy inputs.',
);
}
final maxWeight = capturedWeights.reduce(_maxInt);
final width = max(1, (maxWeight + 1).log2Ceil);
return _highestScorePolicy(
requests: requests,
completedGrant: completedGrant,
policyInputs: [
for (final weight in capturedWeights) Const(weight, width: width),
],
clk: clk,
reset: reset,
name: name,
);
},
);
}