Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chhzh123 opened this issue Mar 15, 2022 · 0 comments
Open

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

chhzh123 opened this issue Mar 15, 2022 · 0 comments

Comments

@chhzh123
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant