What is wrong in this? Because when I execute this it is throwing me an error.
rand byte a,b[10],c;
constraint ab {unique {a,b[2:5],c};}
constraint c1{c==5;}
In reply to Huzefa Halolwala:
Hi,
It works fine with VCS . Which simulator are you using? And post the exact error
I executed your code with VCS and it works fine. Which tool are you using? Is it giving compile error or constraint failure error? Are there any other conflicting constraints?
Also note that the older version of simulators does not support unique keyword. I just copy-pasted the sample code, and it works fine on VCS on EDAPlaygound (but throws compile error in Riviera):
module top();
class A;
rand byte a,b[10],c;
constraint ab {unique {a,b[2:5],c};}
constraint c1{c==5;}
endclass
A obj = new();
initial
begin
repeat(5)
begin
if(!obj.randomize())
begin
$display("Unable to randomize");
$finish;
end
$display("a = %0p",obj);
end
end
endmodule
// Output:
a = '{a:92, b:'{-7, -105, -54, 23, -114, 54, 106, -90, 31, -119} , c:5}
a = '{a:42, b:'{-35, 9, 119, -35, 126, -36, -81, -89, -125, 111} , c:5}
a = '{a:107, b:'{92, -26, -113, 59, -122, -27, 75, -93, -128, -47} , c:5}
a = '{a:-27, b:'{6, 114, 14, 77, 52, 28, -96, -77, -33, 92} , c:5}
a = '{a:87, b:'{-98, -44, 16, -59, -57, -121, 59, -37, 110, -42} , c:5}
Also, the same example is provided in IEEE 1800-2012 Section 18.5.5. So, I doubt there might be some simulator issue.
In reply to sharvil111:
Yes, I am using the VCS tool only and here is my code:
module test();
class Packet;
rand byte a,b[10],c;
constraint ab {unique {a,b[2:5],c};}
constraint c1{c==5;}
endclass
Packet p=new();
initial begin
repeat(10)
if(p.randomize()) $display("%p",p);
endmodule
Output:
“file.sv”, 8: token is ‘unique’
constraint ab {unique {a,b[2:5],c};}
^
System verilog keyword ‘unique’ is not expected to be used in this context.
In reply to Huzefa Halolwala:
Just try it out with 2014 or later version. You can also verify the code at EDAPlaygound, which has newer (2014) VCS version.
In reply to Huzefa Halolwala:
In reply to sharvil111:
“file.sv”, 8: token is ‘unique’
constraint ab {unique {a,b[2:5],c};}
^
System verilog keyword ‘unique’ is not expected to be used in this context.
Yes. Your VCS version might be 2013 or earlier than that. Just move to a newer simulator version.
In reply to sharvil111:
Hey Sharvil,
Is there any difference between randc and unique in terms of randomization??
In reply to Viren_B:
Hi Viren,
Both does the similar work but unique is specific to array contexts and not related to randomization. randc is related to properties and randomization
In reply to Viren_B:
By randc you can have cyclic randomness of a single varaible. While using unique, you can choose a unique combination from a group of variables.
randc int a; // only variable 'a' is having unique value in randomization
rand int a,b,c;
constraint a_cn {unique {a,b,c};} // the variables a,b,c all shall have unique/different values
Moreover, as stated in example, using unique keyword, you can exclude some of the values from some array (use those constrained-excluded values array along with unique).
Refer IEEE 1800-2012 Section 18.5.5 for more information.
In reply to sharvil111:
In reply to Viren_B:
By randc you can have cyclic randomness of a single varaible. While using unique, you can choose a unique combination from a group of variables.
randc int a; // only variable 'a' is having unique value in randomization
rand int a,b,c;
constraint a_cn {unique {a,b,c};} // the variables a,b,c all shall have unique/different values
Moreover, as stated in example, using unique keyword, you can exclude some of the values from some array (use those constrained-excluded values array along with unique).
Refer IEEE 1800-2012 Section 18.5.5 for more information.
Good Explanation…!
Thanks Sharvil111