Systemverilog中operators和expression的记录

1. Equality operators

Equality operators有三种:

  • Logical equality:==, !=,该运算符中如果运算数包含有x/z态,那么结果就是x态。只有在两边的bit都不包含x/z态,最终结果才会为0(False)或1(True)
  • Case equality:===, !==,该运算符中会把两边运算数的x/z态都考虑进去,最终结果肯定是0或1
  • Wildcard equality:==?, !=?,该运算符的右边是wildcard匹配,右边操作数的x或z bit对应于左边的bit可以为任何数字,但左边的x或z不能被认为是wildcard。因此该运算符的结果可能有x/0/1三种结果,如果左边的x/z态不能被右边的wildcard匹配,那么结果就是x态,如果左边的x/z态会被右边的wildcard匹配,那么结果就为0/1

2. short circuit evaluation

只有&&, ||, ->, ?: 可以用short circuit evaluation方法,该方法如下:

第一个operand表达式肯定会被evaluated,对于&&,如果第一个operand结果为false,那么后续的operands就不会evaluated,对于||,如果第一个operand结果是true,那么后续的operands不会被operands。

对于条件运算符(cond_predicate ? expr1 : expr2),如果cond_predicate为True,那么第一个expr1会被evaluated如果cond_predicate为False,那么第二个expr2会被evaludated。如果cond_predicate为x或z态,那么将具体情况具体分析,根据expr1和expr2的值来决定,如下表所示:

3. shift operators

Shift operators有两种类型:logical shift operators(<<, >>)和arithmetic shift operators(<<<, >>>>)。对于左移操作符<<和<<<,空出的bits位补0。对于右移操作符>>和>>>,logical right shift移出的空位bit补0;arithmetic right shift操作如果是对unsigned变量移位,那么也是补0,如果是对signed变量移位,那么需要根据signed变量的最高位来移位,如果operand中含有x/z态bit,那么结果是unknown的。

4. set membership operator

inside左边的expression是singular expression。inside的右边是用逗号分隔的expression或range列表,如果expression是unpacked array,那么它将自动会被展开直到为singular value。open_range_list的value可以重复,所以values和value ranges可以有overlap。

对于非整形expression,inside是采用logical equality(==)运算符来比较的。对于整形expression,inside是使用wildcard equality(==?)来比较的,所以range_list中expression含有的x/z bit不参与比较,但左边的x/z仍然是需要比较的。

inside没有匹配到相等的expression时,如果一些comparison里结果时x,那么将整体返回1'bx。

inside中range的指定时采用[low_bound : high_bound]的方式,$可以可以用于代表左边expression中最小或最大值。如果[:]中左边的值大于右边的值,那么该range会被认为时无效的,没有包含任何value。

5. vector bit-select and part-select addressing

bit-select是从vector、packed arrary、packed structure、parameter或concatenation中选出特定的bits。bit-select或part-select对scalar或real variable或real parameter进行操作是非法的。

有两种类型的part-select:

  • non-indexed part-select:使用vect[msb_expr:lsb_expr]格式,msb_expr和lsb_expr必须是整型恒量表达式,第一个expr应该比第二个expr寻址到更significant bit。
  • indexed part-select语法如下:前两个选择bit从base开始,并逐渐按bit range上升,后两个选择bit从base开始,并逐渐按bit range下降。

example如下:

6. Steps for evaluating an expression

expression的评估步骤:

  • 基于sv的规则确定expression的size;
  • 基于sv的规则确定expression的sign;
  • 将expression的size和type传递给context-determined oprands
  • 将type和size一直传递到simple operand级别。Simple operand也就是最简单的操作数了,不可以分隔为更下一层的operands。

7. Steps for evaluating an assignment

assignment的评估步骤:

  • 决定右手边的size
  • 如果需要,将右手边的size扩展

8. operator overloading

operator可以使用overloading的方式增加额外的功能,例如实现unpacked structure的加减法。

被bind的operator可以使用argument data types来匹配正确的bind function。可以被overload的operators有arithmetic operators、relational operators和assignment。

overload的scope的visibility与data declaration一样的。

例子如下,这个功能还挺有意思的。

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
There are some simple tricks that every design engineer should know to facilitate the usage of SystemVerilog Assertions. Although this paper is not intended to be a comprehensive tutorial on SystemVerilog Assertions, it is worthwhile to give a simplified definition of a property and the concurrent assertion of a property. 1.1 What is an assertion? An assertion is basically a "statement of fact" or "claim of truth" made about a design by a design or verification engineer. An engineer will assert or "claim" that certain conditions are always true or never true about a design. If that claim can ever be proven false, then the assertion fails (the "claim" was false). Assertions essentially become active design comments, and one important methodology treats them exactly like active design comments. More on this in Section 2. A trusted colleague and formal analysis expert[1] reports that for formal analysis, describing what should never happen using "not sequence" assertions is even more important than using assertions to describe always true conditions. 1.2 What is a property? A property is basically a rule that will be asserted (enabled) to passively test a design. The property can be a simple Boolean test regarding conditions that should always hold true about the design, or it can be a sampled sequence of signals that should follow a legal and prescribed protocol. For formal analysis, a property describes the environment of the block under verification, i.e. what is legal behavior of the inputs. 1.3 Two types of SystemVerilog assertions SystemVerilog has two types of assertions: (1) Immediate assertions (2) Concurrent assertions Immediate assertions execute once and are placed inline with the code. Immediate assertions are not exceptionally useful except in a few places, which are detailed in Section 3.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谷公子的藏经阁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值