Verilog 中的 Casex 与 Casez

Casex vs Casez in Verilog

Verilog 中的 casexcasez 有什么区别? 我搜索了一下,找到了这句话:

casez treats all z values in the case alternatives or the case expression as don't cares. All bit positions with z can also represented by ? in that position.

casex treats all x and z values in the case item or the case expression as don't

关心。

例如,第一个和第二个有什么区别:

1-

casez (instr)
7'b1zzzzzzz: // arithmetic
7'b01zzzzzz: // load-reg
7'b00zzzzzz: // store-reg
endcase

2-

 casex (instr)
    7'b1zxxxxzz: // arithmetic
    7'b01zzxxxx: // load-reg
    7'b00xxxzzz: // store-reg
    endcase

Verilog 语言参考手册(现已被 SystemVerilog LRM 取代)对此进行了非常详细的解释。关键区别在于 case 表达式 instr 包含 x 或 z 值。请记住,casexcasez 都会查看 case 项 case 表达式 用于 x 和 z 值。我们称之为对称比较,因为无关值可以出现在任何一个地方。

因此,如果 instr 全部是 x,则 casez 中的 none 项将匹配,但 ALL 中的项将匹配casex 会匹配,模拟器会选择第一项。同样,如果 instr 都是 z,那么 ALL 项将匹配。我认为 casex 是一个无用的结构。

SystemVerilog 将这两个语句替换为 case() inside 语句。它使用非对称比较运算符 ==?,仅将 case 项 中的 x 或 z 视为无关紧要。