verilog 不定态(X态)传播

15 篇文章 6 订阅

verilog语法中if else 和case语句是不能传递x态的。if(1'bx)会默认为0即false,对于case(1'bx),如果有默认default的分支语句,则会匹配到default的语句,如果没有default语句则不会匹配到任何语句。如下代码和波形:

module top_module();
 
    reg sel;
    reg [1:0]out1;
    reg [1:0]out2;
    reg [1:0]out3;
    wire [2:0]out4;
    reg [2:0]out5;
    
    `probe(out1);
    `probe(out2);
    `probe(out3);
    `probe(out4);
    `probe(out5);
    `probe(sel);
    initial `probe_start;
    
    initial begin
        sel<=0;
        #10;
        sel<=1;
        #10;
        sel<=0;
        #10;
        sel<=1'bx;
        #10;
        $finish;
    end
    
    always @(*)begin
        if (sel)
            out1 = 2'b11;
        else 
            out1 = 2'b00;
    end
    always @(*)begin
        case (sel)
            1'b1: out2 = 2'b11;
            1'b0: out2 = 2'b00;
            default: out2 = 2'b01;
        endcase
    end
 
    always @(*)begin
        case (sel)
            1'b1: out3 = 2'b11;
            1'b0: out3 = 2'b00;
        endcase
    end
 
    assign out4 = sel ? 2'b11 : 2'b00;
    
    always @(*) begin
        out5 = sel ? 2'b11 : 2'b00;
    end
 
endmodule

波型:

 这样的问题是:如果使用if和case由于其不能传递X态,因此在仿真时就不能很好的去debug和不定态相关的bug。所以在代码中尽量使用assign+条件表达式(其实本质上是条件表达式,比如out5没有使用assign)代替case和if else。IEEE官方语法手册中写道,条件表达式,在条件是x时,表达式结果是后两个表达式结果的按位计算结果,计算规则如下:

If expression1 evaluates to ambiguous value ( x or z), then both expression2 and expression3 shall be evaluated and their results shall be combined, bit by bit, using Table 28 to calculate the fifinal result unless expression2 or expression3 is real, in which case the result shall be
0 . If the lengths of expression2 and expression3 are different, the shorter operand shall be lengthened to match the longer and zero-fifilled from  the left (the high-order end).

vcs中提供的编译选项-xprop=tmerge/xmerge可以扩散X态传播。

 如上所述,tmerge更符合实际硬件表象,所以用的更多。

除此之外,默认如果不加-xprop选项,那么默认是vmerge模式,即verilog语法模式。

综上vmerge是最乐观的,tmerge最符合实际电路,xmerge最悲观。

具体可以见下面这个例子:

使用xprop config文件xprop.cfg:

merge = xmerge;
tree {top} {xpropOff};
instance {top.DUT} {xpropOn};
module   {dwc_mipi_cdphy_rx_4l3t_ns} {xpropOff};
instance {top.DUT.lb_mipi_rx_top_pre_u.mipi_csi_rx_uint0.mipi_csi_rx_uint_pre.wrapper_dwc_mipi_csi2_rx.cdphy_u}  {xpropOff};
instance {top.DUT.lb_mipi_rx_top_pre_u.mipi_csi_rx_uint1.mipi_csi_rx_uint_pre.wrapper_dwc_mipi_csi2_rx.cdphy_u}  {xpropOff};
instance {top.DUT.lb_mipi_rx_top_pre_u.mipi_csi_rx_uint2.mipi_csi_rx_uint_pre.wrapper_dwc_mipi_csi2_rx.cdphy_u}  {xpropOff};
instance {top.DUT.lb_mipi_rx_top_pre_u.mipi_csi_rx_uint3.mipi_csi_rx_uint_pre.wrapper_dwc_mipi_csi2_rx.cdphy_u}  {xpropOff};
instance {top.DUT.lb_mipi_rx_top_pre_u.mipi_csi_rx_uint4.mipi_csi_rx_uint_pre.wrapper_dwc_mipi_csi2_rx.cdphy_u}  {xpropOff};
instance {top.DUT.lb_mipi_rx_top_pre_u.mipi_csi_rx_uint5.mipi_csi_rx_uint_pre.wrapper_dwc_mipi_csi2_rx.cdphy_u}  {xpropOff};

VCS X-Propagation是一种用于Verilog仿真的选项,用于控制X(未定义或未初始化的值)的传播行为。根据引用\[1\],VCS X-Propagation提供了两种模式:C模式和F模式。在C模式下,如果遇到0 & x的情况,结果将为0,X传播终止;类似地,1 || x的情况下,结果为1。而在F模式下,如果遇到0 & x的情况,结果将为x,1 || x的情况下,结果也为x,X将一直传播下去。 此外,引用\[2\]提到了使用assign语句的原因。尽管if-else和case语句在RTL中不传播X,但使用assign语句可以及时暴露X问题,避免由于RTL写法原因而掩盖X导致的问题。 总结来说,VCS X-Propagation提供了控制X传播行为的选项,C模式和F模式分别决定了X在特定情况下的传播结果。同时,使用assign语句可以帮助及时发现和解决X相关的问题。 #### 引用[.reference_title] - *1* [vcs -xprop的理解](https://blog.csdn.net/weixin_45270982/article/details/113569281)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [X 及基于 VCS 的 X-Propagation 检测](https://blog.csdn.net/weixin_40357487/article/details/129996971)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值