跳转至

输入查询内容

    本页内容

    pack 位流格式改变:检查外部接收端与历史数据

    影响范围

    packet 跨库、DPI 或外部 golden 边界传递时重点核对;同版 pack/unpack 也应覆盖实际对象图、空对象与数组。

    具体差异

    1.2 默认 big_endian=1(msb 在前)、use_metadata=0(pack_object 不写 null 标记、pack_string 不写终止符)。2.0 移除 big_endian/use_metadata/policy 字段,固定为 lsb→msb 顺序;pack_object 恒写 4-bit null 标记(null→4'h0,非空→4'hF);pack_string 恒补 null 字节。依赖这些布局的跨版本 golden、DPI/C 数据契约和留存向量不能直接沿用;是否实际失配取决于所用入口、旧配置和字段内容,不能据此认定所有位流必然不同。

    修改方案

    同版 pack/unpack 仍需验证实际对象类型、空对象和数组长度;跨边界流必须与保留的 1.2 golden 逐位对照。可用 uvm_compat_packer 配合显式 do_pack/do_unpack 固定契约,或统一升级两端格式。不能将替换 packer 本身作为位流兼容性验收。

    若外部模型或保存的数据仍按 1.2 格式读取,可先在目标库中显式传入兼容 packer:

    1
    2
    3
    4
    5
    6
    import uvm_compat_pkg::*;
    // Inside the task/function that packs the existing packet:
    uvm_compat_packer packer = new();
    bit bits[];
    int nbits;
    nbits = packet.pack(bits, packer);
    

    先按“版本与兼容”指南编译 uvm_compat_pkg.svpacket 是已有事务对象;示例只展示调用点,不改变对象的 do_pack 实现。

    nbitsbits 与保存的 1.2 输出逐位对比。同库 pack/unpack 往返成功不能证明格式兼容。涉及嵌套对象、空句柄或 TLM2 通用事务时,兼容 packer 仍可能与旧格式不同,应为外部接口定义固定格式。

    兼容措施与范围

    显式使用兼容包提供的类或宏后生效。直接 pack_field_int / pack_string 已实测恢复旧流;但新 field_object 宏走 with_meta 路径,含嵌套对象的同一 packet 即使用 compat packer 也由 148 位变为 308 位。compat::pack_object 还在写 null 标记前先执行子对象 do_execute_op(src/vcs-uvm-ieee-2020-2.0/compat/uvm_compat_packer.svh:412),与 1.2 顺序不同。显式旧格式示例 tests/uvm_review/serialization_probe.sv 固定四位标记和字段顺序后,两版生成完全相同的 148 位流并成功回读;该例不涵盖循环引用或任意对象图。GP 新增 m_dmi 另见 M08-003

    迁移后验证

    保存 1.2 golden,逐位检查长度和第一个差异;覆盖空对象、嵌套对象和 GP。只有本版 pack/unpack 闭环通过不足以证明跨版本兼容。

    记录本条结果M02-001 · 状态与证据

    已有实测与复现

    补充查阅

    扫描定位与记录结果

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

    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules S6,S44
    

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

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

    源码与标准依据

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

    VCS 内置 UVM-1.2uvm_packer.svh:322(use_metadata)、uvm_packer.svh:358(big_endian=1)

    VCS 内置 uvm-ieee-2020-2.0uvm_packer.svh:49(类定义)、实现见 uvm_packer.svh:584 起(pack_field 等不再查 big_endian)

    标准依据:IEEE 1800.2-2020 §16.5(标准不再定义 big_endian 旋钮,打包布局属实现细节;§16.5.3 注明 state stream 格式"未指定",仅同兼容实现间可移植)

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

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

    src/vcs-uvm-1.2/base/uvm_packer.svh
      // - For queues, dynamic arrays, and associative arrays, pack 32 bits
      //   indicating the size of the array prior to packing individual elements.
    
      bit use_metadata;
    
    
      // Variable: big_endian
      //
      // This bit determines the order that integral data is packed (using
      // <pack_field>, <pack_field_int>, <pack_time>, or <pack_real>) and how the
      // data is unpacked from the pack array (using <unpack_field>,
      // <unpack_field_int>, <unpack_time>, or <unpack_real>). When the bit is set,
      // data is associated msb to lsb; otherwise, it is associated lsb to msb. 
      //
      // The following code illustrates how data can be associated msb to lsb and
      // lsb to msb:
      //
      //|  class mydata extends uvm_object;
      //|
    

    src/vcs-uvm-1.2/base/uvm_packer.svh
      //|    d.pack(bits);  // 'b0010110001001000
      //|  end
    
      bit big_endian = 1;
    
    
      // variables and methods primarily for internal use
    
      static bit bitstream[];   // local bits for (un)pack_bytes
      static bit fabitstream[]; // field automation bits for (un)pack_bytes
      int count;                // used to count the number of packed bits
      uvm_scope_stack scope= new;
    
      bit   reverse_order;      //flip the bit order around
      byte  byte_size     = 8;  //set up bytesize for endianess
      int   word_size     = 16; //set up worksize for endianess
      bit   nopack;             //only count packable bits
    
      uvm_recursion_policy_enum policy = UVM_DEFAULT_POLICY;
    

    完整源码 · SHA256:2c802b943823e0d088bc70ec94ad49f08f2bbee46f451900353d5e926027b4f6

    src/vcs-uvm-ieee-2020-2.0/base/uvm_packer.svh
    // 16.5.1 of 1800.2-2020
    
    // @uvm-ieee 1800.2-2020 auto 16.5.1
    class uvm_packer extends uvm_policy;
    
       // @uvm-ieee 1800.2-2020 auto 16.5.2.3
       `uvm_object_utils(uvm_packer)
    
        uvm_factory m_factory;  
        local uvm_object m_object_references[int];
    
    
      // Function -- NODOCS -- set_packed_*
      // Implementation of P1800.2 16.5.3.1
      //
      // The LRM specifies the set_packed_* methods as being
      // signed, whereas the <uvm_object::unpack> methods are specified
      // as unsigned.  This is being tracked in Mantis 6423.
      //
    

    src/vcs-uvm-ieee-2020-2.0/base/uvm_packer.svh
    // pack_field
    // ----------
    
    function void uvm_packer::pack_field(uvm_bitstream_t value, int size);
      for (int i=0; i<size; i++)
          m_bits[m_pack_iter+i] = value[i];
      m_pack_iter += size;
    endfunction
    
    
    // pack_field_int
    // --------------
    
    function void uvm_packer::pack_field_int(uvm_integral_t value, int size);
      for (int i=0; i<size; i++)
          m_bits[m_pack_iter+i] = value[i];
      m_pack_iter += size;
    endfunction
    

    完整源码 · SHA256:46e8c9a07d8057451745f4d9b1f49549150620837e7a34bc638a6382d45d9ee2

    src/vcs-uvm-ieee-2020-2.0/compat/uvm_compat_packer.svh
      return unpack_str;
    endfunction 
    
    function void pack_object(uvm_object value);
      uvm_field_op field_op;
    
      push_active_object(value);
      field_op = uvm_field_op::m_get_available_op() ;
      field_op.set(UVM_PACK,this,value);
      value.do_execute_op(field_op);
      if (field_op.user_hook_enabled()) begin
         if ((get_active_object_depth() > 1) && use_metadata) begin
            m_bits[m_pack_iter +: 4] = 1;
            m_pack_iter += 4;
         end
        value.do_pack(this);
      end
      else if ((get_active_object_depth() > 1) && use_metadata) begin
         m_bits[m_pack_iter +: 4] = 0;
    

    完整源码 · SHA256:a1ef26565856c33522d710edd7a0e85ee7dbcdd4354ae9e9237a195a3b5f5e16

    术语解释 · 兼容配置

    uvm_tlm_generic_payload do_pack/do_unpack 无条件打包 m_dmi(M08-003)

    返回Comparer / Printer / Packer / Recorder · 迁移清单

    版本适用范围