Re: [myhdl-list] Restrictions for conversion
Brought to you by:
jandecaluwe
From: Norbo <Nor...@gm...> - 2012-05-21 11:29:19
|
> * Adding support for None in the intbv (also setting None as the default > value?) > * Creating initial values in Verilog/VHDL (when not None) > * Changing the verilog continuous assignment to the behavioral statement > in the verilog conversion > * Work through the implementation changes needed, because of the None in > the intbv (boundchecks, etc ..) I started to try to implement these points. the real issues started where i came to the : * Work through the implementation changes needed, because of the None in the intbv (boundchecks, etc .. the issue arises when the intbv has a value of None in the myhdl implementation, and something like this is done: sig1=Signal(intbv(None)[8:)) sig2=Signal(intbv(None)[8:)) @always(clk.posedge) def aritmetic(): square.next=sig1*sig1+sig2*sig2 i first changed all __add__ and __mult__ operater of the intbv to return None as a value if one of the operands is None. But as the two multiplications are done first the last plus operation has two None values (None+None) which doesnt works. So i returned for every operation a new intbv(None). Anyway there seem to be some operators where intbv() are returned and other operaters there is just the value returned (in the orginal code -> has this any special reson?). But there was an other case: mem=[Signal(intbv(0)[8:]) for i in range(200)] @always(clk.posedge) def mem_read(): our.next=mem[addr] if here the addr._val is None then it also crashes. So my short just to try workaround was to subclass list and accept the None as a index class listx(list): def __getitem__(self, key): if key==None: bits=super(listx, self).__getitem__(0)._nrbits return intbv(None)[bits:] return super(listx, self).__getitem__(key) then the implementation would have to look like this: mem=listx([Signal(intbv(0)[8:]) for i in range(200)]) @always(clk.posedge) def mem_read(): our.next=mem[addr] then the issue with the bool arised because if you write code like this: sig=Signal(bool(None)) because bool(None) evaluates to false the _val of the Signal gets false an not None So i tried with a bool definition like the following: def boolx(val=None): if val in (0, 1): return bool(val) else: return None Then i changed all Signal operators (__add__, __sub__, etc..) that they return None if one of the operaters is None which brings the same problem with the plus to the signal as i had in the intbv() which is that two None values can't be added or multiplyed or etc. like in the intbv. then i realized that it probably would just be better to make the Signal as a base class and derive every other type from it, wheter it is (intbv, bool"x" or modbv, enum, etc.). This probably doesnt made sense once when only the intbv existed? or is it done the way it is done because of performance reason? greetings Norbo |