google / google/xls

[DSLX] In struct parametrics parametric argument types other than `u32` should be allowed, including `s32`

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

Description

**Describe the bug**

This does not work:
```
pub struct FixedPoint {
data: uN[NUM_BITS],
}
#[test]
fn test_neg_exp() {
let a = FixedPoint { data: u8:0 };
}
```

because BINARY_EXPONENT is s32. It works if I change it to u32. I really do want a signed value, so this is not acceptable.

Error message, referring to BINARY_EXPONENT when I create `a`:
```
sN[32] vs uN[32]: Dimension s32:-1 must be a `u32` (soon to be `usize`, see https://github.com/google/xls/issues/450 for details).
```

Note that other parametric argument types which are useful to implementers are also disallowed, e.g. `bool` would have been useful to me to make a signed magnitude workaround:

```
pub struct FixedPoint
```

but the above is also not allowed.

**To Reproduce**

Use the code above, try to compile.

**Expected behavior**

That I can make BINARY_EXPONENT signed without issues.

This would be very handy for making an open source fixed point library.

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.