Order of function call via Constraint V/S with covergroup expression

Hi ,

SystemVerilog allows function call from a constraint as well as covergroup expression .

I am trying following 2 codes :: (1) constraint_code (2) covergroup_code

LRM 18.5.12 says ::

  1. Functions that appear in constraint expressions should be automatic (or preserve no state information) and have no side effects.
  2. Function calls in active constraints are executed an unspecified number of times (at least once) in an unspecified order.

LRM 19.5 says ::

  1. Functions shall be automatic (or preserve no state information) and have no side effects .
  2. Functions shall not reference non-constant variables outside the local scope of the function

So via (1) and (3) , it’s illegal to define static variable within the function and assign it from it ( in both codes )

I have following queries ::

(A) Via (2) the order of display within the function called in constraint isn’t defined as per LRM .

**Is  the  order  defined  for  function  called  from  covergroup  expression ?**  

Currently  I  observe  **' item '  is  passed  in  incremental  order  from  min to  max value . Does  the  LRM  guarantee  this  order  ?**

(B) Is it legal to access the queue from the function in both code ?

 The  queue  would  be  assigned  by  user  and  then  used  within  the  function  based  on  user-defined  implementation  in  both  codes.

(C) For covergroups apart from with expression , SV facilitates function call from coverpoint expression .

 **Can  function  be  called  using  any  other  way  ?**

Thanks .

In reply to MICRO_91:

As you have quoted, the code you have written is illegal, but tools do not always catch this kind of error in order to make debugging easier. But the LRM certainly does not prescribe the ordering in this case. Any code you could write should not depend on the order of execution. It is going to be implementation dependent, and could change in any version.

In reply to dave_59:

Thanks Dave for the clarification .

A final question to conclude the thread ( have made small changes to the 2 codes )

Regarding ,[b]as per (4) can I say it’s illegal to access variable q within myfunc in covergroup_code ?

Whereas for constraint_code it’s legal to access non-random array user within the function as the LRM has no such restriction

The general use of these variables ( q , user ) would be within the function .
The function would return a value based on some internal logic.

In reply to MICRO_91:

A non-random variable is effectively a constant as far as constraint expression evaluation is concerned—its value cannot change during the call to randomize().