Constraining leaf elements of 2D Array of handle

Hi Moderators,

Based on discussion in thread, I was trying sum() for 2-dimensional array of handle where I observe unexpected results.

Link: edaplayground

Although the output in $display matches the constraint expression i.e top.sum() is 'd10,

the output of $write differs i.e total no. of leaf elements with value of ON isn’t 10.

My expectation is that out of the 24 leaf elements of enum type, 10 would be ON

Across different tools and multiple seeds I observe that no. of elements with value of ON is 0 or 4 or 8 or 12 or 16 whereas I expected only 10

The amusing thing is on replacing the sum() constraint with the equivalent expression mentioned in the multiline comments, I observe the same unexpected results.

I’d appreciate any insights or suggestions.

Thanks in advance

You have a typo in your $write statement.

Thanks Dave.

The 3rd argument should be top[i].b[j].bb ( previously I had written top[i].b[i].bb )

A final question from my side

If I were to write constraint as

top.sum() with ( item.b.sum with ( int'(item.bb) ) ) == 10;

Why does the 2nd item refer to top[X].b[Y] whereas the 1st item refer to top[X] ?

It seems that item automatically refers to nearest call to sum()

All local iterator variables work this way. If the iterator variables have the same name, the nearest loop variable takes precedence. This effectively hides the outer iterator variable. You should give them unique names.