Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to contrain the number of "1" of a bit-sequence in Systemverilog

Status
Not open for further replies.

weben

Newbie level 5
Joined
May 17, 2011
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,349
In my systemverilog testbench, I need to genrate a 32 bits sequence which randomly contains 5 to 27 bit "1". Can anyone help me to describe the constrant of this random bit-sequence? thanks a lot
 

Code:
rand bit [31:0] value;

constraint random_bit_sequence {$countones(value) inside {[5:27]}; }
 
  • Like
Reactions: weben

    weben

    Points: 2
    Helpful Answer Positive Rating
Thanks Dave,
It's really helpful. But $countones seems only works in Questa. VCS does not support using $contones in contstraint blocks in 2012.09 version.
 

You can try

Code:
rand bit value[31:0];
constraint random_bit_sequence {value.sum() with (int'(item)) inside {[5:27]}; }
 
  • Like
Reactions: weben

    weben

    Points: 2
    Helpful Answer Positive Rating
You can try

Code:
rand bit value[31:0];
constraint random_bit_sequence {value.sum() with (int'(item)) inside {[5:27]}; }

Thanks again. This one works in VCS.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top