google / google/xls

Assigning bit-slices to tuple with pattern matching ?

Open
#1,180 5 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

Sometimes, the [bit-splicing](https://google.github.io/xls/dslx_reference/#bit-slice-expressions) operations can get a bit hard to read, in particular when extracting multiple ranges.

What would be good is to have an option to write assigning to a tuple in a pattern-matching style. Since the right-hand side is of known width, we can assign bits to the left-hand side to a tuple that sums up to the exact same number of bits (and even determine one unknown bit-width).

In the IR, this would just be regular bit-slices.

```rust
let x = u32:42;
let (foo:u1, bar:u2, baz:u29) = x; // bit-splice with all widths defined
let (sign:u1, exp, mantissa:u23) = x; // bit-splice, auto-determine width of exp
let (sign, exp, mantissa:u23) = x; // ERROR: two fields without width
let (sign:u1, _, rounding:u1) = x; // can also be used for "don't care"
```

Possible relevant issue for discussion: bit-endianness needs to be intuitive ( Similar issue with with other bit-slice operations).
Most intuitive would be if it behaves opposite to `++`:

```rust
let (sign:u1, exp, mantissa:u23) = x;
let y = sign ++ exp ++ mantissa;
assert_eq(x, y);
```

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.