Skip to content

Add support for loop unrolling + unknown_iteration_count #286

@hanno-becker

Description

@hanno-becker

When using loop unrolling, we currrently assume that the number of iterations is a multiple of the unrolling factor.

SLOTHY should support the combination of unrolling and an unknown iteration count. The pattern to be produced should look like this:

if loop_cnt < UNROLL:
  jump TAIL

loop:
   BODY
   sub loop_cnt, loop_cnt, UNROLL
   cmp loop_cnt, UNROLL
   branch_if_greater_equal

TAIL:
   cmp loop_cnt #1
   jump TAIL_1
  
  cmp loop_cnt #2 
  jump TAIL_2

  ...

When SW pipelining is used, this also needs to take into account the number of exceptional iterations, e.g. for a loop with early but no late instructions:

cmp loop_cnt, UNROLL:
branch_if_smaller TAIL

... PREAMBLE FOR UNROLLED LOOP ...
sub loop_cnt, loop_cnt, UNROLL
cmp loop_cnt, UNROLL
branch_if_smaller POSTAMBLE

LOOP:
   BODY
   sub loop_cnt, loop_cnt, UNROLL
   cmp loop_cnt, UNROLL
   branch_if_greater_equal LOOP

POSTAMBLE:
 ... POSTAMBLE FOR UNROLLED LOOP...

TAIL:
   cmp loop_cnt #1
   jump TAIL_1
  
  cmp loop_cnt #2 
  jump TAIL_2

  ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions