Skip to content

Commit 5d68bea

Browse files
jackkoenigmwachs5
andauthored
[docs] Add Cookbook entry for Verilog case equality (IsX) (#4605)
Co-authored-by: Megan Wachs <[email protected]>
1 parent 05d2622 commit 5d68bea

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/src/cookbooks/cookbook.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,31 @@ compile(new TooWideOrNarrowUInt(8, 2))
897897
compile(new TooWideOrNarrowUInt(8, 4))
898898
```
899899

900+
## How can I use Verilog "case equality" operators in Chisel?
901+
902+
Verilog has "case equality" (`===`) and inequality (`!==`) operators.
903+
They are typically used to ignore unknown (`X`) values in assertions.
904+
905+
Chisel does not support Verilog `X` directly, but it is possible to check if a value is `X` with `chisel3.util.circt.isX`.
906+
`isX` is commonly used to guard assertions against `X` which gives similar behavior to Verilog case equality.
907+
908+
```scala mdoc:silent:reset
909+
import chisel3._
910+
import chisel3.util.circt.IsX
911+
912+
class AssertButAllowX extends Module {
913+
val in = IO(Input(UInt(8.W)))
914+
915+
// Assert that in is never zero; also do not trigger assert in the presence of X.
916+
assert(IsX(in) || in =/= 0.U, "in should never equal 0")
917+
}
918+
```
919+
920+
```scala mdoc:invisible
921+
// Hidden but will make sure this actually compiles
922+
chisel3.docs.emitSystemVerilog(new AssertButAllowX)
923+
```
924+
900925
## Predictable Naming
901926

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

0 commit comments

Comments
 (0)