Type convertion when doing arimetic on intergers.

Discussion in 'VHDL' started by MLyngsie, Oct 25, 2006.

  1. MLyngsie

    MLyngsie Guest

    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.
    MLyngsie, Oct 25, 2006
    #1
    1. Advertising

  2. MLyngsie

    Dave Pollum Guest

    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
    Dave Pollum, Oct 25, 2006
    #2
    1. Advertising

  3. MLyngsie

    MLyngsie Guest

    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
    MLyngsie, Oct 26, 2006
    #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. Replies:
    8
    Views:
    1,867
    Mike Treseler
    Feb 10, 2005
  2. Kay

    type convertion

    Kay, Sep 1, 2004, in forum: C++
    Replies:
    1
    Views:
    364
    Mike Wahler
    Sep 1, 2004
  3. M.-A. Lemburg
    Replies:
    3
    Views:
    552
    M.-A. Lemburg
    Apr 4, 2005
  4. kaikai
    Replies:
    4
    Views:
    260
    kaikai
    Jan 3, 2006
  5. Allen
    Replies:
    2
    Views:
    285
    Allen
    Dec 25, 2008
Loading...

Share This Page