Re: [myhdl-list] [PATCH] Remove redundant copy operators
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2009-11-04 11:49:52
|
I'm not entirely sure I understand the issue, but here are some upfront remarks. Something like a VHDL alias in its full generality would probably require Python language support. What we can do is try to accomodate for some limited but interesting cases. One issue that I have addressed myself is the fact the MyHDL signal slices aren't signals. I consider this a major weakness, and I have come up with a proposal to address what I consider the most important issues: http://www.myhdl.org/doku.php/meps:mep-105 An implementation is present in the development trunk. I would be interested to hear whether this can be a solution for you. E.g: class ControlWord(object): pass ctrlword = ControlWord() a = intbv(0)[32:] ctrlword.subpart = a(4, 2) # shadow signal, only for reading, note round brackets Then: with Python you can of course do what you want, very clever tricks. This is abvolutely fine for modeling. However, when you also want Verilog/VHDL convertibility, your options are very limited. E.g. something like the above wouldn't work because signals as attributes are not yet supported by the convertor. However, somethink like: subpart = a(4, 2) would be convertible, because the convertor explicitly supports dedicated conversion code for shadow signals. Finally: the copy methods. I agree that they are not as they should be as they are not compatible with subclassing now. However, there was a a reason to have dedicated copy methods instead of the generic ones: performance. The Signal class is using copy all the time, and it makes a difference. However, I have to think about it again, because now that I look at it it may be done much better for the intbv case. Jan Ben wrote: > Hi there, > > First of all, hello to everyone, and thanks for this great initiative > which is MyHDL, till now, I enjoyed using it. > > I ran into trouble though when I was looking for VHDL 'alias' ... I > was trying to make my code more readable when dealing with > ControlWords. > > The first solution I found is to make a always_comb process, but > still, we have to use a .next, so we don't have strictly the 'alias' > behavior. This solution is sort of driven by my "think hardware" mind, > or should I say, education. > > The second solution I found, and there, MyHDL shows its supremacy, is > to use Python as a tool, and not define my ControlWord as intbv, but > to define my own class, say ctrlword that inherit from intbv, redefine > "__getattr__", such that "ctrlword.subpart3" return the right slice > from my intbv. THis also has the advantage that I keep complete > compatibility (think conversion) with the intbv type. Clever isnt't it > ? The only problem I got is that the intbv __copy__ function was > forcing the return value as being an intbv, thus, removing all the > information from my ctrlword. > > As both __copy__ and __deepcopy__ are behaving the same as the Python > default one, I was able to remove them, without influencing the > testsuite result. (By the way on my MacOSX, I have some test failing > with regard to set and Set) > > Here is a patch that does what I described here. > > Best Regards > Benoit > > # HG changeset patch > # User Benoit Allard <ben...@gm...> > # Date 1257160071 -3600 > # Node ID bd6b60949b4e68023e41f49ce853c0058e02019b > # Parent 2ff17ece613127b174cb7a6a9aa8ba765ffcbd01 > Remove useless copy operators > > The default one are making the same, and even beter. > Those one were preventing us to subclass the intbv class, as the copy were > forcing the return type to intbv, removing information about our subclass. > > diff -r 2ff17ece6131 -r bd6b60949b4e myhdl/_intbv.py > --- a/myhdl/_intbv.py Tue Oct 06 07:02:37 2009 -0500 > +++ b/myhdl/_intbv.py Mon Nov 02 12:07:51 2009 +0100 > @@ -90,12 +90,6 @@ > def __hash__(self): > raise TypeError("intbv objects are unhashable") > > - # copy methods > - def __copy__(self): > - return intbv(self) > - def __deepcopy__(self, visit): > - return intbv(self) > - > # iterator method > def __iter__(self): > if not self._nrbits: > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > > > ------------------------------------------------------------------------ > > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a HDL: http://www.myhdl.org VHDL development, the modern way: http://www.sigasi.com Analog design automation: http://www.mephisto-da.com World-class digital design: http://www.easics.com |