what to randomize?

(1) primary input data <==one data

(2)encapsulated input data <== muti group data

(3)protocol exceptions,errors and violations

(4)delays


overview

1.randomization enables users to automatically  generate random input sitimuls for functional verification

2.systemverilog enable user to specify random constrained (legal) values

3.random costraint should be specified using OOP


Randomization in SV

(1) keyword

rand bit [1:0] y;

randc bit [1:0] y;

(2)simple class with random variables

class BUS

rand bit [15:0] addr;

randc bit [31:0] data;

constraint range1{

addr > 1024;

data<16384;

}

endclass

(3)randomize() function <==启动一个随机约束

if success return 1

if failture  return 0

BUS bus = new();

repeat(50) begin

if(bus.randomize() == 1)

$display(bus.addr.bus.data);

else

$display(“randomization failed”);

end

(4) constrain solver ===> seed

the same seed results in the same random value

(5)constraint blocks

constraint constraint_indentifier {

constraint_statmemts

}

(6)simples expressions

only one relational operator(< <= > >= …)

(7)set membership operator:inside

eg1:   class BUS

rand bit[15:0] addr;

randc bit [31:0] data;

constraint range1{

addr inside {[0:1000],[1024:16384]};

data > 1000;

data < 100000;

}

endclass

eg2:

integer fives[0:3] = {5,10,15,20};

rand integer v;

constraint c3 {v inside fives};

constraint c4 !{v inside fives};

(8)weighted distribution:dist

property1: They are a relational test for test membership

property2: They specify a statistical distribution function for the result

:=  <====the same value in the range  every(可以对一个区间也可以对一个独立的数)

/=  <=====to be equally divided by all values     range_weight/n(对一个区间约束)

cannot be used with a randc

eg:

(9)bidirectional constraints

not procedural but declarative

all active at one time

(10) conditional constraints

implication operator –>  相当于 if..else

(11) unconstrainted

rand bit x ;

rand bit [1:0] y;

the same probability

(12)implication

class imp1;

rand bit x;

rand bit [1:0] y;

constraint c_xy{

(x==0) –> (y==0);

}

endclass

(13)implication and bidirectional constraints

class imp_Bid;

rand bit x;

rand bit [1:0] y;

constraint c_xy{

y > 0;

(x==0) –> (y==0);

}

endclass

(14)solve before

class solvebefore;

rand bit x;

rand bit [1:0] y;

constraint c_xy;

{

(x==0) –> y==0;

solve y before x;

}

(15) interative constraints

allows arrayed variable to be constrained in a parameterized manner using loop variables

class c;

rand bye A[4];

constraint C1

{

foreach(A[i])

A[i] inside{2,4,8,16};

}

constraint C2

{

foreach (A[j])

A[j] > 2*j;

}

endclass

(16) functions in constraints

class B;

rand int x,y;

constraint C{x <= F(y);}

constraint D{y inside{2,4,8};}

endclass

1.functions cannot contain output or ref arguments <===ref 相当于inout

2.functions should be automatic  <===automatic可以立即返回值

3.functions that appear  in constraint cannot modify the constraint <===只是简单调用而已

4.functons shall be called before constraints are solved, and their return values shall be treated as state variables

5.random variables used as function argumets shall establish an implicit variable ordering or priority

(17)in_line constraints ---xx.randomize()with{constraints_statememt}

equivalent to adding an extra constraint to any existing one in effect

(18) disabling  random variables ---rand_mode() <==control a random variable is active or inactive

class packed;

rand integer src,dst;

endclass

int r;

packet packect_a=new;

packet_a.rand_mode(0);

packet_b.src.rand_mode(1);

(19)controlling constraints with constraint_mode() <===control a constraints is active or inactive

class packet;

rand interger src,dst;

constraint filter{src>2*dst;}

endclass

function integer toggle_rand(packet p);

if(p.filter.constraint_mode() ==1 )

p.filter.costraint_mode(0);

else

p.filter.constraint_mode(1);

toggle_rand = p.randomize();

endfunction

总结:constraints主要用于transaction中,

