SV搭建testbench的关键概念:CRT(constraint random test),测试集的随机化。

由于对象class由数据和操作组成,所以对数据的随机化一般放在一个class内。(对环境或环境的配置也可以反映在配置参数的随机化上)

一个constraint包括两部分:rand/randc变量声明,constraint约束块。其中randc会在重复之前,周期性取值,constraint约束块中的变量至少有一个rand/randc

变量,constraint约束块必须在{}内,用;来表示多个约束。约束块是一种声明性的代码,并行运行。

SV中的randomize函数有两种引用方法:

1)直接用任意一个class类型的对象引用,作用在整个class的rand/randc类型变量上。 this.randomize(var),只随机var,但是pre/post_randomize也会被调用

  obj.randomize(null),此时的randomize只是作为一个checker,检查solver是否成功,不是作为一个generator。现有值符合constraint,success返回1,failed返回0。

2)std::randomize(,,,) with {} ,其中()内的变量便是需要random的variable,with表示一些random constraint

success = std::randomize(a,b,c) with{a<b,a+b<length} ,随机化成功,返回success为1.

  with约束中的变量如果与调用randomize的obj相同,需要用local::来为变量定位。

3)直接使用$urandom/$urandom_range()等函数。

constraint的引用:一般在一个initial模块或program中引用,采用assert的形式来:assert( p.randomize() );随机化失败后,返回值为0,assert将会打印log,

并退出。还有两个隐性function:pre_randomize(),post_randomize(), 可以加入非randomize变量的初始化,同时留下hook。

几种约束方式:

1) constraint  longth { low < mid;

mid < high;}    //关系操作符必须分开来写

2)constraint   length { len == mid - low;}    //约束块内不能有赋值语句,相反应该用关系运算符

3)constraint   c_dist  { src_dist {0:= 40, [1:3]:=60;}     //:=后表示权重---相等

dst_dist {0:/ 40,  [1:3]:/ 60};}}   //:/后表示权重---比例

4)constraint   c_rang { c inside {[lo:hi]};                       //inside:low-high

b inside {[10:$]};                      //$可以表示边界

!(c inside {[$:30]}); }               //加()可以加!表示非

5)constraint   c_io { (io_space_mode) -> addr[31]==1'b1;    //--->表示if

if (op==READ) len inside {[BYTE:WORD]}; }  //--->if--else

6)constraint   c_xy  {(x==0) -> y==0;      //solve..before可能改变解的概率

solve x before y;}

7)assert (t.randmize() with {addr > 50;    //内嵌式的约束,addr的作用域是class这一级的,randomize的效果等价

addr < 150;} )

随机化的开关控制:

rand bit[7:0] length;

p.length.rand_mode(0);    //设置包长为非随机值

约束的开关控制:

initial  begin

p = new();

p.c_short.constraint_mode(0);   //句柄+约束块+mode,控制这个约束块mode

assert( p.randomize() );

transmit(p);

p.constraint_mode(0);                //句柄+mode,控制整个句柄的mode

p.c_short.constraint_mode(1);

assert( p.randomize() );

transmit(p);

end

对数组的约束:

1)constraint    d_size   {d.size inside {[1:10]};

d.sum == 4'h4; }  //sum的位数与数组中的数的位数相同,所以又是可能达不到想要的范围。

在实际应用中,应该多用变量来控制约束。

SV中的随机化的更多相关文章

  1. SV中的数据类型

    Verilog-1995中规定的数据类型有:变量(reg), 线网(wire), 32位有符号数(integer), 64位无符号数(time), 浮点数(real). SV扩展了reg类型为logi ...

  2. SV中的线程

    SV中线程之间的通信可以让验证组件之间更好的传递transaction. SV对verilog建模方式的扩展:1) fork.....join 必须等到块内的所有线程都执行结束后,才能继续执行块后的语 ...

  3. SV中的Interface和Program

    Interface:SV中新定义的接口方式,用来简化接口连接,使用时注意在module或program之外定义interface,然后通过'include来添加进工程. interface  arb_ ...

  4. SV中的task和function

    SV中class的properties和methods默认都是public的,但是可以声明为local和protected. 一个properties声明为local类型的,则只在该class中的me ...

  5. SV中的OOP

    OOP:Object-Oriented Programming,有两点个人认为适合验证环境的搭建:1)Property(变量)和Method(function/task)的封装,其实是BFM模型更方便 ...

  6. SV中的覆盖率

    SV采用CRT的激励形式,而判断验证进度的标准也就是覆盖率(coverage). 覆盖率的两种指定形式:显式的,直接通过SV来指定出的,如SVA,covergroup. 隐式的,在验证过程中,随&qu ...

  7. 06-SV随机化

    1.受约束的随机测试法(CRT) 随着设计变得越来越大,要产生一个完整的激励集来测试设计的功能变得越来越困难.解决的办法是采用受约束的随机测试法自动产生测试集.CRT环境比定向测试的环境复杂,不仅需要 ...

  8. SV randomize

    randomize中的变量只支持2-state的values,不支持4-states. randc类型的变量不能被约束在solve------before的语句中. constraint可以被定义在c ...

  9. UVM中的class

    UVM中的类包括:基类(base)------------uvm_void/uvm_object/uvm_transaction/uvm_root/uvm_phase/uvm_port_base 报告 ...

随机推荐

  1. VIM 的一些技巧

    vim配置文件 ~/.vimrc 如果没有自己创建一个即可 filetype plugin indent on #打开插件 set number #显示行号 syntax on #语法高亮 set c ...

  2. cadence allegro 封装焊盘编号修改 (引脚编号修改)

    1. 打开dra文件在find里面 off all  然后只点击text 2.点击需要更改的焊盘 3.菜单栏edit - text 4.弹出窗口修改即可 注意: 按照网上的其他操作并没有执行步骤1操作 ...

  3. jquery的$.each如何退出循环和退出本次循环

    https://api.jquery.com/jQuery.each/ We can break the $.each() loop at a particular iteration by maki ...

  4. python获取windows所有com口

    import serial import serial.tools.list_ports port_list = list(serial.tools.list_ports.comports()) po ...

  5. java 中形参与实参的转换

    java中有两个参数,一个是形参,一个是实参. 形参:在函数定义中,整个函数体内部都可以使用,离开了该函数就不能继续使用. 实参:出现在主函数中,进入被调函数后,实参变量也就不能继续使用. publi ...

  6. a new way of thinking about a problem

    PHP Advanced and Object-Oriented Programming Larry Ullman   The first thing that you must understand ...

  7. UITableView左右滑动cell无法显示“删除”按钮的原因分析

    http://www.cocoachina.com/bbs/read.php?tid-145693.html - (void)tableView:(UITableView *)tableView co ...

  8. javaScript 载入自执行

    1.注册可以直接调用f()中的b(),c(),d() .原因?自己想. <!DOCTYPE html> <html> <head> <meta charset ...

  9. mysql 数据操作 多表查询 多表连接查询 外链接之左连接 右连接

    1.外链接之左连接:优先显示左表全部记录   left join 在内连接的基础上保留左表的记录 即便左表有一条记录和右表没有关系,也把他留下 mysql> select * from empl ...

  10. google浏览器mac上跨域问题解决

    open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/ /Use ...