![]() |
|
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error in Modelsim 6.0a | boitsas | Software | 1 | 10-26-2009 05:36 AM |
| VERY WIRED BEHAVIOR OF NERO 7.7.5.1 | tanyaru@hotmail.com | DVD Video | 4 | 04-06-2007 08:45 AM |
| simprim problems on modelsim | saiyijinprince | Hardware | 2 | 04-05-2007 02:24 PM |
| Re: Odd PSU behavior? | w_tom | A+ Certification | 19 | 09-15-2006 10:33 AM |
| You MUST Watch This Before You Vote - Esteemed Shrink Profiles Bush | Barney Lyon | DVD Video | 13 | 11-02-2004 06:21 PM |