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

Allow negative indexing of arrays for negative offset #1491

Open
mikex-oss opened this issue Jun 18, 2024 · 1 comment
Open

Allow negative indexing of arrays for negative offset #1491

mikex-oss opened this issue Jun 18, 2024 · 1 comment
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request

Comments

@mikex-oss
Copy link
Collaborator

What's hard to do? (limit 100 words)

It can be overly verbose to specify the "nth element from the end" for an array. Also, because of the supported negative slice indices for bit slices, users may expect this to work for array indices as well.

Current best alternative workaround (limit 100 words)

Use the explicit length of the array and subtract n, i.e. N - n for the nth element from the end.

Your view of the "best case XLS enhancement" (limit 100 words)

As mentioned in the referenced docs, if we can specify "Python style" slices with offsets for bit slices, it would be useful to be able to do so for arrays.

Counter argument: Rust does not support this (yet?): rust-lang/rfcs#2249

@mikex-oss mikex-oss added the enhancement New feature or request label Jun 18, 2024
@cdleary
Copy link
Collaborator

cdleary commented Jun 25, 2024

I think this is probably documented in other issues but they'd probably be harder to find vs repeating here. :-)

The challenge is that you want static behavior and dynamic behavior to match. I expect that dynamically (at hardware runtime) testing the high bit and then using an adder to do a subtraction is probably going to be consider too hardware costly, and maybe surprising, for hardware engineers.

Bit slices support negative indexing only because they must be compile-time constants. They're compile time constant because the type of the result must be known (i.e. constexpr bitcount).

@meheff meheff added the dslx DSLX (domain specific language) implementation / front-end label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx DSLX (domain specific language) implementation / front-end enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

3 participants