Re: [myhdl-list] intbv wrap
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2011-05-12 15:33:19
|
On 5/11/2011 9:54 AM, Jan Decaluwe wrote: > On 05/11/2011 04:01 PM, Christopher Felton wrote: >> >> On 5/11/2011 7:31 AM, Ben wrote: >>> Hi Chris, >>> >>> I am following your struggle with this feature with great interest, as >>> I do think this would be an interesting addition to MyHDL, however, as >>> an hypothetical future extension to MyHDL, I think this would deserve >>> a MEP ... For now, If I want to understand your design decisions, I >>> have to dig into my mails and look for the relevant part. I for one >>> have for instance a question about the restrictions you enforce. See >>> below. >> Here is the original MEP I wrote. It is not complete and has not been >> updated based on the conversations had here. Also, this MEP simply >> exists in my user space right now. >> >> http://www.myhdl.org/doku.php/user:cfelton:projects:wrap >> >> I will try and update the MEP based on the latest developments when time >> permits. More comment below. >>> >>> On Tue, May 10, 2011 at 13:27, Christopher Felton >>> <chr...@gm...> wrote: >>>> I made a couple of minor adjustments to this patch. >>>> >>>> 1. Made the wrap function private (_wrap) and moved _wrap to __wrap. The >>>> wrap function should not be used directly because it will not covert >>>> correctly. I think for a future (todo) enhancement the wrap function can be >>>> made public and handled by the converter. This is an involved modification. >>>> For now I think it is good to advertise the wrap function was private. >>> >>> I don't really understand the reason of such an enforcement on min and >>> max for the wrapping. Let's be for a moment the devil's advocate and >>> say I want my intbv to be between -3 and 12. Why would MyHDL prevent >>> me to have it wrapped ? >> >> The reason is, we want to model natural behavior of a n-bit word. An >> n-bit word automatically wraps, by truncating the most-significant bits, >> when assigned. We want to prevent the automatic wrap in the example >> because additional logic is required. This is the same for the >> saturate. This enhancement is simply trying to add the natural >> occurring wrap of a n-bit binary word. To model this behavior correctly >> the min and max need to be the full range of the binary word. > > What is "natural" depends entirely on your perspective. If your > perspective is representation, I agree. But if your perspective is > modeling in terms of modulo arithmetic, the restrictions would be > incomprehensible. So, "natural" was a wrong choice of words, inherent should have been used. > > I really think MyHDL should make a difference with Verilog/VHDL here. > We should concentrate on modeling first, and only then on > conversion/synthesizability. As the intbv example shows, sometimes > there isn't even a price to pay! Moreover, we can always impose > additional restrictions for convertiblity, but we may also find > ways to implement more powerful solutions than with Verilog/VHDL. In general I think this is a good approach, adding more modeling features. But I think MyHDL already provides kick-ass "framework" for building all kinds of modeling. If someone wanted an _interesting_ behavior, a derived class with the intbv as the base class, can easily be created. And the user knows this will *not* be convertible (some cases it will be convertible). I am not sure about adding non-convertible features to the intbv class. I think it could be confusing. I would rather see an approach where a derived class with the new modeling is added; to simplify use for developers. And when or if, it has a clear path for conversion then it can be added to the intbv class. I think this would limit confusion and disappointment when trying to convert a design. Also, it adds a little agility by adding classes for just for modeling. These classes can be documented in the manual, etc. In my mind, the current wrap implementation would be added to the intbv to capture the inherent behavior of an n-bit word. And the arbitrary wrapping could be added to an enhanced modeling class. Chris |