其他分享
首页 > 其他分享> > UVM tips and tricks

UVM tips and tricks

作者:互联网

目录

1.Use of Macros to Overcome Errors Faced in Package

2.fork-join_none 中使用loop

3.random 机制

3.1 如果名字重复,使用local

3.2 动态数组需要定义size

3.3 检查randomize 结果

4.uvm_config_db的使用要注意

5. 最小的factory override for stimulus objects

6.避免使用uvm_printer,使用conver2string()

8. Loop performance optimization

9.文件目录


1.Use of Macros to Overcome Errors Faced in Package

package pkg1;
  `include "adder_design.sv"
  `include "tb.sv"
endpackage

package pkg2;
  `include "adder_design.sv"
  `include "adder_tb.sv"
endpackage

module top();
  `ifndef ADDER_DESIGN
  `define ADDER_DESIGN
  import pkg2::*;
  `endif
  ...
endmodule

2.fork-join_none 中使用loop

使用automatic

module top;
  initial begin
    for (int i = 0; i < 4; i++) begin
	  fork
	    automatic int l = i;
	     display(l);
	  join_none
    end
  end
  task display(int i);
	$display("i = %d", i);
  endtask
endmodule

3.random 机制

3.1 如果名字重复,使用local

rand_success = trans.randomize() with {trans.addr == local::addr; };

3.2 动态数组需要定义size

class Ethernet;
      rand bit [3:0]payload[];
      constraint c { payload.size() ==4;}
endclass

3.3 检查randomize 结果

 

4.uvm_config_db的使用要注意

a.尽量避免传递数值,有需要的话可以封装成class

b. wildcard谨慎使用

c. it is recommended to minimize the number of uvm_config_db entries.

...

5. 最小的factory override for stimulus objects

Low performance, 因为多次调用了factory中的create

//Low performance code
task body;
  seq_item item;
  repeat (200) begin
    item = seq_item::type_id::crease("item"0;
    start_item(item);
    if (item.randomize()) begin ... end
    finish_item(item);
  endtask

High performane, 只第一次create,然后clone 它

//High performance
task body;
  seq_item orig_item = seq_item::type_id::create("item");
  seq_item item;
  repeat(200) begin
	$cast(item, orig_item.clone());
	start_item(item);
	assert(item.randomize());
	finish_item(item);
  end 
endtask

6.避免使用uvm_printer,使用conver2string()

在class 自定义conver2string

virtual function string convert2string();
      string s = super.convert2string();
      s = { s, $psprintf( "\nname      : %s", get_name()    ) };
      s = { s, $psprintf( "\nflavor    : %s", flavor.name() ) };
      s = { s, $psprintf( "\ncolor     : %s", color.name()  ) };
      return s;
endfunction: convert2string

7.UVM objections 使用

Objections should only be used by the controlling threads, and it is also very necessary to place the objections in the run-time method of the top level test class, or in the body method of a virtual sequence. Using them in any other place is likely to be unnecessary and also cause a degradation in performance.

在virtual sequence中的body;或者在top level的testcase的run-time method

//High Performance code
class sequence extends uvm_sequence#(seq_item);
 
task body;
seq_item item = seq_item::type_id::create("item");
repeat(5) begin
     start_item(item);
     assert(item.randomize());
     finish_item(item);
 end
 
  sequencer seqr;
 
task body;
   `uvm_objection objection = new("objection");
    sequence seq=    sequence::type_id::create("seq");
    objection.raise_objection(seqr);
    seq.start(seqr);
    objection.drop_objection(seqr);
endtask

8. Loop performance optimization

1.loop的性能取决于loop中的工作

下面高效代码,减少了每次循环化size的计算

//Less efficient code
int arr[];
int total = 0;
for(int i = 0;i< arr.size();i++) begin
  total += arr[i];
end

//High Performance Code
int arr[];
int arr_size;
int tot = 0;
arr_size = arr.size();
for(int i = 0; i < arr_size; i++) begin
  tot += arr[i];
end

9.文件目录

 

 

标签:arr,seq,int,tricks,begin,item,UVM,tips,size
来源: https://blog.csdn.net/ocarvb/article/details/114185360