Re: [myhdl-list] intbv return types and a fixed-point Object
Brought to you by:
jandecaluwe
From: Felton C. <chr...@gm...> - 2009-04-30 20:57:32
|
On Apr 19, 2009, at 3:08 AM, Jan Decaluwe wrote: > Christopher L. Felton wrote: >> Curiosity, what was the rational behind the mathematical operators >> for >> the intbv object returning the integer values and the logic operators >> (shifts, and, or, xor, etc) returning an intbv object? >> >> Example >> a = intbv(1) >> b = intbv(2) >> >> c = a + b >> type(c) >> <type 'int'> >> >> c = a ^ b >> type(c) >> <class 'myhdl._intbv.intbv'> > > If the return value is an intbv, you can slice and index it. > This probably makes sense for "bit-oriented" operations, > and perhaps less for "arithmetic" operations. > Therefore, for the latter case it might be a good idea > to avoid the overhead of intbv construction. > > This is all a little bit arbitrary and speculative - > for example, I haven't done tests to check how significant > the intbv construction overhead exactly is. > We always have the option to change the return type > to intbv if there's a real need. > > Jan > In my experience if you have a type (object) and some operations are performed the result is the same type. Also, I think it would simply matters some what for users (but could cause other issues) not having to use the [:]. There could be more negatives than positives to such a change. I imagine it might be difficult to change at this point because it could affect much of the user code. Also, don't know if it would have any implications on conversion, checking, etc. The reason I had come across this question was because I spend some time putting together a fixed-point object that used the intbv as the base class. Hence it would be convertible. I came across this scenario, for the mathematical operations leave the same implementation as intbv or return the type. I have uploaded a draft document I started for the fixed-point object. It is very (very, very, very) rough at this point http://www.myhdl.org/lib/exe/fetch.php/users:cfelton:projects:myhdlfixedpoint.pdf?id=users%3Acfelton%3Aprojects%3Afxintbv&cache=cache Thanks |