大型SystemVerilog约束的示例

时间:2012-10-30 16:09:49

标签: system-verilog

您能举例说明一个庞大而复杂的SystemVerilog约束吗?越大越好,最好是现实的。也许某些地址计算也取决于其他一些变量。

我正在评估切换我们的IP以使用SystemVerilog约束,我的管理层希望看到创建/理解SystemVerilog约束是多么容易/多难。

2 个答案:

答案 0 :(得分:9)

由于我无法对之前的帖子发表评论,并且我的建议编辑遭到拒绝,我只能添加看似新答案的内容,但不是。感叹!

这是编辑Subbdue的示例以修复以下语法错误:

  1. SV typedef enum {...} <name>;语法,而不是OpenVera enum <name> {...};语法
  2. 使用;
  3. 结束枚举声明
  4. 声明变量channelNumber
  5. ipVersion声明为rand
  6. SV <var> inside { [<min>:<max>] }语法,而不是OpenVera <var> in { min:max }语法
  7. 使用constraint
  8. ; s中结束表达式
  9. SV ->语法,而不是OpenVera =>语法
  10. 修正拼写错误solver - &gt; solve
  11. 修正拼写错误IPVx - &gt; IPVX
  12. 修复示例:

    class RandomConstraints;
        typedef enum {IPV4=2, IPV6, IPVX} IpVersionType;
    
        //Randomly iterate over values without repetition
        randc bit [7:0] cyclicCounter;
        //Regular random variables
        rand bit [15:0] destAddress;
        rand bit [15:0] sourceAddress;
        rand bit [15:0] numberOfPackets;
        rand bit [15:0] packetLength;
        rand bit [3:0] channelNumber;
        rand bit [7:0]  var1;
        rand bit [7:0]  var2;
        rand IpVersionType ipVersion;
    
        //Non-random variables that can be used to control constraints
        bit [15:0] minNumberOfPackets, maxNumberOfPackets;
        bit [15:0] minPacketLength, maxPacketLength;
        integer IPV4Weight, IPV6Weight;
    
        constraint cPacketLength {
            packetLength inside { [ minPacketLength : maxPacketLength ] };
        }
        constraint cChannelNumber {
            channelNumber inside {[0:1]};
        }
        // Assuming total weight adds up to 100
        constraint cIPVersionType {
            ipVersion dist { IPV4 := IPV4Weight, IPV6 := IPV6Weight,
              IPVX := (100 - IPV4Weight - IPV6Weight) };
        }
        //Probability of var1 being 1,2,3,4,5 in the ratio 1,2,4,4,4
        constraint cDist1 {
            var1 dist { 1 := 1, 2 := 2, [3:4] := 4 };
        }
        //Probability of var2 being 1,2,3,4,5 is in the ratio 1,2,4/3,4/3,4/3
        constraint cDist2 {
            var2 dist { 1 := 1, 2 := 2, [3:5] :/ 4 };
        }
        //Implication constraint - if(channelNum == i) then { ... }
        constraint cImplication {
            (channelNumber == 0) -> {
                destAddress inside {[0:200]};
                sourceAddress inside {[201:400]};
            }
            (channelNumber == 1) -> {
                destAddress inside {[201:400]};
                sourceAddress inside {[0:200]};
            }
        }
        //Controlling order of constraints solved using a constraint solver
        constraint order_solver {
            solve channelNumber before destAddress;
            solve channelNumber before sourceAddress;
        }
    
        function new();
            //Setting default min/max packets and min/max packet length
            minNumberOfPackets = 100;
            maxNumberOfPackets = 1000;
            minPacketLength = 128;
            maxPacketLength = 256;
            IPV4Weight = 50;
            IPV6Weight = 30;
        endfunction
    endclass
    

答案 1 :(得分:3)

这是一个例子,可能不是很大而且很复杂,但它应该让你对如何使用约束有一个现实的想法。在这里,您将看到以下使用的概念:

  1. randc和rand - 循环和非循环随机变量
  2. 两种类型的分布式约束
  3. 使用蕴涵运算符 ... 根据另一个变量计算的地址
  4. 使用if条件中的条件
  5. 约束订单解算器
  6. 在构造函数
  7. 中约束随机变量的默认范围
  8. 在约束中使用枚举类型
  9. 希望这有助于......并在线观看评论:

    class RandomConstraints;
        enum IpVersionType {IPV4=2, IPV6, IPVx}
    
        //Randomly iterate over values without repetition
        randc bit [7:0] cyclicCounter;
        //Regular random variables
        rand bit [15:0] destAddress;
        rand bit [15:0] sourceAddress;
        rand bit [15:0] numberOfPackets;
        rand bit [15:0] packetLength;
        rand bit [7:0]  var1;
        rand bit [7:0]  var2;
        IpVersionType ipVersion;
    
        //Non-random variables that can be used to control constraints
        bit [15:0] minNumberOfPackets, maxNumberOfPackets;
        bit [15:0] minPacketLength, maxPacketLength;
        integer IPV4Weight, IPV6Weight;
    
        constraint cPacketLength {
            packetLength in { minPacketLength : maxPacketLength }
        }
        constraint cChannelNumber {
            channelNumber in {0:1}
        }
        constraint cIPVersionType {
            ipVersion dist { IPV4 := IPV4Weight, IPV6 := IPV6Weight, IPVX := (100 - IPV4Weight - IPV6Weight) }
        }
        //Probability of var1 being 1,2,3,4,5 in the ratio 1,2,4,4,4
        constraint cDist1 {
            var1 dist { 1 := 1, 2 := 2, [3:4] := 4 }
        }
        //Probability of var2 being 1,2,3,4,5 is in the ratio 1,2,4/3,4/3,4/3 
        constraint cDist2 {
            var2 dist { 1 := 1, 2 := 2, [3:5] :/ 4 }
        }       
        //Implication constraint - if(channelNum == i) then { ... }
        constraint cImplication {
            (channelNumber == 0) => {
                destAddress in {0:200};
                sourceAddress in {201:400};
            }
            (channelNumber == 1) => {
                destAddress in {201:400};
                sourceAddress in {0:200};
            }
        }
        //Controlling order of constraints solved using a constraint solver
        constraint order_solver {
            solver channelNumber before destAddress;
            solver channelNumber before sourceAddress;
        }
    
        function new();
            //Setting default min/max packets and min/max packet length
            minNumberOfPackets = 100;
            maxNumberOfPackets = 1000;
            minPacketLength = 128;
            maxPacketLength = 256;
            IPV4Weight = 50;
            IPV6Weight = 30;
        endfunction
    endclass