[enhancement] support for array casts
- 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)
Currently one can't cast one DSLX array to another one of compatible size (same element_size*element_depth).
```
0243: fn array_reshape_test() {
0244: assert_eq(
0245: u32[8]:[0, 1, 2, 3, 4, 5, 6, 8] as u64[4],
~~~~~~~~~~~~~~~~~~~~~^--------------------------------^ TypeInferenceError: uN[64][4] Cannot cast from type `uN[32][8]` to type `uN[64][4]`
```
Related #725
### Current best alternative workaround (limit 100 words)
Have a reshape util function that first convert to bits and then to the target array:
```
fn array_reshape
(arr: bits[IN_WIDTH][IN_DEPTH]) -> bits[OUT_WIDTH][OUT_DEPTH] {
const_assert!(OUT_WIDTH * OUT_DEPTH == IN_WIDTH * IN_DEPTH);
let in_bits = for (i, in_bits) in u32:0..IN_DEPTH {
bit_slice_update(in_bits, i * IN_WIDTH, arr[i])
}(zero!());
let out_arr = for (i, out_arr) in u32:0..OUT_DEPTH {
update(out_arr, i, in_bits[(i * OUT_WIDTH)+:bits[OUT_WIDTH]])
}(zero!());
out_arr
}
```
### Your view of the "best case XLS enhancement" (limit 100 words)
We could potentially make this easier by adding `ToBits` trait support for array (see #3383), but I think that instead it would be preferrable to support casting operation when element_size*element_depth doesn't change.
Contributor guide
Assessment
This issue has not been assessed yet.