Modelsim behavior

Discussion in 'VHDL' started by Paul Butler, Aug 9, 2004.

  1. Paul Butler

    Paul Butler Guest

    My understanding of 1076-2002 is that the value "integer'high + 1" is out of
    range for a variable of type integer. Modelsim PE 5.8b seems to implement
    the integer type as a 2's complement 32 bit number so that (integer'high +
    1) = integer'low. For most values of an integer variable D32,
    integer'succ(D32) = D32 + 1. However, for at least one value,
    integer'succ(D32) is out of range while D32+1 is integer'low.

    Is Modelsim's behavior incorrect? How do other simulators behave?

    Paul Butler

    PS I claim that the following code should produce a fatal "out of range"
    error. The code shows that, in Modelsim, adding two positive numbers can
    produce a negative sum.

    entity \Integer range demonstration\ is
    end entity \Integer range demonstration\;

    architecture \Test\ of \Integer range demonstration\ is
    begin

    \32 bit 2's complement\:
    Process is
    variable \Integer Variable\ : integer;
    variable \Increment\, \Decrement\ : integer;
    begin

    \Integer Variable\ := integer'high;

    \Increment\ := \Integer Variable\ + 1;

    assert \Increment\ > \Integer Variable\
    report "integer'high + 1 = " & integer'image(\Increment\);

    \Integer Variable\ := integer'low;

    \Decrement\ := \Integer Variable\ - 1;

    assert \Decrement\ < \Integer Variable\
    report "integer'low - 1 = " & integer'image(\Decrement\);

    wait;

    end process \32 bit 2's complement\;

    end architecture \Test\;
     
    Paul Butler, Aug 9, 2004
    #1
    1. Advertising

  2. On Mon, 9 Aug 2004 09:52:44 -0500, "Paul Butler" <>
    wrote:

    >My understanding of 1076-2002 is that the value "integer'high + 1" is out of
    >range for a variable of type integer. Modelsim PE 5.8b seems to implement
    >the integer type as a 2's complement 32 bit number so that (integer'high +
    >1) = integer'low. For most values of an integer variable D32,
    >integer'succ(D32) = D32 + 1. However, for at least one value,
    >integer'succ(D32) is out of range while D32+1 is integer'low.
    >
    >Is Modelsim's behavior incorrect? How do other simulators behave?


    Scirocco (Synopsys) detects the error if "-debug all" is
    selected at the simulator invocation line.

    I think it gets worse:

    When I first saw this I thought: Ahah, the problem is with
    implementation of "+". It does modulo-2^32 arithmetic,
    erroneously yielding a result -(2^31), but that result
    is in-range and so any range check on assignment to the
    incremented variable will be OK. But then I tried
    defining a subtype

    integer range integer'low+1 to integer'high

    which brings ModelSim's definition of integer into line
    with the LRM's minimum, and outlaws the value -(2^31).
    Then, if "target" is of the new subtype,

    target := integer'high + 1;

    should fail on two counts: the arithmetic overflows
    the base type "integer", but even if that test
    is ignored, the resulting value is out of range for
    assignment to "target". Hmmm, nice theory.
    ModelSim goes ahead and does the assignment anyhow.

    There may well be something about this in ModelTech's
    release notes, but I've no time to trawl through them
    right now - sorry.
    --
    Jonathan Bromley, Consultant

    DOULOS - Developing Design Know-how
    VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

    Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
    Tel: +44 (0)1425 471223 mail:
    Fax: +44 (0)1425 471573 Web: http://www.doulos.com

    The contents of this message may contain personal views which
    are not the views of Doulos Ltd., unless specifically stated.
     
    Jonathan Bromley, Aug 9, 2004
    #2
    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. David Bishop

    Re: ModelSim 5.7 and xilinx libraries

    David Bishop, Jun 28, 2003, in forum: VHDL
    Replies:
    1
    Views:
    2,189
    Tim Hubberstey
    Jun 28, 2003
  2. Yogi V.

    ModelSim Error Msg

    Yogi V., Jul 1, 2003, in forum: VHDL
    Replies:
    3
    Views:
    23,246
    John Moore
    Jul 3, 2003
  3. Manfred Balik

    VHDL Simulation in ModelSim

    Manfred Balik, Jul 15, 2003, in forum: VHDL
    Replies:
    0
    Views:
    1,742
    Manfred Balik
    Jul 15, 2003
  4. Tim Terry
    Replies:
    1
    Views:
    2,076
    Michael Nicklas
    Jul 21, 2003
  5. Mantorok Redgormor
    Replies:
    70
    Views:
    1,763
    Dan Pop
    Feb 17, 2004
Loading...

Share This Page