Skip to content

Commit

Permalink
Gates should output X (never Z) when inputs are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
dmetis committed Jul 20, 2023
1 parent ad73088 commit ed1eaca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
15 changes: 14 additions & 1 deletion lib/src/modules/conditional.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,14 @@ class ConditionalAssign extends Conditional {
guard(driver);
}

_receiverOutput.put(driverValue(driver));

final currentValue = driverValue(driver);
if (!currentValue.isValid ){
_receiverOutput.put(LogicValue.x);
}
else{
_receiverOutput.put(currentValue);
}

if (!drivenSignals.contains(receiver) || receiver.value.isValid) {
drivenSignals.add(receiver);
Expand Down Expand Up @@ -965,6 +972,12 @@ class Case extends Conditional {
}
return;
}

for (final receiver in receivers) {
receiver.put(LogicValue.x);
}



CaseItem? foundMatch;

Expand Down
6 changes: 3 additions & 3 deletions lib/src/modules/gates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,11 @@ class Mux extends Module with InlineSystemVerilog {
/// Executes the functional behavior of the mux.
void _execute() {
if (!_control.value.isValid) {
out.put(_control.value);
out.put(LogicValue.x);
} else if (_control.value == LogicValue.zero) {
out.put(_d0.value);
out.put(_d0.value.isValid ? _d0.value : LogicValue.x);
} else if (_control.value == LogicValue.one) {
out.put(_d1.value);
out.put(_d1.value.isValid ? _d1.value : LogicValue.x);
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/src/utilities/simcompare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class Vector {
}
return arrAssigns.toString();
} else {
return '$signalName = ${inputValues[signalName]};';
final signalVal =
LogicValue.of(inputValues[signalName], width: signal.width);
return '$signalName = $signalVal;';
}
}).join('\n');

Expand Down
18 changes: 15 additions & 3 deletions test/gate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,25 @@ void main() {
test('Mux bus', () async {
final mod = MuxWrapper(Logic(), Logic(width: 8), Logic(width: 8));
await mod.build();
final vectors = [
final vector1 = [
Vector({'control': 1, 'd0': 12, 'd1': 15}, {'y': 15}),
Vector({'control': 0, 'd0': 18, 'd1': 7}, {'y': 18}),
Vector({'control': 0, 'd0': 3, 'd1': 6}, {'y': 3}),
Vector({'control': 0, 'd0': 10, 'd1': LogicValue.z}, {'y': 10}),
Vector({'control': 1, 'd0': LogicValue.z, 'd1': 6}, {'y': 6}),
];
await SimCompare.checkFunctionalVector(mod, vectors);
final simResult = SimCompare.iverilogVector(mod, vectors);

final vector2 = [
Vector(
{'control': 1, 'd0': 6, 'd1': LogicValue.z}, {'y': LogicValue.x}),
Vector(
{'control': LogicValue.z, 'd0': 10, 'd1': 6}, {'y': LogicValue.x}),
Vector(
{'control': 0, 'd0': LogicValue.z, 'd1': 10}, {'y': LogicValue.x}),
];

await SimCompare.checkFunctionalVector(mod, vector1 + vector2);
final simResult = SimCompare.iverilogVector(mod, vector1);
expect(simResult, equals(true));
});

Expand Down

0 comments on commit ed1eaca

Please sign in to comment.