我应该使用 uvm_component/object_utils 宏吗

Should i be using the uvm_component/object_utils macros

我看到很多文章都在谈论您是否应该使用字段宏。

一般准则是:

`uvm_do... macro:

可以用,懒人尽量避免


`uvm_field... macro:

躲避瘟疫。


当然,人们也告诉不要使用

`uvm_component_param_utils... 
`uvm_object_param_utils...

但我似乎无法找到任何人对

的看法
`uvm_component_utils... 
`uvm_object_utils...

应该避免它们吗?或者它们可以毫无问题地使用?

谢谢:)

*_utils 宏不会引入任何性能损失。它们确实节省了一些打字时间,并可能减少印刷错误,但我希望人们在使用宏之前先了解宏背后的代码。参见 http://go.mentor.com/mcem

我总是使用 uvm_field_uvm_object_utils/uvm_component_utils 宏。它们提供了很多漂亮的功能。

我喜欢的一个功能:如果您使用 uvm_field_* 注册,uvm_component 会自动从 uvm_config_db 中为您获取变量。

例如:

class myclass extends uvm_component;

bit enable;
`uvm_component_utils_begin(myclass)
  `uvm_field_int(bit, UVM_ALL_ON) // UVM_READ_ONLY wouldn't work for this feature
`uvm_component_utils_end

virtual class build_phase(uvm_phase phase);
  super.build_phase(phase);
endclass

virtual task run_phase(uvm_phase phase);
  if (enable) begin
     // blah blah
  end
endtask

endclass

要设置位启用,您在更高层级的 class 中所要做的就是 uvm_config_db(int)::set(this, "path/to/class", "enable", 1)

class 本身不需要任何 "get"。有点整洁...

这周我教了我的第一门 UVM 课程(Doulos CTO - John Aynsley - 作为替补)。在他对我的表现的评估中,他对宏说了这样的话,我相信他不会介意我重复:

  • `uvm_component_utils and friends - a good thing
  • `uvm_do and friends - a bit naughty
  • Field macros - evil

我认为您无法绕过这两个宏。

`uvm_component_utils... 
`uvm_object_utils...

这两个开厂了。如果您不使用它们,则必须在每个 uvm_object 或 uvm_component.

中编写相同的几行乏味的样板代码
uvm_component_param_utils
uvm_object_param_utils

和前两个一样,当你的uvm_object或uvm_component有参数的时候需要用到。我发现 uvm_object/uvm_componet 中的参数在某些情况下很方便,但我知道有人认为这是个坏主意。但这是另一场辩论。

就个人而言,我避免使用 uvm_do 宏,我更喜欢完全控制地创建和随机化我的 seq_item,然后使用 `uvm_send(这只是一些样板定序器书保持)

我参加了 Doulos 培训,我记得他们说要避免使用 uvm_field 宏。不知怎的,我只是觉得 uvm_field 宏有点复杂,所以他们只是避免教它,因为我们没有足够的时间。

uvm_field 宏非常有用,特别是如果您构建自己的 uvm_comparer。是否实现自己的 do_copy, do_print 功能是个人喜好问题,但 uvm_comparer 确实很有用。我建议您始终使用 uvm_field