Constraint array

Hi,
I would like to know the difference between the two lines in the constraint statement below:

class array ;
	parameter size = 10;
	parameter int UNIQ = 3;
	rand bit [5:0] array [size];
	rand bit [5:0] rand_element;

	constraint AB {
		array.sum () with (int'(item == rand_element)) == UNIQ;
	//	array.sum () with ((item == rand_element)) == UNIQ;
	}
endclass

The one which is commented out gives constraint errors, the other works fine. The constraint is to have 3 same elements in an array of size 10.

1 Like

Hi, as Dave mentioned the expression will give a 1 bit value, which then needs to cast to int or larger width for the sum constraint to work.

1 Like