Re: [myhdl-list] [PATCH 0 of 2 RFC] Add support for negative indexes
Brought to you by:
jandecaluwe
From: Jan D. <ja...@ja...> - 2013-09-09 08:43:37
|
On 10/13/2012 02:12 AM, Angel Ezquerra wrote: > Python lists have a natural way to access list itemps from the end of > the list, which is to use negative indexes. These patches add this > functionality to MyHDL. > > The first patch adds negative index and slice limit support to the > intbv class. I think this first patch is probably right and not very > controversial intbv's are dual in nature - bit sequence but also integer interpretation. indexing is at the intersection of the two. An index corresponds to a bit position, but also to the power of the bit when expanding the integer in a sum of powers of 2. To match the natural way of writing numbers, intbv slicing is already totally different from any standard python sequence: the direction is reversed. Personally, I haven't seen much need to enhance intbv bit indexing to match what you can do with sequences like lists. However, there is a very good reason to stress the power of two interpretation: when we add a fixbv type, it would be natural to use the same interpretation. Negative indices would represent fractional bits. It also seems natural that the intbv would like a subtype of a general fixbv type. Therefore, I propose to keep intbv indexing like it is. -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a HDL: http://www.myhdl.org VHDL development, the modern way: http://www.sigasi.com World-class digital design: http://www.easics.com |