前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >日常记录(16)SystemVerilog

日常记录(16)SystemVerilog

作者头像
嘘、小点声
发布2021-12-22 08:31:10
3940
发布2021-12-22 08:31:10
举报
文章被收录于专栏:嘘、小点声嘘、小点声

巴科斯-诺尔范式

https://bbs.eetop.cn/thread-887240-1-1.html

称为BNF,是一种典型的元语言。(元语言:用来谈论、观察和分析另一种语言的符号语言)

A randsequence grammar is composed of one or more productions.

一个randsequence语法由一个或多个结果组成。

Each production contains a name and a list of production items.

每个产品都包含一个名称和一个产品项目列表。

Production items are further classified into terminals and nonterminals.

生产项目又分为终端和非终端。

Nonterminals are defined in terms of terminals and other nonterminals.

非终结符是根据终结符和其他非终结符定义的。

A terminal is an indivisible item that needs no further definition than its associated code block.

终端是一个不可分割的项,除了它的相关代码块外,不需要进一步的定义。

Ultimately, every nonterminal is decomposed into its terminals.

最终,每个非终结符都分解成它的终结符。

A production list contains a succession of production items, indicating that the items must be streamed in sequence.

生产列表包含连续的生产项目,这表明这些项目必须按顺序流。

A single production can contain multiple production lists separated by the | symbol.

单个产品可以包含由|符号分隔的多个产品列表。

Production lists separated by a | imply a set of choices, which the generator will make at random.

由|分隔的生产列表意味着一组选择,生成器将随机做出这些选择。

The production main is defined in terms of three nonterminals: first, second, and done.

生产函数main是用三个非终结符定义的:first、second和done。

When main is chosen, it generates the sequence, first, second, and done.

当main被选择时,它会生成序列,第一,第二,最后完成。

When the first production is generated, it is decomposed into its productions, which specify a random choice between add and dec.

当生成第一个产品时,它被分解为它的产品,它指定在add和dec之间的随机选择,

Similarly, the second production specifies a choice between pop and push.

类似地,第二个产品指定在pop和push之间的选择。

All other productions are terminals; they are completely specified by their code block, which in the example displays the production name.

所有其他产品都是终端;它们完全由代码块指定,在示例中代码块显示产品名称。

Thus, the grammar leads to the following possible outcomes

因此,语法导致了以下可能的结果

When the randsequence statement is executed, it generates a grammar-driven stream of random productions.

当执行randsequence语句时,它会生成一个语法驱动的随机结果流。

As each production is generated, the side effects of executing its associated code blocks produce the desired stimulus.

在生成每个产品时,执行其相关代码块的副作用会产生所需的刺激。

In addition to the basic grammar, the sequence generator provides for random weights, interleaving, and other control mechanisms.

除了基本语法之外,序列生成器还提供了随机权值、交错和其他控制机制。

Although the randsequence statement does not intrinsically create a loop, a recursive production will cause looping

尽管randsequence语句本质上并不创建循环,但递归的结果将导致循环.

:=说明权重。

参阅:IEEE Std 1800-2017 SystemVerilog 标准 545-546

参阅:克里斯,SystemVerilog 验证 测试平台编写指南 169。

function

function不消耗仿真时间:也就是不能有仿真时间延迟(#100)、不能有阻塞语句(@posedge clock)或者wait(ready)、不能有事件event,不能调用task,task可以消耗仿真时间; https://blog.csdn.net/weixin_37413070/article/details/107473648

在systemveilog中,允许函数调用task(https://blog.csdn.net/Michael177/article/details/120927586

unique

https://mp.weixin.qq.com/s/F_XcUE8XwUisKIgCvJ3SWw

SystemVerilog中的unique和priority关键字修饰符放在if,case,casez,casex语句之前。表示在一系列条件选项中,有且仅有一项是符合条件的,否则警告

代码语言:javascript
复制
1 unique if (expression)
2   statements
3 else
4   statements
5 
6 priority case (case_expression)
7   case_item_1: case_expression_1
8   case_item_2: case_expression_2
9 endcase

priority关键字

则会在所有的if...else if都不满足条件,并且最后也没有else语句的情况下发出警告。

使用上述关键字并不能保证删除不必要的latch。在case语句中,如果存在case选项丢失,则仍然可能存在latch

rand实现的randc

代码语言:javascript
复制
 1 module test;
 2     parameter N =10;
 3     rand bit[N-1:0] randc_var;
 4     bit[N-1:0] gen_done[$];
 5     
 6     function automatic bit[N-1:0] get_randc();
 7         bit succ = 0;
 8         while(!succ) begin
 9           succ =  std::randomize(randc_var) with  { unique {randc_var,gen_done};};
10         end  
11         //If success push to queue
12         gen_done.push_back(randc_var);
13         if(gen_done.size() == 2**N) begin
14             gen_done.delete();
15         end
16         return randc_var;
17     endfunction
18       
19     initial begin
20         for (int i=0; i <1000; i++) 
21         begin
22             $display("randc[%0d] = %0d", i, get_randc());
23         end
24     end
25 endmodule

不知道效率如何,先记下。

https://cloud.tencent.com/developer/article/1848560

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-12-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 巴科斯-诺尔范式
  • function
  • unique
    • priority关键字
    • rand实现的randc
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档