跳转至

输入查询内容

    本页内容

    uvm_do* 动作宏:约束、sequencer 与优先级的迁移

    影响范围

    调用 deprecated 的旧 sequence 动作宏。

    具体差异

    2.0 主线仅保留 4 个动作宏并加默认实参,单参 `uvm_do(seq) 调用源码兼容;uvm_do_with/uvm_do_on*/uvm_do_pri* 等 15 个变体默认不可用。另有行为差异:默认 sequencer 由 1.2 的 m_sequencer 改为 get_sequencer()(在 sequence 上下文外调用时结果不同);uvm_rand_send 改用 is_item()/get_randomize_enabled() 判定并对非 sequence/item 实参新增 NOT_SEQ_OR_ITEM 警告。

    修改方案

    uvm_do_with(x,{...})uvm_do(x, get_sequencer(), -1, {...}) 或手工 start_item/randomize/finish_item;过渡期可 +define+UVM_ENABLE_DEPRECATED_API

    在 sequence 的 body() 中,req 是已声明的请求句柄,addr 是它的随机字段。

    旧写法:

    `uvm_do_with(req, { addr == 'h100; })
    

    目标写法,保留原 sequencer、默认优先级和地址约束:

    `uvm_do(req, get_sequencer(), -1, { addr == 'h100; })
    

    若原来指定了 sequencer 和优先级:

    1
    2
    3
    4
    // UVM 1.2
    `uvm_do_on_pri_with(req, target_seqr, 100, { addr == 'h100; })
    // UVM 2.0
    `uvm_do(req, target_seqr, 100, { addr == 'h100; })
    

    不要缩成 uvm_do(req),否则原约束会丢失。暂不改代码时,可在目标编译命令中加 +define+UVM_ENABLE_DEPRECATED_API

    本条示例 1.2 2.0 默认 2.0 开启 deprecated
    旧带约束宏 可编译 宏不可用 可编译
    新带参数宏 不适用此旧原型 可编译,保留约束 可编译,保留约束

    在 driver 检查每笔 req.addr=='h100,并确认发送到预期 sequencer;多优先级环境还需检查实际仲裁结果。

    完整旧宏映射如下。x 是 sequence/item 句柄,s 是目标 sequencer,p 是原优先级,c 是含花括号的约束块(如 { addr == 'h100; })。表中的宏调用均带反引号。

    UVM-1.2 旧宏 2.0 目标调用
    uvm_do_pri(x, p) uvm_do(x, get_sequencer(), p)
    uvm_do_with(x, c) uvm_do(x, get_sequencer(), -1, c)
    uvm_do_pri_with(x, p, c) uvm_do(x, get_sequencer(), p, c)
    uvm_create_on(x, s) uvm_create(x, s)
    uvm_do_on(x, s) uvm_do(x, s)
    uvm_do_on_pri(x, s, p) uvm_do(x, s, p)
    uvm_do_on_with(x, s, c) uvm_do(x, s, -1, c)
    uvm_do_on_pri_with(x, s, p, c) uvm_do(x, s, p, c)
    uvm_send_pri(x, p) uvm_send(x, p)
    uvm_rand_send_pri(x, p) uvm_rand_send(x, p)
    uvm_rand_send_with(x, c) uvm_rand_send(x, -1, c)
    uvm_rand_send_pri_with(x, p, c) uvm_rand_send(x, p, c)
    uvm_create_seq(x, cons_if) uvm_create(x, cons_if.consumer_seqr)
    uvm_do_seq(x, cons_if) uvm_do(x, cons_if.consumer_seqr)
    uvm_do_seq_with(x, cons_if, c) uvm_do(x, cons_if.consumer_seqr, -1, c)

    最后三项是两侧 VCS 库提供的 consumer-sequencer 别名。cons_if 必须包含有效的 consumer_seqr 成员;不能把整个接口对象当成 sequencer 传入。

    保留创建与随机化的原意:uvm_create 只创建;uvm_send 发送已有对象且不随机化;uvm_rand_send 对已有对象按目标规则随机化后发送;uvm_do 会创建并执行。旧 uvm_create(x)uvm_do(x)uvm_send(x)uvm_rand_send(x) 的单参形式仍可在 sequence 上下文使用。

    例如先指定 sequencer 创建,再发送已填写的值:

    1
    2
    3
    4
    // UVM 1.2
    `uvm_create_on(req, target_seqr)
    req.addr = 'h100;
    `uvm_send_pri(req, 100)
    
    1
    2
    3
    4
    // UVM 2.0
    `uvm_create(req, target_seqr)
    req.addr = 'h100;
    `uvm_send(req, 100)
    

    若原来是 uvm_rand_send_with,则使用 uvm_rand_send(req, -1, { addr == 'h100; }),保留“使用已有对象并重新随机化”的行为。不要把这两类发送统一改成会重新创建对象的 uvm_do。sequence 自身禁用随机化、父子 sequence 回调和 sequence 上下文外的调用,仍按实际使用条件验证。

    兼容措施与范围

    UVM_ENABLE_DEPRECATED_API 开放本条列出的 15 个旧动作宏,不需要编译 compat 包;它不恢复已删除的注册宏,也不代替约束、sequencer、parent 和优先级验证。

    迁移后验证

    使用带约束、指定 sequencer 和优先级的样例验证新原型;移除 deprecated 后再编译,检查实际激励仍满足约束。

    记录本条结果M09-004 · 状态与证据

    已有实测与复现

    补充查阅

    扫描定位与记录结果

    有扫描规则,覆盖部分可识别写法。脚本检查名称、参数和部分 FLAG 表达式,并对少数直接声明关联使用点;未做完整类型解析或预处理,行为结果仍需验证。

    • C5 · 文本匹配:uvm_do_* 宏移入 deprecated(需 +define+UVM_ENABLE_DEPRECATED_API 或改写)。
    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules C5
    

    核对命中对象及生效分支后,在条目清单记录修改与验证证据;扫描规则记录用于整理命中位置。

    扫描器下载、输入范围与报告说明

    源码与标准依据

    核查方式:源码与实测核对。实测仅覆盖本条所列场景。

    VCS 内置 UVM-1.2uvm_sequence_defines.svh:90uvm_do)、uvm_sequence_defines.svh:146uvm_create_on)、uvm_sequence_defines.svh:162/uvm_sequence_defines.svh:174/uvm_sequence_defines.svh:187/uvm_sequence_defines.svh:199uvm_do_on*)、uvm_sequence_defines.svh:240/uvm_sequence_defines.svh:270/uvm_sequence_defines.svh:282/uvm_sequence_defines.svh:294uvm_send_pri/uvm_rand_send_*) ;补充:uvm_sequence_defines.svh:101

    VCS 内置 uvm-ieee-2020-2.0uvm_sequence_defines.svh:50uvm_create(SEQ_OR_ITEM, SEQR=get_sequencer()))、uvm_sequence_defines.svh:100uvm_do(SEQ_OR_ITEM, SEQR=get_sequencer(), PRIORITY=-1, CONSTRAINTS={}))、uvm_sequence_defines.svh:125uvm_send)、uvm_sequence_defines.svh:145uvm_rand_send);被移除宏见 uvm_sequence_defines.svh:47 起,仅经 +define+UVM_ENABLE_DEPRECATED_API 引入(uvm_macros.svh:130–131,默认不编入)

    标准依据:IEEE 1800.2-2020 §B.3.1.1、§B.3.1.4(uvm_do(SEQ_OR_ITEM, SEQR=get_sequencer(), PRIORITY=-1, CONSTRAINTS={})

    标为“源码标注”或未注明原文核对的条款仅作定位;具体库行为以源码和实测为准。

    引用代码(高亮为引用行);上方行号链接可直接定位。

    src/vcs-uvm-1.2/macros/uvm_sequence_defines.svh
    //|   sub_seq.post_start()        (task)
    //|
    
    `define uvm_do(SEQ_OR_ITEM) \
      `uvm_do_on_pri_with(SEQ_OR_ITEM, m_sequencer, -1, {})
    
    
    // MACRO: `uvm_do_pri
    //
    //| `uvm_do_pri(SEQ_OR_ITEM, PRIORITY)
    //
    // This is the same as `uvm_do except that the sequence item or sequence is
    // executed with the priority specified in the argument
    
    `define uvm_do_pri(SEQ_OR_ITEM, PRIORITY) \
      `uvm_do_on_pri_with(SEQ_OR_ITEM, m_sequencer, PRIORITY, {})
    
    
    // MACRO: `uvm_do_with
    //
    //| `uvm_do_with(SEQ_OR_ITEM, CONSTRAINTS)
    //
    // This is the same as `uvm_do except that the constraint block in the 2nd
    // argument is applied to the item or sequence in a randomize with statement
    // before execution.
    
    `define uvm_do_with(SEQ_OR_ITEM, CONSTRAINTS) \
      `uvm_do_on_pri_with(SEQ_OR_ITEM, m_sequencer, -1, CONSTRAINTS)
    

    src/vcs-uvm-1.2/macros/uvm_sequence_defines.svh
    // to the sequence in which the macro is invoked, and it sets the sequencer to
    // the specified ~SEQR~ argument.
    
    `define uvm_create_on(SEQ_OR_ITEM, SEQR) \
      begin \
      uvm_object_wrapper w_; \
      w_ = SEQ_OR_ITEM.get_type(); \
      $cast(SEQ_OR_ITEM , create_item(w_, SEQR, `"SEQ_OR_ITEM`"));\
      end
    
    
    // MACRO: `uvm_do_on
    //
    //| `uvm_do_on(SEQ_OR_ITEM, SEQR)
    //
    // This is the same as <`uvm_do> except that it also sets the parent sequence to
    // the sequence in which the macro is invoked, and it sets the sequencer to the
    // specified ~SEQR~ argument.
    
    `define uvm_do_on(SEQ_OR_ITEM, SEQR) \
      `uvm_do_on_pri_with(SEQ_OR_ITEM, SEQR, -1, {})
    
    
    // MACRO: `uvm_do_on_pri
    //
    //| `uvm_do_on_pri(SEQ_OR_ITEM, SEQR, PRIORITY)
    //
    // This is the same as <`uvm_do_pri> except that it also sets the parent sequence
    // to the sequence in which the macro is invoked, and it sets the sequencer to
    // the specified ~SEQR~ argument.
    
    `define uvm_do_on_pri(SEQ_OR_ITEM, SEQR, PRIORITY) \
      `uvm_do_on_pri_with(SEQ_OR_ITEM, SEQR, PRIORITY, {})
    
    
    // MACRO: `uvm_do_on_with
    //
    //| `uvm_do_on_with(SEQ_OR_ITEM, SEQR, CONSTRAINTS)
    //
    // This is the same as <`uvm_do_with> except that it also sets the parent
    // sequence to the sequence in which the macro is invoked, and it sets the
    // sequencer to the specified ~SEQR~ argument.
    // The user must supply brackets around the constraints.
    
    `define uvm_do_on_with(SEQ_OR_ITEM, SEQR, CONSTRAINTS) \
      `uvm_do_on_pri_with(SEQ_OR_ITEM, SEQR, -1, CONSTRAINTS)
    
    
    // MACRO: `uvm_do_on_pri_with
    //
    //| `uvm_do_on_pri_with(SEQ_OR_ITEM, SEQR, PRIORITY, CONSTRAINTS)
    //
    // This is the same as `uvm_do_pri_with except that it also sets the parent
    // sequence to the sequence in which the macro is invoked, and it sets the
    // sequencer to the specified ~SEQR~ argument.
    
    `define uvm_do_on_pri_with(SEQ_OR_ITEM, SEQR, PRIORITY, CONSTRAINTS) \
      begin \
      uvm_sequence_base __seq; \
      `uvm_create_on(SEQ_OR_ITEM, SEQR) \
      if (!$cast(__seq,SEQ_OR_ITEM)) start_item(SEQ_OR_ITEM, PRIORITY);\
      if ((__seq == null || !__seq.do_not_randomize) && !SEQ_OR_ITEM.randomize() with CONSTRAINTS ) begin \
        `uvm_warning("RNDFLD", "Randomization failed in uvm_do_with action") \
      end\
      if (!$cast(__seq,SEQ_OR_ITEM)) finish_item(SEQ_OR_ITEM, PRIORITY); \
      else __seq.start(SEQR, this, PRIORITY, 0); \
      end
    
    
    //-----------------------------------------------------------------------------
    //
    // Group: Sequence Action Macros for Pre-Existing Sequences
    

    src/vcs-uvm-1.2/macros/uvm_sequence_defines.svh
    // This is the same as `uvm_send except that the sequence item or sequence is
    // executed with the priority specified in the argument.
    
    `define uvm_send_pri(SEQ_OR_ITEM, PRIORITY) \
      begin \
      uvm_sequence_base __seq; \
      if (!$cast(__seq,SEQ_OR_ITEM)) begin \
         start_item(SEQ_OR_ITEM, PRIORITY);\
         finish_item(SEQ_OR_ITEM, PRIORITY);\
      end \
      else __seq.start(__seq.get_sequencer(), this, PRIORITY, 0);\
      end
    
    
    // MACRO: `uvm_rand_send
    //
    //| `uvm_rand_send(SEQ_OR_ITEM)
    //
    // This macro processes the item or sequence that has been already been
    

    src/vcs-uvm-1.2/macros/uvm_sequence_defines.svh
    // This is the same as `uvm_rand_send except that the sequence item or sequence
    // is executed with the priority specified in the argument.
    
    `define uvm_rand_send_pri(SEQ_OR_ITEM, PRIORITY) \
      `uvm_rand_send_pri_with(SEQ_OR_ITEM, PRIORITY, {})
    
    
    // MACRO: `uvm_rand_send_with
    //
    //| `uvm_rand_send_with(SEQ_OR_ITEM, CONSTRAINTS)
    //
    // This is the same as `uvm_rand_send except that the given constraint block is
    // applied to the item or sequence in a randomize with statement before
    // execution.
    
    `define uvm_rand_send_with(SEQ_OR_ITEM, CONSTRAINTS) \
      `uvm_rand_send_pri_with(SEQ_OR_ITEM, -1, CONSTRAINTS)
    
    
    // MACRO: `uvm_rand_send_pri_with
    //
    //| `uvm_rand_send_pri_with(SEQ_OR_ITEM, PRIORITY, CONSTRAINTS)
    //
    // This is the same as `uvm_rand_send_pri except that the given constraint block
    // is applied to the item or sequence in a randomize with statement before
    // execution.
    
    `define uvm_rand_send_pri_with(SEQ_OR_ITEM, PRIORITY, CONSTRAINTS) \
      begin \
      uvm_sequence_base __seq; \
      if (!$cast(__seq,SEQ_OR_ITEM)) start_item(SEQ_OR_ITEM, PRIORITY);\
      else __seq.set_item_context(this,SEQ_OR_ITEM.get_sequencer()); \
      if ((__seq == null || !__seq.do_not_randomize) && !SEQ_OR_ITEM.randomize() with CONSTRAINTS ) begin \
        `uvm_warning("RNDFLD", "Randomization failed in uvm_rand_send_with action") \
      end\
      if (!$cast(__seq,SEQ_OR_ITEM)) finish_item(SEQ_OR_ITEM, PRIORITY);\
      else __seq.start(__seq.get_sequencer(), this, PRIORITY, 0);\
      end
    
    
    `define uvm_create_seq(UVM_SEQ, SEQR_CONS_IF) \
      `uvm_create_on(UVM_SEQ, SEQR_CONS_IF.consumer_seqr) \
    

    完整源码 · SHA256:8f1f8e8929451dbdf0aacd34e0dc876ab8c62e8910a05b4542e77d1578227344

    src/vcs-uvm-ieee-2020-2.0/macros/uvm_sequence_defines.svh
    // the user can manually set values, manipulate rand_mode and constraint_mode, etc.
    
    // @uvm-ieee 1800.2-2020 auto B.3.1.1
    `define uvm_create(SEQ_OR_ITEM, SEQR=get_sequencer()) \
      begin \
      uvm_object_wrapper w_; \
      w_ = SEQ_OR_ITEM.get_type(); \
      $cast(SEQ_OR_ITEM , create_item(w_, SEQR, `"SEQ_OR_ITEM`"));\
      end
    
    
    // MACRO -- NODOCS -- `uvm_do
    //
    //| `uvm_do(SEQ_OR_ITEM, SEQR=get_sequencer(), PRIORITY=-1, CONSTRAINTS={})
    //
    // This macro takes as an argument a uvm_sequence_item variable or object.
    // The argument is created using <`uvm_create>, which sets the sequencer to
    // the specified ~SEQR~ argument.
    // In the case of an item, it is randomized after the call to
    

    src/vcs-uvm-ieee-2020-2.0/macros/uvm_sequence_defines.svh
    //|
    
    // @uvm-ieee 1800.2-2020 auto B.3.1.4
    `define uvm_do(SEQ_OR_ITEM, SEQR=get_sequencer(), PRIORITY=-1, CONSTRAINTS={}) \
      begin \
      `uvm_create(SEQ_OR_ITEM, SEQR) \
      `uvm_rand_send(SEQ_OR_ITEM, PRIORITY, CONSTRAINTS) \
      end
    
    
    //-----------------------------------------------------------------------------
    //
    // Group -- NODOCS -- Sequence Action Macros for Pre-Existing Sequences
    //
    // These macros are used to start sequences and sequence items that do not
    // need to be created. 
    //-----------------------------------------------------------------------------
    

    src/vcs-uvm-ieee-2020-2.0/macros/uvm_sequence_defines.svh
    // `uvm_do without the create or randomization.
    
    // @uvm-ieee 1800.2-2020 auto B.3.1.2
    `define uvm_send(SEQ_OR_ITEM, PRIORITY=-1) \
      begin \
      uvm_sequence_base __seq; \
      if (!$cast(__seq,SEQ_OR_ITEM)) begin \
         start_item(SEQ_OR_ITEM, PRIORITY);\
         finish_item(SEQ_OR_ITEM, PRIORITY);\
      end \
      else __seq.start(__seq.get_sequencer(), this, PRIORITY, 0);\
      end
    
    
    // MACRO -- NODOCS -- `uvm_rand_send
    //
    //| `uvm_rand_send(SEQ_OR_ITEM, PRIORITY=-1, CONSTRAINTS={})
    //
    // This macro processes the item or sequence that has been already been
    

    src/vcs-uvm-ieee-2020-2.0/macros/uvm_sequence_defines.svh
    // randomization.
    
    // @uvm-ieee 1800.2-2020 auto B.3.1.3
    `define uvm_rand_send(SEQ_OR_ITEM, PRIORITY=-1, CONSTRAINTS={}) \
      begin \
      uvm_sequence_base __seq; \
      if ( SEQ_OR_ITEM.is_item() ) begin \
        start_item(SEQ_OR_ITEM, PRIORITY);\
        if ( ! SEQ_OR_ITEM.randomize() with CONSTRAINTS ) begin \
          `uvm_warning("RNDFLD", "Randomization failed in uvm_rand_send action") \
        end\
        finish_item(SEQ_OR_ITEM, PRIORITY);\
      end \
      else if ( $cast( __seq, SEQ_OR_ITEM ) ) begin \
        __seq.set_item_context(this,SEQ_OR_ITEM.get_sequencer()); \
        if ( __seq.get_randomize_enabled() ) begin \
          if ( ! SEQ_OR_ITEM.randomize() with CONSTRAINTS ) begin \
            `uvm_warning("RNDFLD", "Randomization failed in uvm_rand_send action") \
          end \
    

    完整源码 · SHA256:f63e78e8f476e6f17a2814a5954789951aa09b0946e394d7cf6b9e66c270c43a

    src/vcs-uvm-ieee-2020-2.0/deprecated/macros/uvm_sequence_defines.svh
    // This is the same as `uvm_do except that the sequence item or sequence is
    // executed with the priority specified in the argument
    
    `define uvm_do_pri(SEQ_OR_ITEM, PRIORITY) \
      `uvm_do(SEQ_OR_ITEM, get_sequencer(), PRIORITY, {})
    
    
    // MACRO -- NODOCS -- `uvm_do_with
    //
    //| `uvm_do_with(SEQ_OR_ITEM, CONSTRAINTS)
    //
    // This is the same as `uvm_do except that the constraint block in the 2nd
    // argument is applied to the item or sequence in a randomize with statement
    // before execution.
    
    `define uvm_do_with(SEQ_OR_ITEM, CONSTRAINTS) \
      `uvm_do(SEQ_OR_ITEM, get_sequencer(), -1, CONSTRAINTS)
    

    完整源码 · SHA256:7aec975281745a549a1d875f51e69706af862a48638b500888eccf778d8d7fe9

    src/vcs-uvm-ieee-2020-2.0/uvm_macros.svh
    `include "macros/uvm_callback_defines.svh"
    `include "macros/uvm_reg_defines.svh"
    
    `ifdef UVM_ENABLE_DEPRECATED_API
    `include "deprecated/macros/uvm_sequence_defines.svh"
    `endif
    
    `ifdef VCS
    `ifndef UVM_VCS_ENC
    `define UVM_VCS_GLOBAL_DECLARATIONS
    `define UVM_VCS_DECLARATIONS
    `define UVM_VCS_CHECK(if_expr) if_expr
    `define UVM_VCS_CLP_TF
    `ifdef UVM_VCS_DTL_REFRESH
    `define UVM_VCS_CALL_REFRESH_COMPONENT
    `endif
    `endif
    `endif
    

    完整源码 · SHA256:d85eb414948cb37c6249b33c0c7f728296e86f833a81d772c86e09245d8df764

    术语解释 · 兼容配置

    返回Sequence / Sequencer · 迁移清单

    版本适用范围