Skip to content

Commit

Permalink
Implement ==? !=?
Browse files Browse the repository at this point in the history
  • Loading branch information
povik committed Sep 28, 2024
1 parent 767384d commit f27f116
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ SigSpec RTLILBuilder::Unop(IdString op, SigSpec a, bool a_signed, int y_width)
OP(reduce_and)
OP(reduce_xor)
OP(reduce_xnor)
OP(reduce_bool)
#undef OP
}

Expand Down
5 changes: 5 additions & 0 deletions src/diag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace diag {
slang::DiagCode UnrollLimitExhausted(slang::DiagSubsystem::Netlist, 1022);
slang::DiagCode NoteLoopContributes(slang::DiagSubsystem::Netlist, 1023);

slang::DiagCode NonconstWildcardEq(slang::DiagSubsystem::Netlist, 1023);

slang::DiagGroup unsynthesizable("unsynthesizable", {IffUnsupported, SignalSensitivityAmbiguous, GenericTimingUnsyn, BothEdgesUnsupported, ExpectingIfElseAload,
IfElseAloadPolarity, IfElseAloadMismatch});
slang::DiagGroup sanity("sanity", {EdgeImplicitMixing});
Expand Down Expand Up @@ -88,6 +90,9 @@ namespace diag {

engine.setMessage(NoteLoopContributes, "loop contributes to unroll tally");
engine.setSeverity(NoteLoopContributes, slang::DiagnosticSeverity::Note);

engine.setMessage(NonconstWildcardEq, "wildcard equality unsynthesizable with non-constant right operand");
engine.setSeverity(NonconstWildcardEq, slang::DiagnosticSeverity::Error);
}
};
};
1 change: 1 addition & 0 deletions src/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern slang::DiagCode MemoryNotInferred;
extern slang::DiagCode NoteUsageBlame;
extern slang::DiagCode UnrollLimitExhausted;
extern slang::DiagCode NoteLoopContributes;
extern slang::DiagCode NonconstWildcardEq;
void setup_messages(slang::DiagnosticEngine &engine);
};
};
25 changes: 23 additions & 2 deletions src/slang_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,29 @@ RTLIL::SigSpec SignalEvalContext::operator()(ast::Expression const &expr)
RTLIL::SigSpec left = (*this)(biop.left());
RTLIL::SigSpec right = (*this)(biop.right());

bool invert;
switch (biop.op) {
case ast::BinaryOperator::WildcardEquality:
invert = false;
if (0) {
case ast::BinaryOperator::WildcardInequality:
invert = true;
}
if (!right.is_fully_const()) {
// TODO: scope
netlist.realm.addDiag(diag::NonconstWildcardEq, expr.sourceRange);
ret = netlist.canvas->addWire(NEW_ID, expr.type->getBitstreamWidth());
return ret;
}
return netlist.Unop(
invert ? ID($logic_not) : ID($reduce_bool),
netlist.EqWildcard(left, right),
false, expr.type->getBitstreamWidth()
);
default:
break;
}

bool a_signed = biop.left().type->isSigned();
bool b_signed = biop.right().type->isSigned();

Expand All @@ -1853,8 +1876,6 @@ RTLIL::SigSpec SignalEvalContext::operator()(ast::Expression const &expr)
case ast::BinaryOperator::GreaterThan: type = ID($gt); break;
case ast::BinaryOperator::LessThanEqual: type = ID($le); break;
case ast::BinaryOperator::LessThan: type = ID($lt); break;
//case ast::BinaryOperator::WildcardEquality;
//case ast::BinaryOperator::WildcardInequality;
case ast::BinaryOperator::LogicalAnd: type = ID($logic_and); break;
case ast::BinaryOperator::LogicalOr: type = ID($logic_or); break;
case ast::BinaryOperator::LogicalImplication: type = ID($logic_or); left = netlist.LogicNot(left); a_signed = false; break;
Expand Down
17 changes: 17 additions & 0 deletions tests/various/expr.sv
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,21 @@ function automatic [7:0] f();
endfunction
initial $t(f());

initial begin
$t(4'b0110 ==? 4'b0z10);
$t(4'b0010 ==? 4'b0z10);
$t(4'b1110 ==? 4'b0z10);
$t(4'b0101 ==? 4'bzz01);
$t(4'b1001 ==? 4'bzz01);
$t(4'b1011 ==? 4'bzz01);
$t(4'bzzzz ==? 4'b0000);
$t(4'b0110 ==? 4'b0x10);
$t(4'b0010 ==? 4'b0x10);
$t(4'b1110 ==? 4'b0x10);
$t(4'b0101 ==? 4'bxx01);
$t(4'b1001 ==? 4'bxx01);
$t(4'b1011 ==? 4'bxx01);
$t(4'bxxxx ==? 4'b0000);
end

endmodule

0 comments on commit f27f116

Please sign in to comment.