Functions in constraints

Can I use the function in this constraint?


class abc;
  rand int unsigned data[18];
  
  constraint c1 {
    foreach(data[i]){
      data[i] <= 10;
    }    
  }
  
  function int count_values(int unsigned data[18], int val);
    return (data.sum with (int'(item==val)));
  endfunction
    
  constraint c2 {
    count_values(data,1) == 2;
//    data.sum() with (int'(item==1)) == 2;
  }
endclass

In reply to yourcheers:

You can use that function in a constraint, but there is a near 0% chance of satisfying that constraint. The SystemVerilog solver cannot work backwards and figure out what its inputs need to be to cause a particular function output. Only certain built-in functions are allowed because it knows how to in-line the function into a boolean expression.

In reply to dave_59:

Thanks, did some more experiments and understand that functions are not-bidirectional.