Re: [myhdl-list] intbv.wrap()
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2011-04-19 11:42:22
|
The following are the proposed changes to the intbv class (WIP). I added the attribute but I have not added the "wrap" __setitem__ and i* operators. Need to determine if the intbv.wrap function will remain a public function or move to a private function. If it remains an advertised public function then the conversion will need to handle the wrap function. Feedback always welcome. Note the attached change set is *INCOMPLETE* add for convenience. ---------------------- # Simple test code x = intbv(0, min=-8, max=8) for ii in xrange(x): x[:] = x.wrap(x+1) print x for ii in range(1333): x[:] = x.wrap(x+77) # bound checking will catch errors, more test cases needed # Additions to the intbv class class intbv(object): __slots__ = ('_val', '_min', '_max', '_nrbits', '_range', '_wrap') def __init__(self, val=0, min=None, max=None, wrap=False, _nrbits=0): ... self._nrbits = _nrbits self._wrap = wrap self._range = 2**_nrbits def wrap(self, val): """ Wrap the value back to the range of the inbv The following will check that the defined min-max is the full range of the binary word. If the full range is specified if the value is outside the bounds of the range it will be adjusted to the proper value in bounds. """ assert abs(self.min) == self.max assert (abs(self.min) + self.max) == self._range rval = self.min + ((val +self.max) % self._range) return rval ---------------------- |