What does what standard say about this:

A

Alvin Andries

library IEEE;
use IEEE.STD_LOGIC_1164.all;


comp_value : STD_LOGIC_VECTOR(7 downto 0);


if (comp_value < "000000001") then ...


This passed withhout warning through Synopsys DC and Formality.
Unfortunately, they disagree on what should happen.

Things that bother me about this construct:
1) no ARITH loaded, so where is this defined (I've got IEEE access, so the
proper STD should be ok)?
2) different vector lengths, so I expect troubles

The only thing I could deduce from Mentor's Modelsim source files, is that
STD_LOGIC_VECTOR(L) < STD_LOGIC_VECTOR(L) behaves like UNSIGNEDs where in
place.

Kind regards,
Alvin.
 
K

KJ

Alvin Andries said:
library IEEE;
use IEEE.STD_LOGIC_1164.all;


comp_value : STD_LOGIC_VECTOR(7 downto 0);


if (comp_value < "000000001") then ...


This passed withhout warning through Synopsys DC and Formality.
Unfortunately, they disagree on what should happen.

Things that bother me about this construct:
1) no ARITH loaded, so where is this defined (I've got IEEE access, so the
proper STD should be ok)?

The comparison will be made from left to right through the elements of the
vectors, looking at each element individually. So the comparison will work
like this...
1. check for comp_value(7) < '0'
2. if comp_value(7) = '0' then check for comp_value(6) < '0'
3. Keep going until you get to bit 0.
2) different vector lengths, so I expect troubles
You'll get them too, although I forget just what happens if you try to
compare two vectors of different lengths....it's generally a design error
that you fix, not some behaviour that is of any good use in my experience.
The only thing I could deduce from Mentor's Modelsim source files, is that
STD_LOGIC_VECTOR(L) < STD_LOGIC_VECTOR(L) behaves like UNSIGNEDs where in
place.

Comparison of two std_logic_vectors happens without any numerical
interpretation of those vectors, it is simply an element by element
comparison of those vectors. A particular element of an enumerated type is
considered 'less than' some other thing of that same type if it is to the
'left' of the other thing being compared. If you take a look at
std_logic_1164 and look for the actual definition of the std_ulogic type,
you'll see that it is a list of characters. Those are the enumerations,
that's where you'll find the '0', '1', 'X', '-', 'U', etc. In that list,
'0' will be to the left of '1'.

Of course, one can also provide a function override to "<" and make it come
out however you want it to (like in std_logic_arith), but if no such
override is in place the above mentioned behavour is how the language will
interpret it.

Just curious, in what way Synopsys DC and Formality actually disagree?

KJ
 
A

Andy

message









The comparison will be made from left to right through the elements of the
vectors, looking at each element individually. So the comparison will work
like this...
1. check for comp_value(7) < '0'
2. if comp_value(7) = '0' then check for comp_value(6) < '0'
3. Keep going until you get to bit 0.


You'll get them too, although I forget just what happens if you try to
compare two vectors of different lengths....it's generally a design error
that you fix, not some behaviour that is of any good use in my experience.


Comparison of two std_logic_vectors happens without any numerical
interpretation of those vectors, it is simply an element by element
comparison of those vectors. A particular element of an enumerated type is
considered 'less than' some other thing of that same type if it is to the
'left' of the other thing being compared. If you take a look at
std_logic_1164 and look for the actual definition of the std_ulogic type,
you'll see that it is a list of characters. Those are the enumerations,
that's where you'll find the '0', '1', 'X', '-', 'U', etc. In that list,
'0' will be to the left of '1'.

Of course, one can also provide a function override to "<" and make it come
out however you want it to (like in std_logic_arith), but if no such
override is in place the above mentioned behavour is how the language will
interpret it.

Just curious, in what way Synopsys DC and Formality actually disagree?

KJ

KJ is correct about the left to right comparison, but IINM, it is only
for equal length vectors. If the vector lengths are unequal, the
shorter vector is (supposed to be) always less than the longer vector
regardless of the contents of both. When comparing elements in equal
length vectors, the elements are compared per the order of their
appearance in the std_ulogic type definition. I agree that comparison
of unequal length std_logic_vectors is practically useless in
synthesis.

Andy
 
J

Jonathan Bromley

KJ is correct about the left to right comparison, but IINM, it is only
for equal length vectors. If the vector lengths are unequal, the
shorter vector is (supposed to be) always less than the longer vector
regardless of the contents of both.

I fear you _are_ mistaken, at least in this small detail...

"Built-in" vector comparison is essentially string
comparison. If you were sorting a bunch of strings into
dictionary order, I'm sure you would agree with VHDL
that all the following relations are true:

"AD" > "AC"
"ABCD" > "AABCD" -- shorter string is "larger"
"AACD" > "AAC"

The same thing happens with std_logic_vector, except
that the collating sequence is determined by the order
of characters' appearance in the std_ulogic enumeration
rather than their alphabetical order:

'U' < 'X' < '0' < '1' < 'W' < 'L' < 'H' < 'Z' < '-'

As others have correctly stated, the only *practical*
use of this is that you can compare two std_logic_vector
provided that...
(1) they are of _equal_length_ and
(2) their vectors contain only '0' and '1' elements

If both these conditions are true, you get unsigned
arithmetic comparison. If not, you get very very silly
behaviour; for example
"11" > "101"
"L" > "1"

Of course, the numeric_std package overloads the comparison
operators so that they work "correctly" (i.e. arithmetically)
for any operand lengths. And, of course, that's the right
way to do it.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
(e-mail address removed)
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top