IEEE 200X Fast Track Change Proposal ID: FT-04 Proposer: Jim Lewis (jim@synthworks.com) Status: Open Proposed: 1-March-2003 Analyzed: Peter Ashenden, 25-May-2004 Resolved: Date Enhancement Summary: Min/max operations Related issues: Relevant LRM section: Various - see analysis Enhancement Detail: ---------------------------------------- Min/max operations for types with defined less than (<) and greater than (>) operations Analysis: ---------------------------------------- The only way to determine the minumum or maximum of two values currently is to use an if statement. As a consequence, the operation cannot be embedded as part of an expression without defining a function and calling it. Provision of the operations as predefined operations would be a convenience for the designer. Provision of min and max as infix operators would require introduction of new reserved words and extension of the grammar for expressions. New reserved words would cause incompatibility with legacy models. Hence, it would be better to provide the operations as implicitly defined functions for those types for which "<" and ">" are implicitly defined. Those types are scalar types and discrete array types. Legacy models that declare the identifier min or max would not be broken, since an implicit declaration of a predefined operation is hidden by an explicit declaration of a homograph. The signature of each of the operations for a given type T would be function min (L, R: T) return T; function max (L, R: T) return T; The min and max operations should return the lesser and greater, respectively, of the two operands, determined by comparison using the implicitly declared "<" operation for the type of the operands. An example of use of such operations: signal a : std_logic_vector(a_size-1 downto 0); signal b : std_logic_vector(b_size-1 downto 0); signal sum : std_logic_vector(max(a_size, b_size)-1 downto 0); In reviewing the required LRM changes, it became evident that the terms "predefine operator" and "predefined operation" are not used consistently. The proposed min and max operations are the first non-operator operations for ordered types. Hence, when adding descriptions of these operations to the LRM, it is necessary to make use of the terms operator and operation consistent. LRM Changes: Clause 3: in second paragraph, change "predefined operators (see 7.2)" to "predefined operations (see 3.1.5, 3.2.1.3, 3.3.2 and 3.4.1)". This corrects the omission of cross reference to operations for access and file types, and adds cross reference to the new operations. New 3.1.5 Predefined operations on scalar types Given a type declaration that declares a scalar type T, the following operations are implicitly declared immediately following the type declaration: function min (L, R: T) return T; function max (L, R: T) return T; The MIN operation returns the value of L if L < R, or the value of R otherwise. The MAX operation returns the value of R if L < R, or the value of L otherwise. For both operations, the comparison is performed using the predefined relational operator for the type. New 3.2.1.3 Predefined operations on array types Given a type declaration that declares a discrete array type T (see 7.2.2), the following operations are implicitly declared immediately following the type declaration: function min (L, R: T) return T; function max (L, R: T) return T; The MIN operation returns the value of L if L < R, or the value of R otherwise. The MAX operation returns the value of R if L < R, or the value of L otherwise. For both operations, the comparison is performed using the predefined relational operator for the type. 4.3.3.2: In e), change "predefined operators" to "predefined operations" and "implicit operator" to "implicit operation". This corrects the omission of implicit aliases for non-operator operations and allows for inclusion of aliases for the new operations. 4.3.3.2: In Examples, add the following to the end of the example: -- alias MIN is STD.STANDARD.MIN -- [STD.STANDARD.BIT, STD.STANDARD.BIT -- return STD.STANDARD.BIT]; -- alias MAX is STD.STANDARD.MAX -- [STD.STANDARD.BIT, STD.STANDARD.BIT -- return STD.STANDARD.BIT]; 7.2: In last sentence before Notes, change "predefined operations" to "predefined operators". To be consistent with other predefined operations that are not operators, the min and max operations are defined with named parameters, so they can be called with named association. 7.4.1: In d), change "operator" to "operation". This allows for calls to the new operations to be treated as locally static primaries. 14.2: After declaration of type BOOLEAN, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: BOOLEAN) return BOOLEAN; -- function MAX (L, R: BOOLEAN) return BOOLEAN; 14.2: After declaration of type BIT, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: BIT) return BIT; -- function MAX (L, R: BIT) return BIT; 14.2: After declaration of type CHARACTER, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: CHARACTER) return CHARACTER; -- function MAX (L, R: CHARACTER) return CHARACTER; 14.2: After declaration of type SEVERITY_LEVEL, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: SEVERITY_LEVEL) return SEVERITY_LEVEL; -- function MAX (L, R: SEVERITY_LEVEL) return SEVERITY_LEVEL; 14.2: After declaration of type universal_integer, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: universal_integer) return universal_integer; -- function MAX (L, R: universal_integer) return universal_integer; 14.2: After declaration of type universal_real, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: universal_real) return universal_real; -- function MAX (L, R: universal_real) return universal_real; 14.2: After declaration of type INTEGER, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: INTEGER) return INTEGER; -- function MAX (L, R: INTEGER) return INTEGER; 14.2: After declaration of type REAL, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: REAL) return REAL; -- function MAX (L, R: REAL) return REAL; 14.2: After declaration of type TIME, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: TIME) return TIME; -- function MAX (L, R: TIME) return TIME; 14.2: After declaration of type STRING, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: STRING) return STRING; -- function MAX (L, R: STRING) return STRING; 14.2: After declaration of type BIT_VECTOR, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: BIT_VECTOR) return BIT_VECTOR; -- function MAX (L, R: BIT_VECTOR) return BIT_VECTOR; 14.2: After declaration of type FILE_OPEN_KIND, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: FILE_OPEN_KIND) return FILE_OPEN_KIND; -- function MAX (L, R: FILE_OPEN_KIND) return FILE_OPEN_KIND; 14.2: After declaration of type FILE_OPEN_STATUS, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: FILE_OPEN_STATUS) return FILE_OPEN_STATUS; -- function MAX (L, R: FILE_OPEN_STATUS) return FILE_OPEN_STATUS; 14.3: After the declaration of type LINE, change "predefined operators" to "predefined operations", and add the following commented declaration: -- procedure DEALLOCATE (P: inout LINE); This corrects omission of the predefined operation. 14.3: After declaration of type TEXT, change "predefined operators" to "predefined operations", since none of the predefined operations are operators. 14.3: After declaration of type SIDE, change "predefined operators" to "predefined operations", and add the following commented declarations: -- function MIN (L, R: SIDE) return SIDE; -- function MAX (L, R: SIDE) return SIDE; B196: In last sentence before Notes, change "predefined operation" to "predefined operator". Same reason as for 7.2. New B197 predefined operations: Implicitly defined subprograms and predefined operators that operate on the predefined types. Resolution: ---------------------------------------- [To be performed by the 200X Fast Track Working Group]