hi
i want to write constraint for these values;
A[1]=0
A[2]=0
A[3]=0
A[4]=6
A[5]=6
… A[100]=89;
i wrote like this … constraint cw {A[1]==0;A[2]==0;A[3]==0;A[4]==6;A[5]==6;} // its working
but its very lengthy… SOMETHING LIKE THIS I WANT:- A[1:3]==0; A[4:5]==6; so, when these array index will come, i could get constraints values.
please help.
In reply to Er. Shipra:
You could create a parameter (or variable) representing the value you want and constraint your array to that parameter
class C;
rand int A[101];
parameter int P[101] = '{default:0, 4:6, 5:6, 100:89};
constraint c{foreach(A[i]) A[i]==P[i];}
endclass
Or you can simply make an assigment to A without randomizing it.
In reply to dave_59:
hi
the solution provided by you is working perfectly. i have one more doubt, as in this, we are writing like
parameter int P[101] = '{default:0, 4:6, 5:6, 6:6, 7:6, 100:89};
as a[4], a[5],a[6], a[7] has same value … i need to write it separately like above.but if i have 100 elements having group of each 10 elements carry same value… its become very bulky or it is ok to write all 100 elements like this?
can’t we write it in a range like a[4 to 7]==6 ?
thank you
In reply to Er. Shipra:
There is no easy way to specify a constraint on a range of an array, or in an assignment pattern.
You can use simple variable assignments instead of using a parameter with a single assignment pattern.
a[0:9] = '{default:0};
a[10:19] = '{default:6};
In reply to dave_59:
thank you so much for your suggestions… code is working fine…
i have one doubt regarding struct
typedef struct {
rand bit [0:7] A;
rand bit [0:110] B;
} data;
class trans extends uvm_sequence_item;
`uvm_object_utils(trans)
rand data k[256];
i am writing it like:-
constraint cw {k[0].A==8'h15;} is it correct?
endclass
class driver extends ....
for (int j=0; j<4;j++)
vif_h.A<=trans_h.k[j].A; // shows error as A is not in k
endclass
here, i want to repeat my struct 256 times… but in every repeat value of A is different… so , i want to put constraint on A.
(1)how would i write it… and
(2)how i call this variables a,b in driver because driver shows error as A is not in k. HOW TO CALL STRUCT VALUES IN DRIVER.
please guide
In reply to Er. Shipra:
You can only put constraints on integral variables. k[0].A is an integral variable. But if you are trying to initialize it based on the code in your original question you’ll have to do
constraint cw {foreach (A[I]) k[I].A = A[I];}
You do not show enough code for me to help you with your syntax error.