VHDL Issue Number: 0013 Classification: Language Definition Problem Language Version: VHDL-87 Summary: Interaction of slice prefix and discrete- range directions is unclear. Related Issues: 0096 Relevant LRM Sections: 3.1, 6.5, 7.3.1, 14.1 Key Words and Phrases: Slice, Null, Direction Current Status: VASG-Approved 1076-1993 Disposition: Closed (All Issues Completely Addressed) Disposition Rationale: This IR was incorporated in VHDL93. Superseded By: N/A ------------------------ Date Submitted: 1987/05/29 Author of Submission: Doug Dunlop Author's Affiliation: Intermetrics, Inc. Author's Post Address: 4733 Bethesda Avenue, Suite 415 Bethesda, MD 20814 Author's Phone Number: (301) 657-3775 Author's Fax Number: Author's Net Address: dunlop@inmet.inmet.com ------------------------ Date Analyzed: 1988/11/07 Author of Analysis: Ray Hookway Revision Number: $Revision: 1.7 $ Date Last Revised: $Date: 1995/05/13 19:34:42 $ Description of Problem ---------------------- The direction and bounds of a null slice are not clearly specified by the LRM. Proposed Resolution ------------------- A null slice can occur either if the range is null or if the prefix and discrete range differ in direction. For a null slice due to a null range, both the direction and the bounds of the null slice come from the discrete range. If the prefix and discrete range differ in direction, the direction of the null slice comes from the prefix and its bounds come from the discrete range. VASG-ISAC Analysis & Rationale ------------------------------ The LRM states (section 6.5) that "The bounds of the discrete range define those of the slice and must be of the type of the index of the array. The slice is a null slice if the discrete range is a null range, or if the direction of the discrete range is not the same as that of the object denoted by the prefix." The problem is to define the direction of the slice so that a null slice will result with the bounds determined from the discrete range when the direction of the discrete range differs from the direction of the prefix. In fact, this can be impossible as shown by the fol- lowing example. Example -- This example shows that it may be impossible to define -- the direction of a slice so that a null slice results. begin process type index_type is (red); type int_array is array (index_type range <>) of integer; procedure test (X : int_array) is begin assert X'length = 0; -- X must be null assert X'left = red; -- Bounds are determined by assert X'right = red; -- range red downto red end test; variable A : int_array (red to red) := (red => 1); begin test(A(red downto red)); end process; Note that X is a null array since the direction of the discrete range in the slice A(red downto red) is not the same as the direc- tion of the prefix. On the other hand, the bounds, which are taken from the discrete range, are both red. This is apparently a con- tradiction since a null range is either an ascending range with R < L or a descending range with L < R. Since X'left = X'right, neither of these cases applies and we are forced to conclude that X is not a null array. The problem is that there is no way to describe a null range whose bounds come from the type index_type. This is also a problem in determining the bounds and directions of bit string literals (see section 7.3.1). In this case, a null range is specified by making the rightmost bound of the array value be the predecessor of the left bound for ascending ranges and the successor of the left bound for descending ranges. Note that for the index type index_type this will give an error since there is no predeces- sor of successor of red. The Ada LRM (section 4.2 paragraph 3) is very explicit about this. "The evaluation of a null string literal raises the exception CONSTRAINT_ERROR if the lower bound does not have a predecessor (see 3.5.5)." The VHDL LRM leaves this as an implicit consequence of the attempt to evaluate PRED or SUCC when these are not defined. Since there is no way to describe a null range in the above case, we must define the meaning of the slice A(red downto red) in some other way. One alternative that has been suggested is to have the result of slicing with a discrete range which has the opposite direction from the prefix be to reverse the left to right order of the elements of the resulting array. There is currently no operator in the language which accomplishes this "mirroring" operation. However, it is easy to write a function which will reverse the order of the elements of it's array argument so this does not seem like a necessary addition to the language. Since this is not necessary and it represents further complication of the language, it does not seem like a desir- able addition to the VHDL. The simplest thing to do is to make it illegal to slice an array with a discrete range whose direction differs from the direction of the array. VASG-ISAC Recommendation for IEEE Std 1076-1987 ----------------------------------------------- Interpret paragraph 3 of section 6.5 as follows: The bounds of the discrete range define those of the slice and must be of the type of the index of the array. The slice is a null slice if the discrete range is a null range. It is an error if the direction of the discrete range is not the same as that of the prefix of the slice name. VASG-ISAC Recommendation for Future Revisions --------------------------------------------- Adopt the wording of the previous section. The example in this section that now reads Data(24 to 25) -- a null slice must also be changed, since under the new interpretation, it is an illegal slice, not a null slice. One possibility is Data (24 downto 25) -- a null slice