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. Unfortunately, the identifier min for use as a minimum operation would conflict with the secondary unit min of the predefined type time. After considering numerous alternatives, the working group decided on minimum and maximum as the preferred names for the operations. Provision of minimum and maximum 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 minimum or maximum 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 minimum (L, R: T) return T; function maximum (L, R: T) return T; The minimum and maximum 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(maximum(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 minimum and maximum 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 MINIMUM (L, R: T) return T; function MAXIMUM (L, R: T) return T; The MINIMUM operation returns the value of L if L < R, or the value of R otherwise. The MAXIMUM 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 MINIMUM (L, R: T) return T; function MAXIMUM (L, R: T) return T; The MINIMUM operation returns the value of L if L < R, or the value of R otherwise. The MAXIMUM 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 MINIMUM is STD.STANDARD.MINIMUM -- [STD.STANDARD.BIT, STD.STANDARD.BIT -- return STD.STANDARD.BIT]; -- alias MAXIMUM is STD.STANDARD.MAXIMUM -- [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 minimum and maximum 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 MINIMUM (L, R: BOOLEAN) return BOOLEAN; -- function MAXIMUM (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 MINIMUM (L, R: BIT) return BIT; -- function MAXIMUM (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 MINIMUM (L, R: CHARACTER) return CHARACTER; -- function MAXIMUM (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 MINIMUM (L, R: SEVERITY_LEVEL) return SEVERITY_LEVEL; -- function MAXIMUM (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 MINIMUM (L, R: universal_integer) return universal_integer; -- function MAXIMUM (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 MINIMUM (L, R: universal_real) return universal_real; -- function MAXIMUM (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 MINIMUM (L, R: INTEGER) return INTEGER; -- function MAXIMUM (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 MINIMUM (L, R: REAL) return REAL; -- function MAXIMUM (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 MINIMUM (L, R: TIME) return TIME; -- function MAXIMUM (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 MINIMUM (L, R: STRING) return STRING; -- function MAXIMUM (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 MINIMUM (L, R: BIT_VECTOR) return BIT_VECTOR; -- function MAXIMUM (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 MINIMUM (L, R: FILE_OPEN_KIND) return FILE_OPEN_KIND; -- function MAXIMUM (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 MINIMUM (L, R: FILE_OPEN_STATUS) return FILE_OPEN_STATUS; -- function MAXIMUM (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 MINIMUM (L, R: SIDE) return SIDE; -- function MAXIMUM (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]