Amal,
The current comparison operators are implicitly defined
if you do not explicitly overload them. For an enumerated
type, implicitly left-most values are smaller than right-most
values. Hence, U < X < 0 < 1 < Z < W < L < H < -. For arrays,
comparisons start with the left-most element (like
a dictionary). As a result, comparisons using bit_vector
and std_logic_vector do not work numerically when the
array lengths are not the same. Also for std_logic,
L /= 0 and H /= 1 as it would numerically.
This means you must take caution:
1) Use numeric_std and either signed and unsigned types
or convert to signed and unsigned
2) Make sure arrays are equal length and you
only have driving values (use ieee.std_logic_1164.TO_X01).
3) Use an unsigned package that understands std_logic_vector
to be unsigned - of course expect many to object
In the next revision of the language, new ordering operators
are being added (?>, ?>=, ?<, ?<=) that return std_logic/bit
and are not implicitly defined As a result, it will be an error
if an appropriate package is not referenced. They are also
handy for other use cases such as:
RamSel <= MemSel and Addr > X"1FFF" ;
Cheers,
Jim
> On Mar 20, 1:28 pm, Mike Treseler <mike_trese...@comcast.net> wrote:
>> Amal wrote:
>>> Please give me your input and tell me how VHDL treats bit-string
>>> literals and bit_vector constants.
>> If I want numeric comparison functions
>> to work correctly, I use numeric types.
>> See below.
>> This should make everything flip on
>> the v transition from x"0F" to x"10"
>>
>> -- Mike Treseler
>> _____________________________________
>> library ieee;
>> use ieee.std_logic_1164.all;
>> use ieee.numeric_std.all;
>>
>> entity uns_compare is
>> end entity uns_compare;
>>
>> architecture behav of uns_compare is
>> signal v : unsigned(9 downto 0);
>> signal x1, x2, x3, z1, z2 : boolean;
>> begin
>> x1 <= (v < X"010");
>> x2 <= (v < b"0000_0001_0000");
>> x3 <= (v < "000000010000");
>>
>> z1 <= (v < b"00_0001_0000");
>> z2 <= (v < "0000010000");
>> ...
>>
>> ____________________________________________
>
>
> Yes, Mike, I understand that if you include numeric_std package, you
> are overriding built-in comparison operators, but what happens here
> when you don't? Why should the compiler not give you a warning and
> you get wrong functionality.
>
> The result is:
>
> a 00 01 02 03 4 5 6 7 8 9 10 11 12 13 14 15 16 17
> x1 --------------\________________________________
> x2 --------------\________________________________
> x3 --------------\________________________________
> z1 ---------------------------------------\_______
> z1 ---------------------------------------\_______
>
> Why the change at 5? And why when you do:
> x1 <= (v >= X"010");
>
> you get the same result as:
> x1 <= (v < X"010");
>
> -- Amal
>
|