Hi,
I have a 24 bit variable and i have to restrict its transitions in the randomization to some number.
I want to write a constraint for this to control the transitions to 16. Please give some idea to proceed…
Thanks in Advance,
class A;
rand bit [23:0] AA;
constraint AA_C { //something };
endclass
No rohitk,
as far as you are concerned about 16 bits to set that is wrong. I want only transitions but not how many bits are getting set. Transitions means for example,
AA took randomly the value as 'b1010 ----> No. of transitions are 3
like this…these transitions should not exceed the value 16 that is what i want.
Hope you understood the question what i am asking…
In reply to avpchandra:
I think what you are asking is to look at a series of randomizations, and you are defining a transition as a change from one randomization to the next. Then what you want is
class A;
rand bit [23:0] AA;
constraint AA_C { $countones(const'(AA) ^ AA) == 16;}
endclass // A
In reply to rohitk:
Section 6.24.1 Cast operator says
An expression may be changed to a constant with a const cast.
const'(x)
When casting an expression as a constant, the type of the expression to be cast shall pass through unchanged.
The only effect is to treat the value as though it had been used to define a const variable of the type of the
expression.
Basically it’s like a sampled value at the point of evaluation of the expression.
Thanks Dave, so const casting will add an implicit order on variable and it will retain it’s value from last randomization. Is my understanding correct?
In reply to avpchandra:
I think what you are asking is to look at a series of randomizations, and you are defining a transition as a change from one randomization to the next. Then what you want is
class A;
rand bit [23:0] AA;
constraint AA_C { $countones(const'(AA) ^ AA) == 16;}
endclass // A
Hi Dave,
what you gave is transitions of series of randomization, but i want the variable AA shall not have more than 16 transitions. This is my restriction on variable AA so i mean, whatever the value it takes in randomization but the value should not exceed 16 transitions in it.
But I’m not sure how you are defining a transition, Can you give a few examples and explain how you count transitions. The only example you gave was a 4-bit value, and AA is 24 bits.
In reply to dave_59:
Hi Dave,
Thanks for your interest…
How to count the transitions:****
If you start either from LSB or from MSB, start counting the transitions for every 0 to 1 and 1 to 0 till the end then the total count will be your number of transitions.
Example:
AA = 24’b0010_1011_1010;
Transitions means the bit transitions like 0 to 1 or 1 to 0. So from above we have 7 transitions in the example 1.
AA = 24’b101001010101;
Here the bit transitions are 10.
so, my requirement is these transitions in a randomized variable should not exceed the 16 that is violation.
see below example: Violation case:__
3) AA = 24’b0110_1001_1001_0010_0101_1010_1010_1010
This example contains 24 transitions which is greater than 16 transitions which need to be avoided in the randomization of AA by using the constraint.
In reply to avpchandra:
OK, we are getting closer. I think what you are saying is that if the adjacent bits in AA are not the same, that is a transition. If AA[4] is 1’b1 and AA[5] is 0, that counts as a transition. There can only be 23 adjacent bits in a 24-bit variable.
But your transition counts do not match my understanding. If I re-write your examples using _ everywhere that should be counted as transition
AA = 24’b00000000000000_1_0_1_0_111_0_1_0; // 8 transitions
AA = 24’b000000000000_1_0_1_00_1_0_1_0_1_0_1; // 11 transitions
AA = 24’b0_11_0_1_00_11_00_1_00_1_00_1_0_11_0_1_0_1_0_1_0_1_0_1_0 // this is a 32 bit literal, but there are 24 transitions. There could only be 19 transitions with the 1st 24 bits.
In reply to srikanth_6313:
Hi Srikanth,
Please explain in detail your solution…? Your solution is working
Thanks,
This constraint is not valid for all conditions. Consider a 4 bit number, AA = 4’b0011; Then, $countones((0011 ^ 0001) - 1) is 0. But number of bit transition is 1.