casez,casex and case

在case语句中,敏感表达式与各项值之间的比较,是一种全等比较。

casez与casex语句是case语句的两种变体,三者的表示形式中唯一的区别是三个关键词case、casez、casex的不同。

  • 在casez语句中,如果分支表达式某些位的值为高阻z,那么对这些位的比较就会忽略,不予考虑,而只关注其他位的比较结果。
  • 在casex语句中,则把这种处理方式进一步扩展到对x的处理,即如果比较双方有一方的某些位的值是z或x,那么这些位的比较就不予考虑。

case  treats 'z' & 'x'  as it is
casez treats 'z'        as don't care 
casex treats 'z' & 'x'  as don't care

case:

case (sel) 
    2'b00:      y = a; 
    2'b01:      y = b; 
    2'bx0:      y = c; 
    2'b1x:      y = d; 
    2'bz0:      y = e; 
    2'b1?:      y = f; 
    default :   y = g; 
endcase
Result:  
    sel     y  case item 
    00      a  00 
    11      g  default 
    xx      g  default 
    x0      c  x0 
    1z      f  1? 
    z1      g  default
casez:
casez (sel) 
    2'b00:      y = a; 
    2'b01:      y = b; 
    2'bx0:      y = c; 
    2'b1x:      y = d; 
    2'bz0:      y = e; 
    2'b1?:      y = f; 
    default:    y = g; 
endcase
Result:  
    sel     y  case item 
    00      a  00 
    11      f  1? 
    xx      g  default  
    x0      c  x0 (would have matched with z0(item 5) if item 3 is not present.) 
    1z      d  1x (would have matched with z0(item 5) & 1?(item 6) also.) 
    z1      b  01 (would have matched with 1?(item 6) also.)
casex:
casex (sel) 
    2'b00   :   y = a; 
    2'b01   :   y = b; 
    2'bx0   :   y = c; 
    2'b1x   :   y = d; 
    2'bz0   :   y = e; 
    2'b1?   :   y = f; 
    default :   y = g; 
endcase
Result:  
    sel     y  case item 
    00      a  00 
    11      d  1x (would have matched with 1? also) 
    xx      a  00 (would have matched with 1? also) 
    x0      a  00 (would have matched with all items except 01) 
    1z      c  x0 (would have matched with all items except 00,01) 
    z1      b  01 (would have matched with 1x, 1? also)