google / xls

XLS: Accelerated HW Synthesis
http://google.github.io/xls/
Apache License 2.0
1.21k stars 179 forks source link

Provide a replication operator for arrays/bits #1693

Open mikex-oss opened 2 weeks ago

mikex-oss commented 2 weeks ago

What's hard to do? (limit 100 words)

Create arrays and bit vectors with replicated patterns. SystemVerilog provides the replication operator which works on both, so you can do stuff like:

int n[1:2][1:6] = '{2{'{3{4, 5}}}};

which is equivalent to:

'{'{4,5,4,5,4,5},'{4,5,4,5,4,5}}

Similarly, you can do:

{4{4'b1010, 4'b1001}}

which is equivalent to

32'b10101001101010011010100110101001

Current best alternative workaround (limit 100 words)

You could write for loops to do update and bit_slice_update. Or just copy-paste manually.

Your view of the "best case XLS enhancement" (limit 100 words)

Support this in DSLX.

cdleary commented 2 weeks ago

On the "workaround" -- we can add a stdlib function to do this before adding a builtin, right?

mikex-oss commented 2 weeks ago

I think that makes sense, with the main downside being verbosity...particularly without type generics, you'd have, for example, std::array_repl and std::bits_repl.