slice of signed = unsigned?

Discussion in 'VHDL' started by -DeeT, May 13, 2011.

  1. -DeeT

    -DeeT Guest

    If you take a slice of a signed vector which doesn't include the sign
    bit, is that slice considered to be signed or unsigned? Here's an
    illustration:

    signal v : signed(7 downto 0);
    alias a is v(3 downto 0);
    variable i : integer;
    i := to_integer(a);

    In the above scenario, what is the range of possible values for 'i'?
    Is it 0 to 15, or -8 to +7?

    I ask because a compiler upgrade broke some of my code, by changing
    this behavior (which admittedly I shouldn't have counted on either
    way!).

    Thanks in advance for your thoughts...
    -DT
    -DeeT, May 13, 2011
    #1
    1. Advertising

  2. -DeeT wrote:
    > If you take a slice of a signed vector which doesn't include the sign
    > bit, is that slice considered to be signed or unsigned? Here's an
    > illustration:
    >
    > signal v : signed(7 downto 0);
    > alias a is v(3 downto 0);
    > variable i : integer;
    > i := to_integer(a);


    IEEE Std 1076-1993 (Revision of IEEE Std 1076-1987), page 75

    # 4.3.3.1 Object aliases
    # [...]
    # The name must be a static name (see 6.1) that denotes an object. The
    # base type of the name specified in an alias declaration must be the
    # same as the base type of the type mark in the subtype indication (if
    # the subtype indication is present); this type must not be a multi-
    # dimensional array type. When the object denoted by the name is
    # referenced via the alias defined by the alias declaration, the following
    # rules apply:
    # - If the subtype indication is absent or if it is present and denotes
    # an unconstrained array type:
    # - If the alias designator denotes a slice of an object, then the
    # subtype of the object is viewed as if it were of the subtype
    # specified by the slice
    # - Otherwise, the object is viewed as if it were of the subtype
    # specified in the declaration of the object denoted by the name

    > In the above scenario, what is the range of possible values for 'i'?
    > Is it 0 to 15, or -8 to +7?


    To my understanding the alias is equivalent to a declaration like

    signal a: signed(3 downto 0);

    --
    host -t mx moderators.isc.org
    Alexander Bartolich, May 14, 2011
    #2
    1. Advertising

  3. -DeeT

    Tricky Guest

    On May 13, 6:43 pm, -DeeT <> wrote:
    > If you take a slice of a signed vector which doesn't include the sign
    > bit, is that slice considered to be signed or unsigned?  Here's an
    > illustration:
    >
    > signal v : signed(7 downto 0);
    > alias a is v(3 downto 0);
    > variable i : integer;
    > i := to_integer(a);
    >
    > In the above scenario, what is the range of possible values for 'i'?
    > Is it 0 to 15, or -8 to +7?
    >
    > I ask because a compiler upgrade broke some of my code, by changing
    > this behavior (which admittedly I shouldn't have counted on either
    > way!).
    >
    > Thanks in advance for your thoughts...
    > -DT


    Signed and Unsigned are two completely different types, so slicing
    them just returns a subtype of the base type. But they are similar
    types, so you can cast from one type to the other without a conversion
    function.

    So you could write this instead:

    i := to_integer( unsigned(a) );
    Tricky, May 14, 2011
    #3
    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. Jeremy Pyle
    Replies:
    3
    Views:
    52,543
    Mike Treseler
    Jun 28, 2003
  2. Patrick

    signed to unsigned

    Patrick, Jun 7, 2004, in forum: VHDL
    Replies:
    1
    Views:
    5,496
    Ralf Hildebrandt
    Jun 7, 2004
  3. kyrpa83
    Replies:
    1
    Views:
    605
    kyrpa83
    Oct 17, 2007
  4. Rob1bureau
    Replies:
    1
    Views:
    791
    joris
    Feb 27, 2010
  5. pozz
    Replies:
    12
    Views:
    704
    Tim Rentsch
    Mar 20, 2011
Loading...

Share This Page