当前位置: 首页 > news >正文

systemverilog中的priority if

1 基本概念

        在 SystemVerilog 中,priority - if是一种条件判断结构。它和普通的if - else语句类似,但在条件评估和错误检查方面有自己的特点,主要用于按顺序评估多个条件,并且对不符合预期的情况进行报错。报错如下两点

        当所有条件都不为真时,

        或者如果最后一个 “if” 结构没有 “else” 子句时。

2 语法结构

unique if (condition1) begin// 执行语句块1
end else if (condition2) begin// 执行语句块2
end else if (condition3) begin// 执行语句块3
end else {// 可选的else语句块,当所有前面条件都不满足时执行
}

3 示例

1 No else clause in priority-if(没有else)

module tb;int x = 4;initial begin// This if else if construct is declared to be "unique"// Error is not reported here because there is a "else"// clause in the end which will be triggered when none of// the conditions matchpriority if (x == 3)$display ("x is %0d", x);else if (x == 5)$display ("x is %0d", x);else$display ("x is neither 3 nor 5");// When none of the conditions become true and there// is no "else" clause, then an error is reportedpriority if (x == 3)$display ("x is %0d", x);else if (x == 5)$display ("x is %0d", x);end
endmodule//----------------- simulation log-----------------//
ncsim> run
x is neither 3 nor 5
ncsim: *W,NOCOND: Priority if violation:  Every if clause was false.File: ./testbench.sv, line = 18, pos = 15Scope: tbTime: 0 FS + 1ncsim: *W,RNQUIE: Simulation is complete.

2 Multiple matches in unique-if(匹配多个if)

module tb;int x = 4;initial begin// This if else if construct is declared to be "unique"// When multiple if blocks match, then error is reportedpriority if (x == 4)$display ("1. x is %0d", x);else if (x == 4)$display ("2. x is %0d", x);else$display ("x is not 4");end
endmodule//----------------- simulation log-----------------//
ncsim> run
1. x is 4
ncsim: *W,MCONDE: priority if violation:  Multiple true if clauses at {line=8:pos=15 and line=10:pos=13}.File: ./testbench.sv, line = 8, pos = 15Scope: tbTime: 0 FS + 1ncsim: *W,RNQUIE: Simulation is complete.

http://www.lryc.cn/news/509027.html

相关文章:

  • 图像处理-Ch2-空间域的图像增强
  • css 编写注意-1-命名约定
  • 虚幻引擎反射机制
  • Knife4j Swagger
  • Xcode 16 编译弹窗问题、编译通过无法,编译通过打包等问题汇总
  • 卷积神经网络入门指南:从原理到实践
  • eNSP安装教程(内含安装包)
  • VBA技术资料MF244:利用VBA在图表工作表中创建堆积条形图
  • 【计算机网络安全】网络攻击
  • 20241230 基础数学-线性代数-(1)求解特征值(numpy, scipy)
  • 基于图注意力网络的两阶段图匹配点云配准方法
  • 【半导体光电子器件】课后习题答案和知识点汇总
  • Unity命令行传递自定义参数 命令行打包
  • web-worker应用在大文件切片上传
  • Django 模板分割及多语言支持案例【需求文档】-->【实现方案】
  • C中设计不允许继承的类的实现方法是什么?
  • 面对小白的C语言学习方法
  • 使用libgif库解码全过程(C语言)-包括扩展块的处理
  • blazor实现ASP.NET网站用户批量注册方法
  • SpringCloud 入门(4)—— 网关
  • 什么是WebAssembly?怎么使用?
  • v3s点RGB屏 40pin 800x480,不一样的点屏,不通过chosen。
  • 某科技局国产服务器PVE虚拟化技术文档
  • 中科岩创边坡自动化监测解决方案
  • GPT-O3:简单介绍
  • cudnn版本gpu架构
  • 数据库安全-redisCouchdb
  • ubuntu22.04安装PaddleX3
  • Flutter 实现全局悬浮按钮学习
  • 14-C语言多文件编程