[myhdl-list] fixed-point thoughts : part three
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2013-10-11 03:36:38
|
First, I have the start of a reference implementation available here: https://bitbucket.org/cfelton/myhdl_09dev/src/tip/myhdl/_fixbv.py?at=0.9-dev This reference implementation covers most of the discussions from part 1 and 2 excluding the /resize/ function. The /resize/ function implementation is the topic to be discussed in the rest of this post. resize function ---------------- In part two the conversation focused around fixed-point operations and the need for a /resize/ function. I proposed the /resize/ function as: resize(val, format, [,round_mode='convergent'] [,overflow_mode='saturate'] A use case might look like :: x = Signal(fixbv(0,min=-8,max=8,res=1/16.)) y = Signal(fixbv(0,min=-1,max=1,res=2**-15)) z = Signal(fixbv(0)[x.W+y.W]) @always_seq(clock.posedge, reset=reset) def rtl(): z.next = resize(resize(x, x.W+y.W) + y, z) and/or: @always_seq(clock.posedge,reset=reset) def rtl(): tmp = a*b c.next = resize(tmp, c, round_mode="round") Above I used an attribute not yet discussed, the /W/ attribute. I call this the W-format. It is an object that represents the format of the fixed-point type. The formats can be added, subtracted, multiplied, etc to handle the elaboration (programatic) handling of types. There are two attributes for the format W - FixedPointFormat ojbect format - (wl,iwl,fwl) tuple (just a short-cut for W.format) Before getting to the /resize/ function details, lets review function conversion. MyHDL supports converting functions calls within a convertible generator if the function is part of an assignment and is found on the right-hand side. The function will be convert to a similar Verilog/VHDL function. Just like Verilog and VHDL the function represents combinatorial logic (stateless). An example of a function conversion is: def simple_add(a,b,): c = a + b return c def top(clock,reset,a,b,c): @always_seq(clock.posedge, reset=reset) def rtl(): c.next = simple_add(a,b) return rtl the conversion can be viewed here: https://gist.github.com/cfelton/6788096 I believe, the function conversion is limited to a single level - that is there cannot be a function call in the function. Ok, at this point I have created a dilemma for myself. I have proposed a function type that isn't supported for conversion. The proposed /resize/ function would require considerable elaboration to programatically handle the alignment, different rounding modes, and overflow. I haven't thought of another way to achieve the same goals. At this point we could explore function conversion that supports similar elaboration as a myhdl module (a python function that has myhdl generators)? def resize(val, format, round_mode='floor', overflow_mode='saturate'): # ... if round_mode == 'floor': rfunc = _resize_floor(...) # ... return rfunc() Is this the wrong approach? Or does an "enhanced" function conversion need to be considered? Regards, Chris Felton |