首页 > 解决方案 > 为什么 systemverilog 断言属性中不鼓励“if..else”语句?

问题描述

我正在为以下结构编写断言检查

基本上,我想检查选择信号为 0 时输出是否等于 d1,选择信号为 1 时输出是否等于 d2。

在此处输入图像描述

我做了这样的事情:

property check_mux_out (clk, rst, en, d1, output, d2, select);
   @(posedge clk)
   if (select)
      (rst==0) && (en==1) |-> (output === d2);
   else
      (rst==0) && (en==1) |-> (output === d1);
endproperty

a1: assert property (check_mux_out(inst1_clk, inst1_rst, latch_en, signal1, inst_out, signal2, inst_select)) else $error("ERROR: output not equal input");

但是,我从 https://verificationacademy.com/forums/systemverilog/conditional-statement-assertion-propertyhttps://verificationacademy.com/forums/systemverilog/clock-period-checker-sva发现了一些似乎暗示的帖子if..else 语句不应在 systemverilog 属性中使用。为什么会这样?我做错了什么,为什么?

标签: verilogsystem-veriloghdlsystem-verilog-assertions

解决方案


我想,唯一的建议是避免编写大属性。很容易弄乱代码。if/else 只是增加了大小并有可能进一步混淆它。

您的代码有语法错误。您不能将关键字outptut用作变量名。在if子句;之后,您的代码中还有一个额外的内容。

property check_mux_out (clk, rst, en, d1, out, d2, select);
   @(posedge clk)
   if (select)
      (rst==0) && (en==1) |-> (out === d2) // << no ';'
   else
      (rst==0) && (en==1) |-> (out === d1);
endproperty

你也可以用不同的方式重写它:

property check_mux_out (clk, rst, en, d1, out, d2, select);
   @(posedge clk)
     (rst==0) && (en==1) |-> if (select) (out === d2) else (out === d1);
endproperty

甚至没有 if/else

property check_mux_out (clk, rst, en, d1, out, d2, select);
   @(posedge clk)
  (rst==0) && (en==1) |-> (select) ? (out === d2) : (out === d1);
endproperty

推荐阅读