admin管理员组文章数量:1623793
SystemVerilog对于case/casez/casex语句新增了两个特殊的修饰符:unique及priority。其语法规则如下:
unique case (<case_expression>)
... // case items
endcase
priority case (<case_expression>)
... // case items
endcase
一、unique case
case_expression同时只能匹配一个case_selection_items;一个case_selection_items必须存在与之对应的case_expression。unique修饰符显式指明了该case语句是完整的且并行的,各case分支之间彼此互斥,没有交叠。
When the unique modifier is added, all software tools, including simulators, will generate a warning any time the case statement is executed and the case expression matches multiple case items.
When a case, casez, or casex statement is specified as unique, software tools will issue a run-time warning if the value of the case expression does not match any of the case selection items, and there is no default case.
二、priority case
至少有一个case_selection_items需要匹配case_expression;如果存在多个case_selection_items匹配case_expression,则第一个匹配的分支将会被执行。如果设计者的意图就是可能存在多个case_selection_items同时会匹配上case_expression,那么case_selection_items分支的顺序就显得尤为重要。例如下面这段程序:
always_comb
priority case (1’b1)
irq0: irq = 4’b0001;
irq1: irq = 4’b0010;
irq2: irq = 4’b0100;
irq3: irq = 4’b1000;
endcase
三、与full/parallel_case对比
对于综合而言,unique case等效为full_case+parallel_case,而priority case则等效为full_case。值得注意的是,unique case和priority case是SV语法,而full_case和parallel_case是编译选项。
unique case能够实现与full_case+parallel_case相同的效果,priority case能够实现与full_case相同的效果;除此之外,unique case和priority case还会增加额外的run-time检查,确保case语句设计的正确性,是符合设计者意图的,而后者并不会有这种检查。如参考文档《关于full_case和parallel_case属性》提到的,full_case或parallel_case的使用容易引起错误,造成前仿和后仿结果的不一致,不建议使用,而代之以规范的case编码规范。而若使用unique case或priority case,则会自动引入额外的run-time check来确保case设计的规范性及正确性,并且设计意图更加直观明了。所以推荐使用unique case和priority case,切勿使用full_case和parallel_case编译选项。
四、参考文档
《SystemVerilog for Design》
关于full_case和parallel_case属性
版权声明:本文标题:关于unique case和priority case语法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1728896682a1178501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论