Hello all,
I am having hard times with the SV randomizer, and I cannot find the problem with my code.
The code I am using is as follows:
class TestClass;
rand bit [3:0] opcode ;
rand bit [15:0] req_id ;
rand bit [7:0] master_id ;
rand bit solo ;
bit [2:0] flags ;
bit [31:0] rsv ;
constraint c_opcode {
opcode >= 0 && opcode <= 2;
}
constraint c_master_id {
master_id > 0;
}
constraint c_req_id {
(opcode == 1) -> (req_id == 16'hfe0f);
solve opcode before req_id;
}
function void display();
$display("dbug: opcode=%0d,req_id=0x%h,master_id=%0d,solo=%0b,flags=%0b,rsv=0x%h", opcode, req_id, master_id, solo, flags, rsv);
endfunction
endclass
module RandomTest;
TestClass test;
integer master_id_max;
initial begin
test = new();
master_id_max = 1 + ($urandom % 16);
$display("init: master_id_max=%0d", master_id_max);
for(integer idx = 1; idx <= 1000; idx++) begin
assert( test.randomize() with {
master_id < master_id_max;
} ) else $error("Something went wrong with the randomizer");
test.display();
end
end
endmodule
I have tried to run the code using different seeds, and different seeds give very different results. For instance:
Case #1 xsim RandomTest -tclbatch xsim.in -sv_seed 87654
Results: no errors from the randomizer, but the distribution of the results is somehow strange. The value 0xfe0f appears many times (~25% of the iterations), and also when opcode is different than 1. The histogram of opcode field in this case is: opcode==0 50 times, opcode==1 433 times, opcode==2 65 times and opcode==3 72 times. Why opcode==1 is the most sampled? Do implication constraints bias the randomizer in some way?
Case #2: xsim RandomTest -tclbatch xsim.in -sv_seed 493046407
Results: Every call to randomize triggers the else branch of the assert, and part of the log (first 10 iterations) is given next:
****** xsim v2021.1 (64-bit)
**** SW Build 3247384 on Thu Jun 10 19:36:07 MDT 2021
**** IP Build 3246043 on Fri Jun 11 00:30:35 MDT 2021
** Copyright 1986-2021 Xilinx, Inc. All Rights Reserved.
source xsim.dir/work.RandomTest/xsim_script.tcl
# xsim {work.RandomTest} -autoloadwcfg -tclbatch {xsim.in} -sv_seed 493046407
Time resolution is 1 ps
source xsim.in
## run -all
init: master_id_max=1
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=3,req_id=0x0000,master_id=176,solo=0,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=8,req_id=0x0000,master_id=48,solo=1,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=3,req_id=0x0000,master_id=63,solo=0,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=9,req_id=0x0000,master_id=186,solo=1,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=10,req_id=0x0000,master_id=133,solo=0,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=5,req_id=0x0000,master_id=8,solo=0,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=1,req_id=0x0000,master_id=197,solo=0,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=11,req_id=0x0000,master_id=0,solo=1,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=14,req_id=0x0000,master_id=222,solo=1,flags=0,rsv=0x00000000
WARNING: File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 37 : randomize failed to meet constraint.
Error: Something went wrong with the randomizer
Time: 0 ps Iteration: 0 Process: /RandomTest/Initial31_0 Scope: RandomTest.Block36_1.Block36_2 File: /home/user/docker-volumes/scorbetta-volume/sandbox/vivadio/sv_randomizer/test.sv Line: 39
dbug: opcode=15,req_id=0x0000,master_id=250,solo=1,flags=0,rsv=0x00000000
What is wrong with the code?
Thank you for your help
Cheers
S