Re: [myhdl-list] intb min, max confusion
Brought to you by:
jandecaluwe
From: Angel E. <ang...@gm...> - 2012-10-04 06:43:20
|
I think the comparison to range is not totally accurate. The docstring of the range function is as follows: range([start,] stop[, step]) -> list of integers That is, there is no "max" parameter, but a "stop" parameter. I'm not saying the current behavior should be changed, just that perhaps the parameter name is a bit misleading. Cheers, Angel On Thu, Oct 4, 2012 at 4:48 AM, Christopher Felton <chr...@gm...> wrote: > You would simply use MAXV = 2**NBITS. This is common in > Python (there is a term for it). Example if you use "range(3)" > the list you get is 0,1,2. It doesn't include the 3 only up to. > The intbv works the same, max=N, the max value will be > N-1. Even though a 3bit value was created "len(x) == 3" the max > value was specified and is checked during simulation. > > Hope that helps, > Chris > > > On Wed, Oct 3, 2012 at 6:53 PM, garyr <ga...@fi...> wrote: >> >> It appears to me that the max limit on an intbv value should be > (greater >> than) rather than >= (greater than or equal). In the following code, isn't >> 3 >> a valid value for a 3-bit signal? >> >> from myhdl import * >> def testBench(): >> @instance >> def stimulus(): >> NBITS = 3 >> MAXV = 2**(NBITS-1) >> min = -MAXV >> max = MAXV-1 >> print 'NBITS=%d min=%d max=%d' % (NBITS, min, max) >> x = Signal(intbv(0, min=min, max=max)) >> x.next = min >> yield delay(1) >> print 'x', x >> x.next = max >> yield delay(1) >> print 'x', x >> raise StopSimulation >> return instances() >> tb = testBench() >> Simulation(tb).run(200) >> ====================================== >> >python intbTest.py >> NBITS=3 min=-4 max=3 >> x -4 >> Traceback (most recent call last): >> File "intbTest.py", line 22, in <module> >> Simulation(tb).run(200) >> File "C:\Python26\lib\site-packages\myhdl\_Simulation.py", line 132, in >> run >> waiter.next(waiters, actives, exc) >> File "C:\Python26\lib\site-packages\myhdl\_Waiter.py", line 128, in next >> clause = self.generator.next() >> File "intbTest.py", line 15, in stimulus >> x.next = max >> File "C:\Python26\lib\site-packages\myhdl\_Signal.py", line 200, in >> _set_next >> self._setNextVal(val) >> File "C:\Python26\lib\site-packages\myhdl\_Signal.py", line 266, in >> _setNextIntbv >> self._next._checkBounds() >> File "C:\Python26\lib\site-packages\myhdl\_intbv.py", line 79, in >> _checkBounds >> (self._val, self._max)) >> ValueError: intbv value 3 >= maximum 3 >> >Exit code: 1 >> >> >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> Don't let slow site performance ruin your business. Deploy New Relic APM >> Deploy New Relic app performance management and know exactly >> what is happening inside your Ruby, Python, PHP, Java, and .NET app >> Try New Relic at no cost today and get our sweet Data Nerd shirt too! >> http://p.sf.net/sfu/newrelic-dev2dev >> _______________________________________________ >> myhdl-list mailing list >> myh...@li... >> https://lists.sourceforge.net/lists/listinfo/myhdl-list > > > > ------------------------------------------------------------------------------ > Don't let slow site performance ruin your business. Deploy New Relic APM > Deploy New Relic app performance management and know exactly > what is happening inside your Ruby, Python, PHP, Java, and .NET app > Try New Relic at no cost today and get our sweet Data Nerd shirt too! > http://p.sf.net/sfu/newrelic-dev2dev > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |