你能给出一个大而复杂的SystemVerilog约束的例子吗?越大越好,最好是现实的.也许某些地址计算也取决于其他一些变量.
我正在评估切换我们的IP以使用SystemVerilog约束,我的管理层希望看到创建/理解SystemVerilog约束是多么容易/多难.
由于我无法评论上一篇文章,我的建议编辑被拒绝,我只能添加看起来像新答案但不是.叹!
以下是编辑Subbdue的示例以修复以下语法错误:
typedef enum {...} <name>;语法而不是OpenVera enum <name> {...};语法;channelNumberipVersion为rand<var> inside { [<min>:<max>] }语法而不是OpenVera <var> in { min:max }语法constraints中的结束表达式;->语法而不是OpenVera =>语法solver- >solveIPVx- >IPVX固定示例:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22092 次 |
| 最近记录: |