首页 > 其他分享 >软约束 soft constraint

软约束 soft constraint

时间:2022-08-21 16:00:21浏览次数:83  
标签:constraint soft 2021.09 约束 version data

首先使用关键字 soft 声明软约束。

硬约束之间如果存在矛盾,那么求解器将失败,仿真也会失败。当没有同时满足所有有效硬约束和定义为软约束的解决方案时,求解器将放弃软约束并找到满足剩余硬约束的解决方案,如果还找不到那就出错。软约束仅表示对一种解决方案的偏好,当软约束与其他硬约束相矛盾时,软约束将被放弃。

看一个约束冲突的例子:

class sft;
  rand bit [3:0] data;
  constraint data_range { data > 'hf; }
  constraint data_range1 { data <= 'ha; } //conflicting constraint
endclass
module soft_constr;
  initial begin
    sft sf;
    sf = new();
    repeat(4) begin
      sf.randomize();
      $display("\data = %0h",sf.data);
    end
  end
endmodule

在上边的例子中,这两个约束是冲突的。一个是要求data为>'hf,而另一个是限制data为<='ha。在这种情况下,将收到以下运行时错误 (Synopsys – VCS):

仿真结果:

Compiler version S-2021.09; Runtime version S-2021.09;  Aug 21 03:22 2022

=======================================================

Solver failed when solving following set of constraints 


rand bit[3:0] data; // rand_mode = ON 

constraint data_range    // (from this) (constraint_mode = ON) (testbench.sv:5)
{
   (data > 4'hf);
}

=======================================================

Error-[CNST-CIF] Constraints inconsistency failure
testbench.sv, 13
  Constraints are inconsistent and cannot be solved.
  Please check the inconsistent constraints being printed above and rewrite 
  them.

data = 0
           V C S   S i m u l a t i o n   R e p o r t

 

添加软约束之后:

class sft;
  rand bit [3:0] data;
  constraint data_range { soft data > 'hf; }
  constraint data_range1 { data <= 'ha; } //conflicting constraint
endclass
module soft_constr;
  initial begin
    sft sf;
    sf = new();
    repeat(4) begin
      sf.randomize();
      $display("\data = %0h",sf.data);
    end
  end
endmodule

仿真结果:

Compiler version S-2021.09; Runtime version S-2021.09;  Aug 21 03:32 2022
data = 6
data = 3
data = 0
data = 1
           V C S   S i m u l a t i o n   R e p o r t 

  

再来看一下相同的示例,类约束和内联(inline)约束(with constraint)之间存在冲突。这是软约束最有用的地方。将通用约束声明为软约束,允许内联约束(with 约束)覆盖类约束:

看一个例子:

class sft;
  rand bit [3:0] data;
//class constraint converted to 'soft' constraint
  constraint data_range { soft data > 'hf; }
endclass
module soft_constr;
  initial begin
    sft sf;
    sf = new( );
    repeat(4) begin
    //inline constraint - hard
      sf.randomize( ) with { data <= 'ha;};
      $display("\data = %0h",sf.data);
    end
  end
endmodule

 

 仿真结果:

Compiler version S-2021.09; Runtime version S-2021.09;  Aug 21 03:47 2022
data = 6
data = 3
data = 0
data = 1
           V C S   S i m u l a t i o n   R e p o r t 

 

最后,我们可以禁用软约束:

constraint data_range { disable soft data; } 

 

标签:constraint,soft,2021.09,约束,version,data
From: https://www.cnblogs.com/fuqiangblog/p/16610051.html

相关文章

  • 乘风破浪,遇见最佳跨平台跨终端框架.Net Core/.Net生态 - 官方扩展集锦(Microsoft.Exte
    什么是Microsoft.Extensions.NETPlatformExtensions是一套.Net官方的API集合,提供了一些常用的编程模式和实用工具,例如依赖项注入、日志记录、缓存、Host以及配置等等。......
  • Implication(->) and If-Else constraint
    可以使用蕴含运算符(->)和if-else构造进一步限制随机化。它们都表示两个变量之间的条件关系。隐含运算符用于声明隐含约束的表达式。例如:constraintdataC{(data==......
  • Unique Constraint
    如果不希望组中的任何两个成员在随机化后具有相同的值,需要使用“unique”constraint。“unique”是一个关键词,使用“unique”将生成受约束的rand变量的唯一值。它不仅适......
  • 题解 TSP 但是你有约束
    Description给定一张带权完全图,求一条路径满足不重复经过一个点。在过点\(i\)时,\(1\cdotsi-1\)要么全访问过,要么都没有访问过。点数\(n\)有\(1\len\le1e3......
  • MYSQL-->函数与约束条件
    函数用法函数最常用的地方就是查询语句处select函数(字段)from表名;select字段列表from表名groupby分组字段having函数(字段);字符串函数(字符串要用引......
  • Newtonsoft.Json
    1、序列化stringjsonStr=JsonConvert.SerializeObject(obj)2、反序列化Tobj=JsonConvert.DeserializeObject(jsonStr)3、Newtonsoft.Json扩展方法类///<summa......
  • SystemVerilog 随机化约束速查手册
    SystemVerilog随机化约束速查手册dist关键字权重分布使用dist关键字来实现权重分布:=表示范围内每个权重是相同的:/表示权重要均分到范围的每个值randintsrc;......
  • Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationExceptio
    多表查询时mysql语句报错Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:Column'XX'inwhereclauseisambiguous原因多表查......
  • mysql外键约束 删除
    mysql海量表的创建CREATETABLEdept(/*部门表*/deptnoMEDIUMINTUNSIGNEDNOTNULLDEFAULT0,dnameVARCHAR(20)NOTNULLDEFAULT"",locVARCHAR(13)NOT......
  • 手写实现 js 中的bind,并实现 softBind
    //bind会返回一个硬绑定的新函数,新函数会使用指定的第一个thisCtx去调用原始函数,并将其它参数传给原始函数。硬绑定会降低函数的灵活性,在绑定之后不能通过显式或硬绑定......