Re: [myhdl-list] fxintbv dependency on dspsim
Brought to you by:
jandecaluwe
From: Christopher L. F. <chr...@gm...> - 2009-12-10 02:57:41
|
Jan, some additional information below, Jan Langer wrote: > Hello Christopher, > > Am 09.12.2009 um 06:02 schrieb Christopher L. Felton: >> I will try and reply later with more detail. You want to use the >> *fxintbv* object and not the fxint. Page 8 of the pdf , >> http://www.myhdl.org/lib/exe/fetch.php/users:cfelton:projects:myhdlfixedpoint.pdf >> is an example of convertible fixed-point for add. Should be exactly >> the same for subtract (given no bugs). > > Somehow, I dont really understand it. The return type of the fxintbv > operators is just plain intbv, so I cannot write a - b*c for three > fxintbv variables. If fxintbv does not take care of the point in > operations and I need to remember and adjust it by hand, I dont see > the advantages of fxintbv. fxint seems to do what I need, except the > two questions I wrote yesterday. I am a little confused but maybe I > just want the wrong things :-) Correct, with the fxintbv a little more work needs to be done. But not as much as doing it all manually. Keeping within the design goals of MyHDL nothing will try to evaluate the expression x= a-b*c and adjust the result. But given the design of MyHDL and the elaborate phase there are some options. The fxintbv doesn't do the auto promotion (adjusting the number of bits for the word) but there are helper functions to determine the size of the word based on the operations. These helper functions/methods help during design and analysis but also can make the modules modular. If an input size is adjusted the module will automatically adjust. The example in the PDF (ooppps, just notice didn't include everything in the PDF, my bad) or the example in examples/sos/sos_hdl.py there is a function that gets the types needed. The function uses the fxintbv methods to determine this. This essentially auto-promotes. def getFxTypes(Q,N): # Different fixed-point types (sizes) used fx_t = fxintbv(0, min=-1, max=1, res=2**-Q) fxmul_t = fx_t.ProductRep(fx_t) fxsum_t = fxmul_t.SummationRep(N) return fx_t, fxmul_t, fxsum_t Right now there are a bunch of public functions to assist in auto-promotion and alignment. The ProductRep, AdditionRep, SummationRep will determine the correct "type" given the inputs. For the specific example x = a-b*c something like the following could be done def fxCalc(clk, x, a, b, c): i_t = fxintbv.ProductRep(b,c) x_t = fxintbv.AdditionRep(a, i_t) x.NewRep(x_t.iwl, x_t.fwl) @always(clk.posedge) def rtl_result(): x.next = a-b*c return instances() In this scenario all the promotion and alignment etc will be handled. "x" will be adjusted in the elaboration phase based on the a,b,c inputs. It assumes that x, a, b, c are all of type fxintbv. The benefit of doing this is you will get the auto promotion of "x" when the inputs change and you get some additional functions for fixed point analysis. I think this is a good balance between design flexibility and automation. The fxint does a lot more under the hood (auto promotion, bit alignment) but it is not convertible. I don't think it makes sense for something like fxint to be convertible. You want a little more control when mapping to hardware. I think the fxintbv has the balance between right amount of abstraction and design guidance. Hope that helps .chris In the fixed_point/fxlib/_hdl.py there are some examples. These are intended to be > > > > Jan Langer wrote: >> Hello Christopher, >> I finally switched my design to fxint and in general it works fine. >> However, I have two questions. >> >> Why is for example the result of subtracting two fxint Signals an int? >> To solve this issue I wrote a helper function: >> >> def sigtofx(x): >> return fxint(x.fValue,Q=(x.iwl,x.fwl)) >> >> to convert the signal to an fxint, which has the correct subtraction. >> This is of course not synthesizeable. :-( >> >> The other thing is assignment of fxint signals, which requires >> alignment of the points. I see that this is necessary, but it will >> require tricky slicing operations. I solve it in another helper >> function for now, but is is also not convertible: >> >> def fxassign(dst,src): >> dst.next = fxint(src.fValue,Q=(dst.iwl,dst.fwl)) >> >> For example, converting Q=(5,6) to Q=(5,3) is >> >> Is there a preferred "myhdl"-solution for my problems? >> >> I found two things which might be bugs and I enclose the >> corresponding patch file. >> >> >> >> Thanks for implementing the library, >> Jan >> >> Am 03.12.2009 um 17:09 schrieb Felton Christopher: >>> Attached is my latest dspsys (dspsim) and fixed_point. As I >>> mentioned dspsys is not mature, use at your own risk. >>> >>> On Dec 2, 2009, at 4:37 AM, Jan Langer wrote: >>>> I encountered a problem using the fixed_point library on the myhdl >>>> website. It tries to find a module called dspsim (fixed_point/fxlib/ >>>> _blocks.py, line 23), which is not found on my system. A google search >>>> didn't turn up anything useful. What is it and where can I get it? >> > |