首页 > 其他分享 >SystemVerilog -- 10.1 SystemVerilog Covergroup and Coverpoint

SystemVerilog -- 10.1 SystemVerilog Covergroup and Coverpoint

时间:2024-05-11 23:44:39浏览次数:13  
标签:10.1 clk -- cfg 0x1 cg mode covergroup SystemVerilog

SystemVerilog Covergroup and Coverpoint

SystemVerilog 是一种用户定义的类型,用于封装覆盖率模型的规范。它们可以定义一次,并通过函数在不同位置实例化多次。covergroup new

covergroup可以在包、模块、程序、接口类中定义,通常封装以下信息:

  • A set of coverage points
  • Cross coverage between coverage points
  • An event that defines when the covergroup is sampled
  • Other options to configure coverage object

covergroup

module tb;
// Declare some varibles that can be "sampled" in the covergroup
bit [1:0] mode;
bit [2:0] cfg;

// Declare a clock to act as an event that can be used to sample coverage points within the covergroup
bit clk;
always #20 clk = ~clk;

// "cg" is a covergroup that is sampled at every posedge clk
covergroup cg @ (posedge clk);
  coverpoint mode;
endgroup

// Create an instance of the covergroup
cg cg_inst;

initial begin
  // Instantiate the covergroup object similar to a class object
  cg_inst = new ();
  // Stimulus : Simply assign random values to the coverage variables
  // So that different values can be sampled by the covergroup object
  for (int i = 0; i < 5; i++) begin
    @(negedge clk);
    mode = $random;
    cfg  = $random;
    $display ("[%0t] mode=0x%0h cfg=0x%0h", $time, mode, cfg);
  end
end

// At the end of 500ns, terminate test and print collected coverage
initial begin
  #500 $display ("Coverage = %0.2f %%", cg_inst.get_inst_coverage());
  $finish;
end 
endmodule

模拟日志

ncsim> run
  [40] mode=0x0  cfg=0x1
  [80] mode=0x1  cfg=0x3
  [120] mode=0x1  cfg=0x5
  [160] mode=0x1  cfg=0x2
  [200] mode=0x1  cfg=0x5
  Coverage = 50.00 %
Simulation complete via $finish(1) at time 500 NS + 0

coverpoint

module tb;
  bit [1:0] mode;
  bit [2:0] cfg;

  bit clk;
  always #20 clk = ~clk;

  // "cg" is a covergroup that is sampled at every posedge clk
  // This covergroup has two coverage points, one to cover "mode" and the other to cover "cfg". Mode can take any value from 0 -> 3 and cfg can take any value from 0 -> 7
  covergroup cg @(posedge clk);

  // Coverpoints can optionally have a name before a colon ":"
  cp_mode    : coverpoint mode;
  cp_cfg_10  : coverpoint cfg[1:0];
  cp_cfg_1sb : coverpoint cfg[0];
  cp_sum     : coverpoint (mode + cfg);
  endgroup

  cg   cg_inst;

  initial begin
    @(negedge clk);
    mode = $random;
    cfg  = $random;
    $display ("[%0t] mode=0x%0h cfg=0x%0h", $time, mode, cfg);
  end

  initial begin
    #500 $display ("Coverage = %0.2f %%", cg_inst.get_inst_coverage());
    $finish;
  end 
endmodule

模拟日志

ncsim> run
  [40] mode=0x0  cfg=0x1
  [80] mode=0x1  cfg=0x3
  [120] mode=0x1  cfg=0x5
  [160] mode=0x1  cfg=0x2
  [200] mode=0x1  cfg=0x5
  Coverage = 78.12 %
Simulation complete via $finish(1) at time 500 NS + 0

标签:10.1,clk,--,cfg,0x1,cg,mode,covergroup,SystemVerilog
From: https://www.cnblogs.com/sys-123456/p/18187357

相关文章

  • WPF DataGridTextColumn下的Visibility绑定
    WPF中的DataContext属性非常方便,但在某些情况下,DataContext是不可访问的,比如,当你想绑定的元素不属于其逻辑树或可视树时,想正常使用绑定就可能非常困难……让我们给一个简单的例子予以说明:我们要在DataGrid中显示产品列表。在其中,我们希望能够基于ViewModel中公开的ShowPrice属性......
  • 成吉思汗3_单机_VM虚拟机
    稀有端游成吉思汗1,2,3单机版虚拟机一键端完整版本教程仅限学习使用,禁止商用,一切后果与本人无关,此声明具有法律效应!!!!教程是本人亲自搭建成功的,绝对是完整可运行的,踩过的坑都给你们填上了。如果你是小白也没问题,跟着教程走也是可以搭建成功的,但是一定要有耐心。。。当前教程为成......
  • 全局变量和局部变量以及静态修饰作用
    1,全局变量和全局静态变量a、全局变量:全局变量存放在静态存储区,作用域是全局(对比下面添加static),整个声明周期都可以使用,其他文件如需要使用,需要添加externb、全局静态变量(static):分配的内存与全局变量一样,也是在静态存储内存上,其生命周期也是与整个程序同在的,从程序开始到结束一......
  • 55-jump Game 跳跃游戏
    问题描述Youaregivenanintegerarraynums.Youareinitiallypositionedatthearray'sfirstindex,andeachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Returntrueifyoucanreachthelastindex,orfalseotherwise解释......
  • go channel ->同步
    通道并非用来取代锁,各有不同使用场景。通道解决高级别逻辑层次并发架构,锁则用来保护低级别局部代码安全。●竟态条件:多线程同时读写共享资源(竟态资源)。●临界区:读写竟态资源的代码片段。●互斥锁:同一时刻,只有一个线程能进入临界区。●读写锁:写独占(其他读写均被阻塞),读共享。●信号......
  • 5.11
    jetpackcompose搭建地铁系统页面@OptIn(ExperimentalMaterial3Api::class)@ComposablefunHomeScreen(viewModel:HomeViewModel=viewModel(factory=AppViewModelProvider.Factory)){SideEffect{viewModel.findMetroSystems()}valtabT......
  • golang channel 封装
    对于closed或nil通道,规则如下:无论收发,nil通道都会阻塞。不能关闭nil通道。重复关闭通道,引发panic!向已关闭通道发送数据,引发panic!从已关闭通道接收数据,返回缓冲数据或零值。nil通道是指没有make的变量。鉴于通道关闭后,所有基于此的阻塞都被解除,可用作通知。没......
  • java MySQL的in查询两个字段同时相等的多个数据查询
    在Java中想进行下面的查询,不想写循环一条条查selectid,name,address,age fromuserswherename='A' and address='addr1'selectid,name,address,age fromuserswherename='B' and address='addr2'selectid,name,address,age fromusers......
  • 无题
    1. 应急响应复盘过程中,安全运维人员发现防火墙未能发挥作用,分析原因。一是检查流量是否经过了防火墙:由于防火墙只能对流经它的数据进行控制,因此在对防火墙设置时,必须让其位于不同网络安全区域之间的唯一通道上;二是检查管理员是否根据安全需求合理设计安全策略与规则。三是在条......
  • 蓝桥杯-递增三元组(三种解法,二分, 双指针, 前缀和)
    给定三个整数数组A=[A1,A2,…AN],B=[B1,B2,…BN],C=[C1,C2,…CN],请你统计有多少个三元组(i,j,k)满足:1≤i,j,k≤NAi<Bj<Ck输入格式第一行包含一个整数N。第二行包含N个整数A1,A2,…AN。第三行包含N个整数B1,B2,…BN。第四行包含N个整数C1,C2,…CN。输出格......