What does what standard say about this:

Discussion in 'VHDL' started by Alvin Andries, Nov 12, 2007.

  1. 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.
     
    Alvin Andries, Nov 12, 2007
    #1
    1. Advertising

  2. Mike Treseler, Nov 12, 2007
    #2
    1. Advertising

  3. Alvin Andries

    KJ Guest

    "Alvin Andries" <> wrote in
    message news:4738bfc0$0$7169$2.nl...
    >
    > 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
     
    KJ, Nov 13, 2007
    #3
  4. Alvin Andries

    Andy Guest

    On Nov 12, 6:15 pm, "KJ" <> wrote:
    > "Alvin Andries" <> wrote in
    > messagenews:4738bfc0$0$7169$2.nl...
    >
    >
    >
    >
    >
    > > 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


    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
     
    Andy, Nov 13, 2007
    #4
  5. On Tue, 13 Nov 2007 07:06:26 -0800,
    Andy <> wrote:

    >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

    http://www.MYCOMPANY.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
     
    Jonathan Bromley, Nov 22, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Rahardja
    Replies:
    5
    Views:
    1,127
    John Harrison
    Jul 18, 2003
  2. Xenos
    Replies:
    1
    Views:
    325
    Rob Williscroft
    Jul 10, 2004
  3. Tobias Oed
    Replies:
    11
    Views:
    1,154
    Dan Pop
    Jun 30, 2003
  4. Sten Westerback

    Re: What does the standard say?

    Sten Westerback, Apr 2, 2004, in forum: C Programming
    Replies:
    3
    Views:
    421
    Rob Thorpe
    Apr 6, 2004
  5. r martin

    Re: What does the standard say?

    r martin, Apr 3, 2004, in forum: C Programming
    Replies:
    6
    Views:
    354
    Raymond Martin
    Apr 5, 2004
Loading...

Share This Page