google / google/xls

Allow negative indexing of arrays for negative offset

Open
#1,491 1 comment 0 reactions 0 assignees View on GitHub
dslx enhancement
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

### 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](https://google.github.io/xls/dslx_reference/#public-module-members:~:text=The%20slicing%20operation%20also%20support%20the%20python%20style%20slices%20with%20offsets%20from%20start%20or%20end.%20To%20visualize%2C%20one%20can%20think%20of%20x%5B%20%3A%20%2D1%5D%20as%20the%20equivalent%20of%20x%5Bfrom%20the%20start%20%3A%20bitwidth%20%2D%201%5D.%20Correspondingly%2C%20x%5B%2D1%20%3A%20%5D%20can%20be%20visualized%20as%20%5B%20bitwidth%20%2D%201%20%3A%20to%20the%20end%5D.), 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?): https://github.com/rust-lang/rfcs/issues/2249

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.