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

[docs] Add Cookbook entry for Verilog case equality (IsX) #4605

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Changes from 3 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
25 changes: 25 additions & 0 deletions docs/src/cookbooks/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,31 @@ compile(new TooWideOrNarrowUInt(8, 2))
compile(new TooWideOrNarrowUInt(8, 4))
```

## How can I use Verilog "case equality" operators in Chisel?

Verilog has "case equality" (`===`) and inequality (`!==`) operators.
They are typically used to ignore unknown (`X`) values in assertions.

Chisel does not support SystemVerilog `X` directly, but it is possible to check if a value is `X` with `chisel3.util.circt.isX`.
jackkoenig marked this conversation as resolved.
Show resolved Hide resolved
`isX` is commonly used to guard assertions against `X` which gives similar behavior to Verilog case equality.

```scala mdoc:silent:reset
import chisel3._
import chisel3.util.circt.IsX

class AssertButAllowX extends Module {
val in = IO(Input(UInt(8.W)))

// Assert that in is never zero; also do not trigger assert in the presence of X.
assert(IsX(in) || in =/= 0.U, "in should never equal 0")
}
```

```scala mdoc:invisible
// Hidden but will make sure this actually compiles
chisel3.docs.emitSystemVerilog(new AssertButAllowX)
```

## Predictable Naming

### How do I get Chisel to name signals properly in blocks like when/withClockAndReset?
Expand Down