Re: [myhdl-list] fixed-point thoughts : part two
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2013-09-05 11:29:52
|
On 9/5/13 12:05 AM, Angel Ezquerra wrote: <snip> >> >> The proposed *resized* function will look like: >> >> resize(val,format >> [,round_mode='convergent'] >> [,overflow_mode='saturate']) >> >> Example: >> >> z[:] = resize(x+y,z) > > Probably a basic question, but why do you need [:] here? Doesn't > resize return a fixbv? > The *resize* function will return an /int/ the same as the /intbv/ operations and the /fixbv/ operations. The "[:]" is used because we really want to update the value of /z/ and not have /z/ reference a different object. This needs to be done: first, so it can be converted. For modeling only, we could be a little more flexible but then ... Second, the bound checking would not be possible. Typically, what you would see is: x = Signal(fixbv(0, min=-1, max=1, res=.125)) y = Signal(fixbv(.25, min=-1, max=1, res=.125)) z = Signal(fixbv(0, min=-1, max=1, res=.125)) @always_seq(clock.posedge, reset=reset) def logic(): z.next = resize(x+y,z) As an object the /fixbv/ would work like the /intbv/. > Also, I don't think there is a way for Python to pass the resize > function z's size while using the assignment syntax. If there was > resize() would not need the second parameter, which would be cool. > Maybe the converter could know though... An alternative could be to > add a "set" or "assign" method to the fixbv class. This method would > be equivalent to a resize followed by an assignment? The result would > be: > > z.assign(x+y) > > Which would get rid of the need to use [:] (if there is any) and to > use z both as a parameter to resize and as its output. > As mentioned, for /intbv/ and I would imagine with the /fixbv/ the bit assignment would not be used frequently, it commonly would be handled by Signal assignments. If you are using the /intbv/ and /fixbv/ for some modeling or nonlocal variable, and a property/attribute is more Pythonic than "[:]" we could propose a *val* public property that updates /_val/ attribute and calls the check bounds. z.val = resize(x+y) This would be consistent with the /Signal/. If this change was desired it would be made to the /intbv/ and the /fixbv/, for now "[:]" will be used in the /fixbv/. Regards, Chris |