RTL Reference
unique case and priority case
These keywords state what you promise about a case. The simulator checks the promise and synthesis relies on it.
Syntax
unique case (sel) // exactly one item matches
2'b01: y = a;
2'b10: y = b;
endcase
priority case (1'b1) // at least one matches; the first wins
req[0]: g = 0;
req[1]: g = 1;
endcaseRules
unique: the items do not overlap, and one always matches. They may be tested in parallel.unique0: the items do not overlap, but no match is allowed.priority: at least one item matches, and the order matters.- A broken promise gives a violation report in simulation.
- Synthesis trusts the promise. A value you did not list can then behave differently in hardware.
- A
defaultitem covers the unlisted values and is the safer choice.
Example
module tb;
logic [2:0] req;
logic [1:0] grant;
always_comb begin
grant = 2'd3;
priority case (1'b1)
req[0]: grant = 2'd0;
req[1]: grant = 2'd1;
req[2]: grant = 2'd2;
default: grant = 2'd3;
endcase
end
initial begin
req = 3'b100; #1 $display("req=%b grant=%0d", req, grant);
req = 3'b110; #1 $display("req=%b grant=%0d", req, grant);
req = 3'b111; #1 $display("req=%b grant=%0d", req, grant);
req = 3'b000; #1 $display("req=%b grant=%0d", req, grant);
end
endmodulereq=100 grant=2
req=110 grant=1
req=111 grant=0
req=000 grant=3Common Mistake
Using unique to silence a latch warning
always_comb
unique case (sel)
2'b00: y = a;
2'b01: y = b;
endcase // sel = 2 or 3: y is not assignedThe keyword tells synthesis that 2 and 3 never happen. If they do, simulation and hardware disagree.
Fix: Assign a default before the case, or add a default item.
Learn It Properly
These lessons teach it step by step, with practice problems.
Standard
IEEE 1800-2023, 12.5.3.