以下情况的输出应该是什么?

What should be the output in the following case?

在下面的例子中 o/p 应该是什么?我在不同的编译器上 运行 它,每个编译器得到不同的结果。

module top;
    reg a,b;
    function int  f(string s);
        $display("%s", s);
        return 1;
    endfunction

    initial begin
        $display(" Experiment 1 ");
        if (  f("hello") & (1==0))  begin
            $display(" 1 : if 1 is true");
        end

        $display(" Experiment 2 ");
        if ( (1==0) & f("hello"))  begin
            $display(" 2 : if 2 is true");
        end
        $display(" Experiment 3 ");
        if (  f("hello") && (1==0))  begin
            $display(" 3 : if 3 is true");
        end
        $display(" Experiment 4 ");
        if ( (1==0) && f("hello"))  begin
            $display(" 4 : if 4 is true");
        end
    end
endmodule

来自 lrm 11.4.7 逻辑运算符

The && and || operators shall use short circuit evaluation as follows:

  • The first operand expression shall always be evaluated.
  • For &&, if the first operand value is logically false then the second operand shall not be evaluated.
  • For ||, if the first operand value is logically true then the second operand shall not be evaluated.

据此,hello 应该 而不是 打印在 '4' 中。但是应该打印成'3'。

案例 1 和案例 2 可能易于优化。我在标准中找不到任何会阻止在那里优化功能的内容。所以,我相信 insisive 和 reviera 都表现正确。

不过看起来 synopsys 违反了标准。我的猜测是他们过度优化了案例“3”。