[sv-bc] RE: [sv-ec] Reading array with out-of-range or x/z index

From: Bresticker, Shalom <shalom.bresticker_at_.....>
Date: Tue Jun 10 2008 - 03:17:55 PDT
Reminder: the default initial value for a net is not always z, either.
For a trireg, it is X, so says 6.7. For tri1, tri0, supply1, supply0, it
is unclear whether the initial value should be 1/0, or whether it should
be z that changes before/during time 0 to 1/0. That is a side issue. The
sections below should not be defining the net initial value, just
referencing the specification which is written elsewhere in the LRM.
 
Shalom


________________________________

	From: owner-sv-ec@server.eda.org
[mailto:owner-sv-ec@server.eda.org] On Behalf Of Bresticker, Shalom
	Sent: Tuesday, June 10, 2008 12:10 PM
	To: sv-ec; sv-bc
	Subject: [sv-ec] Reading array with out-of-range or x/z index
	
	

	Hi, 

	Steven Sharp wrote in Mantis 1067, then on 1364: 
	Section 5.2.2 states that for an array reference, if the index
is out of bounds or any bit in the address is x or z, the value of the
reference shall be x. But we have now allowed arrays of reals, which
can't be x, so there is no value specified for that.
	
	One possibility would be to have the reference be 0.0, since
that is the initialization value for reals the same way that x is the
initialization value for non-reals. Another possibility would be NaN,
though that has not been used in any other such situations (e.g.
initialization).
	
	That section is now 11.5.2. The sentence has not changed since
then. 
	Steven later wrote, 
	I believe that the value to be used has been specified as 0.0 in
the 1800 LRM.
	but I did not find such a statement. 

	I found the following: 
	11.5.1 Vector bit-select and part-select addressing contains the
following statements: 
	If the bit-select is out of the address bounds or the bit-select
is x or z, then the value returned by the reference shall be x.

	A part-select that addresses a range of bits that are completely
out of the address bounds of the vector, packed array, packed structure,
parameter or concatenation, or a part-select that is x or z shall yield
the value x when read and shall have no effect on the data stored when
written. Part-selects that are partially out of range shall, when read,
return x for the bits that are out of range and shall, when written,
only affect the bits that are in range.

	11.5.2 Array and memory addressing contains the following: 
	If the index is out of the address bounds or if any bit in the
address is x or z, then the value of the reference shall be x.

	7.4.6 Indexing and slicing of arrays contains: 
	If an index expression is out of the address bounds or if any
bit in the address is X or Z, then the index shall be invalid. The
result of reading from an array with an invalid index shall return the
default uninitialized value for the array element type. Writing to an
array with an invalid index shall perform no operation.

	In 6.8 (Variable declarations), we have 
	Table 6-7 contains the default values for variables if no
initializer is specified. 
	Table 6-7-Default values 
	Type                            Default initial value 
	4-state integral                'X 
	2-state integral                '0 
	real, shortreal                         0.0 
	enumeration                     base type default initial value 
	string                          "" (empty string) 
	event                           new event 
	class                           null 
	chandle (Opaque handle) null 

	In 7.9.6 (Accessing invalid indices) in the subclause on
associative arrays, we have: 
	If an invalid index (i.e., 4-state expression has X's) is used
during a read operation or an attempt is made to read a nonexistent
entry, then a warning shall be issued; and the default initial value for
the array type shall be returned, as shown in Table 7-2. A user
specified default shall not generate a warning and returns the value
specified in 7.10.11.

	Table 7-2-Value read from a nonexistent associative array entry 
	Type of array                   Value read 
	4-state integral type   'X 
	2-state integral type   '0 
	enumeration                     base type default initial value 
	string                          "" 
	class                           null 
	event                           null 
	If an invalid index is used during a write operation, the write
is ignored, and a warning is issued. 


	7.11.1 (Queue operators) says, 
	An invalid index value (i.e., a 4-state expression with X's or
Z's, or a value that lies outside 0...$) shall cause a read operation (e
= Q[n]) to return the default initial value for the type of queue item
(as described in Table 7-2).

	11.4.14.4 (Streaming dynamically sized data) says, 
	If the range expression evaluates to a range greater than the
extent of the array size, the entire array is streamed, and the
remaining items are generated using the default value (as described in
Table 7-2) for the given array.

	I see several issues: 
	1. Table 6-7 differs from Table 7-2 in the case of events. Yet
both are referred to as 'default initial value'. 

	2. Table 6-7 refers only to variables. But (most) nets have 'z
as their default initial value, not 'x. That is ok for Table 6-7 because
it is not talking about net contexts. But elsewhere nets have to be
taken into account.

	3. Table 7-2 omits real and chandle associative array element
types. But these can also be element types of associative arrays. Only
the index types of the such arrays are restricted. The other types need
to be added.

	4. Should reading an out-of-range/non-existent array element
return a default initial value or something else? We see that Table 7-2
currently differs from Table 6-7 for events. Presumably that is
deliberate. Assuming Table 7-2 is correct, it should not be referred to
as a 'default initial value', even though that term has some meaning in
the context of associative arrays.

	5. What should be returned if one reads an array element with an
address containing x/z? The same as the answer to the previous question?

	6. What about net arrays? If reading a net array with an address
which is out-of-range or x/z should return X instead of Z, then it is
again not the default initial value. Reading an out-of-range net
bit-select in Verilog-XL returns X.

	7. 11.5.1 specifies that writing a vector with an invalid
part-select has no effect. It should say the same for bit-selects.

	8. The sentence quoted from 11.5.2 should perhaps be deleted and
being inconsistent with 7.4.6 and also redundant, replacing it instead
with a reference to 7.4.6. Ideally, the subclauses should be merged, but
lacking that, at least remove the contradictions. 

	9. 7.4.6 says, "The result of reading from an array with an
invalid index shall return the default uninitialized value for the array
element type." That sentence probably needs to be updated.

	10. References to 'default initial value' in 7.9.6 and 7.10.11
should be changed. 

	11. If Table 7-2 is to be a general table specifying the value
returned when reading an array with an out-of-range or x/z index, it
should be taken out of the associative array subclause and moved to
7.4.6, and 7.4.6 should reference that table. 

	12. 7.11.1 on queues should presumably not talk about a default
initial value and should reference the table in its new location.

	13. What about 11.4.14.4? This refers to writing new elements.
Considering the types legal in this context, maybe there is no
difference between the two tables, but the terminology and the table
should be consistent with each other. That is, if what is now Table 7-2
is to be used, then they should not be called default values.

	Thanks, 
	Shalom 

	Shalom Bresticker 
	Intel Jerusalem LAD DA 
	+972 2 589-6582 
	+972 54 721-1033 

	
---------------------------------------------------------------------
	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. 

---------------------------------------------------------------------
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, and is
believed to be clean.
Received on Tue Jun 10 03:22:12 2008

This archive was generated by hypermail 2.1.8 : Tue Jun 10 2008 - 03:23:50 PDT