cornell-zhang/heterocl

[API] Remove confusing reversed slicing and add new `.reverse()` API

chhzh123 opened this issue · 0 comments

The bit slicing API was introduced in #291 , but it is confusing when it allows reversed slicing, since the ranges in Python are all left-closed right-open, while the reversed slicing breaks this rule. To avoid confusion, I think we should prevent using reversed slicing and force the begin of the slice smaller than the end of the slice. This is also consistent with other hardware-oriented Python DSLs like PyMTL3 (See Page 8 of the documentation).

For reversing the sliced bits, we need to introduce a new API .reverse(). The grammar and behavior is like the one described in the VHLS documentation. Therefore, we have the following example:

>>> a = 0xabcd0123
>>> a[28:32] # containing the bit of 28, 29, 30, 31
0xa
>>> a[4:24]
0xcd012
>>> a[28:32].reverse()
0x5

And we no longer support grammar like a[32:28] which leads to confusion.