Mixed array randomization constraint

Hi,

I am looking for an elegant way to constrain the number of ones in a mixed array.

I have tried the following


rand bit [255:0] my_mixed_array[256];
constraint  c_ones_count { $countones(my_mixed_array) <= 25; }

getting this error:

Error-[IUUSUA] Invalid use of unpacked [...]
  Invalid use of unpacked structure, union or array
  this.my_mixed_array
  Please check the context where unpacked structure, union or array is used.

Is this a problem of the $countones function? What would be an elegant way to solve this problem?

Later edit:
It seems to be an issue with unpacked arrays in general. I tried rand bit uarr[1000] and I get the same issue.

In reply to dipling:
Hi,

You are passing an array which is unpacked and with many elements into $countones. You can give like

foreach(mixed_array[i])
constraint  c_ones_count { $countones(my_mixed_array[i]) <= 25; }

$countones doesnot work in constraints.

In reply to Anudeep J:

That’s not what I wanted. I wanted max 25 ones in the whole table, your constraint makes it 25 ones per dimension.

In reply to Anudeep J:

$countones takes any bit-stream type which includes unpacked arrays of bits. The problem is you can’t reference an unpacked array in a constraint expression without using a foreach or array reduction construct. Try this

   constraint c{my_mixed_array.sum() with ($countones(item)) <100;}

In reply to dave_59:

Dave, this is still producing the “Invalid use of unpacked” error.

In reply to dipling:
Works for me. You’ll need to contact your vendor for support.

In reply to dave_59:

when properly done it does work :-).
Thank you!