ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[SV]SystemVerilog Randomization

2020-04-08 16:07:51  阅读:379  来源: 互联网

标签:rand addr inside atype SV Randomization bit randomize SystemVerilog


                         SystemVerilog Randomization

 

一、OOP Based Randomization

1、Two types of random properties are supported:

  • rand

  • randc

2、randand randcproperties are randomized when the class method randomize()is called:

  • Randomize property value to full range of data type

  • randomize()is built-in with every class

  • 1 is returned if successful, 0 if randomization failed

3、randproperties can assume any legal value:

  • Values can repeat without exhausting all possible values

4、randcproperties can be up to 16 bits:

  • Exhaust all values before repeating any individual value

  • For non-repeating bit values > 16 bits, use concatenation

 

二、Implication and Order Constraints

1、Implication operators:

  • ->
  • if ( … ) … [ else … ]
  • Caution: does not imply solving order
typedef enum { low, mid, high } AddrType;
class MyBus;
  rand bit[7:0] addr;
  rand AddrType atype;
  constraint addr_range {
    (atype == low ) ->addr inside { [0:15] };
    (atype == mid ) ->addr inside { [16:127] };
    (atype == high) ->addr inside { [128:255] };
    // same as:
    // if(atype == low) addr inside { [0:15] };
    // if(atype == mid) addr inside { [16:127] };
    // if(atype == high) addr inside { [128:255] };
  }
endclass

2、Dictating solver order

  • randcis solved before randproperties
  • solve-beforeconstruct set solving order for same type random properties
  • Can not force randto be randomized before randcproperties
  • $void(rand_property)solves rand_propertiesfirst
class MyBus;
  rand bit flag;
  rand int addr;
  constraint addr_range {
    if ( flag == 0 ) addr == 0;
    else addr inside { [1:1024] };
    solveflag beforeaddr;
    // solve addr before flag; // what’s the difference?
    // alternative:
    // if ( $void(flag) == 0 ) addr == 0;
  }
endclass

 

三、Effects of Calling randomize()

1、When randomize()executes, three events occur

  • pre_randomize()is called
  • Randomization is executed
  • post_randomize()is called

2、pre_randomize()

  • Optional
  • Set/Correct constraints before randomization

3、post_randomize()

  • Optional
  • Make corrections after randomization
  • Example: CRC
class Packet;
  int test_mode;
  rand bit[3:0] sa, da;
  rand bit[7:0] payload[];
  bit[15:0] crc;
  constraint LimitA {
    sa inside { [0:7] };
    da inside { [0:7] };
    payload.size() inside { [2:4] };
  }

  function void pre_randomize();
    if(test_mode) recnstr(test_mode)
  endfunction

  function void post_randomize();
    gen_crc();
  endfunction

  virtual function void recnstr(int mode);
  endtask

endclass

 

4、Inline Constraints

  • syntax: obj.randomize( ) with{ <new constraints> };

 

5、Controlling randProperty Randomization

  • task/function int object_name.property.rand_mode ( 0 | 1 );
program automatic test;
  class Node;
    rand int x, y, z;
    constraint Limit1 {
      x inside {[0:16]}; y inside {[23:41]};
      z < y; z > x;
    }
  endclass

  initial begin
    Node obj1 = new();
    obj1.x.rand_mode(0);
    if (!obj1.randomize()) ...;
  end

endprogram

 

 

标签:rand,addr,inside,atype,SV,Randomization,bit,randomize,SystemVerilog
来源: https://blog.csdn.net/gsjthxy/article/details/105341253

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有