SPeCS Packages Documentation
    Preparing search index...
    • Unrolls a range do-loop by the given factor.

      Two loops replace the original:

      • A main loop that steps by factor, with the body replicated factor times (each copy substitutes var with var+offset for offset 0..factor-1).
      • A cleanup loop that handles the remaining < factor iterations with the original body. When factor exactly divides the trip count, the cleanup loop's bounds produce a no-op and it generates no iterations.

      If the loop is not a range loop, has an explicit non-unit step, or factor is ≤ 1, the loop is left unchanged and returned as a single-element array.

      Parameters

      • $loop: DoStatement

        The do-loop to unroll.

      • factor: number

        The unroll factor (must be ≥ 2).

      Returns DoStatement[]

      The replacement loops inserted into the AST, in source order.

      // Before (factor = 4):
      // do i = 1, n
      // a(i) = b(i)
      // end do

      // After:
      // do i = 1, (n) - 3, 4
      // a(i) = b(i); a(i+1) = b(i+1); a(i+2) = b(i+2); a(i+3) = b(i+3)
      // end do
      // do i = (1) + (((n) - (1) + 1) / 4) * 4, n
      // a(i) = b(i)
      // end do