newbie
newbie

Reputation: 4789

Default statement in SystemVerilog Case

I'm trying to understand following scenario:

typedef enum logic [2:0] {
   ONE, TWO, THREE, FOUR, FIVE
} enum_t;

A case statement with enum_t type in case expression:

enum_t case_expression;
logic [2:0] result;

case (case_expression)
   ONE: result = 3'b000;
   TWO: result = 3'b001;
   THREE: result = 3'b010;
   FOUR: result = 3'b011;
   FIVE: result = 3'b100;
endcase

I'm not sure or clear about following :

I don't have much expereince in synthesis. So I would appreciate any feedback. Thanks!

Upvotes: 1

Views: 5544

Answers (3)

SSalvi
SSalvi

Reputation: 1

I believe "unique case" is a directive to synthesis tool mentioning all cases are enumerated. This would prevent a latch. If in simulation if none of the ENUM values are on the case expression, then during simulation a runtime error will be reported.

Upvotes: 0

Ravi m r
Ravi m r

Reputation: 1

If "case_expression" takes the value "x", the case statement will not be able to resolve which case to enter. If default case were to be mentioned, it would gracefully enter the default case. You will see runtime error if case_expression takes value of "x" if default is not mentioned.

Upvotes: 0

dave_59
dave_59

Reputation: 42623

This depends on how strongly typed your synthesis tool is. Unfortunately, there are a number of ways that your case_expression could have the value 3'b111 (through casting and poor error checking in some simulation tools). So its best to put the default in for safety's sake.

Upvotes: 0

Related Questions