xls icon indicating copy to clipboard operation
xls copied to clipboard

Support decrementing indices in DSLX for loop

Open vincent-mirian-google opened this issue 3 years ago • 0 comments
trafficstars

DSLX loops are constrained to incrementing indices. For loop traversal, the developer may need to reverse their array prior and after the loop statement.

Example:

Array = Reverse(Array)
Array = Incrementing For loop 
Array = Reverse(Array)

A reverse function for each array may be needed. Example of a reverse function:

const SIZE= uint32_t:8;

fn reverse_array(array: int64_t[SIZE]) ->
  int64_t[STREAM_LENGTH_SIZE] {
  for (i, new_array): (uint32_t, int64_t[SIZE])
      in range(uint32_t:0, SIZE/uint32_t:2) {
      let first: int64_t = array[i];
      let second: int64_t = array[SIZE- i - uint32_t:1];
      let array = update(array, SIZE- i - uint32_t:1, first);
      update(array, i, second)
  }(array)
}

There are two solutions. A reverse function in std lib or enable decrementing traversal.

Related to https://github.com/google/xls/issues/634, the DSLX loops must start from 0 and increment.

vincent-mirian-google avatar Jun 07 '22 20:06 vincent-mirian-google