we have bit[999:0] addr variable, when you are randomizing the addr value continuous 7 ones random positions expect remaining bits are zero"0"
What have you tried? What works? What doesn’t work? If you post an example on EDA Plaground, others can provide assistance.
Hi @cgales
I need to get an idea how to write contarint for that
Could you please give idea how to write constraint for that please
if you provide atleats idea to write a constraint for above question so that it could helpfull to me
Hi Everyone
Could you please help me on this Constraint
rand bit[999:0] addr;
constraint c1 {$countones(addr) == 'd7;} // constraint for 7 ones
constraint c2 {for(int i=0; i<=999; i = i+7)
if(addr[i] && ((addr[i-1:0]==0) || (i ==0)))
(addr[i+6:i] == 7’b1111111); } //constraint for continuous ones
Hi @Harika_Baratam
I have tried using above constraint but it is not giving proper solution
Please find the EDA link above
0100000010000000000000000000000000000000001000000010000000000001000000000100000000000000000100000000
It is giving in between contonius ones of seven
But My requirment should be like below pattern
Please help me out how to get below pattern using constraint
00000000000000000000000000000000000000001111111000000000000000000000000000000000000
Hi @prasanthB1,
Try the below code, its working!
rand bit[999:0] var1;
rand int index;
constraint c1 {$countones(var1) == 'd7;} //constraint for 7 ones
constraint c2 {var1[index+:7] == 7’b1111111;} //constraint for continuous ones
constraint c3 {index inside {[0:992]};} //constraint for selecting index
I have tired with your your constraints I dont think so its not working which i’m expected output .
If its working at your end could you please share the EDA link Once
Please find the EDA link Which i tried my end Hope this soultion will works I belive
// Constraint to ensure exactly 7 continuous ones at random positions
constraint addr_c {
pos inside {[0:993]}; // Ensure position allows for 7 continuous bits
addr == (1000’b0 | (7’b1111111 << pos)); // Set 7 ones at position ‘pos’
}
class pattern;
rand bit [999:0] data;
rand int index;
constraint c1 {$countones(data) == 'd7;}
constraint c2 {index inside {[0:992]};}
constraint c3 {data[index+:7] == 7'b1111111;}
endclass
module top;
pattern p = new();
initial begin
repeat(10) begin
assert(p.randomize());
$display("%0d -> %h", p.index, p.data);
end
end
373 → 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fe000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
601 → 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fe000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
769 → 00000000000000000000000000000000000000000000000000000000fe000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
544 → 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
285 → 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fe00000000000000000000000000000000000000000000000000000000000000000000000
689 → 0000000000000000000000000000000000000000000000000000000000000000000000000000fe0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
85 → 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fe000000000000000000000
627 → 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003f8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
975 → 00003f8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
712 → 00000000000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Thanks for sharing the solution