Re: [myhdl-list] Error in Intbv class?
Brought to you by:
jandecaluwe
From: Forumulator B. <for...@gm...> - 2016-03-03 19:19:20
|
True, because the value wrapped by the class is still a standard unconstrained int. Thus, accessing something like: >>a=intbv(5)[4:] >>a[6] false Where as it should raise an out of bounds exception.Can someone comment on this so that I could possibly try to fix this. While we're on the topic, i also think that the __setitem__ method should be seperately implemented for modbv too, so that wrap around behaviour can be extended to slices of an object. For example. >>a=modbv(5)[4:] >>a[4:1]=20 should give a value of 12 for a instead of giving an error. Are these issues trivial? On Thu, Mar 3, 2016 at 8:35 PM, Samuele Disegna <sm...@gm...> wrote: > Hi again, while analyzing the _intbv code I noticed a related problem: > > An Exception is Not risen when accessing a out of bound bit of a > constrained intbv. > This seems a real problem to me. > > I tested it by using the example code at > http://docs.myhdl.org/en/stable/manual/hwtypes.html#bit-indexing and > modifing it for using a constrained intbv: > > from myhdl import Signal, delay, Simulation, always_comb, instance, intbv, > bin > > def bin2gray(B, G, width): > """ Gray encoder. > > B -- input intbv signal, binary encoded > G -- output intbv signal, gray encoded > width -- bit width > """ > > @always_comb > def logic(): > for i in range(width): > G.next[i] = B[i+1] ^ B[i] > > return logic > > def testBench(width): > > B = Signal(intbv(0)[3:]) > G = Signal(intbv(0)[3:]) > > dut = bin2gray(B, G, width) > > @instance > def stimulus(): > for i in range(2**width): > B.next = intbv(i)[3:] > yield delay(10) > print("B: " + bin(B, width) + "| G: " + bin(G, width)) > > return dut, stimulus > > sim = Simulation(testBench(width=3)) > sim.run() > > > On Thu, Mar 3, 2016 at 2:24 PM, Samuele Disegna <sm...@gm...> wrote: > >> Hello, Last message was empty, my mistake. >> >> On Thu, Mar 3, 2016 at 2:10 PM, Samuele Disegna <sm...@gm...> wrote: >> >>> >>> >>> On Thu, Mar 3, 2016 at 1:14 PM, Forumulator Bing <for...@gm...> >>> wrote: >>> >>>> Hello, >>>> >>>> I may have found a potential bug in intbv: >>>> >>>> >>> a=intbv(5)[4:0] >>>> >>> a[6:0]=20 >>>> Traceback (most recent call last): >>>> File "<stdin>", line 1, in <module> >>>> File "/usr/local/lib/python3.4/dist-packages/myhdl/_intbv.py", line >>>> 180, in __setitem__ >>>> self._handleBounds() >>>> File "/usr/local/lib/python3.4/dist-packages/myhdl/_intbv.py", line >>>> 77, in _handleBounds >>>> (self._val, self._max)) >>>> ValueError: intbv value 20 >= maximum 16 >>>> >>> a >>>> intbv(20) >>>> >>>> It gives a ValueError, but still sets the value of a to 20. Would this >>>> be considered a bug since an exception is thrown? >>>> >>>> >>> From what I see on myhdl code min/max bounds handling is done later than >> assignment and it seems independent. >> Therefore I would say it is not a bug. We could document this behaviour. >> Is it possible to subclass the exception to a documented ValueBoundError >> that define the behaviour? >> >> You can find the related code at >> https://github.com/jandecaluwe/myhdl/blob/master/myhdl/_intbv.py >> def __setitem__(self, key, val): >> >> Regards >> > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > > |