If 语句是否会停止检查是否满足第一个 OR 条件?
Will an If statement stop checking if the first OR condition is met?
SystemVerilog 是评估整个 if
语句还是评估最小值以获得结果?
例如:
if (condition1 && condition2) begin
...
end
if (condition1 || condition2) begin
...
end
第一种情况,如果condition1
为False,是否会计算condition2
?
在第二种情况下,如果 condition1
为真,是否会评估 condition2
?
此行为也称为 short-circuit evaluation。
参考 IEEE 1800-2017,第 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.
因此,对于您的 if
语句中的运算符,可能不会计算所有表达式。
要查看哪些运算符具有相似的行为,哪些没有,请参阅第 11.3.5 节 运算符表达式短路。
SystemVerilog 是评估整个 if
语句还是评估最小值以获得结果?
例如:
if (condition1 && condition2) begin
...
end
if (condition1 || condition2) begin
...
end
第一种情况,如果condition1
为False,是否会计算condition2
?
在第二种情况下,如果 condition1
为真,是否会评估 condition2
?
此行为也称为 short-circuit evaluation。
参考 IEEE 1800-2017,第 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.
因此,对于您的 if
语句中的运算符,可能不会计算所有表达式。
要查看哪些运算符具有相似的行为,哪些没有,请参阅第 11.3.5 节 运算符表达式短路。