RE: [sv-ec] Functions in constraints

From: Ryan, Ray <Ray_Ryan_at_.....>
Date: Tue Jun 16 2009 - 17:49:49 PDT
Shalom,
 
In a general sense here is how the variable ordering works.
 
First values are determined for all randc variable. Each gets the
next value in the cycle for that variable. These values are then
treated as state (constant) values for the remainder of the
randomization.
 
Next consider function calls. Randomize does NOT look into function
calls. Therefore,
if a constraint contains a function call, the function must be evaluated
before the 
constraint can be evaluated. In order to evaluate (call) a function, all
the arguments
must be known (constant). If any of the arguments to a function are
random variables,
randomized values must first be choosen for those variable. 
 
So consider the constraints:
        x < f1 ( y );
        y < f1 ( z );
        z < 10;
        z < x;
 
This requires that:
        a value is choosen for 'y' before evaluating the constraint "x <
f1 ( y )"
        a value is choosen for 'z' before evaluating the constraint "y <
f1 ( z )"
Therefore the solver will
        first choose a value for 'z'
        then choose a value for 'y'
        then coose a value for 'x'
[NOTE, I am not using the word 'solved' because the ordering discussed
in 18.5.11 
 is different from the ordering defined by "solve-before" constraints. ]
 
In choosing a value for 'z', the solve will consider any constraints on
'z' that do not
reference random variables to be choosen after 'z'. Here a value for 'z'
is choosen
meeting the constraint "z < 10". Say the value 5 is selected (z is now
5)
 
Then the call to "f1 (z)" is evaluated [ie. f1(5)]. Say the result is
23;
 
Next a value for 'y' is choose. Here the constraint "y < 23" applies.
Say the
value 20 is selected (y is now 20).
 
Then the call to " f1 (y)" is evaluated [ie. f2(20)]. Say the result is
7.
 
Now there are no remaing function calls, so the rest can be solved. That
is,
a value is choosen for 'x' with the constraints:
        "x < f1(y)"  which is now  "x < 7"
        "z < x"       which is now "5 < x"
 
 
As an additional note, the ordering introduced by function calls can 
cause the solver to fail as a result of an earlier choosen value. For 
example, say the value 8 is choosen for 'z' and then based the value
choosen for 'y' the result of "f1(y)" is 4. Now the constraints for
choosing a value for 'x' are:
        "x < f1(y)"  which is  "x < 4"
        " z < x "     which is "8 < x"
In this case, the solver will fail and return a status of 0 AND none 
of the random variables will have changed value (including the randc
variables).
 
Ray Ryan
 



________________________________

	From: owner-sv-ec@server.eda.org
[mailto:owner-sv-ec@server.eda.org] On Behalf Of Bresticker, Shalom
	Sent: Tuesday, June 16, 2009 5:40 AM
	To: sv-ec@server.eda.org
	Subject: [sv-ec] Functions in constraints
	
	
	
	Hi,
	 
	Chris Spear pointed out that the text in 18.5.11 on functions in
constraints is unclear.
	 
	The text says,
	 
	"- Functions shall be called before constraints are solved, and
their return values shall be treated as state variables.
	 
	- Random variables used as function arguments shall establish an
implicit variable ordering or priority. Constraints that include only
variables with higher priority are solved before other, lower priority
constraints. Random variables solved as part of a higher priority set of
constraints become
	state variables to the remaining set of constraints. For
example:
	 
	class B;
	rand int x, y;
	constraint C { x <= F(y); }
	constraint D { y inside { 2, 4, 8 } ; }
	endclass
	 
	forces y to be solved before x. Thus, constraint D is solved
separately before constraint C, which uses the values of y and F(y) as
state variables. In SystemVerilog, the behavior for variable ordering
implied by function arguments differs from the behavior for ordering
specified using the "solve...before..." constraint; function argument
variable ordering subdivides the solution space thereby changing it.
Because constraints on higher priority variables are solved without
considering lower priority constraints at all, this subdivision can
cause the overall constraints to fail. Within each prioritized set of
constraints, cyclical (randc) variables are solved first."
	 
	These two dashed items seem contradictory. The first says that
functions are called before constraints are solved, but the example
shows constraint D being solved before the call to F(y).
	 
	Apparently a simple, and at first glance reasonable,
interpretation of the first dashed item, that ALL functions in
constraints are solved before ANY constraints are solved, is not the
correct interpretation.
	 
	What is the correct interpretation?
	 
	Is the second dashed item to be considered a continuation of the
first, denoting an exception to the general rule, and saying that only
those constraints needed to be solved to order to evaluate the function
calls are solved before the functions?
	 
	Or is the first dashed item to be interpreted as saying that
functions in a certain constraint are called before that particular
constraint is solved, but there is no necessary order between a function
in one constraint and another, unrelated constraint?
	 
	Is there a difference between these two interpretations?
	 
	If a function reads the value of a random variable which has no
constraint on it, I assume it is simply randomly assigned a value?
	 
	Also, the last sentence mentions randc variables. Is the
interpretation that first function calls are evaluated, then randc
variables are solved for, then rand variables?
	 
	Thanks,
	Shalom
	 
	Shalom Bresticker
	Intel LAD DA
	Jerusalem, Israel
	+972  2 589 6582 (office)
	+972 54 721 1033 (cell)
	 
	 
	
---------------------------------------------------------------------
	Intel Israel (74) Limited
	
	This e-mail and any attachments may contain confidential
material for
	the sole use of the intended recipient(s). Any review or
distribution
	by others is strictly prohibited. If you are not the intended
	recipient, please contact the sender and delete all copies.

	-- 
	This message has been scanned for viruses and 
	dangerous content by MailScanner <http://www.mailscanner.info/>
, and is 
	believed to be clean. 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Tue Jun 16 17:53:04 2009

This archive was generated by hypermail 2.1.8 : Tue Jun 16 2009 - 17:53:55 PDT