Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit case default #13

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2159,25 +2159,37 @@ default to be implicitly defined. Case statements without a `default` branch
can cause signals to be undriven. Setting default values of signals at the top
of an `always` procedures is good practice and ensures that signals are never
metastable when a case match fails. For example,

```sv
always_comb begin
y = 0;
case(x)
case (x)
1: y = 1;
endcase
end

```
If the case match fails, `y` wouldn't infer memory or be undriven because the
default value is defined before the `case`.

If the case match on `x` fails, `y` would not infer memory or be undriven
because the default value is defined before the `case`.

This rule is a more lenient version of `case_default`. It adapts to a specific
coding style of setting default values to signals at the top of a procedural
block to ensure that signals have a default value regardless of the logic in the
procedural block. As such, this rule will only consider values set
**unconditionally** at the top of the procedural block as a default and will
disregard assignments made in conditional blocks like `if`/`else`, etc. If this
coding style is not preferred, it is strongly suggested to use the rules
mentioned below as they offer stricter guarantees.

See also:
- **case_default**
- **explicit_case_default**

- **case_default**
- **explicit_case_default**

The most relevant clauses of IEEE1800-2017 are:
- 12.5 Case statement

- 12.5 Case statement



Expand Down
24 changes: 18 additions & 6 deletions md/syntaxrules-explanation-implicit_case_default.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ default to be implicitly defined. Case statements without a `default` branch
can cause signals to be undriven. Setting default values of signals at the top
of an `always` procedures is good practice and ensures that signals are never
metastable when a case match fails. For example,

```sv
always_comb begin
y = 0;
case(x)
case (x)
1: y = 1;
endcase
end

```
If the case match fails, `y` wouldn't infer memory or be undriven because the
default value is defined before the `case`.

If the case match on `x` fails, `y` would not infer memory or be undriven
because the default value is defined before the `case`.

This rule is a more lenient version of `case_default`. It adapts to a specific
coding style of setting default values to signals at the top of a procedural
block to ensure that signals have a default value regardless of the logic in the
procedural block. As such, this rule will only consider values set
**unconditionally** at the top of the procedural block as a default and will
disregard assignments made in conditional blocks like `if`/`else`, etc. If this
coding style is not preferred, it is strongly suggested to use the rules
mentioned below as they offer stricter guarantees.

See also:
- **case_default**
- **explicit_case_default**

- **case_default**
- **explicit_case_default**

The most relevant clauses of IEEE1800-2017 are:
- 12.5 Case statement

- 12.5 Case statement
Loading