I want to constrain my address in Packet class such that
addr is 32 bit unpacked array of 32 bit vectors and it is declared in Packet class as
class Packet;
rand bit [31:0] dest_addr;
rand bit [31:0] source_addr;
rand bit [7:0] data_length;
rand byte data[];
rand byte fcs;
rand bit [31:0] addr [0:3];
string name;
rand bit [28:0] n;
rand bit [3:0] test;
static int count;
rand da_kind_t da_kind;
rand fcs_kind_t fcs_kind;
rand length_kind_t length_kind;
constraint c_n {
n != 0;
}
//Word alignment constraint
constraint c_addr {
foreach(addr[i])
addr[i] == 4*n;
}
with the error message :
Driver_mem.sv(20): randomize() failed due to conflicts between the following constraints:
# Packet.sv(29): c_n { (n != 0); }
# Where:
# n = 29'h00000000 /* non-random */
# ** Note: (vsim-7130) Enabling enhanced debug (-solvefaildebug=2) may generate a more descriptive constraint contradiction report.
# Time: 0 ps Iteration: 2 Instance: /tb_router/test
# ** Note: (vsim-7106) Use vsim option '-solvefailtestcase[=filename]' to generate a simplified testcase that will reproduce the failure.
# Time: 0 ps Iteration: 2 Instance: /tb_router/test
However the constraint resolver fails. I have also tried these methods, which also fail.
constraint c_addr {
foreach(addr[i])
addr[i][31:2] != 0;
addr[i][1:0] == 0;
}
This method also fails
constraint c_addr {
addr[0] > 0;
addr[1] > 0;
addr[2] > 0;
addr[3] > 0;
}
constraint c_addr1 {
foreach(addr[i])
addr[i][1:0] == 0;
}
with the output message:
Driver_mem.sv(20): randomize() failed due to conflicts between the following constraints:
# Packet.sv(23): c_addr { (addr[0] > 0); }
# Packet.sv(24): c_addr { (addr[1] > 0); }
# Packet.sv(25): c_addr { (addr[2] > 0); }
# Packet.sv(26): c_addr { (addr[3] > 0); }
# Packet.sv(31): c_addr1 { (addr[3][1:0] == 0); }
# Packet.sv(31): c_addr1 { (addr[2][1:0] == 0); }
# Packet.sv(31): c_addr1 { (addr[1][1:0] == 0); }
# Packet.sv(31): c_addr1 { (addr[0][1:0] == 0); }
# Packet.sv(97): c_dest_addr { (dest_addr inside { addr[3], addr[2], addr[1], addr[0] }); }
# Where:
# addr[0][1:0] = 2'h0
# addr[1][1:0] = 2'h0
# addr[2][1:0] = 2'h0
# addr[3][1:0] = 2'h0
# dest_addr = 0 /* non-random */
# Given:
# bit [31:0] addr[3]
# bit [31:0] addr[2]
# bit [31:0] addr[1]
# bit [31:0] addr[0]
Also these 4 methods, though does not fail but gives the output as
# addr0: 0x00000000
# addr1: 0x00000000
# addr2: 0x00000000
# addr3: 0x00000000
//Word alignment constraint
constraint c_addr {
foreach(addr[i]) {
addr[i][31:2] != 0;
addr[i][1:0] == 0;
}
}
constraint c_addr0 {
addr[0] == 4*(n+1);
addr[1] == 4*(n+2);
addr[2] == 4*(n+3);
addr[3] == 4*(n+4);
}
constraint c_addr0 {
addr[0] == 4*(n+1);
addr[1] == addr[0] + 4;
addr[2] == addr[1] + 4;
addr[3] == addr[2] + 4;
}
constraint c_addr0 {
foreach(addr[i])
addr[i] == (i+4);
}
The Packet is for a 1x4 router verification and the requirement is that address of the destination port has to be word aligned, at the same a non 0 value. Any help is appreciated. Also, please note that the addr is to be randomized just once, i.e just one set of 4 unique non 0 word aligned addressses and if I just provide word aligned constraint, I get always one addr in the array which is 0x00000000.
Well, I could resolve this issue through some complex process. But a better simpler approach is still awaited and appreciated. The constraint I took is
constraint c_addrn {
foreach(addr[i])
if(i >0)
addr[i] == addr[i-1] + 4;
}
Firstly, I took
rand bit [31:0] addr [0:15];
instead of
rand bit [31:0] addr [0:3];
So that I get a broader range of address values even if constraint does not resolve for one or two addresses in the range. Then in my Driver class, I declared an array
bit [31:0] addr [16];
and a queue
bit [31:0] q[$];
And then copied the Packet address into the Driver class addr
foreach(p.addr[i])
addr[i] = p.addr[i];
And copied this local array into a queue for items != 0
foreach(addr[i])
q = addr.find with (item != 32'b0);
Finally at the start task, I did q.pop_front 4 times
@(posedge ipif.clk)
memif.mem_data <= q.pop_front;
So, the output display for the Packet address and output of queue were
# addr is 0xfffffff8
# addr is 0xfffffffc
# addr is 0x00000000
# addr is 0x00000004
# addr is 0x00000008
# addr is 0x0000000c
# addr is 0x00000010
# addr is 0x00000014
# addr is 0x00000018
# addr is 0x0000001c
# addr is 0x00000020
# addr is 0x00000024
# addr is 0x00000028
# addr is 0x0000002c
# addr is 0x00000030
# addr is 0x00000034
# addr0: 0xfffffff8
# addr1: 0xfffffffc
# addr2: 0x00000004
# addr3: 0x00000008
User contributions licensed under CC BY-SA 3.0