verilog - 为什么 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-property 和 https://verificationacademy.com/forums/systemverilog/clock-period-checker-sva发现了一些似乎暗示的帖子if..else 语句不应在 systemverilog 属性中使用。为什么会这样?我做错了什么,为什么?
解决方案
我想,唯一的建议是避免编写大属性。很容易弄乱代码。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
推荐阅读
- java - 如何将字符串传递给 mybatis 集合列中的参数?
- tensorflow - Implement custom loss function in Tensorflow 2.0
- node.js - 打字稿忽略 MakeDirectoryOptions 的 fs.d.ts 定义
- css - 如何在css中保持纵横比?
- python - Python 列表组合
- javascript - 这个JQuery可编辑内容代码有什么解决方案吗
- python - 如何使用 Flask 处理事件流中的异常
- python - Python tkinter after method causes window to freeze
- antlr4 - 如何摆脱词汇模式
- javascript - 关于在柏树中排序表的断言