【问题标题】:what does "virtual" mean when applied to a SystemVerilog interface?当应用于 SystemVerilog 接口时,“虚拟”是什么意思?
【发布时间】:2020-02-27 08:14:01
【问题描述】:

下面SystemVerilog代码中的“virtual tinyalu_bfm”是什么意思?示例:

        uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm);

如果我省略了 virtual 关键字,会有什么不同吗?只是好奇,因为 virtual 的通常 oop 含义仅适用于类或类成员,这是一个示例,它应用于一个接口,该接口被传递到作为 UVM 包的一部分的静态函数中......只是想知道为什么我需要在这种情况下称它为虚拟的,它的目的是使它成为虚拟的。

    module top;

        // UVM Framework
        import uvm_pkg::*;
        `include "uvm_macros.svh"

        import   tinyalu_pkg::*;       //import all tb classes and types

        tinyalu_bfm       bfm();

        // invoke APIs from uvm_pkg to start test...
        initial begin
            uvm_config_db #(virtual tinyalu_bfm)::set(null, "*", "bfm", bfm);

            run_test();  
        end

    endmodule : top
    interface tinyalu_bfm;

       byte         unsigned        A;
       byte         unsigned        B;
       bit          clk;
       bit          reset_n;

       initial begin
          clk = 0;
          forever begin
             #10;
             clk = ~clk;
          end
       end

       task reset_alu();
          reset_n = 1'b0;
          @(negedge clk);
          @(negedge clk);
          reset_n = 1'b1;
          start = 1'b0;
       endtask : reset_alu

      task send_op(input byte iA, input byte iB, input operation_t iop, output shortint alu_result);
           // ...       
       endtask : send_op

    endinterface : tinyalu_bfm

再看这里...接口对象也被声明为虚拟...为什么?

 // FILE: random_test.svh
    class random_test extends uvm_test;
        // ... 
        virtual tinyalu_bfm bfm;

        function new (string name, uvm_component parent);
            super.new(name,parent);
            if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm))
                $fatal("Failed to get BFM");
        endfunction : new

        task run_phase(uvm_phase phase);
            //...
        endtask : run_phase

    endclass

【问题讨论】:

  • 请参阅第 10 章:高级接口,“用于验证的系统 Verilog”,2012 年第 3 版,作者:Chris Spear 和 Greg Tumbush……“虚拟接口的更好名称应该是”参考接口。”

标签: system-verilog uvm


【解决方案1】:

SystemVerilog 被创建为与 Verilog 完全向后兼容,但新保留的关键字除外。因此 SystemVerilog 尽可能重用或重载现有关键字以减少关键字膨胀。接口名称前面的virtual 关键字意味着您声明的变量类型包含实际 接口实例的句柄,而不是实际接口实例,

【讨论】:

  • 我认为所有 SystemVerilog 类变量都类似于 java,它们是空引用,直到某个进程将 new() 分配给类引用变量... module Foo; FooClass_t FooBar = new(42);端模块;但是,SystemVerilog 接口变量更像是经典的 C++ 类......你不需要对它们调用 new,因为存储已经以类似于模块对象的方式静态分配......所以它们是有意义的重载 virtual 表示接口变量是引用。 virtual 是一个不幸的关键字选择......“ref”更有意义
  • 是的,SystemVerilog 类系统来自同样开发 Java 的 Sun Microsystems,因此有相似之处。但不幸的是,ref 关键字已被用于参数声明,无法用于数据类型。
【解决方案2】:

在普通编程语言中,virtual interface 的模拟是指针或引用(指向接口对象)。它用作系统 verilog 测试台组件中的参考,将其作为函数或任务参数传递或将其存储在类或其他地方。

系统 verilog 是一门巨大的语言,其中有很多丑陋之处。 virtual 关键字肯定被过度使用,就像在这种情况下一样。本来可以有更好的选择。

|

【讨论】:

    【解决方案3】:

    我建议使用以下定义宏来弥补 SystemVerilog 设计人员选择重载虚拟关键字的不良语言是一种奇怪的方式:

        `define REFERENCE virtual
    
        module top;
    
            // UVM Framework
            import uvm_pkg::*;
            `include "uvm_macros.svh"
    
            import   tinyalu_pkg::*;       //import all tb classes and types
    
            tinyalu_bfm       bfm();
    
            // invoke APIs from uvm_pkg to start test...
            initial begin
                uvm_config_db #(`REFERENCE tinyalu_bfm)::set(null, "*", "bfm", bfm);
    
                run_test();  
            end
    
        endmodule : top
    
        interface tinyalu_bfm;
        // ...
    
        endinterface : tinyalu_bfm
    

    再看这里...接口对象也被声明为虚拟...为什么?

     // FILE: random_test.svh
        class random_test extends uvm_test;
            // ... 
            `REFERENCE tinyalu_bfm bfm;
    
            function new (string name, uvm_component parent);
                super.new(name,parent);
                if(!uvm_config_db #(`REFERENCE tinyalu_bfm)::get(null, "*","bfm", bfm))
                    $fatal("Failed to get BFM");
            endfunction : new
    
            task run_phase(uvm_phase phase);
                //...
            endtask : run_phase
    
        endclass
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 2013-12-21
      • 2011-04-27
      • 2012-01-02
      • 2021-06-10
      • 1970-01-01
      相关资源
      最近更新 更多