[myhdl-list] Re: range object
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2005-03-03 09:56:39
|
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!). > 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 |