-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Deferred Contentions Before this commit, contentions were checked at output nodes and if a disagreeing value was found (only exception being Tristates), the simulation would error out with a contention error. This is not correct since some contentions might occur temporarily and might resolved in the same play() cycle down the resolution queue. This commit maintains an [effectively] set of all contentions that are found during resolution. Some contentions might get resolved in the simulation and they are removed from the set. At the end of the play cycle, if any contentions remain, then only those are real contentions and are reported. This commit also removes the special contentionPending check for Tristate as this should be handled by the new contention system. * Add back Tristate special check Turns out we need it.
- Loading branch information
Showing
4 changed files
with
143 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @class | ||
* ContentionPendingData | ||
* | ||
* Data structure to store pending contentions in the circuit. | ||
**/ | ||
export default class ContentionPendingData { | ||
constructor() { | ||
// Map<Node, Set<Node>> | ||
this.contentionPendingMap = new Map(); | ||
this.totalContentions = 0; | ||
} | ||
|
||
// Adds | ||
add(ourNode, theirNode) { | ||
if (this.contentionPendingMap.has(ourNode)) { | ||
if (!this.contentionPendingMap.get(ourNode).has(theirNode)) this.totalContentions++; | ||
this.contentionPendingMap.get(ourNode).add(theirNode); | ||
return; | ||
} | ||
|
||
this.totalContentions++; | ||
this.contentionPendingMap.set(ourNode, new Set([theirNode])); | ||
} | ||
|
||
has(ourNode) { | ||
return this.contentionPendingMap.has(ourNode); | ||
} | ||
|
||
// Removes contention entry ourNode -> theirNode. | ||
remove(ourNode, theirNode) { | ||
if (!this.contentionPendingMap.has(ourNode) || !this.contentionPendingMap.get(ourNode).has(theirNode)) return; | ||
|
||
this.contentionPendingMap.get(ourNode).delete(theirNode); | ||
if (this.contentionPendingMap.get(ourNode).size == 0) this.contentionPendingMap.delete(ourNode); | ||
this.totalContentions--; | ||
} | ||
|
||
// Removes all contentionPending entries for ourNode. | ||
// Since ourNode is strictly a NODE_OUTPUT, we should remove all contentions for the node when the | ||
// node resolves. | ||
removeAllContentionsForNode(ourNode) { | ||
if (!this.contentionPendingMap.has(ourNode)) return; | ||
|
||
const contentionsForOurNode = this.contentionPendingMap.get(ourNode); | ||
for (const theirNode of contentionsForOurNode) this.remove(ourNode, theirNode); | ||
} | ||
|
||
// Removes contention entry ourNode -> theirNode if the contention between them has resolved. | ||
removeIfResolved(ourNode, theirNode) { | ||
if (ourNode.bitWidth === theirNode.bitWidth && (ourNode.value === theirNode.value || ourNode.value === undefined)) | ||
this.remove(ourNode, theirNode); | ||
} | ||
|
||
removeIfResolvedAllContentionsForNode(ourNode) { | ||
if (!this.contentionPendingMap.has(ourNode)) return; | ||
|
||
const contentionsForOurNode = this.contentionPendingMap.get(ourNode); | ||
for (const theirNode of contentionsForOurNode) this.removeIfResolved(ourNode, theirNode); | ||
} | ||
|
||
size() { | ||
return this.totalContentions; | ||
} | ||
|
||
// Returns a list of [ourNode, theirNode] for all contentions. | ||
nodes() { | ||
var items = []; | ||
for (const [ourNode, contentionSet] of this.contentionPendingMap) { | ||
for (const theirNode of contentionSet) items.push([ourNode, theirNode]); | ||
} | ||
|
||
return items; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters