Re: [myhdl-list] Re: range object
Brought to you by:
jandecaluwe
From: Haitao Z. <ha...@gm...> - 2005-03-03 18:56:57
|
On Thu, 03 Mar 2005 11:49:08 +0100, Jan Decaluwe <ja...@ja...> wrote: > Haitao Zhang wrote: > > Another nice to have :) > > > > In VHDL one could define a range type and define a constant with it, > > so that one can associate a symbolic name say CTRL_FIELD with 7 > > DOWNTO 3, and then one can refer to register(CTRL_FIELD). In Verilog > > one can probably get by with macro defines. However in Python the > > native slicing is limited to integer arguments (?), so one has to > > define two named constants instead of passing an indexing object. > > This is not correct. Consider: > > >>> from myhdl import intbv > >>> a = intbv(0xffff) > >>> CTRL_FIELD = slice(4, 2) > >>> type(CTRL_FIELD) > <type 'slice'> > >>> a[CTRL_FIELD] > intbv(3L) > >>> a[CTRL_FIELD] = 0 > >>> hex(a) > '0xFFF3L' > > The slice object is not often used explicitly in Python code but > probably deserves more attention. (Warning: toVerilog doesn't > support his - as always, patches are welcome!). > Thanks for the tip! This is exactly what I want for now. (Matlab behaviour is probably an over kill unless one has no-contigous field, which for hardware designer only happens under special circumstances). I will see what I can do about toVerilog when I get that far. Haitao > > This feature is handy when one needs to define control register > > fields. It allows one to define the named constants in one place. > > > > In Matlab one can index any vector with another vector. I don't see > > why this shouldn't be doable in Python as well. Maybe just no need for > > it, until the hardware designers come along? Is the simplest way to > > overload __getslice__ to accept a tuple (defining range)? > > (__getslice__ is deprecated, use __getitem__ instead. Look in > the 0.4.1 code for intbv to see how slicing is implemented.) > More than you probably need has been done by lots of people doing > lots of work. Check out the Numeric Python extension for a Python > with MatLab-like functionality. Also check SciPy. (Warning: > there is a LOT of material to study.) > > Regards, Jan > > -- > Jan Decaluwe - Resources bvba - http://jandecaluwe.com > Losbergenlaan 16, B-3010 Leuven, Belgium > Using Python as a hardware description language: > http://jandecaluwe.com/Tools/MyHDL/Overview.html > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list > |