为什么在 systemverilog 断言属性中不鼓励“if..else”语句?

问题描述

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

Basically,I want to check that output is equal to d1 when select signal is 0 and output is equal to d2 when select signal is 1.

enter image description here

我做了这样的事情:

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 似乎表明不应在 systemverilog 属性中使用 if..else 语句。为什么会这样?我做错了什么?为什么?

解决方法

我想,唯一的建议是避免编写大的属性。很容易弄乱代码。 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,select);
   @(posedge clk)
     (rst==0) && (en==1) |-> if (select) (out === d2) else (out === d1);
endproperty

甚至没有 if/else

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