Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > slice of signed = unsigned?

Reply
Thread Tools

slice of signed = unsigned?

 
 
-DeeT
Guest
Posts: n/a
 
      05-13-2011
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
 
Reply With Quote
 
 
 
 
Alexander Bartolich
Guest
Posts: n/a
 
      05-14-2011
-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
 
Reply With Quote
 
 
 
 
Tricky
Guest
Posts: n/a
 
      05-14-2011
On May 13, 6:43*pm, -DeeT <d...@dt.prohosting.com> 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) );
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a signed binary number into a signed one ? Rob1bureau VHDL 1 02-27-2010 12:13 AM
signed(12 downto 0) to signed (8 downto 0) kyrpa83 VHDL 1 10-17-2007 06:58 PM
Null slice? Synthesis in XST? Brandon VHDL 0 08-31-2005 09:16 PM
Concurrent assignments to std_ulogic_vector slice is OK with ModelSim Nicolas Matringe VHDL 9 06-14-2004 10:10 PM
How to get a slice of INTEGER type out? walala VHDL 1 09-05-2003 08:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57