VERILOG031: “default” should be the last item of a “case” statement
Summary
| Reliability | Security | Maintainability | Code attribute | Effort to fix | Tags |
|---|---|---|---|---|---|
| - | - | MEDIUM | Intentionality | Clear | 5min | synthesis, readability, vscode, simulation, linter |
Description
Related rules
Move the default clause to the end of the case statement.
Noncompliant code example
unique casez (select) default: operand = '0; // Noncompliant: Should be moved to the end 3'b000: operand = accum0 >> 0; 3'b001: operand = accum0 >> 1; 3'b010: operand = accum1 >> 0; 3'b011: operand = accum1 >> 1; 3'b1??: operand = regfile[select[1:0]]; endcase
Compliant solution
unique casez (select) 3'b000: operand = accum0 >> 0; 3'b001: operand = accum0 >> 1; 3'b010: operand = accum1 >> 0; 3'b011: operand = accum1 >> 1; 3'b1??: operand = regfile[select[1:0]]; default: operand = '0; endcase
To improve readability, default should be the last item of a case statement.
Parameters
No parameters.