nvc icon indicating copy to clipboard operation
nvc copied to clipboard

Type universal integer expression errors

Open diogratia opened this issue 11 years ago • 2 comments

A two fer:

entity univ1 is
end entity;

architecture foo of univ1 is
    signal i:   integer := Time'POS(Time'High);  -- should produce error

    -- 6.4.2.3 Signal declarations, para 5, first sentence:
    -- If the signal declaration includes the assignment symbol followed by an
    --  expression, it shall be of the same type as the signal. Such an
    --  expression is said to be a default expression.
    --
    -- -1993 4.3.1.2 Signal declarations, para 6, first sentence:
    -- If the signal declaration includes the assignment symbol followed by
    --  an expression, it must be of the same type as the signal.

    -- 'POS returns universal integer
    -- 
begin
    assert False 
    report "i = " & integer'IMAGE(i)  -- shows left clipping instead of error
    severity ERROR;
end architecture;

And

entity univ2 is
end entity;

architecture foo of univ2 is

begin
    assert False 
    report "Time'HIGH = " & Time'IMAGE(Time'VAL(Time'POS(Time'HIGH)))
    severity NOTE;
    assert False
    report "should produce 9223372036854775807"
    severity NOTE;
end architecture;

-- 'POS returns universal integer
--  'VAL parameter is any integer type (including universal integer)

universal integer is 64 bit.

diogratia avatar Jan 15 '15 04:01 diogratia

The place this implicit conversion from universal integer to type integer appears to come from is in IEEE Std 1076-1993 7.5 Universal expressions (9.5 -2008), para 4:

For the evaluation of an operation of a universal expression, the following rules apply. If the result is of type universal_integer, then the values of the operands and the result must lie within the range of the integer type with the widest range provided by the implementation, excluding type universal_integer itself. If the result is of type universal_real, then the values of the operands and the result must lie within the range of the floating point type with the widest range provided by the implementation, excluding type universal_real itself.

Clearly there's a need for understanding what an operation is, for which we can turn to 3. Types (5. -2008):

A type is characterized by a set of values and a set of operations. The set of operations of a type includes the explicitly declared subprograms that have a parameter or result of the type. The remaining operations of a type are the basic operations and the predefined operators (see 7.2 ). These operations are each implicitly declared for a given type declaration immediately after the type declaration and before the next explicit declaration, if any.

While both 'POS and 'VAL are functions they are not explicitly declared.

The definition of basic operation is also found in 3., and does include a predefined attribute:

-- A numeric literal (for a universal type), the literal null (for an access type), a string literal, a bit string literal, an aggregate, or a predefined attribute.

So the behavior exhibited by nvc limiting the output appears correct (and completely non-useful). It says you need to have an implementation defined type INTEGER that matches universal integer range to take advantage of the range of universal integer. ("must lie within the range of the integer type with the widest range provided by the implementation, excluding type universal_integer itself").

A check: entity tell_integer_range is end entity;

architecture foo of tell_integer_range is
begin
    assert FALSE
    report "integer range from " & integer'image(integer'low) & " to " 
                              & integer'image(integer'high)
    severity NOTE;
end architecture;

nvc has a 32 bit integer range. (ghdl, too)

It says you can't declare your own BIG integer type and benefit from the universal integer type range. Effectively integer must be the same range as universal integer to reap any benefit of universal integer range.

This also your own physical types based on a range wider than integer, meaning that operations with 64 bit based physical types are limited to 32 bit accuracy for integer operations although noting both ghdl and nvc implement double accuracy type real, presumably limiting accuracy or range when converting to an integer type.

And all this according to the LRM.

diogratia avatar Jan 19 '15 05:01 diogratia

This has been fixed, finally.

nickg avatar Oct 12 '21 15:10 nickg