Modelsim behavior

P

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\;
 
On Mon, 9 Aug 2004 09:52:44 -0500, "Paul Butler" <Paul.Butler@ni.com>
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:jonathan.bromley@doulos.com
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.
 

Welcome to EDABoard.com

Sponsor

Back
Top