Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Type convertion when doing arimetic on intergers.

Reply
Thread Tools

Type convertion when doing arimetic on intergers.

 
 
MLyngsie
Guest
Posts: n/a
 
      10-25-2006
Dear All,

What is the resulting range of an arithmetic operation on ranged
integers?
E.g. with the following two signals.

signal X : integer range 1 to 255;
signal Y : integer range 1 to 255;

And then some ware in the code.

if ( X > Y/2) then .......

Our linding tools report a warning here stating the X is 8 bit wide and
Y/2 is only 7 bit.
So the simple question is now.

What is the range of Y/2?

The general question is. What is the range of any arithmetic operation
on ranged integers?
Which rules control this?
Where in the LRM is this described?

Regards,
Mogens.

 
Reply With Quote
 
 
 
 
Dave Pollum
Guest
Posts: n/a
 
      10-25-2006

MLyngsie wrote:
> Dear All,
>
> What is the resulting range of an arithmetic operation on ranged
> integers?
> E.g. with the following two signals.
>
> signal X : integer range 1 to 255;
> signal Y : integer range 1 to 255;
>
> And then some ware in the code.
>
> if ( X > Y/2) then .......
>
> Our linding tools report a warning here stating the X is 8 bit wide and
> Y/2 is only 7 bit.
> So the simple question is now.
>
> What is the range of Y/2?
>
> The general question is. What is the range of any arithmetic operation
> on ranged integers?
> Which rules control this?
> Where in the LRM is this described?
>
> Regards,
> Mogens.


Since Y is 8-bits, then (Y/2) is an 7-bit value. If Y is not used
except in your if statement, then the HDL compiler figures out that it
only needs 7-bits for Y.
BTW, why is the low range for both X and Y '1', instead of '0'?

-Dave Pollum

 
Reply With Quote
 
 
 
 
MLyngsie
Guest
Posts: n/a
 
      10-26-2006
Hi Dave,
Thank you for the answer.

This is also what I assumed. But where is this stated in the LRM.
It you lock in section 7.2.6 "Multiplying operators" of the LRM it is
just stated that the result is of the same type as the operands. This
section doesn't really describe anything about the range of integers.

Regarding the lower range of the type definition. It is just there so
that an error will be issued if a value that is out of the expected
range is assigned.

Regards,
Mogens

 
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
How to do type convertion for template class? Allen C++ 2 12-25-2008 11:58 AM
type convertion between template kaikai C++ 4 01-03-2006 03:54 PM
type convertion of an unconstrained output in a port map ygrugni@hotmail.com VHDL 8 02-10-2005 06:53 PM
type convertion Kay C++ 1 09-01-2004 04:38 AM
Convertion php to asp.net : PB lecture fichier .ini isore ASP .Net 0 07-01-2004 05:52 PM



Advertisments