google / google/xls

constexpr primitive for array sizes

Open
#431 0 comments 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

Currently when writing a for loop over an array or arrays of known size, you need to redundantly specify the size in the range bounds like this:

```
fn eq_by_element(x: TestBlob[3], y: TestBlob[3]) -> bool {
for (i, eq):(u32, bool) in range (u32:0, u32:3) {
eq && x[i] == y[i] && blob_eq(y[i], x[i])
}(true)
}
```

If the array sizes might change, this is tedious to keep track of and potentially wasteful when the range is too large (since out-of-bounds indexing is defined to be the last element in DSLX).

One way to avoid the repetition would be to make the function parametric, but that can be overkill. Instead if we had a primitive that evaluated to a compile-time constant for the array size we could write the range in terms of that, avoiding the repetition.

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.