Systemverilog Enhancements Priority Unique Unique
Systemverilog Enhancements Priority Unique Unique
Priority/Unique/Unique0
Clifford E. Cummings
Sunburst Design, Inc.
14355 SW Allen Blvd., Suite #100
Beaverton, OR 97005
1-503-641-8446
[email protected]
3. PARALLEL_CASE BASICS
When an engineer declares that a case statement is a
parallel_case case statement, the engineer is asserting that
it is only possible to match the case expression to one and only
one (or none) of the case items. The engineer has declared that the
case expression shall only uniquely match up to only one of the that is tested during simulation, and (2) if during simulation a
case items. priority case command is executed but the case expression
does not match any of the case items, the simulator will report a
This declaration is intended to inform the synthesis tool that no
warning or violation (see sections 7 and 8).
priority encoders are required to build the logic in the case
statement and that each tested case item in the case statement When an engineer adds the priority keyword to a case
can be treated as if it were a unique if statement. The resultant statement, the engineer has assumed that it is only possible to
logic would be both smaller and faster than if the case items had match the defined case items in the case statement and therefore
been assembled into a set of priority logic. it is safe to treat all other potential matching patterns as don't-
cares. If during simulation, none of the listed case items matches
Like the full_case directive, the biggest problem with the
the case expression, then the engineer's initial assumption was
parallel_case directive is that it is a potential command to wrong and it should be flagged as some form of violation for the
the synthesis tool but it is a comment to the simulator, so if the engineer to fix, because the synthesis tool has been directed to
parallel_case directive causes the synthesis tool to take treat the unspecified pattern as a don't-care. From a designer's
actions to optimize the design, those same optimizations will not perspective, the best simulation behavior under these
be executed by the simulator, which again makes it possible to circumstances would be to abort the simulation with a violation
have a mismatch between pre- and post-synthesis simulations. message (see sections 8 and 9). This would help eliminate
This again can be the source of design problems in the final incorrect design assumptions that could cause the design to have a
synthesized design. fatal design flaw.
always_comb begin
y = '0;
unique0 case ({en,a})
3'b100 : y[a]='1;
3'b101 : y[a]='1;
3'b110 : y[a]='1;
3'b111 : y[a]='1;
endcase
end
endmodule
Example 4 - SystemVerilog-2009 unique0 case decoder to
Figure 2 - 2-to-4 Decoder with dangling enable - WRONG replicate parallel_case functionality
synthesis result
One of the nice features of the unique0 keyword is that it forces
Since unique is a recognized simulation keyword with the simulator to ensure that either none or only one of the case
simulation semantics, the simulation should report a violation items can be reached during execution of any case statement.
whenever the always_comb procedure is executed when en =
0. When one compares making a pre-default assignment prior to a
case statement, to adding a case-default, I have found that
For the 2-to-4 decoder model, it is desirable to add uniqueness making the pre-default assignment is both more effective at
testing without adding the full_case testing and optimization. removing latches and typically yields equal or better synthesis
Prior the to addition of the unique0 keyword, in order to cancel
results. Why does a pre-default remove latches better than a priority/unique cannot be reliably used because it is too
case-default? easy for design errors to go unnoticed. Engineers have requested a
more strongly tested version of the same constructs; hence, the
Consider the 2-to-4 decoder with case-default in Example 5.
SystemVerilog-2009 violation enhancement of the next section.
module dec2_4e (
output logic [3:0] y, 8. SYSTEMVERILOG-2009 VIOLATIONS
input logic [1:0] a, (*NEW*)
input logic en);
In SystemVerilog-2009, a new type of violation checking replaces
the SystemVerilog-2005 warning checks for unique and
always_comb begin
unique case ({en,a}) priority constructs, as well as the new unique0 construct.
3'b100 : y[a]='1; Strictly speaking, the violation checking is not a stronger check; it
3'b101 : y[a]='1; is just a different check, but with user encouragement, we might
3'b110 : y[a]='1; convince EDA vendors to turn the violation into a stronger check
3'b111 : y[a]='1; (see section 9).
default: y = '0; Clause 12.4.2.1 of the new SystemVerilog-2009 standard states:
endcase
end A unique, unique0, or priority violation check is
endmodule evaluated at the time the statement is executed, but violation
Example 5 - ERROR - 2-to-4 decoder with case-default - reporting is deferred until the Observed region of the current
infers latches time step.
In this decoder example, the combination of unique case with
case-default appears to have all possible cases covered, but Since all module RTL code is executed in the Active Region set
the common mistake is that the explicit case items only set one of that includes the Active events region where all of the properly
the four outputs, which means that the other three outputs must coded[2] always_comb procedures are executed, the
remain unchanged (they must be latched). combinational logic will iterate and settle out within the Active
region before any violations can be reported in the Observed
It is very easy to make a latch-inference coding mistake using a region (see Figure 3).
case-default when multiple outputs are assigned in the same
case statement. If the same case-default is repositioned to
be a pre-default assignment at the top of the always_comb
block, then all latches will be removed. As long as all outputs are
assigned to anything (even X's) at the top of the procedure, no
latch inference will occur. This technique is simple, effective and
synthesis efficient.
7. SYSTEMVERILOG-2005 WARNINGS
SystemVerilog-2005 requires a simulator to report warnings if a Figure 3 - SystemVerilog-2009 Event Scheduling - Violation
priority or unique test-expression does not match any of the checks in Observed Region
listed case items or if-tests.
Consider the fully coded 2-to-1 mux example based on the
SystemVerilog-2005 similarly requires a simulator to report example code in clause 12.5.3.1 of the IEEE SystemVerilog-2009
warnings if a unique case test-expression would match more Standard.
than one of the listed case items during simulation, or if more than The descriptions in 12.5.3 mentions several cases in which a
one of the unique if-test conditions would match during violation report shall be generated by unique-case, unique0-
simulation. case, or priority-case statements. These violation checks
The priority testing is essentially a strict must-match test shall be immune to false violation reports due to zero-delay
while the unique testing is essentially a strict onehot test. glitches in the active region set (see 4.4.1).
In this example the unique case is checking for overlap in the If vendors are unwilling to provide the abort-on-violation
two case_item selects. When a and not_a are in states 0 and 1 capability, then this enhancement has done nothing more than to
respectively and a transitions to 1, the following sequence of change the warning messages from "warning" to "violation" and
events can happen (see Figure 4): little has been gained.
(1) a changes from 0 to 1, which would cause process a1 and Engineers, unite! Tell your vendors that you would like a vendor
b1 to trigger with indeterminate order. For this example, option (such as a command line switch) to force
assume that process b1 triggers first. priority/unique violations to cause the simulation to abort.
(2) Process b1 triggers and both a and not_a both 10. ACKNOWLEDGEMENTS
momentarily have the values of 1. My thanks to my friends and colleagues Heath Chambers of HMC
Design Verification and Shalom Bresticker of Intel Israel for
(2a) In process b1, the unique case could be executed while a
offering valuable suggestions to improve the quality and content
and not_a are both true, so the violation check for of this paper.
uniqueness will fail, and the scheduled failure will be
reported in the Observed region.
11. REFERENCES [4] "IEEE Standard Verilog Hardware Description Language,"
[1] Clifford E. Cummings, '"full_case parallel_case", the Evil IEEE Computer Society, IEEE, New York, NY, IEEE Std
Twins of Verilog Synthesis,' SNUG'99 Boston Proceedings, 1364-2001
Boston, MA, 1999. Also available at [5] "IEEE Standard For SystemVerilog - Unified Hardware
www.sunburst-design.com/papers Design, Specification and Verification Language," IEEE
[2] Clifford E. Cummings, “Nonblocking Assignments in Computer Society, IEEE, New York, NY, IEEE Std 1800-
Verilog Synthesis, Coding Styles That Kill!,” SNUG-2000 2005
proceedings, March 2000. Also available at [6] "IEEE Standard For SystemVerilog - Unified Hardware
www.sunburst-design.com/papers Design, Specification and Verification Language," IEEE
[3] Don Mills and Clifford E. Cummings, “RTL Coding Styles Computer Society, IEEE, New York, NY, IEEE Std 1800-
That Yield Simulation and Synthesis Mismatches,” SNUG- 2009
1999 Proceedings, March 1999. Also available at [7] "SystemVerilog 3.0 Accellera's Extensions to Verilog,"
www.lcdm-eng.com/papers.htm and www.sunburst- Accellera, 2002, freely downloadable from:
design.com/papers www.systemverilog.org