VHDL Issue Number: 0001 Classification: Language Definition Problem Language Version: VHDL-87 Summary: It is not clear whether array operands for logical operators must be of the same base type. In fact, operand and result types are not spelled out at all. Related Issues: Relevant LRM Sections: 7.2.1 Key Words and Phrases: logical operator, one-dimensional array type, BOOLEAN Current Status: ISAC-Approved 1076-1993 Disposition: Closed Disposition Rationale: Section 7.2.1 updated Superseded By: N/A -------------------- Date Submitted: 1990/09/09 Author of Submission: Mark Alexandre Author's Affiliation: Microelectronics and Computer Technology Corp. (MCC) Author's Post Address: 3500 West Balcones Center Drive Austin, Texas 78759-6509 Author's Phone Number: (512) 338-3339 Author's Fax Number: Author's Net Address: Alexandre@MCC.com ---------------------- Date Analyzed: 1990/10/02 Author of Analysis: Clive R. Charlwood Revision Number: $Revision: 1.9 $ Date Last Revised: $Date: 1995/07/26 17:14:04 $ Description of Problem ---------------------- Section 7.2.1, Logical Operators, says: They are also defined for any one-dimensional array type whose element type is BIT or BOOLEAN. ... the operands must be arrays of the same length,...and the result is an array with the same index range as the left operand. There is no explicit statement that the operands for the binary (dyadic) operators must be of the same type. The wording of the quotation above is open to interpretation either way. The accompanying truth tables are also ambiguous with regard to any required type correspondences. In fact, Section 7.2.1 does not even explicitly state that for simple scalar operands, both operands must be of the same type: either BOOLEAN or BIT. This leaves open the possibility of expressions such as the following: '1' or TRUE -- Valid VHDL expressions? '0' /= '1' and '0' Furthermore, since Section 7.2.1 does not mention result types, it can only be inferred that the result type of a logical operation is the same as the type of the operand(s). However, if the above expressions were valid, it is not clear what the result type would be. In Ada, the type correspondence requirements are made quite explicit. Section 4.5.1 of the Ada LRM starts off: The following logical operators are predefined for any boolean type and any one-dimensional array type whose components are of a boolean type; in either case the two operands have the same type. This is followed by the usual table with columns for operator, operation, operand type and result type. This table makes it clear that the result is always of the same type as the operands. [ Note: This issue came up as a result of analysis at MCC of one of the tests originally created at Intermetrics: E-07-2-1-0004a. That test presupposes that (array) operands need not be of the same type. ] Proposed Resolution ------------------- In our view, it is necessary for both operands of a binary logical operator to be of the same (base) type. If this were not so, then it would not be clear what should be the type of the result. The only two possibilities would be: (1) the result type is the same as the type of the left operand, or (2) the result must be determinable from context. Neither of these strikes us as very desirable. We see no reason not to follow the example of Ada on this issue. Section 7.2.1 of the VHDL LRM should be interpreted as if it had explicitly stated that in all cases, both operands must have the same type. It follows from this that the result is of the same type, but it would be nice is there had been the usual table, with entries such as the following: Operator Operation Operand type Result type and conjunction BOOLEAN BOOLEAN BIT BIT any array of BOOLEAN same array type any array of BIT same array type VASG-ISAC Analysis & Rationale ------------------------------ This is a problem. The solution is relatively straightforward. The paragraph starting "The following logical operators ..." needs to be rewritten to explicitly state that both operands of a binary logical operator must be of the same type. For example: The logical operators _and_, _or_, _nand_, _nor_, _xor_, and _not_ are defined for predefined types BIT and BOOLEAN. They are also defined for any one-dimensional array type whose element type is BIT or BOOLEAN. For the binary operators _and_, _or_, _nand_, _nor_, and _xor_ the operands must both be of the same type. Furthermore, in the case of the one-dimensional arrays they must be arrays of the same length, the operation is performed on matching elements of the arrays, and the result is an array with the same index range as the left operand. For the unary operator _not_, the operation is performed on each element of the operand, and the result is an array with the same index range as the operand. (The text "_and_" indicates that the text should be emboldened.) VASG-ISAC Recommendation for IEEE Std 1076-1987 ----------------------------------------------- Read the paragraph "The following logical operators ..." as the paragraph shown in the Analysis & Rationale section above. VASG-ISAC Recommendation for Future Revisions --------------------------------------------- 1. Change the paragraph "The following logical operators ..." to the paragraph shown in the Analysis & Rationale section above. 2. Add a table that explicitly states each valid operator/operand(s)/result combination.