Re: [myhdl-list] intbv improvement?
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2009-03-04 20:55:05
|
Neal Becker wrote: > Jan Decaluwe wrote: > >> Neal Becker wrote: >>> I would find this addition to the intbv constructor helpful: >>> >>> class intbv(object): >>> __slots__ = ('_val', '_min', '_max', '_nrbits') >>> >>> def __init__(self, val=None, min=None, max=None, _nrbits=0, >>> is_signed=False): >>> if _nrbits: >>> if (is_signed): >>> self._min = -1 << (_nrbits-1) >>> self._max = ~(-1 << (_nrbits-1)) >>> else: >>> self._min = 0 >>> self._max = 2**_nrbits >> I infer that you want to use _nrbits as an end user also? >> This is not how the type is set up. _nrbits is intended >> to be a private parameter of the constructor for internal >> use. >> >> One of the goals of intbv is to get rid of unsigned/signed >> thinking as much as possible, and push the use of fine-grained >> range control as high-level alternative. >> (I'm actually writing a paper about this, almost finished.) >> >> Jan >> > > I want to make sure my value is converted to verilog signed. AFAICT, the > only way I have now to do this is with intbv specifying min and max, rather > than nrbits? Yes. > That's OK, but a little inconvenient. Here I disagree, I actually believe the opposite is true though I understand it goes against current conventional wisdom. Note that by using min and max, you never have to think or worry about the difference between signed/unsigned. The convertor should solve the issues for you. My upcoming essay deals exactly with these issues in detail, please stay tuned! (in one week or so) Jan -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a hardware description language: http://www.myhdl.org |