systemverilog(3)之Randomize的更多相关文章

  1. [转载]转一篇Systemverilog的一个牛人总结

    原文地址:转一篇Systemverilog的一个牛人总结作者:dreamylife Systemverilog 数据类型 l       合并数组和非合并数组 1)合并数组: 存储方式是连续的,中间没 ...

  2. SystemVerilog基本语法总结(上)

    SystemVerilog基本语法总结(上) 在总结SV的语法之前,先分享一些关于SV的笔试题目,这样更显得具有针对性的总结. a. 验证中,代码覆盖率是指(衡量哪些设计代码在激活触发,而哪一些则一直 ...

  3. VBA使用的Randomize和DoEvents

    Randomize private function getInt() dim n,m as integer Randomize n=1 m=3 getInt=Int((m+1-n)*rnd + n) ...

  4. SystemVerilog的历史

    随着软件的功能需求越来越复杂,C语言不足以解决现有的问题,于是C++被发明了:C++的指针漫天飞,对内存的处理过于复杂,于是Java被发明了:芯片的功能不断地扩大,Verilog不足以应对日益复杂的芯 ...

  5. Randomize select algorithm 随机选择算法

    从一个序列里面选择第k大的数在没有学习算法导论之前我想最通用的想法是给这个数组排序,然后按照排序结果返回第k大的数值.如果使用排序方法来做的话时间复杂度肯定至少为O(nlgn). 问题是从序列中选择第 ...

  6. vim中systemverilog的高亮显示

    vim中systemverilog的高亮显示 Linux中的vim显示systemverilog语法高亮 windows中的gvim显示systemverilog语法高亮 Linux系统 查看打开vi ...

  7. SystemVerilog搭建验证平台使用DPI时遇到的问题及解决方案

    本文目的在于分享一下把DPI稿能用了的过程,主要说一下平台其他部分搭建好之后,在完成DPI相关工作阶段遇到的问题,以及解决的办法. 工作环境:win10 64bit, Questasim 10.1b ...

  8. SystemVerilog语言简介(三)

    15. 强制类型转换 Verilog不能将一个值强制转换成不同的数据类型.SystemVerilog通过使用'操作符提供了数据类型的强制转换功能.这种强制转换可以转换成任意类型,包括用户定义的类型.例 ...

  9. SystemVerilog语言简介(二)

    6. 用户定义的类型 Verilog不允许用户定义新的数据类型.SystemVerilog通过使用typedef提供了一种方法来定义新的数据类型,这一点与C语言类似.用户定义的类型可以与其它数据类型一 ...

随机推荐

  1. PostgreSQL - 模糊查询

    前言 like.not like在SQL中用于模糊查询,%表示任意个字符,_表示单个任意字符,如果需要在模糊查询中查询这两个通配符,需要用ESCAPE进行转义,如下: select * from ta ...

  2. Gym - 101810H ACM International Collegiate Programming Contest (2018)

    bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #de ...

  3. json数据有换行符时提交不成功的坑

    这是在有多行文本框表单提交时遇到的问题.. 整理所有的表达数据,合并到一个json中然后jsonp方式提交给后端时,发现只要有换行符,总是提交失败. 目前的解决办法就是在合并数据的时候把换行\n替换为 ...

  4. Ceizenpok’s formula Gym - 100633J 扩展Lucas定理 + 中国剩余定理

    http://codeforces.com/gym/100633/problem/J 其实这个解法不难学的,不需要太多的数学.但是证明的话,我可能给不了严格的证明.可以看看这篇文章 http://ww ...

  5. android开发学习 ------- 仿QQ侧滑效果的实现

    需要做一个仿QQ侧滑删除的一个效果: 一开始是毫无头绪,百度找思路,找到  https://blog.csdn.net/xiaxiazaizai01/article/details/53036994  ...

  6. C#调用C库的注意事项

    作者:朱金灿 来源:http://blog.csdn.net/clever101 注意事项一: 从C#的exe进入C库的源码进行调试,需要先"启用非托管代码调试",如下图: 注意事 ...

  7. 制作 Favicon.ico 图标教程

    摘要:有一些站长认为 favicon.ico 图标对于一个网站没有什么作用.甚至有一些站长认为,少加载一个图片,页面设计展现的速度更快些.的确,理论上是对的,但乐猪认为这种想法是肤浅的!有这种想法的站 ...

  8. 字符串、String等转换

    (1) String 转换为字符串 例:String s = "abcde";char[] a = s.toCharArray(); (2) 字符串转换为Stringchar[] ...

  9. Notepad++设计Tab制表符为4个空格

    Notepad++中,常常需要将一个Tab制表符转换成4个空格.这种情况大多发生在对空白检查严格的情况下,比如Python程序. 设置 → 首选项 → 制表符设置 → 勾选“ 转换为空格 ”.

  10. 电脑连接海信电视 HDMI

    注意:我们家的电视是海信的,所以不能代表所有的电视哦~~~ 家里电视有线电视已经过期很长时间了,早就想把电脑连接到电视上用电视做显示器的心了,今天来兴趣了,就弄了一下!!! 用电脑连接电视需要先解决两 ...