xls icon indicating copy to clipboard operation
xls copied to clipboard

Allow negative indexing of arrays for negative offset

Open mikex-oss opened this issue 1 year ago • 1 comments

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

It can be overly verbose to specify the "nth element from the end" for an array. Also, because of the supported negative slice indices for bit slices, users may expect this to work for array indices as well.

Current best alternative workaround (limit 100 words)

Use the explicit length of the array and subtract n, i.e. N - n for the nth element from the end.

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

As mentioned in the referenced docs, if we can specify "Python style" slices with offsets for bit slices, it would be useful to be able to do so for arrays.

Counter argument: Rust does not support this (yet?): https://github.com/rust-lang/rfcs/issues/2249

mikex-oss avatar Jun 18 '24 19:06 mikex-oss

I think this is probably documented in other issues but they'd probably be harder to find vs repeating here. :-)

The challenge is that you want static behavior and dynamic behavior to match. I expect that dynamically (at hardware runtime) testing the high bit and then using an adder to do a subtraction is probably going to be consider too hardware costly, and maybe surprising, for hardware engineers.

Bit slices support negative indexing only because they must be compile-time constants. They're compile time constant because the type of the result must be known (i.e. constexpr bitcount).

cdleary avatar Jun 25 '24 03:06 cdleary