Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Support unroll factors #3

Open
schneiderfelipe opened this issue Jul 6, 2021 · 1 comment
Open

Support unroll factors #3

schneiderfelipe opened this issue Jul 6, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@schneiderfelipe
Copy link
Owner

This can be done without information on loop length.

proc searchChar(s: string, c: char): int =
  unroll(4): for i in 0 .. s.high:
    if s[i] == c: return i
  result = -1

should produce something like

proc searchChar(s: string, c: char): int =
  for i in countup(0, s.high, 4):  # unroll factor goes here
    if s[i] == c: return i
    if s[i+1] == c: return i+1
    if s[i+2] == c: return i+2
    if s[i+3] == c: return i+3

  let n = ((s.high - 0) div 4) * 4 + 0  # we can do better here
  for i in n..s.high:  # eventually left out elements
    if s[i] == c: return i
  result = -1

We can even employ a default value for when the loop length is not known in advance.

@schneiderfelipe schneiderfelipe added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jul 6, 2021
@schneiderfelipe schneiderfelipe added this to the 0.2 milestone Jul 6, 2021
@schneiderfelipe
Copy link
Owner Author

Interesting reference (with a more useful example).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant