Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Modelsim behavior

Reply
Thread Tools

Modelsim behavior

 
 
Paul Butler
Guest
Posts: n/a
 
      08-09-2004
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\;


 
Reply With Quote
 
 
 
 
Jonathan Bromley
Guest
Posts: n/a
 
      08-09-2004
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.
 
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
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
xilinx logiblox and modelsim SE 5.6 Tim Terry VHDL 1 07-21-2003 03:25 PM
VHDL Simulation in ModelSim Manfred Balik VHDL 0 07-15-2003 02:12 PM
ModelSim Error Msg Yogi V. VHDL 3 07-03-2003 10:48 AM
Re: ModelSim 5.7 and xilinx libraries David Bishop VHDL 1 06-28-2003 04:53 PM



Advertisments